Example #1
0
  return (tree: Tree, context: SchematicContext) => {
    for (let file of options.deleteFiles) {
      tree.delete(file);
    }

    context.addTask(new RunSchematicTask('ng-post-post-update', {}));
  };
Example #2
0
  return (host: Tree, context: SchematicContext) => {
    const oldConfigPath = getConfigPath(host);
    const configPath = normalize('angular.json');
    context.logger.info(`Updating configuration`);
    const config: JsonObject = {
      '$schema': './node_modules/@angular/cli/lib/config/schema.json',
      version: 1,
      newProjectRoot: 'projects',
      projects: extractProjectsConfig(oldConfig, host, logger),
    };
    const defaultProject = extractDefaultProject(oldConfig);
    if (defaultProject !== null) {
      config.defaultProject = defaultProject;
    }
    const cliConfig = extractCliConfig(oldConfig);
    if (cliConfig !== null) {
      config.cli = cliConfig;
    }
    const schematicsConfig = extractSchematicsConfig(oldConfig);
    if (schematicsConfig !== null) {
      config.schematics = schematicsConfig;
    }
    const targetsConfig = extractTargetsConfig(oldConfig);
    if (targetsConfig !== null) {
      config.architect = targetsConfig;
    }

    context.logger.info(`Removing old config file (${oldConfigPath})`);
    host.delete(oldConfigPath);
    context.logger.info(`Writing config file (${configPath})`);
    host.create(configPath, JSON.stringify(config, null, 2));

    return host;
  };
Example #3
0
  return (host: Tree, context: SchematicContext) => {
    if (host.exists(npmrc)) {
      host.delete(npmrc);
    }

    if (options.type === 'remove') {
      return ;
    }

    host.create(npmrc, `sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org`);
  };
Example #4
0
File: file.ts Project: wexz/delon
export function overwriteFile(
  host: Tree,
  filePath: string,
  sourcePath?: string,
  overwrite = false,
): Tree {
  const isExists = host.exists(filePath);
  if (overwrite || isExists) {
    try {
      const buffer = fs.readFileSync(sourcePath);
      const content = buffer ? buffer.toString('utf-8') : '';
      if (overwrite) {
        if (isExists) {
          host.delete(filePath);
        }
        host.create(filePath, content);
      } else {
        host.overwrite(filePath, content);
      }
    } catch {}
  }
  return host;
}
  return (tree: Tree) => {
    const source = tree.read(polyfillPath);
    if (!source) {
      return;
    }

    // normalize line endings to increase hash match chances
    const content = source.toString().replace(/\r\n|\r/g, '\n');

    // Check if file is unmodified, if so then replace and return
    const hash = createHash('md5');
    hash.update(content);
    const digest = hash.digest('hex');
    if (knownPolyfillHashes.includes(digest)) {
      // Replace with new project polyfills file
      // This removes the need to parse and also updates all included comments

      // mergeWith overwrite doesn't work so clear out existing file
      tree.delete(polyfillPath);

      return mergeWith(
        apply(url('../../application/files/src'), [
          filter(path => path === '/polyfills.ts.template'),
          move('/polyfills.ts.template', polyfillPath),
        ]),
        MergeStrategy.Overwrite,
      );
    }

    if (!content.includes('core-js')) {
      // no action required if no mention of core-js
      return;
    }

    const sourceFile = ts.createSourceFile(polyfillPath,
      content,
      ts.ScriptTarget.Latest,
      true,
    );
    const imports = sourceFile.statements
      .filter(s => s.kind === ts.SyntaxKind.ImportDeclaration) as ts.ImportDeclaration[];

    if (imports.length === 0) { return; }

    // Start the update of the file.
    const recorder = tree.beginUpdate(polyfillPath);

    const applicationPolyfillsStart = content.indexOf(applicationPolyfillsHeader);
    const browserPolyfillsStart = content.indexOf(browserPolyfillsHeader);

    let addHeader = false;
    for (const i of imports) {
      const module = ts.isStringLiteral(i.moduleSpecifier) && i.moduleSpecifier.text;
      // We do not want to remove imports which are after the "APPLICATION IMPORTS" header.
      if (module && toDrop[module] && applicationPolyfillsStart > i.getFullStart()) {
        recorder.remove(i.getFullStart(), i.getFullWidth());
        if (i.getFullStart() <= browserPolyfillsStart) {
          addHeader = true;
        }
      }
    }

    // We've removed the header since it's part of the JSDoc of the nodes we dropped
    if (addHeader) {
      recorder.insertLeft(0, header);
    }

    tree.commitUpdate(recorder);
  };
Example #6
0
File: index.ts Project: wexz/delon
 .forEach(p => host.delete(p));
Example #7
0
File: alain.ts Project: wexz/delon
export function tryAddFile(host: Tree, path: string, content: string) {
  if (host.exists(path)) {
    host.delete(path);
  }
  host.create(path, content);
}
Example #8
0
 return (tree: Tree, context: SchematicContext) => {
   tree.delete(options.deletePath);
   context.addTask(new RunSchematicTask('ng-post-post-update', {}));
 };