From 19e6b913d37204755ea4eb81454707bb07a774b7 Mon Sep 17 00:00:00 2001 From: cenfun Date: Fri, 22 Mar 2024 12:44:02 +0800 Subject: [PATCH] add docs index --- package.json | 2 +- scripts/docs.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 scripts/docs.js diff --git a/package.json b/package.json index 20003d17..b0b53ea1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/docs.js b/scripts/docs.js new file mode 100644 index 00000000..6b19e06d --- /dev/null +++ b/scripts/docs.js @@ -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 = ['

Monocart Coverage Reports

'); + + 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();