constructor()

in websites/mini-program/scripts/watchMd.js [10:37]


  constructor() {
    this.watcher = null;

    const rootPath = path.resolve(process.cwd(), '../../packages/bui-core/src');
    const svgIconMdPath = path.resolve(
      process.cwd(),
      '../../packages/bui-icons/src',
    );
    const dirs = fse.readdirSync(rootPath);
    const mdPathList = [svgIconMdPath];
    dirs.forEach((dir) => {
      const componentPath = path.resolve(rootPath, dir);
      if (fse.lstatSync(componentPath).isDirectory()) {
        const files = fse.readdirSync(componentPath);
        files.forEach((file) => {
          // 原来的 '.md' 改为 'zh-CN.md'
          if (file.split('.').slice(1).join('.') === 'zh-CN.md') {
            mdPathList.push(path.resolve(componentPath, file));
          }
        });
      }
    });

    this.watcher = chokidar.watch(mdPathList, {
      persistent: true,
      awaitWriteFinish: true,
    });
  }