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

TypeScript json-utils.findPropertyInAstObject函数代码示例

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

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



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

示例1: replacePropertyInAstObject

function replacePropertyInAstObject(
    recorder: UpdateRecorder, node: JsonAstObject, propertyName: string, value: JsonValue,
    indent: number) {
  const property = findPropertyInAstObject(node, propertyName);
  if (property === null) {
    throw new Error(`Property ${propertyName} does not exist in JSON object`);
  }
  const {start, text} = property;
  recorder.remove(start.offset, text.length);
  const indentStr = '\n' +
      ' '.repeat(indent);
  const content = JSON.stringify(value, null, '  ').replace(/\n/g, indentStr);
  recorder.insertLeft(start.offset, content);
}
开发者ID:cyrilletuzi,项目名称:angular,代码行数:14,代码来源:index.ts


示例2: return

 return (host: Tree, context: SchematicContext) => {
   const packageJson = 'package.json';
   if (!host.exists(packageJson)) {
     throw new Error(`Could not find ${packageJson}`);
   }
   const content = host.read(packageJson);
   if (!content) {
     throw new Error('Failed to read package.json content');
   }
   const jsonAst = parseJsonAst(content.toString());
   if (!isJsonAstObject(jsonAst)) {
     throw new Error(`Failed to parse JSON for ${packageJson}`);
   }
   const deps = findPropertyInAstObject(jsonAst, 'dependencies');
   if (!isJsonAstObject(deps)) {
     throw new Error(`Failed to find dependencies in ${packageJson}`);
   }
   const rxjs = findPropertyInAstObject(deps, 'rxjs');
   if (!rxjs) {
     throw new Error(`Failed to find rxjs in dependencies of ${packageJson}`);
   }
   const value = rxjs.value as string;  // value can be version or range
   const match = value.match(/(\d)+\.(\d)+.(\d)+$/);
   if (match) {
     const [_, major, minor] = match;
     if (major < '6' || (major === '6' && minor < '4')) {
       const recorder = host.beginUpdate(packageJson);
       replacePropertyInAstObject(recorder, deps, 'rxjs', '~6.4.0');
       host.commitUpdate(recorder);
     }
   } else {
     context.logger.info(
         'Could not determine version of rxjs. \n' +
         'Please make sure that version is at least 6.4.0.');
   }
   return host;
 };
开发者ID:alxhub,项目名称:angular,代码行数:37,代码来源:index.ts


示例3: return

  return (host: Tree) => {
    const packageJson = 'package.json';
    if (!host.exists(packageJson)) {
      throw new Error(`Could not find ${packageJson}`);
    }
    const packageJsonContent = host.read(packageJson);
    if (!packageJsonContent) {
      throw new Error('Failed to read package.json content');
    }
    const jsonAst = parseJsonAst(packageJsonContent.toString()) as JsonAstObject;
    const deps = findPropertyInAstObject(jsonAst, 'dependencies') as JsonAstObject;
    const devDeps = findPropertyInAstObject(jsonAst, 'devDependencies') as JsonAstObject;

    const angularCoreNode = findPropertyInAstObject(deps, '@angular/core');
    if (!angularCoreNode) {
      throw new Error('@angular/core dependency not found in package.json');
    }
    const angularCoreVersion = angularCoreNode.value as string;

    const devDependencies: {[k: string]: string} = {
      '@angular/bazel': angularCoreVersion,
      // TODO(kyliau): Consider moving this to latest-versions.ts
      '@bazel/bazel': '^0.22.1',
      '@bazel/ibazel': '^0.9.0',
      '@bazel/karma': '^0.23.2',
      '@bazel/typescript': '^0.23.2',
    };

    const recorder = host.beginUpdate(packageJson);
    for (const packageName of Object.keys(devDependencies)) {
      const version = devDependencies[packageName];
      const indent = 4;
      insertPropertyInAstObjectInOrder(recorder, devDeps, packageName, version, indent);
    }
    host.commitUpdate(recorder);
    return host;
  };
开发者ID:BobChao87,项目名称:angular,代码行数:37,代码来源:index.ts


示例4: return

  return (host: Tree, context: SchematicContext) => {
    const {name} = options;
    const workspacePath = `${name}/angular.json`;
    if (!host.exists(workspacePath)) {
      throw new SchematicsException(`Workspace file ${workspacePath} not found.`);
    }
    const workspaceBuffer = host.read(workspacePath) !;
    const workspaceJsonAst = parseJsonAst(workspaceBuffer.toString()) as JsonAstObject;
    const projects = findPropertyInAstObject(workspaceJsonAst, 'projects');
    if (!projects) {
      throw new SchematicsException('Expect projects in angular.json to be an Object');
    }
    const project = findPropertyInAstObject(projects as JsonAstObject, name);
    if (!project) {
      throw new SchematicsException(`Expected projects to contain ${name}`);
    }
    const recorder = host.beginUpdate(workspacePath);
    const indent = 6;
    replacePropertyInAstObject(
        recorder, project as JsonAstObject, 'architect', {
          'build': {
            'builder': '@angular/bazel:build',
            'options': {'targetLabel': '//src:bundle.js', 'bazelCommand': 'build'},
            'configurations': {'production': {'targetLabel': '//src:bundle'}}
          },
          'serve': {
            'builder': '@angular/bazel:build',
            'options': {'targetLabel': '//src:devserver', 'bazelCommand': 'run'},
            'configurations': {'production': {'targetLabel': '//src:prodserver'}}
          },
          'extract-i18n': {
            'builder': '@angular-devkit/build-angular:extract-i18n',
            'options': {'browserTarget': `${name}:build`}
          },
          'test': {
            'builder': '@angular/bazel:build',
            'options': {'bazelCommand': 'test', 'targetLabel': '//src/...'}
          },
          'lint': {
            'builder': '@angular-devkit/build-angular:tslint',
            'options': {
              'tsConfig': ['src/tsconfig.app.json', 'src/tsconfig.spec.json'],
              'exclude': ['**/node_modules/**']
            }
          }
        },
        indent);

    const e2e = `${options.name}-e2e`;
    const e2eNode = findPropertyInAstObject(projects as JsonAstObject, e2e);
    if (e2eNode) {
      replacePropertyInAstObject(
          recorder, e2eNode as JsonAstObject, 'architect', {
            'e2e': {
              'builder': '@angular/bazel:build',
              'options': {'bazelCommand': 'test', 'targetLabel': '//e2e:devserver_test'},
              'configurations': {'production': {'targetLabel': '//e2e:prodserver_test'}}
            },
            'lint': {
              'builder': '@angular-devkit/build-angular:tslint',
              'options': {'tsConfig': 'e2e/tsconfig.e2e.json', 'exclude': ['**/node_modules/**']}
            }
          },
          indent);
    }

    host.commitUpdate(recorder);
    return host;
  };
开发者ID:cyrilletuzi,项目名称:angular,代码行数:69,代码来源:index.ts


示例5:

 const depsToInstall = Object.keys(devDependencies).filter((name) => {
   return !findPropertyInAstObject(devDeps, name);
 });
开发者ID:alxhub,项目名称:angular,代码行数:3,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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