本文整理匯總了TypeScript中vs/base/common/path.dirname函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dirname函數的具體用法?TypeScript dirname怎麽用?TypeScript dirname使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了dirname函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getCLIPath
function getCLIPath(execPath: string, appRoot: string, isBuilt: boolean): string {
// Windows
if (isWindows) {
if (isBuilt) {
return path.join(path.dirname(execPath), 'bin', `${product.applicationName}.cmd`);
}
return path.join(appRoot, 'scripts', 'code-cli.bat');
}
// Linux
if (isLinux) {
if (isBuilt) {
return path.join(path.dirname(execPath), 'bin', `${product.applicationName}`);
}
return path.join(appRoot, 'scripts', 'code-cli.sh');
}
// macOS
if (isBuilt) {
return path.join(appRoot, 'bin', 'code');
}
return path.join(appRoot, 'scripts', 'code-cli.sh');
}
示例2: mkdirp
export async function mkdirp(path: string, mode?: number, token?: CancellationToken): Promise<void> {
const mkdir = async () => {
try {
await promisify(fs.mkdir)(path, mode);
} catch (error) {
// ENOENT: a parent folder does not exist yet
if (error.code === 'ENOENT') {
return Promise.reject(error);
}
// Any other error: check if folder exists and
// return normally in that case if its a folder
try {
const fileStat = await stat(path);
if (!fileStat.isDirectory()) {
return Promise.reject(new Error(`'${path}' exists and is not a directory.`));
}
} catch (statError) {
throw error; // rethrow original error
}
}
};
// stop at root
if (path === dirname(path)) {
return Promise.resolve();
}
try {
await mkdir();
} catch (error) {
// Respect cancellation
if (token && token.isCancellationRequested) {
return Promise.resolve();
}
// ENOENT: a parent folder does not exist yet, continue
// to create the parent folder and then try again.
if (error.code === 'ENOENT') {
await mkdirp(dirname(path), mode);
return mkdir();
}
// Any other error
return Promise.reject(error);
}
}
示例3: realcaseSync
export function realcaseSync(path: string): string | null {
const dir = dirname(path);
if (path === dir) { // end recursion
return path;
}
const name = (basename(path) /* can be '' for windows drive letters */ || path).toLowerCase();
try {
const entries = readdirSync(dir);
const found = entries.filter(e => e.toLowerCase() === name); // use a case insensitive search
if (found.length === 1) {
// on a case sensitive filesystem we cannot determine here, whether the file exists or not, hence we need the 'file exists' precondition
const prefix = realcaseSync(dir); // recurse
if (prefix) {
return join(prefix, found[0]);
}
} else if (found.length > 1) {
// must be a case sensitive $filesystem
const ix = found.indexOf(name);
if (ix >= 0) { // case sensitive
const prefix = realcaseSync(dir); // recurse
if (prefix) {
return join(prefix, found[ix]);
}
}
}
} catch (error) {
// silently ignore error
}
return null;
}
示例4: download
download(from: URI, to: string = path.join(tmpdir(), generateUuid())): Promise<string> {
from = this.getUriTransformer().transformOutgoingURI(from);
const dirName = path.dirname(to);
let out: fs.WriteStream;
return new Promise<string>((c, e) => {
return mkdirp(dirName)
.then(() => {
out = fs.createWriteStream(to);
out.once('close', () => c(to));
out.once('error', e);
const uploadStream = this.channel.listen<UploadResponse>('upload', from);
const disposable = uploadStream(result => {
if (result === undefined) {
disposable.dispose();
out.end(() => c(to));
} else if (Buffer.isBuffer(result)) {
out.write(result);
} else if (typeof result === 'string') {
disposable.dispose();
out.end(() => e(result));
}
});
});
});
}
示例5: 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);
}
}));
}
示例6: test
test('resolve', async () => {
await pfs.mkdirp(path.dirname(fooBackupPath));
fs.writeFileSync(fooBackupPath, 'foo');
const model = new BackupFilesModel(service.fileService);
const resolvedModel = await model.resolve(URI.file(workspaceBackupPath));
assert.equal(resolvedModel.has(URI.file(fooBackupPath)), true);
});
示例7: test
test('copyFile - same file should throw', async () => {
const source = await service.resolveFile(URI.file(join(testDir, 'index.html')));
const targetParent = URI.file(dirname(source.resource.fsPath));
const target = targetParent.with({ path: posix.join(targetParent.path, posix.basename(source.resource.path)) });
try {
await service.copyFile(source.resource, target, true);
} catch (error) {
assert.ok(error);
}
});
示例8: test
test('resolve', () => {
return pfs.mkdirp(path.dirname(fooBackupPath)).then(() => {
fs.writeFileSync(fooBackupPath, 'foo');
const model = new BackupFilesModel();
return model.resolve(workspaceBackupPath).then(model => {
assert.equal(model.has(Uri.file(fooBackupPath)), true);
});
});
});