本文整理汇总了TypeScript中path.posix.basename方法的典型用法代码示例。如果您正苦于以下问题:TypeScript posix.basename方法的具体用法?TypeScript posix.basename怎么用?TypeScript posix.basename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类path.posix
的用法示例。
在下文中一共展示了posix.basename方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: factoryFor
factoryFor(original: ts.SourceFile, genFilePath: string): ts.SourceFile {
const relativePathToSource =
'./' + path.posix.basename(original.fileName).replace(TS_DTS_SUFFIX, '');
// Collect a list of classes that need to have factory types emitted for them.
const symbolNames = original
.statements
// Pick out top level class declarations...
.filter(ts.isClassDeclaration)
// which are named, exported, and have decorators.
.filter(
decl => isExported(decl) && decl.decorators !== undefined &&
decl.name !== undefined)
// Grab the symbol name.
.map(decl => decl.name !.text);
// For each symbol name, generate a constant export of the corresponding NgFactory.
// This will encompass a lot of symbols which don't need factories, but that's okay
// because it won't miss any that do.
const varLines = symbolNames.map(
name => `export const ${name}NgFactory = new i0.ɵNgModuleFactory(${name});`);
const sourceText = [
// This might be incorrect if the current package being compiled is Angular core, but it's
// okay to leave in at type checking time. TypeScript can handle this reference via its path
// mapping, but downstream bundlers can't. If the current package is core itself, this will be
// replaced in the factory transformer before emit.
`import * as i0 from '@angular/core';`,
`import {${symbolNames.join(', ')}} from '${relativePathToSource}';`,
...varLines,
].join('\n');
return ts.createSourceFile(
genFilePath, sourceText, original.languageVersion, true, ts.ScriptKind.TS);
}
示例2: generate
generate(genFilePath: string, readFile: (fileName: string) => ts.SourceFile | null): ts.SourceFile
|null {
const originalPath = this.map.get(genFilePath) !;
const original = readFile(originalPath);
if (original === null) {
return null;
}
const relativePathToSource =
'./' + path.posix.basename(original.fileName).replace(TS_DTS_SUFFIX, '');
// Collect a list of classes that need to have factory types emitted for them. This list is
// overly broad as at this point the ts.TypeChecker hasn't been created, and can't be used to
// semantically understand which decorated types are actually decorated with Angular decorators.
//
// The exports generated here are pruned in the factory transform during emit.
const symbolNames = original
.statements
// Pick out top level class declarations...
.filter(ts.isClassDeclaration)
// which are named, exported, and have decorators.
.filter(
decl => isExported(decl) && decl.decorators !== undefined &&
decl.name !== undefined)
// Grab the symbol name.
.map(decl => decl.name !.text);
let sourceText = '';
if (symbolNames.length > 0) {
// For each symbol name, generate a constant export of the corresponding NgFactory.
// This will encompass a lot of symbols which don't need factories, but that's okay
// because it won't miss any that do.
const varLines = symbolNames.map(
name => `export const ${name}NgFactory = new i0.ɵNgModuleFactory(${name});`);
sourceText = [
// This might be incorrect if the current package being compiled is Angular core, but it's
// okay to leave in at type checking time. TypeScript can handle this reference via its path
// mapping, but downstream bundlers can't. If the current package is core itself, this will
// be replaced in the factory transformer before emit.
`import * as i0 from '@angular/core';`,
`import {${symbolNames.join(', ')}} from '${relativePathToSource}';`,
...varLines,
].join('\n');
}
// Add an extra export to ensure this module has at least one. It'll be removed later in the
// factory transformer if it ends up not being needed.
sourceText += '\nexport const ɵNonEmptyModule = true;';
const genFile = ts.createSourceFile(
genFilePath, sourceText, original.languageVersion, true, ts.ScriptKind.TS);
if (original.moduleName !== undefined) {
genFile.moduleName =
generatedModuleName(original.moduleName, original.fileName, '.ngfactory');
}
return genFile;
}
示例3: getUpdateFile
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
const basePath = this.getBasePath()
// space is not supported on GitHub
const name = path.posix.basename(versionInfo.path).replace(/ /g, "-")
return {
name: name,
url: `https://github.com${basePath}/download/v${versionInfo.version}/${name}`,
sha2: versionInfo.sha2,
}
}
示例4: getFileList
return getFileList(updateInfo).map(it => {
const name = path.posix.basename(it.url).replace(/ /g, "-")
const asset = updateInfo.assets.find(it => it != null && it.name === name)
if (asset == null) {
throw newError(`Cannot find asset "${name}" in: ${JSON.stringify(updateInfo.assets, null, 2)}`, "ERR_UPDATER_ASSET_NOT_FOUND")
}
return {
url: new URL(asset.url),
info: it,
}
})
示例5: copyToAppDir
export async function copyToAppDir(folderName: string, inputFilePath: string, fileType: availableFileTypes): Promise<string> {
if (! await exists(inputFilePath)) {
throw new Error('The file does not exist: ' + inputFilePath)
} else if (await isDirectory(inputFilePath)) {
throw new Error('You can only store files, no directories')
}
const targetFolder = await ensureFolderExists(await getFilePath(folderName, fileType))
const filename = posix.basename(inputFilePath)
const targetFilePath = `${targetFolder}/${encode(filename)}`
return await copyFile(inputFilePath, targetFilePath)
}
示例6: getUpdateFile
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
if (isUseOldMacProvider()) {
return versionInfo as any
}
// space is not supported on GitHub
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
return {
name,
url: formatUrl({path: this.getBaseDownloadPath(versionInfo.version, name), ...this.baseUrl} as any),
sha2: versionInfo.sha2,
sha512: versionInfo.sha512,
}
}
示例7: hasMetadataFile
// TODO - consider nested node_modules
/**
* Check whether the given folder needs to be included in the ngcc compilation.
* We do not care about folders that are:
*
* - symlinks
* - node_modules
* - do not contain a package.json
* - do not have a typings property in package.json
* - do not have an appropriate metadata.json file
*
* @param folderPath The absolute path to the folder.
*/
function hasMetadataFile(folderPath: string): boolean {
const folderName = path.basename(folderPath);
if (folderName === 'node_modules' || lstatSync(folderPath).isSymbolicLink()) {
return false;
}
const packageJsonPath = path.join(folderPath, 'package.json');
if (!existsSync(packageJsonPath)) {
return false;
}
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
if (!packageJson.typings) {
return false;
}
// TODO: avoid if packageJson contains built marker
const metadataPath =
path.join(folderPath, packageJson.typings.replace(/\.d\.ts$/, '.metadata.json'));
return existsSync(metadataPath);
}
示例8: getUpdateFile
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
if (isUseOldMacProvider()) {
return versionInfo as any
}
// space is not supported on GitHub
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
const result: FileInfo = {
name,
url: newUrlFromBase(this.getBaseDownloadPath(versionInfo.version, name), this.baseUrl).href,
sha512: versionInfo.sha512,
}
const packages = versionInfo.packages
const packageInfo = packages == null ? null : (packages[process.arch] || packages.ia32)
if (packageInfo != null) {
result.packageInfo = {
...packageInfo,
file: newUrlFromBase(this.getBaseDownloadPath(versionInfo.version, packageInfo.file), this.baseUrl).href,
}
}
return result
}
示例9: getModuleId
export function getModuleId(url: string) {
const baseName = path.basename(url);
const lastDotIndex = baseName.lastIndexOf('.');
const mainName = baseName.substring(0, lastDotIndex);
return dashToCamelCase(mainName);
}
示例10:
return service.resolveFile(uri.file(path.join(testDir, 'index.html'))).then(source => {
const targetParent = uri.file(path.dirname(source.resource.fsPath));
const target = targetParent.with({ path: path.posix.join(targetParent.path, path.posix.basename(source.resource.path)) });
return service.copyFile(source.resource, target, true).then(copied => {
assert.equal(copied.size, source.size);
});
});