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


TypeScript pfs.mkdirp函數代碼示例

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


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

示例1: test

	test('simple file operations, ignore', async () => {
		let request: IWatcherRequest = { basePath: testDir, ignored: ['**/b/**', '**/*.js', '.git/**'] };
		service.setRoots([request]);
		await wait(300);

		assert.equal(service.wacherCount, 1);

		// create various ignored files
		let file1 = path.join(bFolder, 'file1.txt'); // hidden
		await pfs.writeFile(file1, 'Hello');
		let file2 = path.join(b2Folder, 'file2.txt'); // hidden
		await pfs.writeFile(file2, 'Hello');
		let folder1 = path.join(bFolder, 'folder1'); // hidden
		await pfs.mkdirp(folder1);
		let folder2 = path.join(aFolder, 'b'); // hidden
		await pfs.mkdirp(folder2);
		let folder3 = path.join(testDir, '.git'); // hidden
		await pfs.mkdirp(folder3);
		let folder4 = path.join(testDir, '.git1');
		await pfs.mkdirp(folder4);
		let folder5 = path.join(aFolder, '.git');
		await pfs.mkdirp(folder5);
		let file3 = path.join(aFolder, 'file3.js'); // hidden
		await pfs.writeFile(file3, 'var x;');
		let file4 = path.join(aFolder, 'file4.txt');
		await pfs.writeFile(file4, 'Hello');
		await assertFileEvents(result, [{ path: file4, type: FileChangeType.ADDED }, { path: folder4, type: FileChangeType.ADDED }, { path: folder5, type: FileChangeType.ADDED }]);

		// move some files
		let movedFile1 = path.join(folder2, 'file1.txt'); // from ignored to ignored
		await pfs.rename(file1, movedFile1);
		let movedFile2 = path.join(aFolder, 'file2.txt'); // from ignored to visible
		await pfs.rename(file2, movedFile2);
		let movedFile3 = path.join(aFolder, 'file3.txt'); // from ignored file ext to visible
		await pfs.rename(file3, movedFile3);
		await assertFileEvents(result, [{ path: movedFile2, type: FileChangeType.ADDED }, { path: movedFile3, type: FileChangeType.ADDED }]);

		// delete all files
		await pfs.del(movedFile1); // hidden
		await pfs.del(movedFile2);
		await pfs.del(movedFile3);
		await pfs.del(folder1); // hidden
		await pfs.del(folder2); // hidden
		await pfs.del(folder3); // hidden
		await pfs.del(folder4);
		await pfs.del(folder5);
		await pfs.del(file4);
		await assertFileEvents(result, [{ path: movedFile2, type: FileChangeType.DELETED }, { path: movedFile3, type: FileChangeType.DELETED }, { path: file4, type: FileChangeType.DELETED }, { path: folder4, type: FileChangeType.DELETED }, { path: folder5, type: FileChangeType.DELETED }]);
	});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:49,代碼來源:chockidarWatcherService.test.ts

示例2: test

	test('writeFile - parallel write on same files works and is sequentalized', function (done: () => void) {
		const id = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id);
		const newDir = path.join(parentDir, 'pfs', id);
		const testFile = path.join(newDir, 'writefile.txt');

		const onMkdirp = error => {
			if (error) {
				return onError(error, done);
			}

			assert.ok(fs.existsSync(newDir));

			TPromise.join([
				pfs.writeFile(testFile, 'Hello World 1', null),
				pfs.writeFile(testFile, 'Hello World 2', null),
				TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', null)),
				pfs.writeFile(testFile, 'Hello World 4', null),
				TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', null))
			]).done(() => {
				assert.equal(fs.readFileSync(testFile), 'Hello World 5');

				extfs.del(parentDir, os.tmpdir(), () => { }, done);
			}, error => onError(error, done));
		};

		pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
	});
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:28,代碼來源:pfs.test.ts

示例3: test

	test('writeFile - parallel write on different files works', function () {
		const id = uuid.generateUuid();
		const parentDir = path.join(os.tmpdir(), 'vsctests', id);
		const newDir = path.join(parentDir, 'pfs', id);
		const testFile1 = path.join(newDir, 'writefile1.txt');
		const testFile2 = path.join(newDir, 'writefile2.txt');
		const testFile3 = path.join(newDir, 'writefile3.txt');
		const testFile4 = path.join(newDir, 'writefile4.txt');
		const testFile5 = path.join(newDir, 'writefile5.txt');

		return pfs.mkdirp(newDir, 493).then(() => {
			assert.ok(fs.existsSync(newDir));

			return Promise.all([
				pfs.writeFile(testFile1, 'Hello World 1', null),
				pfs.writeFile(testFile2, 'Hello World 2', null),
				pfs.writeFile(testFile3, 'Hello World 3', null),
				pfs.writeFile(testFile4, 'Hello World 4', null),
				pfs.writeFile(testFile5, 'Hello World 5', null)
			]).then(() => {
				assert.equal(fs.readFileSync(testFile1), 'Hello World 1');
				assert.equal(fs.readFileSync(testFile2), 'Hello World 2');
				assert.equal(fs.readFileSync(testFile3), 'Hello World 3');
				assert.equal(fs.readFileSync(testFile4), 'Hello World 4');
				assert.equal(fs.readFileSync(testFile5), 'Hello World 5');

				return pfs.del(parentDir, os.tmpdir());
			});
		});
	});
開發者ID:donaldpipowitch,項目名稱:vscode,代碼行數:30,代碼來源:pfs.test.ts

示例4: test

	test('default', async function () {
		await mkdirp(parentDir);
		fs.writeFileSync(installSource, 'my.install.source');
		const props = await resolveWorkbenchCommonProperties(nestStorage2Service, commit, version, 'someMachineId', installSource);
		assert.ok('commitHash' in props);
		assert.ok('sessionID' in props);
		assert.ok('timestamp' in props);
		assert.ok('common.platform' in props);
		assert.ok('common.nodePlatform' in props);
		assert.ok('common.nodeArch' in props);
		assert.ok('common.timesincesessionstart' in props);
		assert.ok('common.sequence' in props);
		// assert.ok('common.version.shell' in first.data); // only when running on electron
		// assert.ok('common.version.renderer' in first.data);
		assert.ok('common.platformVersion' in props, 'platformVersion');
		assert.ok('version' in props);
		assert.equal(props['common.source'], 'my.install.source');
		assert.ok('common.firstSessionDate' in props, 'firstSessionDate');
		assert.ok('common.lastSessionDate' in props, 'lastSessionDate'); // conditional, see below, 'lastSessionDate'ow
		assert.ok('common.isNewSession' in props, 'isNewSession');
		// machine id et al
		assert.ok('common.instanceId' in props, 'instanceId');
		assert.ok('common.machineId' in props, 'machineId');
		fs.unlinkSync(installSource);
		const props_1 = await resolveWorkbenchCommonProperties(nestStorage2Service, commit, version, 'someMachineId', installSource);
		assert.ok(!('common.source' in props_1));
	});
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:27,代碼來源:commonProperties.test.ts

示例5: save

export function save(file: string, content: string): any {
	mkdirp(dirname(file)).then(() => {
		return writeFile(file, content, 'ascii');
	}, err => {
		//
	});
}
開發者ID:AjuanM,項目名稱:vscode,代碼行數:7,代碼來源:fileAccessor.ts

示例6: test

	test('basics (corrupt DB falls back to empty DB if backup is corrupt)', async () => {
		const storageDir = uniqueStorageDir();

		await mkdirp(storageDir);

		const storagePath = join(storageDir, 'storage.db');
		let storage = new SQLiteStorageImpl({ path: storagePath });

		const items = new Map<string, string>();
		items.set('foo', 'bar');
		items.set('some/foo/path', 'some/bar/path');
		items.set(JSON.stringify({ foo: 'bar' }), JSON.stringify({ bar: 'foo' }));

		await storage.updateItems({ insert: items });
		await storage.close();

		await writeFile(storagePath, 'This is now a broken DB');
		await writeFile(`${storagePath}.backup`, 'This is now also a broken DB');

		storage = new SQLiteStorageImpl({ path: storagePath });

		const storedItems = await storage.getItems();
		equal(storedItems.size, 0);

		await testDBBasics(storagePath);

		await del(storageDir, tmpdir());
	});
開發者ID:,項目名稱:,代碼行數:28,代碼來源:

示例7: extractEntry

function extractEntry(stream: Readable, fileName: string, mode: number, targetPath: string, options: IOptions, token: CancellationToken): TPromise<void> {
	const dirName = path.dirname(fileName);
	const targetDirName = path.join(targetPath, dirName);
	if (targetDirName.indexOf(targetPath) !== 0) {
		return TPromise.wrapError(new Error(nls.localize('invalid file', "Error extracting {0}. Invalid file.", fileName)));
	}
	const targetFileName = path.join(targetPath, fileName);

	let istream: WriteStream;

	once(token.onCancellationRequested)(() => {
		if (istream) {
			istream.close();
		}
	});

	return mkdirp(targetDirName, void 0, token).then(() => new TPromise((c, e) => {
		if (token.isCancellationRequested) {
			return;
		}

		istream = createWriteStream(targetFileName, { mode });
		istream.once('close', () => c(null));
		istream.once('error', e);
		stream.once('error', e);
		stream.pipe(istream);
	}));
}
開發者ID:developers23,項目名稱:vscode,代碼行數:28,代碼來源:zip.ts

示例8: extractEntry

function extractEntry(stream: Readable, fileName: string, mode: number, targetPath: string, options: IOptions, token: CancellationToken): Promise<void> {
	const dirName = path.dirname(fileName);
	const targetDirName = path.join(targetPath, dirName);
	if (targetDirName.indexOf(targetPath) !== 0) {
		return Promise.reject(new Error(nls.localize('invalid file', "Error extracting {0}. Invalid file.", fileName)));
	}
	const targetFileName = path.join(targetPath, fileName);

	let istream: WriteStream;

	Event.once(token.onCancellationRequested)(() => {
		if (istream) {
			istream.destroy();
		}
	});

	return Promise.resolve(mkdirp(targetDirName, undefined, token)).then(() => new Promise<void>((c, e) => {
		if (token.isCancellationRequested) {
			return;
		}

		try {
			istream = createWriteStream(targetFileName, { mode });
			istream.once('close', () => c());
			istream.once('error', e);
			stream.once('error', e);
			stream.pipe(istream);
		} catch (error) {
			e(error);
		}
	}));
}
開發者ID:joelday,項目名稱:vscode,代碼行數:32,代碼來源:zip.ts

示例9: test

	test('Migrate Data', async () => {
		class StorageTestEnvironmentService extends EnvironmentService {

			constructor(private workspaceStorageFolderPath: string, private _extensionsPath) {
				super(parseArgs(process.argv), process.execPath);
			}

			get workspaceStorageHome(): string {
				return this.workspaceStorageFolderPath;
			}

			get extensionsPath(): string {
				return this._extensionsPath;
			}
		}

		const storageDir = uniqueStorageDir();
		await mkdirp(storageDir);

		const storage = new StorageService(new InMemoryStorageDatabase(), new NullLogService(), new StorageTestEnvironmentService(storageDir, storageDir));
		await storage.initialize({ id: String(Date.now()) });

		storage.store('bar', 'foo', StorageScope.WORKSPACE);
		storage.store('barNumber', 55, StorageScope.WORKSPACE);
		storage.store('barBoolean', true, StorageScope.GLOBAL);

		await storage.migrate({ id: String(Date.now() + 100) });

		equal(storage.get('bar', StorageScope.WORKSPACE), 'foo');
		equal(storage.getInteger('barNumber', StorageScope.WORKSPACE), 55);
		equal(storage.getBoolean('barBoolean', StorageScope.GLOBAL), true);

		await storage.close();
		await del(storageDir, tmpdir());
	});
開發者ID:donaldpipowitch,項目名稱:vscode,代碼行數:35,代碼來源:storageService.test.ts


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