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

TypeScript shelljs.set函数代码示例

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

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



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

示例1: require

  const onSpecCompleted = (format: string) => {
    if (preserveOutput) {
      const {tmpdir} = require('os');
      const {cp, mkdir, rm, set} = require('shelljs');

      const tempRootDir = join(tmpdir(), 'ngcc-spec', format);
      const outputDir = OUTPUT_PATH;

      set('-e');
      rm('-rf', tempRootDir);
      mkdir('-p', tempRootDir);
      cp('-R', join(support.basePath, outputDir), tempRootDir);

      global.console.log(`Copied '${outputDir}' to '${tempRootDir}'.`);
    }
  };
开发者ID:DeepanParikh,项目名称:angular,代码行数:16,代码来源:ngcc_spec.ts


示例2: main

function main(args: string[]): number {
  // Exit immediately when encountering an error.
  shx.set('-e');

  // Keep track of whether an error has occured so that we can return an appropriate exit code.
  let errorHasOccured = false;

  // This utility expects all of its arguments to be specified in a params file generated by
  // bazel (see https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file).
  const paramFilePath = args[0];

  // Bazel params may be surrounded with quotes
  function unquoteParameter(s: string) { return s.replace(/^'(.*)'$/, '$1'); }

  // Parameters are specified in the file one per line.
  const params = fs.readFileSync(paramFilePath, 'utf-8').split('\n').map(unquoteParameter);

  const [
      // Output directory for the npm package.
      out,

      // The package segment of the ng_package rule's label (e.g. 'package/common').
      srcDir,

      // The bazel-bin dir joined with the srcDir (e.g. 'bazel-bin/package.common').
      // This is the intended output location for package artifacts.
      binDir,

      // The bazel-genfiles dir joined with the srcDir (e.g. 'bazel-bin/package.common').
      genfilesDir,

      // JSON data mapping each entry point to the generated bundle index and
      // flat module metadata, for example
      // {"@angular/core": {
      //     "index": "bazel-bin/packages/core/core.js",
      //     "typing": "bazel-bin/packages/core/core.d.ts",
      //     "metadata": "bazel-bin/packages/core/core.metadata.json"
      //  },
      // ...
      // }
      modulesManifestArg,

      // Path to the package's README.md.
      readmeMd,

      // List of rolled-up flat ES2015 modules
      fesm2015Arg,

      // List of rolled-up flat ES5 modules
      fesm5Arg,

      // List of individual ES2015 modules
      esm2015Arg,

      // List of individual ES5 modules
      esm5Arg,

      // List of all UMD bundles generated by rollup.
      bundlesArg,

      // List of all files in the ng_package rule's srcs.
      srcsArg,

      // List of all files in the ng_package rule's data.
      dataArg,

      // Path to the package's LICENSE.
      licenseFile,
  ] = params;

  const fesm2015 = fesm2015Arg.split(',').filter(s => !!s);
  const fesm5 = fesm5Arg.split(',').filter(s => !!s);
  const esm2015 = esm2015Arg.split(',').filter(s => !!s);
  const esm5 = esm5Arg.split(',').filter(s => !!s);
  const bundles = bundlesArg.split(',').filter(s => !!s);
  const srcs = srcsArg.split(',').filter(s => !!s);
  const dataFiles: string[] = dataArg.split(',').filter(s => !!s);
  const modulesManifest = JSON.parse(modulesManifestArg);

  if (readmeMd) {
    copyFile(readmeMd, out);
  }

  /**
   * Writes a file into the package based on its input path, relativizing to the package path.
   * @param inputPath Path to the file in the input tree.
   * @param fileContent Content of the file.
   */
  function writeFileFromInputPath(inputPath: string, fileContent: string) {
    // We want the relative path from the given file to its ancestor "root" directory.
    // This root depends on whether the file lives in the source tree (srcDir) as a basic file
    // input to ng_package, the bin output tree (binDir) as the output of another rule, or
    // the genfiles output tree (genfilesDir) as the output of a genrule.
    let rootDir: string;
    if (inputPath.includes(binDir)) {
      rootDir = binDir;
    } else if (inputPath.includes(genfilesDir)) {
      rootDir = genfilesDir;
    } else {
      rootDir = srcDir;
//.........这里部分代码省略.........
开发者ID:IdeaBlade,项目名称:angular,代码行数:101,代码来源:packager.ts


示例3: main

function main(args: string[]): number {
  shx.set('-e');
  const
      [out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
       licenseFile] = args;
  const fesms2015 = fesms2015Arg.split(',').filter(s => !!s);
  const fesms5 = fesms5Arg.split(',').filter(s => !!s);
  const bundles = bundlesArg.split(',').filter(s => !!s);
  const srcs = srcsArg.split(',').filter(s => !!s);

  shx.mkdir('-p', out);

  let primaryEntryPoint: string|null = null;
  const secondaryEntryPoints = new Set<string>();

  function replaceVersionPlaceholders(filePath: string) {
    if (stampData) {
      const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
      return shx.sed(/0.0.0-PLACEHOLDER/, version, filePath);
    }
    return shx.cat(filePath);
  }

  function writeFesm(file: string, baseDir: string) {
    const parts = path.basename(file).split('__');
    const entryPointName = parts.join('/').replace(/\..*/, '');
    if (primaryEntryPoint === null || primaryEntryPoint === entryPointName) {
      primaryEntryPoint = entryPointName;
    } else {
      secondaryEntryPoints.add(entryPointName);
    }
    const filename = parts.splice(-1)[0];
    const dir = path.join(baseDir, ...parts);
    shx.mkdir('-p', dir);
    shx.cp(file, dir);
    shx.mv(path.join(dir, path.basename(file)), path.join(dir, filename));
  }

  function moveBundleIndex(f: string) {
    let ext: string;

    if (f.endsWith('.d.ts'))
      ext = '.d.ts';
    else if (f.endsWith('.metadata.json'))
      ext = '.metadata.json';
    else
      throw new Error('Bundle index files should be .d.ts or .metadata.json');

    const relative = path.relative(binDir, f);
    let outputPath: string|undefined = undefined;
    for (const secondary of secondaryEntryPoints.values()) {
      if (relative.startsWith(secondary)) {
        const filename = secondary.split('/').pop();
        outputPath = path.join(out, secondary, filename + ext);
      }
    }
    if (!outputPath) {
      outputPath = path.join(out, primaryEntryPoint + ext);
    }
    return outputPath;
  }

  if (readmeMd) {
    shx.cp(readmeMd, path.join(out, 'README.md'));
  }

  fesms2015.forEach(fesm2015 => writeFesm(fesm2015, path.join(out, 'esm2015')));
  fesms5.forEach(fesm5 => writeFesm(fesm5, path.join(out, 'esm5')));

  const bundlesDir = path.join(out, 'bundles');
  shx.mkdir('-p', bundlesDir);
  bundles.forEach(bundle => { shx.cp(bundle, bundlesDir); });

  const allsrcs = shx.find('-R', binDir);
  allsrcs.filter(filter('.d.ts')).forEach((f: string) => {
    const content = fs.readFileSync(f, {encoding: 'utf-8'})
                        // Strip the named AMD module for compatibility with non-bazel users
                        .replace(/^\/\/\/ <amd-module name=.*\/>\n/, '');
    let outputPath: string;
    if (f.endsWith('.bundle_index.d.ts')) {
      outputPath = moveBundleIndex(f);
    } else {
      outputPath = path.join(out, path.relative(binDir, f));
    }
    shx.mkdir('-p', path.dirname(outputPath));
    fs.writeFileSync(outputPath, content);
  });

  for (const src of srcs) {
    replaceVersionPlaceholders(src).to(path.join(out, path.relative(srcDir, src)));
  }

  allsrcs.filter(filter('.bundle_index.metadata.json')).forEach((f: string) => {
    replaceVersionPlaceholders(f).to(moveBundleIndex(f));
  });

  const licenseBanner = licenseFile ? fs.readFileSync(licenseFile, {encoding: 'utf-8'}) : '';

  for (const secondaryEntryPoint of secondaryEntryPoints.values()) {
    const baseName = secondaryEntryPoint.split('/').pop();
//.........这里部分代码省略.........
开发者ID:robwormald,项目名称:angular,代码行数:101,代码来源:packager.ts


示例4: main

function main(args: string[]): number {
  shx.set('-e');
  args = fs.readFileSync(args[0], {encoding: 'utf-8'}).split('\n').map(s => s === '\'\'' ? '' : s);
  const
      [out, srcDir, binDir, readmeMd, fesms2015Arg, fesms5Arg, bundlesArg, srcsArg, stampData,
       licenseFile] = args;
  const fesms2015 = fesms2015Arg.split(',').filter(s => !!s);
  const fesms5 = fesms5Arg.split(',').filter(s => !!s);
  const bundles = bundlesArg.split(',').filter(s => !!s);
  const srcs = srcsArg.split(',').filter(s => !!s);

  shx.mkdir('-p', out);

  let primaryEntryPoint: string|null = null;
  const secondaryEntryPoints = new Set<string>();

  function replaceVersionPlaceholders(filePath: string, content: string) {
    if (stampData) {
      const version = shx.grep('BUILD_SCM_VERSION', stampData).split(' ')[1].trim();
      // Split the replacement into separate strings so we don't match it while publishing
      return content.replace(
          new RegExp(
              '0.0.0' +
                  '-PLACEHOLDER',
              'g'),
          version);
    }
    return content;
  }

  /**
   * Inserts properties into the package.json file(s) in the package so that
   * they point to all the right generated artifacts.
   *
   * @param filePath file being copied
   * @param content current file content
   */
  function amendPackageJson(filePath: string, content: string) {
    const parsedPackage = JSON.parse(content);
    let nameParts = parsedPackage['name'].split('/');
    // for scoped packages, we don't care about the scope segment of the path
    if (nameParts[0].startsWith('@')) nameParts = nameParts.splice(1);
    let rel = Array(nameParts.length - 1).fill('..').join('/');
    if (!rel) {
      rel = '.';
    }
    const indexFile = nameParts[nameParts.length - 1];
    parsedPackage['main'] = `${rel}/bundles/${nameParts.join('-')}.umd.js`;
    parsedPackage['module'] = `${rel}/esm5/${indexFile}.js`;
    parsedPackage['es2015'] = `${rel}/esm2015/${indexFile}.js`;
    parsedPackage['typings'] = `./${indexFile}.d.ts`;
    return JSON.stringify(parsedPackage, null, 2);
  }

  function writeFesm(file: string, baseDir: string) {
    const parts = path.basename(file).split('__');
    const entryPointName = parts.join('/').replace(/\..*/, '');
    if (primaryEntryPoint === null || primaryEntryPoint === entryPointName) {
      primaryEntryPoint = entryPointName;
    } else {
      secondaryEntryPoints.add(entryPointName);
    }
    const filename = parts.splice(-1)[0];
    const dir = path.join(baseDir, ...parts);
    shx.mkdir('-p', dir);
    shx.cp(file, dir);
    shx.mv(path.join(dir, path.basename(file)), path.join(dir, filename));
  }

  function moveBundleIndex(f: string) {
    let ext: string;

    if (f.endsWith('.d.ts'))
      ext = '.d.ts';
    else if (f.endsWith('.metadata.json'))
      ext = '.metadata.json';
    else
      throw new Error('Bundle index files should be .d.ts or .metadata.json');

    const relative = path.relative(binDir, f);
    let outputPath: string|undefined = undefined;
    for (const secondary of secondaryEntryPoints.values()) {
      if (relative.startsWith(secondary)) {
        const filename = secondary.split('/').pop();
        outputPath = path.join(out, secondary, filename + ext);
      }
    }
    if (!outputPath) {
      outputPath = path.join(out, primaryEntryPoint + ext);
    }
    return outputPath;
  }

  if (readmeMd) {
    shx.cp(readmeMd, path.join(out, 'README.md'));
  }

  fesms2015.forEach(fesm2015 => writeFesm(fesm2015, path.join(out, 'esm2015')));
  fesms5.forEach(fesm5 => writeFesm(fesm5, path.join(out, 'esm5')));

//.........这里部分代码省略.........
开发者ID:cironunes,项目名称:angular,代码行数:101,代码来源:packager.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript shelljs.tempdir函数代码示例发布时间:2022-05-25
下一篇:
TypeScript shelljs.sed函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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