• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript chokidar.watch函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中chokidar.watch函数的典型用法代码示例。如果您正苦于以下问题:TypeScript watch函数的具体用法?TypeScript watch怎么用?TypeScript watch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了watch函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: startWatch

    /* 监听模式 */
    startWatch(): void {
      let config = this.config;

      let watchFile: Array<string> = [];
      if (config.file || config.file.length) {
        for(let file of config.file) {
          file = file.replace(/\\/g, '/');
          watchFile.push(path.resolve(this.basePath, file));
        }
        if (this.configFile) {
          // 命令行模式没有配置文件
          watchFile.push(this.configFile);
        }
        if (config.browserSync) {
          if (!this.browserSync) {
            this.browserSync = browserSync.create();
          }
          if (config.browserSync.init) {
            this.browserSync.init(config.browserSync.init);
          }
          else {
            this.browserSync.init();
          }
          this.watcher = this.browserSync.watch(watchFile).on('change', this.compileCallback.bind(this));
        }
        else {
          console.log('watch model,files:\n'+watchFile.join('\n'));
          this.watcher = chokidar.watch(watchFile).on('change', this.compileCallback.bind(this));
        }
      }
    }
开发者ID:thinkjs,项目名称:autocommand-cli,代码行数:32,代码来源:watch.ts


示例2: processFile

    .then(() => {
        if (program['watch']) {
            let watcher = chokidar.watch('*', { cwd: workingDirectory });

            watcher
                .on('add', path => {
                    if (match.test(path)) {
                        processFile(pathUtils.join(workingDirectory, path));
                    }
                })
                .on('change', path => {
                    if (match.test(path)) {
                        processFile(pathUtils.join(workingDirectory, path));
                    }
                })
                .on('unlink', path => {
                    if (match.test(path)) {
                        let destFileName = getDestFileName(pathUtils.join(workingDirectory, path));

                        if (fs.existsSync(destFileName)) {
                            fs.unlinkSync(destFileName)
                        }
                    }
                });

            let watched = watcher.getWatched();
        }
    });
开发者ID:Bolisov,项目名称:sass-css-modules-to-typings-converter,代码行数:28,代码来源:index.ts


示例3: eventChannel

    chan = yield eventChannel((emit) => {
      const watcher = chokidar.watch(allUris);
  
      watcher.on("ready", () => {

        const emitChange = (path) => {
          
          const mtime = fs.lstatSync(path).mtime;

          const fileCacheItem = initialFileCache.find((item) => item.filePath === path);

          if (fileCacheItem && fileCacheItem.mtime === mtime) {
            return;
          }
          const newContent = fs.readFileSync(path, "utf8");
          const publicPath = getPublicFilePath(path, state);

          // for internal -- do not want this being sent over the network since it is slow
          emit(fileContentChanged(path, publicPath, newContent, mtime));
        }

        watcher.on("add", emitChange);
        watcher.on("change", emitChange);

        watcher.on("unlink", (path) => {
          emit(fileRemoved(path, getPublicFilePath(path, state)));
        });
      });

      return () => {
        watcher.close();
      };
    });
开发者ID:cryptobuks,项目名称:tandem,代码行数:33,代码来源:uri-watcher.ts


示例4: watchFiles

    private watchFiles(watchPaths: string[])
    {
        this.clearModifyTimeout();

        if (watchPaths.length > 0)
        {
            let theThis = this;

            this.fileWatcher = fs_watcher.watch(watchPaths);

            this.fileWatcher.on('change',
                function (path, stats)
                {
                    theThis.clearModifyTimeout();
                    theThis.reloadTimer = setTimeout(
                        function ()
                        {
                            theThis.reloadActiveModel();
                            theThis.notifyModelUpdate();
                            theThis.reloadTimer = undefined;
                        },
                        400);
                });
        }
    }
开发者ID:legatoproject,项目名称:legato-af,代码行数:25,代码来源:lspClient.ts


示例5: createFsWatcher

export function createFsWatcher(events: d.BuildEvents, paths: string, opts: any) {
  const chokidar = require('chokidar');
  const watcher = chokidar.watch(paths, opts);

  watcher
    .on('change', (path: string) => {
      events.emit('fileUpdate', path);
    })
    .on('add', (path: string) => {
      events.emit('fileAdd', path);
    })
    .on('unlink', (path: string) => {
      events.emit('fileDelete', path);
    })
    .on('addDir', (path: string) => {
      events.emit('dirAdd', path);
    })
    .on('unlinkDir', (path: string) => {
      events.emit('dirDelete', path);
    })
    .on('error', (err: any) => {
      console.error(err);
    });

  return watcher;
}
开发者ID:franktopel,项目名称:stencil,代码行数:26,代码来源:node-fs-watcher.ts


示例6: reportDiagnostics

 onFileChange: (options, listener, ready: () => void) => {
   if (!options.basePath) {
     reportDiagnostics([{
       category: ts.DiagnosticCategory.Error,
       messageText: 'Invalid configuration option. baseDir not specified',
       source: api.SOURCE,
       code: api.DEFAULT_ERROR_CODE
     }]);
     return {close: () => {}};
   }
   const watcher = chokidar.watch(options.basePath, {
     // ignore .dotfiles, .js and .map files.
     // can't ignore other files as we e.g. want to recompile if an `.html` file changes as well.
     ignored: /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json)/,
     ignoreInitial: true,
     persistent: true,
   });
   watcher.on('all', (event: string, path: string) => {
     switch (event) {
       case 'change':
         listener(FileChangeEvent.Change, path);
         break;
       case 'unlink':
       case 'add':
         listener(FileChangeEvent.CreateDelete, path);
         break;
       case 'unlinkDir':
       case 'addDir':
         listener(FileChangeEvent.CreateDeleteDir, path);
         break;
     }
   });
   watcher.on('ready', ready);
   return {close: () => watcher.close(), ready};
 },
开发者ID:angularbrasil,项目名称:angular,代码行数:35,代码来源:perform_watch.ts


示例7: fileReload

export function fileReload(path: string, callback: ContentReadyCallback) {
    const watcher: fs.FSWatcher = watch(path);

    watcher.on('add', file=>readContent(file, callback));
    watcher.on('change', file=>readContent(file, callback));
    watcher.on('error', error=>console.log(`Watcher error: ${error}`));
}
开发者ID:pbalaga,项目名称:craftdb,代码行数:7,代码来源:file-reload.ts


示例8: constructor

  constructor(path: string, handleUpdate: any) {
    this.currentPath = path
    this.handleUpdate = handleUpdate

    this.watcher = chokidar.watch(this.currentPath)
    this.watcher.on('add', this.onUpdate.bind(this))
    this.watcher.on('change', this.onUpdate.bind(this))
  }
开发者ID:civic,项目名称:markcat,代码行数:8,代码来源:watcher.ts


示例9: watch

export function watch(watchDirectory: FilePath, sourcePath: FilePath, outputFolder: FilePath) {

    let watcher = chokidar.watch([watchDirectory + globSuffix])
        .on('add', () => build(sourcePath, outputFolder))
        .on('change', () => build(sourcePath, outputFolder));

    return watcher;
}
开发者ID:ondratra,项目名称:soliditySapper,代码行数:8,代码来源:solidityCompiler.ts


示例10: watchConfigFiles

 private watchConfigFiles() {
   const watcher = chokidar.watch([configFile, secretsFile, webpackFile], {
     cwd: this.appDir,
     ignoreInitial: true
   })
   watcher.on("add", this.onConfigFileUpdate.bind(this, "add"))
   watcher.on("change", this.onConfigFileUpdate.bind(this, "change"))
 }
开发者ID:dianpeng,项目名称:fly,代码行数:8,代码来源:file_app_store.ts



注:本文中的chokidar.watch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript chokidar.FSWatcher类代码示例发布时间:2022-05-24
下一篇:
TypeScript child_process.exec类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap