How to use the @angular-devkit/core.normalize 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 / angular_devkit / build_angular / src / utils / normalize-file-replacements.ts View on Github external
function normalizeFileReplacement(
  fileReplacement: FileReplacement,
  root?: Path,
): NormalizedFileReplacement {
  let replacePath: Path;
  let withPath: Path;
  if (fileReplacement.src && fileReplacement.replaceWith) {
    replacePath = normalize(fileReplacement.src);
    withPath = normalize(fileReplacement.replaceWith);
  } else if (fileReplacement.replace && fileReplacement.with) {
    replacePath = normalize(fileReplacement.replace);
    withPath = normalize(fileReplacement.with);
  } else {
    throw new Error(`Invalid file replacement: ${JSON.stringify(fileReplacement)}`);
  }

  // TODO: For 7.x should this only happen if not absolute?
  if (root) {
    replacePath = join(root, replacePath);
  }
  if (root) {
    withPath = join(root, withPath);
  }

  return { replace: replacePath, with: withPath };
}
github johandb / svg-drawing-tool / node_modules / @angular-devkit / architect / testing / test-project-host.js View on Github external
appendToFile(path, str) {
        const content = core_1.virtualFs.fileBufferToString(this.scopedSync().read(core_1.normalize(path)));
        this.scopedSync().write(core_1.normalize(path), core_1.virtualFs.stringToFileBuffer(content.concat(str)));
    }
    fileMatchExists(dir, regex) {
github angular / angular-cli / packages / angular_devkit / core / src / virtual-fs / host / memory_spec.ts View on Github external
it('makes every path absolute', () => {
    const host = new SyncDelegateHost(new SimpleMemoryHost());

    const buffer = stringToFileBuffer('hello');
    const buffer2 = stringToFileBuffer('hello 2');

    host.write(normalize('file1'), buffer);
    host.write(normalize('/sub/file2'), buffer);
    host.write(normalize('sub/file2'), buffer2);
    expect(host.isFile(normalize('file1'))).toBe(true);
    expect(host.isFile(normalize('/file1'))).toBe(true);
    expect(host.isFile(normalize('/sub/file2'))).toBe(true);
    expect(host.read(normalize('sub/file2'))).toBe(buffer2);
    expect(host.isDirectory(normalize('/sub'))).toBe(true);
    expect(host.isDirectory(normalize('sub'))).toBe(true);
  });
});
github angular / angular-cli / packages / angular_devkit / build_angular / src / utils / webpack-file-system-host-adapter.ts View on Github external
stat(path: string, callback: Callback): void {
    const p = normalize('/' + path);
    const result = this._host.stat(p);

    if (result === null) {
      const o = this._host.exists(p).pipe(
        switchMap(exists => {
          if (!exists) {
            throw new FileDoesNotExistException(p);
          }

          return this._host.isDirectory(p).pipe(
            mergeMap(isDirectory => {
              return (isDirectory ? of(0) : this._host.read(p).pipe(
                map(content => content.byteLength),
              )).pipe(
                map(size => [isDirectory, size]),
              );
github angular / angular-cli / packages / @angular / cli / utilities / config.ts View on Github external
level: 'local' | 'global' = 'local',
): experimental.workspace.Workspace | null {
  const cached = cachedWorkspaces.get(level);
  if (cached != undefined) {
    return cached;
  }

  const configPath = level === 'local' ? projectFilePath() : globalFilePath();

  if (!configPath) {
    cachedWorkspaces.set(level, null);

    return null;
  }

  const root = normalize(path.dirname(configPath));
  const file = normalize(path.basename(configPath));
  const workspace = new experimental.workspace.Workspace(
    root,
    new NodeJsSyncHost(),
  );

  workspace.loadWorkspaceFromHost(file).subscribe();
  cachedWorkspaces.set(level, workspace);

  return workspace;
}
github ngxs / schematics / src / utils / transform-options.ts View on Github external
function setOptionsValue(target, defaultSourceRoot: string) {
  target.path =
    target.path !== undefined
      ? join(normalize(defaultSourceRoot), target.path)
      : normalize(defaultSourceRoot);

  if (target.name) {
    const location: Location = new Parser().nameParser(target);
    target.name = strings.dasherize(location.name);
    target.path = join(strings.dasherize(location.path) as Path, target.name);
  }

  return target;
}
github nrwl / nx / packages / next / src / schematics / application / application.ts View on Github external
architect.serve.options = {
        ...architect.serve.options,
        customServerPath: options.server
      };
    }

    architect.export = {
      builder: '@nrwl/next:export',
      options: {
        buildTarget: `${options.projectName}:build`
      }
    };

    architect.lint = generateProjectLint(
      normalize(options.appProjectRoot),
      join(normalize(options.appProjectRoot), 'tsconfig.json'),
      options.linter
    );

    json.projects[options.projectName] = {
      root: options.appProjectRoot,
      sourceRoot: options.appProjectRoot,
      projectType: 'application',
      schematics: {},
      architect
    };

    json.defaultProject = json.defaultProject || options.projectName;

    return json;
  });
}
github rxweb / rxweb / rxweb.io / node_modules / @schematics / angular / migrations / update-6 / index.js View on Github external
if (typeof asset === 'string') {
                return core_1.normalize(appRoot + '/' + asset);
            }
            else {
                if (asset.allowOutsideOutDir) {
                    logger.warn(core_1.tags.oneLine `
              Asset with input '${asset.input}' was not migrated because it
              uses the 'allowOutsideOutDir' option which is not supported in Angular CLI 6.
            `);
                    return null;
                }
                else if (asset.output) {
                    return {
                        glob: asset.glob,
                        input: core_1.normalize(appRoot + '/' + asset.input),
                        output: core_1.normalize('/' + asset.output),
                    };
                }
                else {
                    return {
                        glob: asset.glob,
                        input: core_1.normalize(appRoot + '/' + asset.input),
                        output: '/',
                    };
                }
            }
        }
        function _buildConfigurations() {
github angular / angular-cli / packages / angular_devkit / schematics / src / tree / virtual.ts View on Github external
protected _normalizePath(path: string): Path {
    return normalize('/' + path);
  }
  protected get tree(): ReadonlyMap { return this._tree; }