當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript shelljs.find函數代碼示例

本文整理匯總了TypeScript中shelljs.find函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript find函數的具體用法?TypeScript find怎麽用?TypeScript find使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了find函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: findAllPackageJsonFiles

export function findAllPackageJsonFiles(rootDirectory: string): string[] {
  // TODO(gkalpak): Investigate whether skipping `node_modules/` directories (instead of traversing
  //                them and filtering out the results later) makes a noticeable difference.
  const paths = Array.from(find(rootDirectory));
  return paths.filter(
      path => PACKAGE_JSON_REGEX.test(path) &&
          !NODE_MODULES_REGEX.test(path.slice(rootDirectory.length)));
}
開發者ID:hulkike,項目名稱:angular,代碼行數:8,代碼來源:utils.ts

示例2: it

  it('should run ngcc without errors', () => {
    const nodeModulesPath = path.join(basePath, 'node_modules');
    console.error(nodeModulesPath);
    const commonPath = path.join(nodeModulesPath, '@angular/common');
    const exitCode = mainNgcc([commonPath]);

    console.warn(find('node_modules_ngtsc').filter(p => p.endsWith('.js') || p.endsWith('map')));

    console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js').stdout);
    console.warn(cat('node_modules_ngtsc/@angular/common/fesm2015/common.js.map').stdout);

    expect(exitCode).toBe(0);
  });
開發者ID:hulkike,項目名稱:angular,代碼行數:13,代碼來源:ngcc_spec.ts

示例3: convertLfToCrlfAll

    async function convertLfToCrlfAll(baseDir: string) {
        await Promise.all<{ target: string, content: string }>(
            shell
                .find(baseDir)
                .filter(target => {
                    const match = target.match(/\.(.+)$/);
                    return (
                        (!match && target.endsWith("LICENSE")) ||
                        (match &&
                            (match[1] === "html" ||
                                match[1] === "js" ||
                                match[1] === "css" ||
                                match[1] === "txt" ||
                                match[1] === "ini"
                            ))
                    );
                })
                .map(
                    target =>
                        new Promise((resolve, reject) => {
                            fs.readFile(target, (err, data) => {
                                if (err) {
                                    console.error(err);
                                    reject(err);
                                    return;
                                }
                                resolve({
                                    target,
                                    content: convertLfToCrlf(data.toString("utf8"))
                                });
                            })
                        })
                )
        ).then(contents =>
            contents.map(
                prop =>
                    new Promise((resolve, reject) =>
                        fs.writeFile(prop.target, prop.content, err => {
                            if (err) {
                                console.error(err);
                                reject(err);
                                return;
                            }
                            resolve();
                        })
                    )
            )
        );

    }
開發者ID:WWAWing,項目名稱:WWAWing,代碼行數:50,代碼來源:make-wwawing-dist.ts

示例4: _cleanFiles

    private _cleanFiles(callback: (err: any) => void): void {
        this.emitter.emit('info', 'Cleaning Files: ' + this.path);
        if (!shell.test('-d', this.path)) {
            callback(null);
            return;
        }

        var candidates = shell.find(this.path).filter((file) => { return this.ext === '*' || file.endsWith('.' + this.ext); });

        var _that = this;
        var delCount = 0;
        async.forEachSeries(candidates,
            function (candidate, done: (err: any) => void) {
                fs.stat(candidate, (err, stats) => {
                    if (err) {
                        done(null);
                        return;
                    }

                    if (stats.isDirectory()) {
                        done(null);
                        return;
                    }

                    var fileAgeSeconds = (new Date().getTime() - stats.mtime.getTime()) / 1000;
                    if (fileAgeSeconds > _that.ageSeconds) {
                        ++delCount;
                        _that.emitter.emit('deleted', candidate);
                        shell.rm(candidate);
                    }                    

                    // ignoring errors - log and keep going
                    done(null);
                })
            }, function (err) {
                _that.emitter.emit('info', 'deleted file count: ' + delCount);
                // ignoring errors. log and go
                callback(null);
            });        
    }
開發者ID:itsananderson,項目名稱:vso-agent,代碼行數:40,代碼來源:diagnostics.ts

示例5: expect

 () => { expect(shx.find('esm5').filter(f => f.endsWith('.ngsummary.js'))).toEqual([]); });
開發者ID:zackarychapple,項目名稱:angular,代碼行數:1,代碼來源:core_package.spec.ts

示例6: it

 it('should not contain any *.ngsummary.js files', () => {
   expect(shx.find('esm2015').filter(f => f.endsWith('.ngsummary.js'))).toEqual([]);
 });
開發者ID:zackarychapple,項目名稱:angular,代碼行數:3,代碼來源:core_package.spec.ts

示例7: main


//.........這裏部分代碼省略.........
    shx.mkdir('-p', path.dirname(outputPath));
    fs.writeFileSync(outputPath, fileContent, 'utf-8');
  }

  /**
   * Copies a file into the package based on its input path, relativizing to the package path.
   * @param inputPath a path relative to the binDir, typically from a file in the deps[]
   */
  function copyFileFromInputPath(inputPath: string) {
    writeFileFromInputPath(inputPath, fs.readFileSync(inputPath, 'utf-8'));
  }

  /**
   * Relativize the path where a file is written.
   * @param file a path containing a re-rooted segment like .esm5 or .es6
   * @param suffix the re-rooted directory
   * @param outDir path where we copy the file, relative to the out
   */
  function writeEsmFile(file: string, suffix: string, outDir: string) {
    const root = file.substr(0, file.lastIndexOf(suffix + path.sep) + suffix.length + 1);
    const rel = path.dirname(path.relative(path.join(root, srcDir), file));
    if (!rel.startsWith('..')) {
      copyFile(file, path.join(out, outDir), rel);
    }
  }

  esm2015.forEach(file => writeEsmFile(file, '.es6', 'esm2015'));
  esm5.forEach(file => writeEsmFile(file, '.esm5', 'esm5'));

  bundles.forEach(bundle => { copyFile(bundle, out, 'bundles'); });
  fesm2015.forEach(file => { copyFile(file, out, 'fesm2015'); });
  fesm5.forEach(file => { copyFile(file, out, 'fesm5'); });

  const allsrcs = shx.find('-R', binDir);
  allsrcs.filter(hasFileExtension('.d.ts')).forEach((f: string) => {
    const content = fs.readFileSync(f, 'utf-8')
                        // Strip the named AMD module for compatibility with non-bazel users
                        .replace(/^\/\/\/ <amd-module name=.*\/>\n/, '');
    writeFileFromInputPath(f, content);
  });

  // Copy all `data` files into the package. These are files that aren't built by the ng_package
  // rule, but instead are just straight copied into the package, e.g. global CSS assets.
  dataFiles.forEach(f => copyFileFromInputPath(f));

  // Iterate through the entry point modules
  // We do this first because we also record new paths for the esm5 and esm2015 copies
  // of the index JS file, which we need to amend the package.json.
  Object.keys(modulesManifest).forEach(moduleName => {
    const moduleFiles = modulesManifest[moduleName];
    const relative = path.relative(binDir, moduleFiles['index']);

    moduleFiles['esm5_index'] = path.join(binDir, 'esm5', relative);
    moduleFiles['esm2015_index'] = path.join(binDir, 'esm2015', relative);

    copyFileFromInputPath(moduleFiles['metadata']);
  });

  // Root package name (e.g. '@angular/common'), captures as we iterate through sources below.
  let rootPackageName = '';
  const packagesWithExistingPackageJson = new Set<string>();

  for (const src of srcs) {
    if (src.includes(binDir) || src.includes(genfilesDir)) {
      errorHasOccured = true;
      console.error(
開發者ID:IdeaBlade,項目名稱:angular,代碼行數:67,代碼來源:packager.ts

示例8: mdUrl

const tpl = sh.cat(template);

// Prepare output folder (create, clean, copy sources)
sh.mkdir("-p", output);
sh.rm("-rf", output + "/*");
sh.cp("-R", folder + "/*", output);

// Start processing. Outline:
//
// 1. Get all files
// 2. Sort them
// 3. Group them hierachically
// 4. Parse files and generate output html files

sh.cd(output);
const all = sh.find("*");

const mds = all
  .filter(file => file.match(mdR))
  .sort(sortByPreferences.bind(null, preferences))
  .map(file => {
    const content = sh.cat(file).toString(); // The result is a weird not-string
    return {
      path: file,
      url: mdUrl(file),
      content,
      html: md2html(content)
    };
  });

const groupedMds: FileTree<StringFile> = mds.reduce(
開發者ID:joakin,項目名稱:markdown-folder-to-html,代碼行數:31,代碼來源:cli.ts

示例9: 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

示例10:

import * as path from 'path';
import * as shell from 'shelljs';

// 清理上傳目錄
shell.rm('-rf', 'upload');
shell.mkdir('upload');

// 同步資源文件
shell.find('src').filter(item => {
  return item.match(/\.(html|ico)$/);
}).forEach(item => {
  const dest = item.replace(/^src\b/, 'dist');
  shell.mkdir('-p', path.dirname(dest));
  shell.cp(item, dest);
});
開發者ID:whosesmile,項目名稱:koa-scaffold,代碼行數:15,代碼來源:sync.static.ts


注:本文中的shelljs.find函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。