API docs integrate into user docs

This commit is contained in:
zadam 2023-01-10 22:48:56 +01:00
parent 4385a02f6b
commit 05c04a35a7

View file

@ -58,7 +58,11 @@ const getFilesRecursively = (directory) => {
} }
}; };
getFilesRecursively('./tmp/api_docs'); const TMP_API_DOCS = './tmp/api_docs';
const TMP_FE_DOCS = TMP_API_DOCS + '/frontend_api';
const TMP_BE_DOCS = TMP_API_DOCS + '/backend_api';
getFilesRecursively(TMP_API_DOCS);
for (const sourcePath of sourceFiles) { for (const sourcePath of sourceFiles) {
const content = fs.readFileSync(sourcePath).toString(); const content = fs.readFileSync(sourcePath).toString();
@ -79,63 +83,144 @@ for (const sourcePath of sourceFiles) {
const META_PATH = './docs/user_guide/!!!meta.json'; const META_PATH = './docs/user_guide/!!!meta.json';
const meta = JSON.parse(fs.readFileSync(META_PATH).toString()); const meta = JSON.parse(fs.readFileSync(META_PATH).toString());
meta.files[0].children = meta.files[0].children.filter(note => note.title !== 'API docs'); function findNoteMeta(noteMeta, name, notePath) {
meta.files[0].children.push(getApiMeta()); if (noteMeta.title === name) {
return {
noteMeta,
filePath: '/' + noteMeta.dataFileName,
notePath
};
}
for (const childMeta of noteMeta.children || []) {
const ret = findNoteMeta(childMeta, name, [...notePath, childMeta.noteId]);
if (ret) {
return {
noteMeta: ret.noteMeta,
filePath: '/' + noteMeta.dirFileName + ret.path,
notePath: ret.notePath
};
}
}
return null;
}
const {noteMeta: scriptApiDocsRoot, filePath: scriptApiDocsRootFilePath, notePath: scriptApiDocsRootNotePath} =
findNoteMeta(meta.files[0], 'Script API', ['_scriptApi']);
const BE_FILES = ['AbstractBeccaEntity', 'BAttribute', 'BBranch', 'BEtapiToken', 'BNote', 'BNoteRevision', 'BOption', 'BRecentNote', 'module-sql'];
const FE_FILES = ['FNote', 'FAttribute', 'FBranch', 'FNoteComplement'];
scriptApiDocsRoot.children = getScriptApiMeta();
fs.writeFileSync(META_PATH, JSON.stringify(meta, null, 2)); fs.writeFileSync(META_PATH, JSON.stringify(meta, null, 2));
function getApiMeta() { const scriptApiDocsRootDir = './docs/user_guide' + scriptApiDocsRootFilePath.substr(0, scriptApiDocsRootFilePath.length - 5);
return {
"isClone": false, fs.mkdirSync(scriptApiDocsRootDir, {recursive: true});
"noteId": "_apiDocs", fs.mkdirSync(scriptApiDocsRootDir + '/BackendScriptApi', {recursive: true});
"notePath": [ fs.mkdirSync(scriptApiDocsRootDir + '/FrontendScriptApi', {recursive: true});
"_userGuide",
"_apiDocs" const BE_ROOT = scriptApiDocsRootDir + '/BackendScriptApi.html';
], const FE_ROOT = scriptApiDocsRootDir + '/FrontendScriptApi.html';
"title": "API docs",
"notePosition": 10, fs.copyFileSync(TMP_BE_DOCS + '/BackendScriptApi.html', BE_ROOT);
"prefix": null, fs.copyFileSync(TMP_FE_DOCS + '/FrontendScriptApi.html', FE_ROOT);
"isExpanded": false,
"type": "text", function rewriteLinks(rootFilePath, files, dir) {
"mime": "text/html", let content = fs.readFileSync(rootFilePath).toString();
"attributes": [],
"format": "html", for (const file of files) {
"dataFileName": "API docs.html", content = content.replaceAll(`href="${file}.html"`, `href="${dir}/${file}.html"`);
"children": [ }
{
"isClone": false, fs.writeFileSync(rootFilePath, content);
"noteId": "_frontendApi", }
"notePath": [
"_userGuide", for (const file of BE_FILES) {
"_frontendApi" fs.copyFileSync(TMP_BE_DOCS + '/' + file + '.html', scriptApiDocsRootDir + '/BackendScriptApi/' + file + '.html');
], }
"title": "API docs", rewriteLinks(BE_ROOT, BE_FILES, 'BackendScriptApi');
"notePosition": 10,
"prefix": null, for (const file of FE_FILES) {
"isExpanded": false, fs.copyFileSync(TMP_FE_DOCS + '/' + file + '.html', scriptApiDocsRootDir + '/FrontendScriptApi/' + file + '.html');
"type": "text", }
"mime": "text/html", rewriteLinks(FE_ROOT, FE_FILES, 'FrontendScriptApi');
"attributes": [],
"format": "html", function createChildren(files, notePath) {
"dataFileName": "FrontendScriptApi.html" let positionCounter = 0;
},
{ const camelCase = name => name.charAt(0).toLowerCase() + name.substr(1);
"isClone": false,
"noteId": "_backendApi", return files.map(file => {
"notePath": [ positionCounter += 10;
"_userGuide",
"_backendApi" return {
], "isClone": false,
"title": "API docs", "noteId": "_file",
"notePosition": 20, "notePath": [
"prefix": null, ...notePath,
"isExpanded": false, '_' + camelCase(file)
"type": "text", ],
"mime": "text/html", "title": file,
"attributes": [], "notePosition": positionCounter,
"format": "html", "prefix": null,
"dataFileName": "BackendScriptApi.html" "isExpanded": false,
} "type": "text",
] "mime": "text/html",
}; "attributes": [],
} "format": "html",
"dataFileName": file + ".html"
}
});
}
function getScriptApiMeta() {
return [
{
"isClone": false,
"noteId": "_frontendApi",
"notePath": [
...scriptApiDocsRootNotePath,
"_frontendApi"
],
"title": "API docs",
"notePosition": 10,
"prefix": null,
"isExpanded": false,
"type": "text",
"mime": "text/html",
"attributes": [],
"format": "html",
"dataFileName": "FrontendScriptApi.html",
"children": createChildren(FE_FILES, [
...scriptApiDocsRootNotePath,
"_frontendApi"
])
},
{
"isClone": false,
"noteId": "_backendApi",
"notePath": [
...scriptApiDocsRootNotePath,
"_backendApi"
],
"title": "API docs",
"notePosition": 20,
"prefix": null,
"isExpanded": false,
"type": "text",
"mime": "text/html",
"attributes": [],
"format": "html",
"dataFileName": "BackendScriptApi.html",
"children": createChildren(BE_FILES, [
...scriptApiDocsRootNotePath,
"_backendApi"
])
}
];
}