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

TypeScript compiler-cli.readConfiguration函数代码示例

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

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



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

示例1: lazyRoutesTest

function lazyRoutesTest() {
  const basePath = path.join(__dirname, '../ngtools_src');
  const project = path.join(basePath, 'tsconfig-build.json');

  const config = readConfiguration(project);
  const host = ts.createCompilerHost(config.options, true);
  const program = createProgram({
    rootNames: config.rootNames,
    options: config.options, host,
  });

  config.options.basePath = basePath;
  config.options.rootDir = basePath;

  const lazyRoutes = program.listLazyRoutes('app.module#AppModule');
  const expectations: {[route: string]: string} = {
    './lazy.module#LazyModule': 'lazy.module.ts',
    './feature/feature.module#FeatureModule': 'feature/feature.module.ts',
    './feature/lazy-feature.module#LazyFeatureModule': 'feature/lazy-feature.module.ts',
    './feature.module#FeatureModule': 'feature/feature.module.ts',
    './lazy-feature-nested.module#LazyFeatureNestedModule': 'feature/lazy-feature-nested.module.ts',
    'feature2/feature2.module#Feature2Module': 'feature2/feature2.module.ts',
    './default.module': 'feature2/default.module.ts',
    'feature/feature.module#FeatureModule': 'feature/feature.module.ts'
  };

  lazyRoutes.forEach(lazyRoute => {
    const routeName = lazyRoute.route;

    // Normalize the module path and the expected module path so that these can be compared
    // on Windows where path separators are not consistent with TypeScript internal paths.
    const modulePath = path.normalize(lazyRoute.referencedModule.filePath);
    const expectedModulePath = path.normalize(path.join(basePath, expectations[routeName]));

    assert(routeName in expectations, `Found a route that was not expected: "${routeName}".`);
    assert(
        modulePath === expectedModulePath,
        `Route "${routeName}" does not point to the expected absolute path ` +
            `"${expectedModulePath}". It points to "${modulePath}"`);
  });

  // Verify that all expectations were met.
  assert.deepEqual(
      lazyRoutes.map(lazyRoute => lazyRoute.route), Object.keys(expectations),
      `Expected routes listed to be: \n` +
          `  ${JSON.stringify(Object.keys(expectations))}\n` +
          `Actual:\n` +
          `  ${JSON.stringify(Object.keys(lazyRoutes))}\n`);
}
开发者ID:Cammisuli,项目名称:angular,代码行数:49,代码来源:test_ngtools_api.ts


示例2: lazyRoutesTest

function lazyRoutesTest() {
  const basePath = path.join(__dirname, '../ngtools_src');
  const project = path.join(basePath, 'tsconfig-build.json');

  const config = readConfiguration(project);
  const host = ts.createCompilerHost(config.options, true);
  const program = ts.createProgram(config.rootNames, config.options, host);

  config.options.basePath = basePath;

  const lazyRoutes = __NGTOOLS_PRIVATE_API_2.listLazyRoutes(
      {program, host, angularCompilerOptions: config.options, entryModule: 'app.module#AppModule'});

  const expectations: {[route: string]: string} = {
    './lazy.module#LazyModule': 'lazy.module.ts',
    './feature/feature.module#FeatureModule': 'feature/feature.module.ts',
    './feature/lazy-feature.module#LazyFeatureModule': 'feature/lazy-feature.module.ts',
    './feature.module#FeatureModule': 'feature/feature.module.ts',
    './lazy-feature-nested.module#LazyFeatureNestedModule': 'feature/lazy-feature-nested.module.ts',
    'feature2/feature2.module#Feature2Module': 'feature2/feature2.module.ts',
    './default.module': 'feature2/default.module.ts',
    'feature/feature.module#FeatureModule': 'feature/feature.module.ts'
  };

  Object.keys(lazyRoutes).forEach((route: string) => {
    assert(route in expectations, `Found a route that was not expected: "${route}".`);
    assert(
        lazyRoutes[route] == path.join(basePath, expectations[route]),
        `Route "${route}" does not point to the expected absolute path ` +
            `"${path.join(basePath, expectations[route])}". It points to "${lazyRoutes[route]}"`);
  });

  // Verify that all expectations were met.
  assert.deepEqual(
      Object.keys(lazyRoutes), Object.keys(expectations), `Expected routes listed to be: \n` +
          `  ${JSON.stringify(Object.keys(expectations))}\n` +
          `Actual:\n` +
          `  ${JSON.stringify(Object.keys(lazyRoutes))}\n`);
}
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:39,代码来源:test_ngtools_api.ts


示例3: main

/**
 * Main method.
 * Standalone program that executes the real codegen and tests that
 * ngsummary.json files are used for libraries.
 */
function main() {
  console.log(`testing usage of ngsummary.json files in libraries...`);
  const basePath = path.resolve(__dirname, '..');
  const project = path.resolve(basePath, 'tsconfig-build.json');
  const readFiles: string[] = [];
  const writtenFiles: {fileName: string, content: string}[] = [];

  class AssertingHostContext extends NodeCompilerHostContext {
    readFile(fileName: string): string {
      if (/.*\/node_modules\/.*/.test(fileName) && !/.*ngsummary\.json$/.test(fileName) &&
          !/package\.json$/.test(fileName)) {
        // Only allow to read summaries and package.json files from node_modules
        // TODO (mhevery): Fix this. TypeScript.d.ts does not allow returning null.
        return null !;
      }
      readFiles.push(path.relative(basePath, fileName));
      return super.readFile(fileName);
    }
    readResource(s: string): Promise<string> {
      readFiles.push(path.relative(basePath, s));
      return super.readResource(s);
    }
  }

  const config = readConfiguration(project);
  config.options.basePath = basePath;
  // This flag tells ngc do not recompile libraries.
  config.options.generateCodeForLibraries = false;

  console.log(`>>> running codegen for ${project}`);
  codegen(
      config,
      (host) => {
        host.writeFile = (fileName: string, content: string) => {
          fileName = path.relative(basePath, fileName);
          writtenFiles.push({fileName, content});
        };
        return new AssertingHostContext();
      })
      .then((exitCode: any) => {
        console.log(`>>> codegen done, asserting read files`);
        assertSomeFileMatch(readFiles, /^node_modules\/.*\.ngsummary\.json$/);
        assertNoFileMatch(readFiles, /^node_modules\/.*\.metadata.json$/);
        assertNoFileMatch(readFiles, /^node_modules\/.*\.html$/);
        assertNoFileMatch(readFiles, /^node_modules\/.*\.css$/);

        assertNoFileMatch(readFiles, /^src\/.*\.ngsummary\.json$/);
        assertSomeFileMatch(readFiles, /^src\/.*\.html$/);
        assertSomeFileMatch(readFiles, /^src\/.*\.css$/);

        console.log(`>>> asserting written files`);
        assertWrittenFile(writtenFiles, /^src\/module\.ngfactory\.ts$/, /class MainModuleInjector/);

        console.log(`done, no errors.`);
        process.exit(exitCode);
      })
      .catch((e: any) => {
        console.error(e.stack);
        console.error('Compilation failed');
        process.exit(1);
      });
}
开发者ID:angularbrasil,项目名称:angular,代码行数:67,代码来源:test_summaries.ts


示例4: codeGenTest

function codeGenTest(forceError = false) {
  const basePath = path.join(__dirname, '../ngtools_src');
  const srcPath = path.join(__dirname, '../src');
  const project = path.join(basePath, 'tsconfig-build.json');
  const readResources: string[] = [];
  const wroteFiles: string[] = [];

  const config = readConfiguration(project);
  const delegateHost = ts.createCompilerHost(config.options, true);
  const host: ts.CompilerHost = Object.assign(
      {}, delegateHost,
      {writeFile: (fileName: string, ...rest: any[]) => { wroteFiles.push(fileName); }});
  const program = ts.createProgram(config.rootNames, config.options, host);

  config.options.basePath = basePath;

  console.log(`>>> running codegen for ${project}`);
  if (forceError) {
    console.log(`>>> asserting that missingTranslation param with error value throws`);
  }
  return __NGTOOLS_PRIVATE_API_2
      .codeGen({
        basePath,
        compilerOptions: config.options, program, host,

        angularCompilerOptions: config.options,

        // i18n options.
        i18nFormat: 'xlf',
        i18nFile: path.join(srcPath, 'messages.fi.xlf'),
        locale: 'fi',
        missingTranslation: forceError ? 'error' : 'ignore',

        readResource: (fileName: string) => {
          readResources.push(fileName);
          if (!host.fileExists(fileName)) {
            throw new Error(`Compilation failed. Resource file not found: ${fileName}`);
          }
          return Promise.resolve(host.readFile(fileName));
        }
      })
      .then(() => {
        console.log(`>>> codegen done, asserting read and wrote files`);

        // Assert for each file that it has been read and each `ts` has a written file associated.
        const allFiles = glob.sync(path.join(basePath, '**/*'), {nodir: true});

        allFiles.forEach((fileName: string) => {
          // Skip tsconfig.
          if (fileName.match(/tsconfig-build.json$/)) {
            return;
          }

          // Assert that file was read.
          if (fileName.match(/\.module\.ts$/)) {
            const factory = fileName.replace(/\.module\.ts$/, '.module.ngfactory.ts');
            assert(wroteFiles.indexOf(factory) != -1, `Expected file "${factory}" to be written.`);
          } else if (fileName.match(/\.css$/) || fileName.match(/\.html$/)) {
            assert(
                readResources.indexOf(fileName) != -1,
                `Expected resource "${fileName}" to be read.`);
          }
        });

        console.log(`done, no errors.`);
      })
      .catch((e: Error) => {
        if (forceError) {
          assert(
              e.message.match(`Missing translation for message`),
              `Expected error message for missing translations`);
          console.log(`done, error catched`);
        } else {
          console.error(e.stack);
          console.error('Compilation failed');
          throw e;
        }
      });
}
开发者ID:angularbrasil,项目名称:angular,代码行数:79,代码来源:test_ngtools_api.ts


示例5: i18nTest

function i18nTest() {
  const basePath = path.join(__dirname, '../ngtools_src');
  const project = path.join(basePath, 'tsconfig-build.json');
  const readResources: string[] = [];
  const wroteFiles: string[] = [];

  const config = readConfiguration(project);
  const delegateHost = ts.createCompilerHost(config.options, true);
  const host: ts.CompilerHost = Object.assign(
      {}, delegateHost,
      {writeFile: (fileName: string, ...rest: any[]) => { wroteFiles.push(fileName); }});
  const program = ts.createProgram(config.rootNames, config.options, host);

  config.options.basePath = basePath;

  console.log(`>>> running i18n extraction for ${project}`);
  return __NGTOOLS_PRIVATE_API_2
      .extractI18n({
        basePath,
        compilerOptions: config.options, program, host,
        angularCompilerOptions: config.options,
        i18nFormat: 'xlf',
        locale: undefined,
        outFile: undefined,
        readResource: (fileName: string) => {
          readResources.push(fileName);
          if (!host.fileExists(fileName)) {
            throw new Error(`Compilation failed. Resource file not found: ${fileName}`);
          }
          return Promise.resolve(host.readFile(fileName));
        },
      })
      .then(() => {
        console.log(`>>> i18n extraction done, asserting read and wrote files`);

        const allFiles = glob.sync(path.join(basePath, '**/*'), {nodir: true});

        assert(wroteFiles.length == 1, `Expected a single message bundle file.`);

        assert(
            wroteFiles[0].endsWith('/ngtools_src/messages.xlf'),
            `Expected the bundle file to be "message.xlf".`);

        allFiles.forEach((fileName: string) => {
          // Skip tsconfig.
          if (fileName.match(/tsconfig-build.json$/)) {
            return;
          }

          // Assert that file was read.
          if (fileName.match(/\.css$/) || fileName.match(/\.html$/)) {
            assert(
                readResources.indexOf(fileName) != -1,
                `Expected resource "${fileName}" to be read.`);
          }
        });

        console.log(`done, no errors.`);
      })
      .catch((e: Error) => {
        console.error(e.stack);
        console.error('Extraction failed');
        throw e;
      });
}
开发者ID:cartant,项目名称:angular,代码行数:65,代码来源:test_ngtools_api.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript compiler-cli.CodeGenerator类代码示例发布时间:2022-05-28
下一篇:
TypeScript compiler-cli.performCompilation函数代码示例发布时间: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