Skip to content

Commit

Permalink
feat: 重命名watch.js为cli/watch.mjs并更新相关引用
Browse files Browse the repository at this point in the history
- 调整文件路径以适应模块化结构。
  • Loading branch information
Null committed Aug 2, 2024
1 parent 354efbb commit 900b9fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions watch.js → cli/watch.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const path = require('path');
const fs = require('fs');
const chokidar = require('chokidar');
import path from 'path';
import fs from 'fs-extra';
import chokidar from 'chokidar';
import { __dirname } from './util.mjs';

const templates = path.resolve(process.cwd(), './packages/hooks/src/**/');
// 获取 docs 下的文件目录地址
const docsDir = path.resolve(__dirname, 'docs');
const docsDir = path.resolve(__dirname, '../docs');

let watcher = chokidar.watch([templates], {
persistent: true,
Expand All @@ -14,24 +15,23 @@ let watcher = chokidar.watch([templates], {
watcher.on('ready', function () {
// 添加
watcher.on('add', function (filePath) {
console.log('add', filePath);
syncFile(filePath, 'add');
});

// 改变
watcher.on('change', function (filePath) {
console.log('change', filePath);
syncFile(filePath, 'change');
});

// 删除
watcher.on('unlink', function (filePath) {
console.log('unlink', filePath);
syncFile(filePath, 'unlink');
});
});

function exec(cmd) {
return require('child_process').execSync(cmd).toString().trim();
}

// 文件的增删查改
function syncFile(filePath, action) {
const relativePath = path.relative(path.resolve(process.cwd(), './packages/hooks/src'), filePath);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eslint": "eslint --fix ./packages/**/*.{js,ts} ",
"cli": "node cli/index.mjs init",
"build:file": "node cli/generate-docs.mjs",
"wt": "node watch.js",
"wt": "node cli/watch.mjs",
"docs:dev": "node cli/start.mjs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
Expand Down

0 comments on commit 900b9fe

Please sign in to comment.