Files
directus/docs/build.js
Ben Haynes 1b87e4555f Docs structure (#9071)
* WIP

* updates

* docs updates

* structure

* big structure update

* docs module icon change

* in-app docs nav

* more content and structure changes

* Remove redundant

* Fix docs build in app

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
2021-10-25 21:19:23 -04:00

47 lines
1.3 KiB
JavaScript

const path = require('path');
const fse = require('fs-extra');
const dirTree = require('directory-tree');
// eslint-disable-next-line no-console
console.log('Building docs...');
const tree = dirTree('.', {
extensions: /\.md$/,
exclude: /(node_modules|.vuepress|.vscode|dist|README.md)/,
normalizePath: true,
attributes: ['type', 'extension'],
});
const index = `export default ${generateIndex(tree.children)};`;
fse.ensureDirSync('dist');
fse.writeFileSync('dist/index.js', index);
// eslint-disable-next-line no-console
console.log('Built docs');
function generateIndex(tree) {
const children = tree
.map((child) => {
if (child.type === 'file') {
const baseName = path.posix.basename(child.name, child.extension);
const basePath = path.posix.join(
path.posix.dirname(child.path),
path.posix.basename(child.path, child.extension)
);
return `{name:'${baseName}',path:'${basePath}',import:()=>import('../${child.path}')}`;
} else if (child.type === 'directory') {
const children = generateIndex(child.children);
if (children === '[]') return null;
return `{name:'${child.name}',path:'${child.path}',children:${children}}`;
} else {
return null;
}
})
.filter((child) => child !== null);
return `[${children.join(',')}]`;
}