How to use @nrwl/workspace - 10 common examples

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 nstudio / xplat / packages / xplat / src / schematics / application / index.spec.ts View on Github external
fit('should create Nx node', async () => {
      appTree = Tree.empty();
      appTree = createEmptyWorkspace(appTree);
      const options: XplatHelpers.Schema = { ...defaultOptions };
      options.platforms = 'node';

      const tree = await runSchematic('app', options, appTree);
      const files = tree.files;
      // console.log('files:', files);

      expect(tree.exists('/apps/node-sample/src/main.ts')).toBeTruthy();

      let fileContent = getFileContent(tree, '/apps/node-sample/src/main.ts');
      // console.log(fileContent);
      expect(
        fileContent.indexOf(`console.log('Hello World!')`)
      ).toBeGreaterThanOrEqual(0);
    });
github nstudio / xplat / packages / angular / src / schematics / feature / index.spec.ts View on Github external
it('should create feature module for specified project WITH Routing and adjustSandbox', async () => {
    const options: XplatFeatureHelpers.Schema = {
      ...defaultOptions,
      projects: 'nativescript-viewer'
    };
    appTree = Tree.empty();
    appTree = createXplatWithNativeScriptWeb(appTree, true);

    // manually update home.component to prep for sandobx
    const homeCmpPath = `/apps/nativescript-viewer/src/features/home/components/home.component.html`;
    createOrUpdate(appTree, homeCmpPath, sandboxHomeSetup());
    // console.log('homecmp:', getFileContent(tree, homeCmpPath));

    options.onlyProject = true;
    options.adjustSandbox = true;
    options.routing = true;
    options.name = 'foo-with-dash';
    let tree = await runSchematic('feature', options, appTree);
    // console.log('---------')
    // console.log('homecmp:', getFileContent(tree, homeCmpPath));
  });
});
github nstudio / xplat / packages / xplat / src / utils / general.ts View on Github external
export function updateJsonFile(tree: Tree, path: string, jsonData: any) {
  try {
    // if (tree.exists(path)) {
    tree.overwrite(path, serializeJson(jsonData));
    // }
    return tree;
  } catch (err) {
    // console.warn(err);
    throw new SchematicsException(`${path}: ${err}`);
  }
}
github nrwl / nx / packages / react / src / utils / ast-utils.ts View on Github external
ts.SyntaxKind.CallExpression
  ) as ts.CallExpression[];

  for (const expr of calls) {
    const inner = expr.expression;
    if (
      ts.isPropertyAccessExpression(inner) &&
      /ReactDOM/i.test(inner.expression.getText()) &&
      inner.name.getText() === 'render'
    ) {
      return expr;
    }
  }

  // 2. Try to find render from 'react-dom'.
  const imports = findNodes(
    source,
    ts.SyntaxKind.ImportDeclaration
  ) as ts.ImportDeclaration[];
  const hasRenderImport = imports.some(
    i =>
      i.moduleSpecifier.getText().includes('react-dom') &&
      /\brender\b/.test(i.importClause.namedBindings.getText())
  );
  if (hasRenderImport) {
    const calls = findNodes(
      source,
      ts.SyntaxKind.CallExpression
    ) as ts.CallExpression[];
    for (const expr of calls) {
      if (expr.expression.getText() === 'render') {
        return expr;
github nrwl / nx / packages / react / src / utils / ast-utils.ts View on Github external
export function findMainRenderStatement(
  source: ts.SourceFile
): ts.CallExpression | null {
  // 1. Try to find ReactDOM.render.
  const calls = findNodes(
    source,
    ts.SyntaxKind.CallExpression
  ) as ts.CallExpression[];

  for (const expr of calls) {
    const inner = expr.expression;
    if (
      ts.isPropertyAccessExpression(inner) &&
      /ReactDOM/i.test(inner.expression.getText()) &&
      inner.name.getText() === 'render'
    ) {
      return expr;
    }
  }

  // 2. Try to find render from 'react-dom'.
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 / cypress / src / schematics / cypress-project / cypress-project.ts View on Github external
return (): Rule => {
    // host.delete(`${options.projectRoot}/tsconfig.e2e.json`);
    return mergeWith(
      apply(url('./files'), [
        template({
          tmpl: '',
          ...options,
          offsetFromRoot: offsetFromRoot(options.projectRoot)
        }),
        move(options.projectRoot)
      ])
    );
  };
}
github nrwl / nx / packages / angular / src / schematics / library / library.ts View on Github external
options.projectDirectory
        }').then(module => module.${options.moduleName})}`
      )
    ]);

    const tsConfig = findClosestTsConfigApp(host, options.parentModule);
    if (tsConfig) {
      const tsConfigAppSource = host.read(tsConfig)!.toString('utf-8');
      const tsConfigAppFile = ts.createSourceFile(
        tsConfig,
        tsConfigAppSource,
        ts.ScriptTarget.Latest,
        true
      );

      const offset = offsetFromRoot(path.dirname(tsConfig));
      insert(host, tsConfig, [
        ...addIncludeToTsConfig(
          tsConfig,
          tsConfigAppFile,
          `\n    , "${offset}${options.projectRoot}/src/index.ts"\n`
        )
      ]);
    } else {
      // we should warn the user about not finding the config
    }

    return host;
  };
}
github nrwl / nx / packages / schematics / migrations / legacy-migrations / 20171205-remove-npmscope-from-tslintjson.ts View on Github external
run: () => {
    updateJsonFile('tslint.json', json => {
      const ruleName = 'nx-enforce-module-boundaries';
      const rule = ruleName in json.rules ? json.rules[ruleName] : null;

      // Only modify when the rule is configured with optional arguments
      if (
        Array.isArray(rule) &&
        typeof rule[1] === 'object' &&
        rule[1] !== null
      ) {
        rule[1].npmScope = undefined;
      }
    });
  }
};