当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fs.watchFile函数代码示例

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


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

示例1: _reject

    return this._makeChild((child, resolve, reject) => {
      function _reject(message: string) {
        const pidFile = 'testingbot-tunnel.pid';
        if (existsSync(pidFile)) {
          // Remove the pidfile to ensure the running tunnel app shuts
          // down
          unlinkSync(pidFile);
        }
        reject(message);
      }

      // Polling API is used because we are only watching for one file, so
      // efficiency is not a big deal, and the `fs.watch` API has extra
      // restrictions which are best avoided
      watchFile(readyFile, { persistent: false, interval: 1007 }, function(
        current,
        previous
      ) {
        if (Number(current.mtime) === Number(previous.mtime)) {
          // readyFile hasn't been modified, so ignore the event
          return;
        }

        unwatchFile(readyFile);
        resolve();
      });

      let lastMessage: string;
      this._handle = on(child.stderr, 'data', (data: string) => {
        data = String(data);
        data.split('\n').forEach(message => {
          if (message.indexOf('INFO: ') === 0) {
            message = message.slice('INFO: '.length);
            // the tunnel produces a lot of repeating messages
            // during setup when the status is pending; deduplicate
            // them for sanity
            if (
              message !== lastMessage &&
              message.indexOf('>> [') === -1 &&
              message.indexOf('<< [') === -1
            ) {
              this.emit({
                type: 'status',
                target: this,
                status: message
              });
              lastMessage = message;
            }
          } else if (message.indexOf('SEVERE: ') === 0) {
            _reject(message);
          } else if (message.indexOf('An error ocurred:') === 0) {
            _reject(message);
          }
        });
      });

      executor(child, resolve, reject);
    }, readyFile);
开发者ID:theintern,项目名称:digdug,代码行数:58,代码来源:TestingBotTunnel.ts

示例2: constructor

  constructor() {
    marked.setOptions({
      langPrefix: 'hljs ',
      highlight: function (code: string, lang: string) {
        return hljs.highlight(lang, code).value;
      }
    });

    fs.watchFile(entriesFilename, () => this.loadBlogEntries());
    this.loadBlogEntries(); 
  }
开发者ID:eliakaris,项目名称:blog,代码行数:11,代码来源:BlogProvider.ts

示例3: writeFile

 writeFile('testfile', 'test content', () => {
   watchFile('testfile', {persistent: false, interval: 1000}, (curr, prev) => {
     expect(curr.size).toBe(16);
     expect(prev.size).toBe(12);
     expect(zoneASpec.onScheduleTask).toHaveBeenCalled();
     expect(Zone.current.name).toBe('A');
     unwatchFile('testfile');
     unlink('testfile', () => {
       done();
     });
   });
   writeFile('testfile', 'test new content', () => {});
 });
开发者ID:jahtalab,项目名称:zone.js,代码行数:13,代码来源:fs.spec.ts

示例4: close

                watchFile: (fileName, callback) => {
                    // watchFile polls a file every 250ms, picking up file notifications.
                    _fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);

                    return {
                        close() { _fs.unwatchFile(fileName, fileChanged); }
                    };

                    function fileChanged(curr: any, prev: any) {
                        if (+curr.mtime <= +prev.mtime) {
                            return;
                        }

                        callback(fileName);
                    };
                },
开发者ID:GrimoireGL,项目名称:atom-typescript,代码行数:16,代码来源:sys.ts

示例5: setTimeout

  setTimeout(() => {
    const selfSourceFiles = new Set<string>()
    for (let filename of fs.readdirSync(__dirname)) {
      selfSourceFiles.add(Path.join(__dirname, filename))
    }
    selfSourceFiles.add(sourceDir)

    let isClosing = false
    const onSourceChanged = (curr: fs.Stats, prev :fs.Stats) => {
      // console.log(process.pid, 'server changed')
      for (let filename of selfSourceFiles) {
        fs.unwatchFile(filename)
      }

      for (let filename of sourceFiles) {
        fs.unwatchFile(filename)
      }

      if (process.env.IS_SUBPROCESS) {
        process.exit(0)
        return
      }

      if (isClosing) {
        return
      }
      isClosing = true

      if (httpServer) {
        // console.log(process.pid, 'closing server', httpServer.listening)
        httpServer.close(() => {
          setTimeout(restartAsSubproc, 100)
        })
        httpServer.unref()
      } else {
        setTimeout(restartAsSubproc, 100)
      }
    }

    for (let filename of selfSourceFiles) {
      fs.watchFile(filename, {interval:200}, onSourceChanged)
    }
  }, 500)
开发者ID:rsms,项目名称:co,代码行数:43,代码来源:parse-debugger.ts

示例6: fileChanged

                watchFile: (fileName, callback, pollingInterval) => {
                    if (useNonPollingWatchers) {
                        const watchedFile = watchedFileSet.addFile(fileName, callback);
                        return {
                            close: () => watchedFileSet.removeFile(watchedFile)
                        };
                    }
                    else {
                        _fs.watchFile(fileName, { persistent: true, interval: pollingInterval || 250 }, fileChanged);
                        return {
                            close: () => _fs.unwatchFile(fileName, fileChanged)
                        };
                    }

                    function fileChanged(curr: any, prev: any) {
                        if (+curr.mtime <= +prev.mtime) {
                            return;
                        }

                        callback(fileName);
                    }
                },
开发者ID:8Observer8,项目名称:TypeScript,代码行数:22,代码来源:sys.ts

示例7: watchFile

    return this._makeChild((child, resolve, reject) => {
      let stdout: string[] | null = [];

      // Polling API is used because we are only watching for one file, so
      // efficiency is not a big deal, and the `fs.watch` API has extra
      // restrictions which are best avoided
      watchFile(readyFile, { persistent: false, interval: 1007 }, function(
        current,
        previous
      ) {
        if (Number(current.mtime) === Number(previous.mtime)) {
          // readyFile hasn't been modified, so ignore the event
          return;
        }

        unwatchFile(readyFile);
        readHandle.destroy();
        exitHandle.destroy();
        stdout = null;
        resolve();
      });

      // The cbt tunnel outputs its startup error messages on stdout.
      // Capture any data on stdout and display it if the process exits
      // early.
      const readHandle = on(child.stdout, 'data', (data: any) => {
        stdout!.push(String(data));
      });
      const exitHandle = on(child, 'exit', function() {
        process.stderr.write(stdout!.join(''));
      });

      this._handle = createCompositeHandle(readHandle, exitHandle);

      executor(child, resolve, reject);
    }, readyFile);
开发者ID:theintern,项目名称:digdug,代码行数:36,代码来源:CrossBrowserTestingTunnel.ts

示例8: onModify

	/** Calls the callback if the file is modified. */
	onModify(callback: () => void) {
		fs.watchFile(this.path, (curr, prev) => {
			if (curr.mtime > prev.mtime) return callback();
		});
	}
开发者ID:AdmiralZachbar,项目名称:Pokemon-Showdown,代码行数:6,代码来源:fs.ts

示例9: require

const fs = require('fs');

// read and watch config json.
export let config = readConfig();

fs.watchFile('./config.json', function () {
    config = readConfig();

    console.info('*** CONFIG CHANGED ***');
    console.log('New Config: ', config);
});

function readConfig() {
    let cfg = JSON.parse(fs.readFileSync('./config.json'));

    // now override settings with secrets from environment variables
    cfg.azure.storageConnectionString = process.env.HOOPY_CONNECTION_STRING;
    cfg.pushbullet.apiKey = process.env.HOOPY_PUSHBULLET_KEY;
    cfg.hoopHouseThresholds.email = process.env.HOOPY_HOOP_HOUSE_EMAIL;
    cfg.ifttt.key = process.env.HOOPY_IFTTT_KEY;

    let channelMap = cfg.thingSpeak.channelMap;
    channelMap.find((e) => e.name === 'tom-office').key = process.env.HOOPY_THINGSPEAK_OFFICE_KEY;
    channelMap.find((e) => e.name === 'hoopy-inside').key = process.env.HOOPY_THINGSPEAK_HOOPHOUSE_KEY;

    return cfg;
}
开发者ID:tommck,项目名称:hoopy,代码行数:27,代码来源:config.ts

示例10: executeFile

        console.log('File changed => Kill process: ', currentChild.pid);
        currentChild.send('exit');
        //currentChild.kill();
        //currentChild.emit('exit');
        //currentChild.stderr.removeAllListeners();
        //currentChild.stdout.removeAllListeners();
        //currentChild.removeAllListeners();
        process.kill(currentChild.pid);
        currentChild = undefined;
    }
}
function executeFile() {
    console.log('Executing file: ', filename);
    currentChild = child_process.fork(filename); //'node ' + 
    //receive message from child;
    //currentChild.on('message', value => {
    //    console.log('result emitted: ', value);
    //});

}
fs.watchFile(filename, (curr, prev) => {
    killChild();
    if (fs.existsSync(filename)) executeFile();
});

executeFile();

process.on('exit', () => {
    killChild();
});
开发者ID:howardyan93,项目名称:NgNode,代码行数:30,代码来源:watch.ts


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