chore: add watch
scripts.
This commit is contained in:
parent
5094fac68a
commit
a612c2b971
@ -22,6 +22,7 @@ git clone git@github.com:jaywcjlove/reference.git
|
|||||||
```shell
|
```shell
|
||||||
npm i # 安装依赖
|
npm i # 安装依赖
|
||||||
npm run build # 编译输出 HTML
|
npm run build # 编译输出 HTML
|
||||||
|
npm run start # 监听 md 文件编译输出 HTML
|
||||||
```
|
```
|
||||||
|
|
||||||
HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静态页面在浏览器中打开预览。
|
HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静态页面在浏览器中打开预览。
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"private": false,
|
"private": false,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node scripts/build.mjs",
|
"build": "node scripts/build.mjs",
|
||||||
"start": "node scripts/build.mjs"
|
"start": "node scripts/watch.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,6 +20,7 @@
|
|||||||
"keywords": [],
|
"keywords": [],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@wcj/markdown-to-html": "^2.0.15",
|
"@wcj/markdown-to-html": "^2.0.15",
|
||||||
|
"chokidar": "^3.5.3",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"recursive-readdir-files": "^2.3.0",
|
"recursive-readdir-files": "^2.3.0",
|
||||||
"rehype-document": "^6.1.0",
|
"rehype-document": "^6.1.0",
|
||||||
|
@ -3,15 +3,15 @@ import path from 'path';
|
|||||||
import recursiveReaddirFiles from 'recursive-readdir-files';
|
import recursiveReaddirFiles from 'recursive-readdir-files';
|
||||||
import { create } from './create.mjs';
|
import { create } from './create.mjs';
|
||||||
|
|
||||||
const OUTOUT = path.resolve(process.cwd(), 'dist');
|
export const OUTOUT = path.resolve(process.cwd(), 'dist');
|
||||||
const DOCS = path.resolve(process.cwd(), 'docs');
|
export const DOCS = path.resolve(process.cwd(), 'docs');
|
||||||
const CSSPATH = path.resolve(process.cwd(), 'scripts/style.css');
|
export const CSSPATH = path.resolve(process.cwd(), 'scripts/style.css');
|
||||||
const CSS_OUTPUT_PATH = path.resolve(OUTOUT, 'style/style.css');
|
export const CSS_OUTPUT_PATH = path.resolve(OUTOUT, 'style/style.css');
|
||||||
|
|
||||||
async function createHTML(files = [], num = 0) {
|
export async function createHTML(files = [], num = 0) {
|
||||||
const dataFile = files[num];
|
const dataFile = files[num];
|
||||||
if (!dataFile) {
|
if (!dataFile) {
|
||||||
console.log('\ndone!')
|
console.log(' \n done!\n')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++num;
|
++num;
|
||||||
|
19
scripts/watch.mjs
Normal file
19
scripts/watch.mjs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import chokidar from 'chokidar';
|
||||||
|
import { getStat } from 'recursive-readdir-files';
|
||||||
|
import { run, DOCS, createHTML } from './index.mjs';
|
||||||
|
|
||||||
|
;(async () => {
|
||||||
|
await run();
|
||||||
|
const homeMdPath = path.relative(process.cwd(), 'README.md')
|
||||||
|
const watcher = chokidar.watch([DOCS, homeMdPath], {
|
||||||
|
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
||||||
|
persistent: true
|
||||||
|
});
|
||||||
|
|
||||||
|
watcher.on('change', async (path) => {
|
||||||
|
const stats = await getStat(path)
|
||||||
|
createHTML([stats]);
|
||||||
|
})
|
||||||
|
.on('error', error => console.log(`Watcher error: ${error}`))
|
||||||
|
})();
|
Loading…
x
Reference in New Issue
Block a user