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

TypeScript fs.watch函数代码示例

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

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



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

示例1: addDirWatcher

                function addDirWatcher(dirPath: Path): void {
                    if (dirWatchers.contains(dirPath)) {
                        const watcher = dirWatchers.get(dirPath);
                        watcher.referenceCount += 1;
                        return;
                    }

                    const watcher: DirectoryWatcher = _fs.watch(
                        dirPath,
                        { persistent: true },
                        (eventName: string, relativeFileName: string) => fileEventHandler(eventName, relativeFileName, dirPath)
                    );
                    watcher.referenceCount = 1;
                    dirWatchers.set(dirPath, watcher);
                    return;
                }
开发者ID:stanhuff,项目名称:TypeScript,代码行数:16,代码来源:sys.ts


示例2: addDirWatcher

                function addDirWatcher(dirPath: string): void {
                    if (hasProperty(dirWatchers, dirPath)) {
                        const watcher = dirWatchers[dirPath];
                        watcher.referenceCount += 1;
                        return;
                    }

                    const watcher: DirectoryWatcher = _fs.watch(
                        dirPath,
                        { persistent: true },
                        (eventName: string, relativeFileName: string) => fileEventHandler(eventName, relativeFileName, dirPath)
                    );
                    watcher.referenceCount = 1;
                    dirWatchers[dirPath] = watcher;
                    return;
                }
开发者ID:Jason1978-Z,项目名称:TypeScript,代码行数:16,代码来源:sys.ts


示例3: watchDebouncedByFilename

export function watchDebouncedByFilename(directory, eventHandler) {
  log(`Setting up file watching for '${directory}'`);

  let callback = eventHandler;

  // Handle Node.js + FSEvents bug
  if (process.platform === 'darwin') {
    callback = function(event, filename) {
      if (filename != null) {
        arguments[1] = iconv.decode(iconv.encode(filename, 'iso-8859-1'), 'utf-8');
      }
      eventHandler.apply(null, arguments);
    };
  }

  // Group events based on filename (2nd argument)
  fs.watch(directory, { recursive: true }, debounce(callback, 50, 1));
}
开发者ID:JannesMeyer,项目名称:lumos,代码行数:18,代码来源:file-watcher.ts


示例4: watchFile

export function watchFile(filepath: string, onChange: () => void): Disposable {
  let callback = debounce(onChange, 100)
  try {
    let watcher = fs.watch(filepath, {
      persistent: true,
      recursive: false,
      encoding: 'utf8'
    }, () => {
      callback()
    })
    return Disposable.create(() => {
      watcher.close()
    })
  } catch (e) {
    return Disposable.create(() => {
      // noop
    })
  }
}
开发者ID:illarionvk,项目名称:dotfiles,代码行数:19,代码来源:index.ts


示例5: function

 executeTrigger: async function (trigger)
 {
     switch (trigger.name)
     {
         case 'watch':
             var stat = await promisify(fs.stat)(trigger.params['path'] as string);
             if (stat.isDirectory() || stat.isFile())
             {
                 var id = uuid();
                 var watcher = fs.watch(trigger.params['path'] as string, function (event, fileName)
                 {
                     if (!trigger.params['event'] || trigger.params['event'] == event)
                         server.trigger({ id: id, data: { path: fileName, mtime: new Date().toJSON() } });
                 });
                 registeredTriggers[id] = watcher;
             }
             break;
     }
     return null;
 }
开发者ID:domojs,项目名称:lifttt,代码行数:20,代码来源:fs.ts


示例6: constructor

	constructor(isWatch: boolean) {
		this._isWatch = isWatch;
		this.stream = es.through();
		this._inputFiles = monacodts.getIncludesInRecipe().map((moduleId) => {
			if (/\.d\.ts$/.test(moduleId)) {
				// This source file is already in .d.ts form
				return path.join(REPO_SRC_FOLDER, moduleId);
			} else {
				return path.join(REPO_SRC_FOLDER, `${moduleId}.ts`);
			}
		});

		// Install watchers
		this._watchers = [];
		if (this._isWatch) {
			this._inputFiles.forEach((filePath) => {
				const watcher = fs.watch(filePath);
				watcher.addListener('change', () => {
					this._inputFileChanged[filePath] = true;
					// Avoid hitting empty files... :/
					setTimeout(() => this.execute(), 10);
				});
				this._watchers.push(watcher);
			});

			const recipeWatcher = fs.watch(monacodts.RECIPE_PATH);
			recipeWatcher.addListener('change', () => {
				this._recipeFileChanged = true;
				// Avoid hitting empty files... :/
				setTimeout(() => this.execute(), 10);
			});
			this._watchers.push(recipeWatcher);
		}

		this._inputFileChanged = {};
		this._inputFiles.forEach(file => this._inputFileChanged[file] = true);
		this._recipeFileChanged = true;
		this._dtsFilesContents = {};
		this._dtsFilesContents2 = {};
	}
开发者ID:DonJayamanne,项目名称:vscode,代码行数:40,代码来源:compilation.ts


示例7: transpile

function transpile(fileNames: string[], options: ts.CompilerOptions) {
    console.time("transpile");
    var files = fileNames.filter(f => !isDTS(f));
    if (isIncremental) {
        files = files.filter(hasChanged);
    }
    files.forEach(tsPath => {
        var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
        var jsSource = ts.transpile(tsSource, options);
        var jsPath = getJsPath(tsPath);
        fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function(err) { console.log(err); });
        if (isIncremental) {
            console.log(" - " + tsPath);
        }
    });
    console.timeEnd("transpile");
    
    if (isWatching) {
        // NOTE: Perhaps on file change before incremental compilation we should read the tsconfig.json again and update only tsconfig.json files.

        console.log("Watching for changes...");
        fs.watch(".", { persistent: true, recursive: true, encoding: "utf8" }, (event, file) => {
            try {
                if (isTS(file) && !isDTS(file) && file.indexOf("platforms/android/") < 0 && file.indexOf("platforms/ios/") < 0) {
                    var tsPath = file;
                    var label = " - " + tsPath;
                    console.time(label);
                    var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
                    var jsSource = ts.transpile(tsSource, options);
                    var jsPath = getJsPath(tsPath);
                    fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function(err) { console.log(err); });
                    console.timeEnd(label);
                }
            } catch(e) {
                // console.log(e);
            }
        });
    }
}
开发者ID:CedarLogic,项目名称:NativeScript,代码行数:39,代码来源:tsc-dev.ts


示例8:

let server = net.createServer((socket) => {
  console.log('Subscriber connected');
  socket.write(JSON.stringify({ 
    type: 'watching', 
	  file: filename
  }) + '\n');
  
  //watcher setup
  let watcher = fs.watch(filename, () => {
    socket.write(JSON.stringify({ 
	  type: 'changed',
	  file: filename,
	  timestamp: Date.now()
    }) + '\n');	  
  });	
  
  //Cleanup
  socket.on('close', () => {
    console.log('Subscriber disconnected');	  
	watcher.close();
  });
});
开发者ID:dam,项目名称:explore_web_frameworks,代码行数:22,代码来源:net-watcher-json-server.ts


示例9: setTimeout

        fs.stat(crashFolder, (err, stats) => {
            let crashObject: { [key: string]: string } = {};
            if (err) {
                // If the directory isn't there, we have a problem...
                crashObject["fs.stat: err.code"] = err.code;
                telemetry.logLanguageServerEvent("MacCrash", crashObject, null);
                return;
            }

            // vscode.workspace.createFileSystemWatcher only works in workspace folders.
            try {
                fs.watch(crashFolder, (event, filename) => {
                    if (event !== "rename") {
                        return;
                    }
                    if (filename === prevCrashFile) {
                        return;
                    }
                    prevCrashFile = filename;
                    if (!filename.startsWith("Microsoft.VSCode.CPP.")) {
                        return;
                    }
                    // Wait 5 seconds to allow time for the crash log to finish being written.
                    setTimeout(() => {
                        fs.readFile(path.resolve(crashFolder, filename), 'utf8', (err, data) => {
                            if (err) {
                                // Try again?
                                fs.readFile(path.resolve(crashFolder, filename), 'utf8', handleCrashFileRead);
                                return;
                            }
                            handleCrashFileRead(err, data);
                        });
                    }, 5000);
                });
            } catch (e) {
                // The file watcher limit is hit (may not be possible on Mac, but just in case).
            }
        });
开发者ID:swyphcosmo,项目名称:vscode-cpptools,代码行数:38,代码来源:extension.ts


示例10: Error

/// <reference path="../../typings/node/node.d.ts" />
"use strict";
import * as fs from 'fs';
import { spawn } from 'child_process';

const filename = process.argv[2]; 

if(!filename) {
  throw Error('A file to watch must be specified');
}

fs.watch(filename, () => {
  let ls = spawn('ls', ['-lh', filename]);
  ls.stdout.pipe(process.stdout);
});
console.log(`Watching ${filename} for changes`);
开发者ID:dam,项目名称:explore_web_frameworks,代码行数:16,代码来源:watcher.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs.watchFile函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.utimesSync函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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