Skip to content

Commit

Permalink
add docs index
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Mar 22, 2024
1 parent 2c3392b commit 19e6b91
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"test-merge": "node ./test/test-merge.js",
"test-merge-istanbul": "node ./test/test-merge-istanbul.js",
"test-client": "node ./test/test-client.js",
"test-all": "npm run test-node && npm run test-browser && npm run test-cli && npm run test-tsx && npm run test-merge",
"test-all": "npm run test-node && npm run test-browser && npm run test-cli && npm run test-tsx && npm run test-merge && node ./scripts/docs.js",
"test": "npx mcr npm run test-all -c test/mcr.config.mcr.js",
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
"dev": "sf d v8",
Expand Down
42 changes: 42 additions & 0 deletions scripts/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fs = require('fs');
const path = require('path');

const Util = require('../lib/utils/util.js');

const buildDocs = () => {

console.log('build docs ...');

const docsDir = path.resolve(__dirname, '../docs');
const list = fs.readdirSync(docsDir, {
withFileTypes: true
});

const html = ['<h3><a href="https://github.com/cenfun/monocart-coverage-reports">Monocart Coverage Reports</a></h3><ul>'];
for (const item of list) {
if (item.isDirectory()) {
const indexPath = path.resolve(docsDir, item.name, 'index.html');
if (fs.existsSync(indexPath)) {
html.push(`<li><a href="${item.name}/index.html">${item.name}</a></li>`);
}
}
}

html.push('</ul>');

const markdownTemplate = fs.readFileSync(path.resolve(__dirname, 'template/markdown.html'), {
encoding: 'utf-8'
});

const content = Util.replace(markdownTemplate, {
placeholder_title: 'Monocart Coverage Reports',
placeholder_content: html.join('')
});

fs.writeFileSync(path.resolve(__dirname, '../docs/index.html'), content);

console.log('generated docs/index.html');

};

buildDocs();

0 comments on commit 19e6b91

Please sign in to comment.