本文整理汇总了TypeScript中@angular-devkit/core.relative函数的典型用法代码示例。如果您正苦于以下问题:TypeScript relative函数的具体用法?TypeScript relative怎么用?TypeScript relative使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了relative函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildRelativePath
export function buildRelativePath(from: string, to: string): string {
from = normalize(from);
to = normalize(to);
// Convert to arrays.
const fromParts = from.split('/');
const toParts = to.split('/');
// Remove file names (preserving destination)
fromParts.pop();
const toFileName = toParts.pop();
const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));
let pathPrefix = '';
// Set the path prefix for same dir or child dir, parent dir starts with `..`
if (!relativePath) {
pathPrefix = '.';
} else if (!relativePath.startsWith('.')) {
pathPrefix = `./`;
}
if (pathPrefix && !pathPrefix.endsWith('/')) {
pathPrefix += '/';
}
return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
}
示例2: resolve
const isInside = (base: Path, potential: Path): boolean => {
const absoluteBase = resolve(workspace.root, base);
const absolutePotential = resolve(workspace.root, potential);
const relativePotential = relative(absoluteBase, absolutePotential);
if (!relativePotential.startsWith('..') && !isAbsolute(relativePotential)) {
return true;
}
return false;
};
示例3: importPath
export function importPath(from: Path, to: Path): string {
const relativePath = relative(dirname(from), dirname(to));
if (relativePath.startsWith('.')) {
return relativePath;
}
if (!relativePath) {
return generateCurrentDirImport(basename(to));
}
return generateCurrentDirImport(join(relativePath, basename(to)));
}
示例4: actions
get actions(): Action[] {
const scopedActions = [];
for (const action of this._base.actions) {
if (!action.path.startsWith(this._root.scope + '/')) {
continue;
}
if (action.kind !== 'r') {
scopedActions.push({
...action,
path: join(NormalizedRoot, relative(this._root.scope, action.path)),
});
} else if (action.to.startsWith(this._root.scope + '/')) {
scopedActions.push({
...action,
path: join(NormalizedRoot, relative(this._root.scope, action.path)),
to: join(NormalizedRoot, relative(this._root.scope, action.to)),
});
}
}
return scopedActions;
}
示例5: _recursiveList
private async _recursiveList(path: Path, items: string[]): Promise<string[]> {
const fragments = await this._host.list(path).toPromise();
for (const fragment of fragments) {
const item = join(path, fragment);
if (await this._host.isDirectory(item).toPromise()) {
await this._recursiveList(item, items);
} else {
items.push('/' + relative(normalize(this.base), item));
}
}
return items;
}
示例6: normalize
.map(assetPattern => {
// Normalize string asset patterns to objects.
if (typeof assetPattern === 'string') {
const assetPath = normalize(assetPattern);
const resolvedAssetPath = resolve(root, assetPath);
// Check if the string asset is within sourceRoot.
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
throw new MissingAssetSourceRootException(assetPattern);
}
let glob: string, input: Path, output: Path;
let isDirectory = false;
try {
isDirectory = host.isDirectory(resolvedAssetPath);
} catch {
isDirectory = true;
}
if (isDirectory) {
// Folders get a recursive star glob.
glob = '**/*';
// Input directory is their original path.
input = assetPath;
} else {
// Files are their own glob.
glob = basename(assetPath);
// Input directory is their original dirname.
input = dirname(assetPath);
}
// Output directory for both is the relative path from source root to input.
output = relative(resolvedSourceRoot, resolve(root, input));
// Return the asset pattern in object format.
return { glob, input, output };
} else {
// It's already an AssetPatternObject, no need to convert.
return assetPattern;
}
});
示例7: tap
tap((output: BrowserBuilderOutput) => {
const path = relative(host.root(), join(normalize(output.outputPath), 'main.js'));
const content = virtualFs.fileBufferToString(
host.scopedSync().read(path),
);
switch (buildCount) {
case 1:
expect(content).toContain('var a = 2');
host.writeMultipleFiles({
'src/my-js-file.js': `console.log(1); export const a = 1;`,
});
break;
case 2:
expect(content).toContain('var a = 1');
break;
}
buildCount++;
}),
示例8: map
map(isDirectory => {
let glob: string, input: Path, output: Path;
if (isDirectory) {
// Folders get a recursive star glob.
glob = '**/*';
// Input directory is their original path.
input = assetPath;
} else {
// Files are their own glob.
glob = basename(assetPath);
// Input directory is their original dirname.
input = dirname(assetPath);
}
// Output directory for both is the relative path from source root to input.
output = relative(resolvedSourceRoot, resolve(root, input));
// Return the asset pattern in object format.
return { glob, input, output };
}),
示例9: return
return (host: Tree) => {
if (!options.module) {
return host;
}
const modulePath = normalize('/' + options.module);
const text = host.read(modulePath);
if (text === null) {
throw new SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const importModulePath = normalize(
`/${options.path}/`
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
+ strings.dasherize(options.name)
+ '.module',
);
const relativeDir = relative(dirname(modulePath), dirname(importModulePath));
const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
+ '/' + basename(importModulePath);
const changes = addImportToModule(source, modulePath,
strings.classify(`${options.name}Module`),
relativePath);
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
示例10: buildRelativePath
export function buildRelativePath(from: string, to: string): string {
const {
path: fromPath,
filename: fromFileName,
directory: fromDirectory,
} = parsePath(from);
const {
path: toPath,
filename: toFileName,
directory: toDirectory,
} = parsePath(to);
const relativePath = relative(fromDirectory, toDirectory);
const fixedRelativePath = relativePath.startsWith('.')
? relativePath
: `./${relativePath}`;
return !toFileName || toFileName === 'index.ts'
? fixedRelativePath
: `${
fixedRelativePath.endsWith('/')
? fixedRelativePath
: fixedRelativePath + '/'
}${convertToTypeScriptFileName(toFileName)}`;
}