How to use the @nrwl/workspace.updateJsonInTree function in @nrwl/workspace

To help you get started, weโ€™ve selected a few @nrwl/workspace 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 nrwl / nx / packages / angular / src / schematics / application / application.ts View on Github external
return (host: Tree) => {
    // patching the spec file because of a bug in the CLI application schematic
    // it hardcodes "app" in the e2e tests
    const spec = `${options.e2eProjectRoot}/src/app.e2e-spec.ts`;
    const content = host.read(spec).toString();
    host.overwrite(
      spec,
      content.replace('my-app app is running!', `Welcome to ${options.name}!`)
    );

    return chain([
      updateJsonInTree(getWorkspacePath(host), json => {
        const project = {
          root: options.e2eProjectRoot,
          projectType: 'application',
          architect: {
            e2e: json.projects[options.name].architect.e2e,
            lint: {
              builder: '@angular-devkit/build-angular:tslint',
              options: {
                tsConfig: `${options.e2eProjectRoot}/tsconfig.e2e.json`,
                exclude: [
                  '**/node_modules/**',
                  '!' + join(normalize(options.e2eProjectRoot), '**')
                ]
              }
            }
          }
github nstudio / xplat / packages / workspace / src / utils / xplat.ts View on Github external
export function updateLint(host: Tree, context: SchematicContext) {
  const prefix = getPrefix();

  return updateJsonInTree('tslint.json', json => {
    json.rules = json.rules || {};
    // remove forin rule as collides with LogService
    delete json.rules['forin'];
    // adjust console rules to work with LogService
    json.rules['no-console'] = [true, 'debug', 'time', 'timeEnd', 'trace'];
    json.rules['directive-selector'] = [true, 'attribute', prefix, 'camelCase'];
    json.rules['component-selector'] = [true, 'element', prefix, 'kebab-case'];

    return json;
  })(host, context);
}
github nrwl / nx / packages / schematics / migrations / update-7-0-0 / update-7-0-0.spec.ts View on Github external
it('should update ng-packagr dependencies', async () => {
    initialTree = await schematicRunner
      .callRule(
        updateJsonInTree('package.json', json => {
          json.devDependencies = {
            ...json.devDependencies,
            'ng-packagr': '^3.0.0'
          };

          return json;
        }),
        initialTree
      )
      .toPromise();
    const result = await schematicRunner
      .runSchematicAsync('update-7.0.0', {}, initialTree)
      .toPromise();

    const devDependencies = JSON.parse(result.readContent('package.json'))
      .devDependencies;
github nrwl / nx / packages / schematics / migrations / update-8-0-0 / update-8-0-0.spec.ts View on Github external
it('should be set to @nrwl/nest if @nestjs/core is present', async () => {
      initialTree = await schematicRunner
        .callRule(
          updateJsonInTree('package.json', json => ({
            ...json,
            dependencies: {
              '@nestjs/core': '5.6.0',
              express: '4.16.3'
            }
          })),
          initialTree
        )
        .toPromise();
      const tree = await schematicRunner
        .runSchematicAsync('update-8.0.0', {}, initialTree)
        .toPromise();

      const defaultCollection = readJsonInTree(tree, 'workspace.json').cli
        .defaultCollection;
      expect(defaultCollection).toEqual('@nrwl/nest');
github nrwl / nx / packages / nest / src / schematics / init / init.spec.ts View on Github external
it('should not be set if something else was set before', async () => {
      tree = await callRule(
        updateJsonInTree('workspace.json', json => {
          json.cli = {
            defaultCollection: '@nrwl/angular'
          };

          return json;
        }),
        tree
      );
      const result = await runSchematic('init', {}, tree);
      const workspaceJson = readJsonInTree(result, 'workspace.json');
      expect(workspaceJson.cli.defaultCollection).toEqual('@nrwl/angular');
    });
  });
github bennymeg / nx-electron / src / schematics / init / init.ts View on Github external
function moveDependency(): Rule {
  return updateJsonInTree('package.json', json => {
    json.dependencies = json.dependencies || {};

    delete json.dependencies['nx-electron'];
    delete json.dependencies['electron'];
    delete json.dependencies['electron-packager'];
    delete json.dependencies['rimraf'];

    return json;
  });
}
github nstudio / xplat / packages / schematics / migrations / update-7-1-0 / update-7-1-0.ts View on Github external
function updateRootPackage(tree: Tree, context: SchematicContext) {
  return updateJsonInTree('package.json', json => {
    json.scripts = json.scripts || {};
    json.dependencies = json.dependencies || {};
    json.dependencies = {
      ...json.dependencies,
      'nativescript-angular': '~7.1.0',
      'tns-core-modules': '~5.1.0'
    };
    json.devDependencies = json.devDependencies || {};
    json.devDependencies = {
      ...json.devDependencies,
      'tns-platform-declarations': '~5.1.0'
    };

    return json;
  })(tree, context);
}
github nrwl / nx / packages / angular / src / schematics / library / library.ts View on Github external
function updateNgPackage(options: NormalizedSchema): Rule {
  if (!options.publishable) {
    return noop();
  }
  const dest = `${offsetFromRoot(options.projectRoot)}dist/libs/${
    options.projectDirectory
  }`;
  return chain([
    updateJsonInTree(`${options.projectRoot}/ng-package.json`, json => {
      let $schema = json.$schema;
      if (json.$schema && json.$schema.indexOf('node_modules') >= 0) {
        $schema = `${offsetFromRoot(
          options.projectRoot
        )}${json.$schema.substring(
          json.$schema.indexOf('node_modules'),
          json.$schema.length
        )}`;
      }
      return {
        ...json,
        dest,
        $schema
      };
    })
  ]);
github nrwl / nx / packages / nest / src / schematics / init / init.ts View on Github external
function moveDependency(): Rule {
  return updateJsonInTree('package.json', json => {
    json.dependencies = json.dependencies || {};

    delete json.dependencies['@nrwl/nest'];
    return json;
  });
}
github nrwl / nx / packages / jest / src / schematics / init / init.ts View on Github external
nxVersion
} from '../../utils/versions';
import { Rule } from '@angular-devkit/schematics';
import { stripIndents } from '@angular-devkit/core/src/utils/literals';

const updatePackageJson = chain([
  addDepsToPackageJson(
    {},
    {
      '@nrwl/jest': nxVersion,
      jest: jestVersion,
      '@types/jest': jestTypesVersion,
      'ts-jest': tsJestVersion
    }
  ),
  updateJsonInTree('package.json', json => {
    json.dependencies = json.dependencies || {};
    delete json.dependencies['@nrwl/jest'];
    return json;
  })
]);

const createJestConfig = (host: Tree) => {
  if (!host.exists('jest.config.js')) {
    host.create(
      'jest.config.js',
      stripIndents`
  module.exports = {
    testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
    transform: {
      '^.+\\.(ts|js|html)$': 'ts-jest'
    },