• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript schematics.Tree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular-devkit/schematics.Tree的典型用法代码示例。如果您正苦于以下问题:TypeScript Tree类的具体用法?TypeScript Tree怎么用?TypeScript Tree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: createFile

function createFile(remoteFiles: Tree, { path, file }: { path: string, file: FileEntry }) {
    if (!file) {
        console.log(`missing: ${path}`)
    }

    remoteFiles.create(path, file.content);
}
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:7,代码来源:index.ts


示例2: hasNgModuleImport

export function hasNgModuleImport(tree: Tree, modulePath: string, className: string): boolean {
  const moduleFileContent = tree.read(modulePath);

  if (!moduleFileContent) {
    throw new SchematicsException(`Could not read Angular module file: ${modulePath}`);
  }

  const parsedFile = ts.createSourceFile(modulePath, moduleFileContent.toString(),
      ts.ScriptTarget.Latest, true);
  const ngModuleMetadata = findNgModuleMetadata(parsedFile);

  if (!ngModuleMetadata) {
    throw new SchematicsException(`Could not find NgModule declaration inside: "${modulePath}"`);
  }

  for (let property of ngModuleMetadata!.properties) {
    if (!ts.isPropertyAssignment(property) || property.name.getText() !== 'imports' ||
        !ts.isArrayLiteralExpression(property.initializer)) {
      continue;
    }

    if (property.initializer.elements.some(element => element.getText() === className)) {
      return true;
    }
  }

  return false;
}
开发者ID:Nodarii,项目名称:material2,代码行数:28,代码来源:ng-module-imports.ts


示例3: createAppModuleWithEffects

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;
}
开发者ID:WinGood,项目名称:platform,代码行数:30,代码来源:create-app-module.ts


示例4: createReducers

export function createReducers(tree: Tree, path?: string) {
  tree.create(
    path || '/src/app/reducers/index.ts',
    `
    import {
      ActionReducer,
      ActionReducerMap,
      createFeatureSelector,
      createSelector,
      MetaReducer
    } from '@ngrx/store';
    import { environment } from '../../environments/environment';
    
    export interface State {
    
    }
    
    export const reducers: ActionReducerMap<State> = {
    
    };
    
    
    export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : [];
  `
  );

  return tree;
}
开发者ID:WinGood,项目名称:platform,代码行数:28,代码来源:create-reducers.ts


示例5: it

  it('works', () => {
    const runner = new SchematicTestRunner('schematics', collectionPath);
    const tree = runner.runSchematic('my-full-schematic', { name: 'str' }, Tree.empty());

    // Listing files
    expect(tree.files.sort()).toEqual(['/allo', '/hola', '/test1', '/test2']);
  });
开发者ID:DevIntent,项目名称:angular-cli,代码行数:7,代码来源:index_spec.ts


示例6: Readable

    return new Observable<Tree>(obs => {
      const input = new Readable({
        encoding: 'utf8',
        read(): void {
          this.push(buffer);
          this.push(null);
        },
      });

      const chunks: Array<Buffer> = [];
      const output = new Writable({
        write(chunk: string | Buffer, encoding: string, callback: Function): void {
          chunks.push(typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk);
          callback();
        },
        final(callback: (error?: Error) => void): void {
          const full = Buffer.concat(chunks);
          host.overwrite(path, full.toString());
          callback();
          obs.next(host);
          obs.complete();
        },
      });

      input.pipe(rewriter).pipe(output);
    });
开发者ID:baconwaffles,项目名称:angular-cli,代码行数:26,代码来源:index.ts


示例7: it

 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';/);
 });
开发者ID:WinGood,项目名称:platform,代码行数:7,代码来源:index.spec.ts


示例8: it

    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.');
    });
开发者ID:Nodarii,项目名称:material2,代码行数:7,代码来源:index.spec.ts


示例9: return

  return (tree: Tree, _context: SchematicContext) => {

    const localFiles = url("./files")(_context) as Tree;
    const updateFiles = getUpdateFiles(localFiles);
    const createFiles = getCreateFiles(localFiles);

    if (updateFiles.length > 0) {
        updateFiles.forEach(f => updateFile(tree, f));
    }

    if (createFiles.length > 0) {
        createFiles.forEach(f => createFile(tree, f));
    }

    const config = tree.read(".angular-cli.json");
    if (config) {
        const asJson = JSON.parse(config.toString());
        asJson.apps[0].assets.push("config.json");
        tree.overwrite(".angular-cli.json", JSON.stringify(asJson, null, 2));
    }

    // angular 6
    const configA6 = tree.read("angular.json");
    if (configA6) {
        const asJson = JSON.parse(configA6.toString());

        Object.entries(asJson.projects).forEach(([,value] : any) => {
            const options = value.architect &&
                value.architect.build &&
                value.architect.build.options;

            const assets = options && options.assets;
            if (assets) {
                assets.push("src/config.json");
            }
            const styles = options && options.styles;
            if (styles) {
                styles.push("src/theme.css");
            }
        });

        tree.overwrite("angular.json", JSON.stringify(asJson, null, 2));
    }

    return tree;
  };
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:46,代码来源:index.ts


示例10: addPackageToPackageJson

export function addPackageToPackageJson(host: Tree, type: string, pkg: string, version: string) {
  if (host.exists('package.json')) {
    const sourceText = host.read('package.json')!.toString('utf-8');
    const json = JSON.parse(sourceText);
    if (!json[type]) {
      json[type] = {};
    }

    if (!json[type][pkg]) {
      json[type][pkg] = version;
    }

    host.overwrite('package.json', JSON.stringify(json, null, 2));
  }

  return host;
}
开发者ID:Assperia,项目名称:ionic,代码行数:17,代码来源:package.ts


示例11: findModuleFromOptions

// Looks up and finds the path to the app module (or other module if specified)
function findModuleFromOptions(host: Tree, options: ComponentOptions): Path | undefined {
    const modulePath = normalize(
      '/' + options.sourceDir + '/' + (options.appRoot) + '/' + options.module);
    const moduleBaseName = normalize(modulePath).split('/').pop();

    if (host.exists(modulePath)) {
      return normalize(modulePath);
    } else if (host.exists(modulePath + '.ts')) {
      return normalize(modulePath + '.ts');
    } else if (host.exists(modulePath + '.module.ts')) {
      return normalize(modulePath + '.module.ts');
    } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
      return normalize(modulePath + '/' + moduleBaseName + '.module.ts');
    } else {
      throw new Error('Specified module does not exist');
    }
}
开发者ID:beqom,项目名称:clarity,代码行数:18,代码来源:index.ts


示例12: it

  it('works', () => {
    const runner = new SchematicTestRunner('schematics', collectionPath);
    const tree = runner.runSchematic('add', {
      module: 'app'
    }, Tree.empty());

    expect(tree.files).toEqual(['/hello']);
  });
开发者ID:beqom,项目名称:clarity,代码行数:8,代码来源:index_spec.ts


示例13: getSourceFile

export function getSourceFile(host: Tree, path: string): ts.SourceFile {
  const buffer = host.read(path);
  if (!buffer) {
    throw new SchematicsException(`Could not find file for path: ${path}`);
  }
  const content = buffer.toString();
  return ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
}
开发者ID:TomLiu-GitHub,项目名称:ngx-weui,代码行数:8,代码来源:ast.ts


示例14: addImportToModule

function addImportToModule(
  host: Tree,
  path: string,
  symbolName: string,
  fileName: string,
) {
  const source = getTsSource(host, path);
  const change = insertImport(
    source,
    path,
    symbolName,
    fileName,
  ) as InsertChange;
  const declarationRecorder = host.beginUpdate(path);
  declarationRecorder.insertLeft(change.pos, change.toAdd);
  host.commitUpdate(declarationRecorder);
}
开发者ID:wexz,项目名称:delon,代码行数:17,代码来源:alain.ts


示例15: return

 return (tree: Tree, context: SchematicContext) => {
   debugger;
   // We pass information back to the test.
   tree.create(
     (context.schematic.description as any).extra,  // tslint:disable-line:no-any
     (context.schematic.collection.description as any).extra,  // tslint:disable-line:no-any
   );
 };
开发者ID:DevIntent,项目名称:angular-cli,代码行数:8,代码来源:factory.ts


示例16: getTsSource

function getTsSource(host: Tree, path: string): ts.SourceFile {
  const text = host.read(path);
  if (text === null) {
    throw new SchematicsException(`File ${path} does not exist.`);
  }
  const sourceText = text.toString('utf-8');
  return ts.createSourceFile(path, sourceText, ts.ScriptTarget.Latest, true);
}
开发者ID:wexz,项目名称:delon,代码行数:8,代码来源:alain.ts


示例17: return

 return (host: Tree) => {
   const gitignore = '/.gitignore';
   if (!host.exists(gitignore)) {
     return host;
   }
   const gitIgnoreContent = host.read(gitignore).toString();
   if (gitIgnoreContent.includes('\n/bazel-out\n')) {
     return host;
   }
   const compiledOutput = '# compiled output\n';
   const index = gitIgnoreContent.indexOf(compiledOutput);
   const insertionIndex = index >= 0 ? index + compiledOutput.length : gitIgnoreContent.length;
   const recorder = host.beginUpdate(gitignore);
   recorder.insertRight(insertionIndex, '/bazel-out\n');
   host.commitUpdate(recorder);
   return host;
 };
开发者ID:bestao,项目名称:angular,代码行数:17,代码来源:index.ts


示例18: overwriteTargetBuilder

 /** Overwrites a target builder for the workspace in the given tree */
 function overwriteTargetBuilder(tree: Tree, targetName: string, newBuilder: string) {
   const workspace = getWorkspace(tree);
   const project = getProjectFromWorkspace(workspace);
   const targetConfig = project.architect && project.architect[targetName] ||
                        project.targets && project.targets[targetName];
   targetConfig['builder'] = newBuilder;
   tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
 }
开发者ID:codef0rmer,项目名称:material2,代码行数:9,代码来源:index.spec.ts


示例19: findRoutingModule

export function findRoutingModule(tree: Tree, path: Path): Path | undefined {
  if (isOutsidePlayground(path)) {
    return;
  }

  const moduleFile = tree.getDir(path).subfiles.find(isRoutingModule);
  return moduleFile ? join(path, moduleFile) : findRoutingModule(tree, dirname(path));
}
开发者ID:kevinheader,项目名称:nebular,代码行数:8,代码来源:playground.ts


示例20: getWorkspace

export function getWorkspace(host: Tree): Workspace {
  const configBuffer = host.read(ANGULAR_CLI_WORKSPACE_PATH);
  if (configBuffer === null) {
    throw new SchematicsException('Could not find angular.json');
  }

  return JSON.parse(configBuffer.toString());
}
开发者ID:davidgabrichidze,项目名称:material2,代码行数:8,代码来源:config.ts



注:本文中的@angular-devkit/schematics.Tree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript schematics.UpdateRecorder类代码示例发布时间:2022-05-28
下一篇:
TypeScript schematics.SchematicEngine类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap