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


TypeScript event-stream.through函數代碼示例

本文整理匯總了TypeScript中event-stream.through函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript through函數的具體用法?TypeScript through怎麽用?TypeScript through使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了through函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

	return function (token?: util.ICancellationToken) {

		const utf8Filter = util.filter(data => /(\/|\\)test(\/|\\).*utf8/.test(data.path));
		const tsFilter = util.filter(data => /\.ts$/.test(data.path));
		const noDeclarationsFilter = util.filter(data => !(/\.d\.ts$/.test(data.path)));

		const input = es.through();
		const output = input
			.pipe(utf8Filter)
			.pipe(bom())
			.pipe(utf8Filter.restore)
			.pipe(tsFilter)
			.pipe(util.loadSourcemaps())
			.pipe(ts(token))
			// .pipe(build ? reloadTypeScriptNodeModule() : es.through())
			.pipe(noDeclarationsFilter)
			.pipe(build ? nls() : es.through())
			.pipe(noDeclarationsFilter.restore)
			.pipe(sourcemaps.write('.', {
				addComment: false,
				includeContent: !!build,
				sourceRoot: options.sourceRoot
			}))
			.pipe(tsFilter.restore)
			.pipe(reporter.end(emitError));

		return es.duplex(input, output);
	};
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:28,代碼來源:compilation.ts

示例2: monacodtsTask

function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream {

	const basePath = path.resolve(process.cwd(), out);

	const neededFiles: { [file: string]: boolean; } = {};
	monacodts.getFilesToWatch(out).forEach(function (filePath) {
		filePath = path.normalize(filePath);
		neededFiles[filePath] = true;
	});

	const inputFiles: { [file: string]: string; } = {};
	for (let filePath in neededFiles) {
		if (/\bsrc(\/|\\)vs\b/.test(filePath)) {
			// This file is needed from source => simply read it now
			inputFiles[filePath] = fs.readFileSync(filePath).toString();
		}
	}

	const setInputFile = (filePath: string, contents: string) => {
		if (inputFiles[filePath] === contents) {
			// no change
			return;
		}
		inputFiles[filePath] = contents;
		const neededInputFilesCount = Object.keys(neededFiles).length;
		const availableInputFilesCount = Object.keys(inputFiles).length;
		if (neededInputFilesCount === availableInputFilesCount) {
			run();
		}
	};

	const run = () => {
		const result = monacodts.run(out, inputFiles);
		if (!result.isTheSame) {
			if (isWatch) {
				fs.writeFileSync(result.filePath, result.content);
			} else {
				resultStream.emit('error', 'monaco.d.ts is no longer up to date. Please run gulp watch and commit the new file.');
			}
		}
	};

	let resultStream: NodeJS.ReadWriteStream;

	if (isWatch) {
		watch('build/monaco/*').pipe(es.through(function () {
			run();
		}));
	}

	resultStream = es.through(function (data) {
		const filePath = path.normalize(path.resolve(basePath, data.relative));
		if (neededFiles[filePath]) {
			setInputFile(filePath, data.contents.toString());
		}
		this.emit('data', data);
	});

	return resultStream;
}
開發者ID:jumpinjackie,項目名稱:sqlopsstudio,代碼行數:60,代碼來源:compilation.ts

示例3: createStatsStream

export function createStatsStream(group: string, log?: boolean): es.ThroughStream {

	const entry = new Entry(group, 0, 0);
	_entries.set(entry.name, entry);

	return es.through(function (data) {
		const file = data as File;
		if (typeof file.path === 'string') {
			entry.totalCount += 1;
			if (Buffer.isBuffer(file.contents)) {
				entry.totalSize += file.contents.length;
			} else if (file.stat && typeof file.stat.size === 'number') {
				entry.totalSize += file.stat.size;
			} else {
				// funky file...
			}
		}
		this.emit('data', data);
	}, function () {
		if (log) {
			if (entry.totalCount === 1) {
				fancyLog(`Stats for '${ansiColors.grey(entry.name)}': ${Math.round(entry.totalSize / 1204)}KB`);

			} else {
				const count = entry.totalCount < 100
					? ansiColors.green(entry.totalCount.toString())
					: ansiColors.red(entry.totalCount.toString());

				fancyLog(`Stats for '${ansiColors.grey(entry.name)}': ${count} files, ${Math.round(entry.totalSize / 1204)}KB`);
			}
		}

		this.emit('end');
	});
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:35,代碼來源:stats.ts

示例4: createAdditionalLanguageFiles

export function createAdditionalLanguageFiles(languages: string[], i18nBaseDir: string, baseDir?: string): ThroughStream {
	return through(function(file: File) {
		let basename = path.basename(file.relative);
		if (basename.length < NLS_JSON.length || NLS_JSON !== basename.substr(basename.length - NLS_JSON.length)) {
			this.emit('data', file);
			return;
		}
		let filename = file.relative.substr(0, file.relative.length - NLS_JSON.length);
		let json;
		if (file.isBuffer()) {
			json = JSON.parse(file.contents.toString('utf8'));
			let resolvedBundle = resolveMessageBundle(json);
			languages.forEach((language) => {
				let result = createLocalizedMessages(filename, resolvedBundle, language, i18nBaseDir, baseDir);
				if (result.problems && result.problems.length > 0) {
					result.problems.forEach(problem => log(problem));
				}
				if (result.messages) {
					this.emit('data', new File({
						base: file.base,
						path: path.join(file.base, filename) + '.nls.' + iso639_3_to_2[language] + '.json',
						contents: new Buffer(JSON.stringify(result.messages, null, '\t').replace(/\r\n/g, '\n'), 'utf8')
					}));
				}
 			});
		} else {
			this.emit('error', `Failed to read component file: ${file.relative}`)
		}
		this.emit('data', file);
	});
}
開發者ID:wskplho,項目名稱:vscode-nls-dev,代碼行數:31,代碼來源:main.ts

示例5: it

	it('should buffer stuff and return a stream with the buffered data', done => {
		const src = [1, 2, 3];
		const inp = es.readArray(src);
		inp.pipe(util.buffer()).pipe(es.through((data: any[]) => {
			should.exist(data);
			data.should.eql(src);
			done();
		}));
	});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:gulp-util-tests.ts

示例6: reloadTypeScriptNodeModule

function reloadTypeScriptNodeModule(): NodeJS.ReadWriteStream {
	var util = require('gulp-util');
	function log(message: any, ...rest: any[]): void {
		util.log(util.colors.cyan('[memory watch dog]'), message, ...rest);
	}

	function heapUsed(): string {
		return (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) + ' MB';
	}

	return es.through(function (data) {
		this.emit('data', data);
	}, function () {

		log('memory usage after compilation finished: ' + heapUsed());

		// It appears we are running into some variant of
		// https://bugs.chromium.org/p/v8/issues/detail?id=2073
		//
		// Even though all references are dropped, some
		// optimized methods in the TS compiler end up holding references
		// to the entire TypeScript language host (>600MB)
		//
		// The idea is to force v8 to drop references to these
		// optimized methods, by "reloading" the typescript node module

		log('Reloading typescript node module...');

		var resolvedName = require.resolve('typescript');

		var originalModule = require.cache[resolvedName];
		delete require.cache[resolvedName];
		var newExports = require('typescript');
		require.cache[resolvedName] = originalModule;

		for (var prop in newExports) {
			if (newExports.hasOwnProperty(prop)) {
				originalModule.exports[prop] = newExports[prop];
			}
		}

		log('typescript node module reloaded.');

		this.emit('end');
	});
}
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:46,代碼來源:compilation.ts

示例7: processNlsFiles

export function processNlsFiles(): ThroughStream {
	return through(function(file: File) {
		let fileName = path.basename(file.path);
		if (fileName === 'nls.metadata.json') {
			let json = null;
			if (file.isBuffer()) {
				json = JSON.parse(file.contents.toString('utf8'));
			} else {
				this.emit('error', `Failed to read component file: ${file.relative}`)
			}
			if (BundledFormat.is(json)) {
				processCoreBundleFormat(json, this);
			}
		}
		this.emit('data', file);
	});
}
開發者ID:DMVillan,項目名稱:vscode,代碼行數:17,代碼來源:i18n.ts

示例8: function

	return function () {
		const compile = createCompile(src, build, true);

		const srcPipe = es.merge(
			gulp.src(`${src}/**`, { base: `${src}` }),
			gulp.src('node_modules/typescript/lib/lib.d.ts'),
		);

		// Do not write .d.ts files to disk, as they are not needed there.
		const dtsFilter = util.filter(data => !/\.d\.ts$/.test(data.path));

		return srcPipe
			.pipe(compile())
			.pipe(dtsFilter)
			.pipe(gulp.dest(out))
			.pipe(dtsFilter.restore)
			.pipe(src !== 'src' ? es.through() : monacodtsTask(out, false));
	};
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:18,代碼來源:compilation.ts

示例9: fromLocal

export function fromLocal(extensionPath: string): Stream {
	const result = es.through();

	vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn })
		.then(fileNames => {
			const files = fileNames
				.map(fileName => path.join(extensionPath, fileName))
				.map(filePath => new File({
					path: filePath,
					stat: fs.statSync(filePath),
					base: extensionPath,
					contents: fs.createReadStream(filePath) as any
				}));

			es.readArray(files).pipe(result);
		})
		.catch(err => result.emit('error', err));

	return result;
}
開發者ID:jinlongchen2018,項目名稱:vscode,代碼行數:20,代碼來源:extensions.ts

示例10: 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


注:本文中的event-stream.through函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。