Exemplo n.º 1
0
 it('should find a module', () => {
   tree.create('/projects/my-proj/src/app.module.ts', '');
   options.module = 'app.module.ts';
   options.path = '/projects/my-proj/src';
   const modPath = findModuleFromOptions(tree, options);
   expect(modPath).toEqual('/projects/my-proj/src/app.module.ts' as Path);
 });
Exemplo n.º 2
0
 it('should find a module if nameFormatter is provided', () => {
   tree.create('/projects/my-proj/src/app_test.module.ts', '');
   options.path = '/projects/my-proj/src';
   options.nameFormatter = strings.underscore;
   const modPath = findModuleFromOptions(tree, options);
   expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
 });
Exemplo n.º 3
0
    it('should not overwrite existing custom theme files', () => {
      appTree.create('/projects/material/custom-theme.scss', 'custom-theme');
      const tree = runner.runSchematic('ng-add-setup-project', {theme: 'custom'}, appTree);

      expect(tree.readContent('/projects/material/custom-theme.scss')).toBe('custom-theme',
          'Expected the old custom theme content to be unchanged.');
    });
Exemplo n.º 4
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;
  };
Exemplo n.º 5
0
/**
 * Insert a custom theme to project style file. If no valid style file could be found, a new
 * Scss file for the custom theme will be created.
 */
function insertCustomTheme(project: WorkspaceProject, projectName: string, host: Tree,
                           workspace: WorkspaceSchema) {

  const stylesPath = getProjectStyleFile(project, 'scss');
  const themeContent = createCustomTheme(projectName);

  if (!stylesPath) {
    if (!project.sourceRoot) {
      throw new SchematicsException(`Could not find source root for project: "${projectName}". ` +
        `Please make sure that the "sourceRoot" property is set in the workspace config.`);
    }

    // Normalize the path through the devkit utilities because we want to avoid having
    // unnecessary path segments and windows backslash delimiters.
    const customThemePath = normalize(join(project.sourceRoot, defaultCustomThemeFilename));

    if (host.exists(customThemePath)) {
      console.warn(yellow(`Cannot create a custom Angular Material theme because
          ${bold(customThemePath)} already exists. Skipping custom theme generation.`));
      return;
    }

    host.create(customThemePath, themeContent);
    addThemeStyleToTarget(project, 'build', host, customThemePath, workspace);
    return;
  }

  const insertion = new InsertChange(stylesPath, 0, themeContent);
  const recorder = host.beginUpdate(stylesPath);

  recorder.insertLeft(insertion.pos, insertion.toAdd);
  host.commitUpdate(recorder);
}
Exemplo n.º 6
0
  return (host: Tree, context: SchematicContext) => {
    const name = options.name || getWorkspace(host).defaultProject;
    if (!name) {
      throw new Error('Please provide a name for Bazel workspace');
    }
    validateProjectName(name);

    if (!host.exists('yarn.lock')) {
      host.create('yarn.lock', '');
    }

    const workspaceVersions = {
      'RULES_NODEJS_VERSION': '0.18.6',
      'RULES_NODEJS_SHA256': '1416d03823fed624b49a0abbd9979f7c63bbedfd37890ddecedd2fe25cccebc6',
      'RULES_SASS_VERSION': '1.17.0',
    };

    return mergeWith(apply(url('./files'), [
      applyTemplates({
        utils: strings,
        name,
        'dot': '.', ...workspaceVersions,
        routing: hasRoutingModule(host),
        sass: hasSassStylesheet(host),
      }),
    ]));
  };
Exemplo n.º 7
0
 it('should import Store into the component', () => {
   const options = { ...defaultOptions, state: 'reducers' };
   appTree.create('/src/app/reducers', '');
   const tree = schematicRunner.runSchematic('container', options, appTree);
   const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
   expect(content).toMatch(/import\ {\ Store\ }\ from\ '@ngrx\/store';/);
 });
Exemplo n.º 8
0
 it('should import the state path if provided', () => {
   const options = { ...defaultOptions, state: 'reducers' };
   appTree.create('/src/app/reducers', '');
   const tree = schematicRunner.runSchematic('container', options, appTree);
   const content = getFileContent(tree, '/src/app/foo/foo.component.ts');
   expect(content).toMatch(/import \* as fromStore from '..\/reducers';/);
 });
function createFile(remoteFiles: Tree, { path, file }: { path: string, file: FileEntry }) {
    if (!file) {
        console.log(`missing: ${path}`)
    }

    remoteFiles.create(path, file.content);
}
Exemplo n.º 10
0
export function createAppModuleWithEffects(
  tree: Tree,
  path: string,
  effects?: string
): Tree {
  tree.create(
    path || '/src/app/app.module.ts',
    `
    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { EffectsModule } from '@ngrx/effects';

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        ${effects}
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
  `
  );

  return tree;
}