-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const dotenv = require('dotenv') | ||
const env = process.env.ENV || 'DEV' | ||
dotenv.config({ path: '.env.' + env }) | ||
|
||
// FIXME: reorder categories into a more structured order? | ||
// eg: wcif, events, groups, persons, cluster, ...? | ||
const categories = [ | ||
'array', | ||
'boolean', | ||
'cluster', | ||
// FIXME: not that All useful. | ||
//'display', | ||
'events', | ||
'groups', | ||
'help', | ||
'math', | ||
'persons', | ||
'sheets', | ||
'staff', | ||
'table', | ||
'time', | ||
'tuple', | ||
'udf', | ||
'util', | ||
'wcif', | ||
] | ||
|
||
const functionToAnchorName = (name, genericParams) => { | ||
if (typeof this.generated === 'undefined') { | ||
this.generated = [] | ||
} | ||
const baseName = `${name.toLowerCase()}${genericParams ? genericParams.map(t => t.toLowerCase()).join('-') : ''}` | ||
let suffix = 1 | ||
let generatedName = baseName | ||
while (this.generated.includes(generatedName)) { | ||
generatedName = `${baseName}-${suffix++}` | ||
} | ||
this.generated.push(generatedName) | ||
return generatedName | ||
} | ||
|
||
const functionName = (name, genericParams) => `${name}${genericParams ? `\\<${genericParams.join(', ')}>` : ''}` | ||
|
||
const stringForArg = ({ name, type, defaultValue, nullable, canBeExternal, repeated, lazy, docs }) => { | ||
const properties = [] | ||
// FIXME: document what lazy/repeated means. | ||
if (nullable) { | ||
properties.push('(can be null)') | ||
} | ||
if (canBeExternal) { | ||
properties.push('(can be external)') | ||
} | ||
if (repeated) { | ||
properties.push('(repeated)') | ||
} | ||
if (lazy) { | ||
properties.push('(lazy)') | ||
} | ||
const propertiesString = properties.length > 0 ? ` *${properties.join('')}*` : '' | ||
const helpForArg = docs ? ` | ||
${docs}` : '' | ||
|
||
return ` - *${type.replace('<', '\\<')}* **${name}**${defaultValue !== undefined ? `=${defaultValue}`:''}${propertiesString}${helpForArg}` | ||
} | ||
|
||
const stringForFunction = ({ name, genericParams, docs, outputType, args, mutations}) => ` | ||
### ${functionName(name, genericParams)} | ||
${docs || 'TODO'} | ||
- Args:${args.length === 0 ? ' none' : `\n${args.map(stringForArg).join('\n')}`} | ||
- Returns: **${outputType.replace('<', '\\<')}** | ||
- WCIF changes: **${mutations && mutations.length > 0 ? `${mutations.join(', ')}` : 'none'}**` | ||
|
||
const documentation = categories.map(c => { | ||
const functions = require(`./functions/${c}.js`).functions | ||
return `## ${c} | ||
${functions.map(stringForFunction).join('\n')} | ||
` | ||
}).join('\n') | ||
|
||
const tocFunction = ({ name, genericParams }) => ` - [${functionName(name, genericParams)}](#${functionToAnchorName(name, genericParams)})` | ||
const toc = categories.map(c => { | ||
const functions = require(`./functions/${c}.js`).functions | ||
return ` - [${c}](#${c}) | ||
${functions.map(tocFunction).join('\n')}` | ||
}).join('\n') | ||
|
||
const { exec } = require('node:child_process') | ||
|
||
exec('git log -1 --oneline | cut -d " " -f 1 | tr -d "\n"', (_, stdout ) => { | ||
|
||
console.log(`# CompScript API reference | ||
*This documentation was automatically generated on commit [${stdout}](https://github.com/cubingusa/compscript/commit/${stdout}) with \`npm run gen-docs-api\`, don't edit this file directly.* | ||
## Index | ||
${toc} | ||
${documentation}`) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters