當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs.watch函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。