How to use the @angular-devkit/core.relative function in @angular-devkit/core

To help you get started, we’ve selected a few @angular-devkit/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular-cli / packages / schematics / angular / utility / find-module.ts View on Github external
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;
}
github manfredsteyer / angular-crud / angular-crud / src / schematics-angular-utils / find-module.ts View on Github external
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;
}
github angular / angular-cli / packages / angular_devkit / architect / testing / test-project-host.ts View on Github external
concatMap(from => {
        const to = join(this.root(), relative(this._templateRoot, from));

        return this.read(from).pipe(
          concatMap(buffer => this.write(to, buffer)),
        );
      }),
      map(() => { }),
github rxweb / rxweb / rxweb.io / node_modules / @schematics / angular / application / index.js View on Github external
styleext: options.style,
            viewEncapsulation: options.viewEncapsulation,
        };
        const workspace = config_1.getWorkspace(host);
        let newProjectRoot = workspace.newProjectRoot;
        let appDir = `${newProjectRoot}/${options.name}`;
        let sourceRoot = `${appDir}/src`;
        let sourceDir = `${sourceRoot}/app`;
        let relativePathToWorkspaceRoot = appDir.split('/').map(x => '..').join('/');
        const rootInSrc = options.projectRoot !== undefined;
        if (options.projectRoot !== undefined) {
            newProjectRoot = options.projectRoot;
            appDir = `${newProjectRoot}/src`;
            sourceRoot = appDir;
            sourceDir = `${sourceRoot}/app`;
            relativePathToWorkspaceRoot = core_1.relative(core_1.normalize('/' + sourceRoot), core_1.normalize('/'));
            if (relativePathToWorkspaceRoot === '') {
                relativePathToWorkspaceRoot = '.';
            }
        }
        const tsLintRoot = appDir;
        const e2eOptions = {
            name: `${options.name}-e2e`,
            relatedAppName: options.name,
            rootSelector: appRootSelector,
        };
        if (options.projectRoot !== undefined) {
            e2eOptions.projectRoot = 'e2e';
        }
        return schematics_1.chain([
            addAppToWorkspaceFile(options, workspace),
            options.skipPackageJson ? schematics_1.noop() : addDependenciesToPackageJson(),
github sbb-design-systems / sbb-angular / schematics / example-migration / index.js View on Github external
directory.visit((path, entry) => {
                if (entry) {
                    const rel = core.relative(directory.path, path).replace(dir, renamed);
                    const originalComponentName = componentName(dir);
                    const renamedComponentName = componentName(renamed);
                    const content = entry.content
                        .toString('utf8')
                        .replace(new RegExp(dir, 'g'), renamed)
                        .replace(originalComponentName, renamedComponentName);
                    const target = core.join(targetDir.path, renamed, rel);
                    if (tree.exists(target)) {
                        tree.overwrite(target, content);
                    }
                    else {
                        tree.create(target, content);
                        moduleContent = moduleContent
                            .replace(`${dir}/${dir}.component`, `${renamed}/${renamed}.component`)
                            .replace(new RegExp(originalComponentName, 'g'), renamedComponentName);
                    }
github angular / angular-cli / packages / angular_devkit / build_angular / src / angular-cli-files / utilities / service-worker / index.ts View on Github external
private async _recursiveList(path: Path, items: string[]): Promise {
    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;
  }
}
github ngrx / store-devtools-builds / schematics-core / utility / find-module.js View on Github external
function buildRelativePath(from, to) {
        const { path: fromPath, filename: fromFileName, directory: fromDirectory, } = parsePath(from);
        const { path: toPath, filename: toFileName, directory: toDirectory, } = parsePath(to);
        const relativePath = core_1.relative(fromDirectory, toDirectory);
        const fixedRelativePath = relativePath.startsWith('.')
            ? relativePath
            : `./${relativePath}`;
        return !toFileName || toFileName === 'index.ts'
            ? fixedRelativePath
            : `${fixedRelativePath.endsWith('/')
                ? fixedRelativePath
                : fixedRelativePath + '/'}${convertToTypeScriptFileName(toFileName)}`;
    }
    exports.buildRelativePath = buildRelativePath;
github fossasia / susper.com / node_modules / @schematics / angular / module / index.js View on Github external
return (host) => {
        if (!options.module) {
            return host;
        }
        const modulePath = core_1.normalize('/' + options.module);
        const text = host.read(modulePath);
        if (text === null) {
            throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
        }
        const sourceText = text.toString('utf-8');
        const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
        const importModulePath = core_1.normalize(`/${options.sourceDir}/${options.path}/`
            + (options.flat ? '' : stringUtils.dasherize(options.name) + '/')
            + stringUtils.dasherize(options.name)
            + '.module');
        const relativeDir = core_1.relative(core_1.dirname(modulePath), core_1.dirname(importModulePath));
        const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
            + '/' + core_1.basename(importModulePath);
        const changes = ast_utils_1.addImportToModule(source, modulePath, stringUtils.classify(`${options.name}Module`), relativePath);
        const recorder = host.beginUpdate(modulePath);
        for (const change of changes) {
            if (change instanceof change_1.InsertChange) {
                recorder.insertLeft(change.pos, change.toAdd);
            }
        }
        host.commitUpdate(recorder);
        return host;
    };
}
github akveo / nebular / schematics / utils / path.ts View on Github external
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)));
}
github nestjs / schematics / src / utils / path.solver.ts View on Github external
public relative(from: Path, to: Path): string {
    const placeholder = '/placeholder';
    const relativeDir = relative(
      dirname((placeholder + from) as Path),
      dirname((placeholder + to) as Path),
    );
    return (relativeDir.startsWith('.')
      ? relativeDir
      : './' + relativeDir
    ).concat(relativeDir.length === 0 ? basename(to) : '/' + basename(to));
  }
}