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


TypeScript globby.sync函數代碼示例

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


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

示例1: globby

(async () => {
    let result: string[];
    result = await globby('*.tmp');
    result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']);

    result = globby.sync('*.tmp');
    result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']);

    result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])}));
    result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])}));
})();
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:globby-tests.ts

示例2: mapLimit

const parseAndReportFiles = (fileGlobs: string[], program: ReporterProgramArgs): void => {
    // Get all files and their resolved globs
    const files = globby.sync(fileGlobs, {
        cwd: process.cwd(),
        ignore: program.ignore || [],
        onlyFiles: true,
    });

    if (!files || !files.length) {
        console.log(logSymbols.warning, 'No files found for reporting');
        process.exit(1);
    }

    // Parallel read all of the given files
    mapLimit(
        files,
        concurrencyLimit,
        (file, cb) => readFile(resolve(process.cwd(), file), 'utf8', cb),
        (err, results: string[]) => {
            if (err) {
                console.log(err);
                process.exit(1);
            }
            const todos = results
                .map(content => JSON.parse(content))
                // filter files without any parsed content
                .filter(item => item && item.length > 0)
                .reduce((items, item) => items.concat(item), []);

            outputTodos(todos, program);
        }
    );
};
開發者ID:pgilad,項目名稱:leasot,代碼行數:33,代碼來源:cli-reporter.ts

示例3: getFiles

 getFiles(): Files {
   return {
     lists: globby
       .sync('*.json', {
         cwd: path.join(this.importDir, 'lists/'),
       })
       .map(p => path.join(this.importDir, 'lists/', p)),
     nodes: globby
       .sync('*.json', {
         cwd: path.join(this.importDir, 'nodes/'),
       })
       .map(p => path.join(this.importDir, 'nodes/', p)),
     relations: globby
       .sync('*.json', {
         cwd: path.join(this.importDir, 'relations/'),
       })
       .map(p => path.join(this.importDir, 'relations/', p)),
   }
 }
開發者ID:ahmb84,項目名稱:prisma,代碼行數:19,代碼來源:Importer.ts

示例4: execute

        /**
         * Misc resources are special because a single file input may generate multiple
         * input/output configurations.
         *
         * Let's take an example. If you have a configuration like:
         *
         * misc:
         *   input: 'assets/images/**'
         *   output: 'public/images'
         *
         * This will copy every file in the 'assets/images' folder into 'public/images'.
         * But 'assets/images' may contain sub folders, and if so, they have to be kept!
         *
         * So the line "input: 'assets/images/**'" will generate as many input/output configurations
         * as there are sub folders when resolving the glob.
         *
         * It's a bit ugly but the fastest way to handle this without restructuring the whole GulpTask class is
         * to create sub tasks for each sub input/output pair.
         *
         * This method does exactly that.
         *
         * When a file generates a sub task, it is removed from the current task's input.
         */
        public execute(): any {
            let subTasks: GulpTask[] = [];
            let originalInputs: any = [];

            for (let i = 0; i < this.configuration.input.length; ++i) {
                for (let j = 0; j < this.configuration.input[i].files.length; ++j) {
                    let path = this.configuration.input[i].files[j];
                    if (path.isGlob && path.globBase) {
                        let indexed: {[key: string]: PackageInputOutputConfiguration} = {};
                        let files: string[] = globby.sync(path.absolute);
                        for (let k = 0; k < files.length; ++k) {
                            if (!FileSystem.isDirectory(files[k])) {
                                let relativeDir = FileSystem.getDirectoryName(files[k]).substring(path.globBase.length);
                                if (!Utils.isSet(indexed[relativeDir])) {
                                    let newInput = Utils.clone(this.configuration.input[i]);
                                    let newOutput = Utils.clone(this.configuration.output);

                                    newInput.files = [];
                                    newOutput.dev.absolute += relativeDir;
                                    newOutput.prod.absolute += relativeDir;
                                    indexed[relativeDir] = {watch: [], input: [newInput], output: newOutput};
                                }
                                indexed[relativeDir].input[0].files.push({
                                    packageId: path.packageId,
                                    original: files[k],
                                    absolute: files[k],
                                    extension: FileSystem.getExtension(files[k]),
                                    isGlob: false,
                                    globBase: ''
                                });
                            }
                        }
                        for (let p in indexed) {
                            if (indexed.hasOwnProperty(p)) {
                                subTasks.push(new MiscTask(this.gulpfile, this.packageName, indexed[p], this.processorsManager));
                            }
                        }
                        originalInputs.push(Utils.clone(this.configuration.input[i]));
                        this.configuration.input[i].files.splice(j--, 1);
                    }
                }
            }
            let stream: any = super.execute();
            this.configuration.input = originalInputs;
            for (let i = 0; i < subTasks.length; ++i) {
                const nextStream: any = subTasks[i].execute();
                if (nextStream !== null) {
                    stream = (stream !== null) ? merge(stream, nextStream) : nextStream;
                }
            }
            return stream;
        }
開發者ID:Stnaire,項目名稱:gulp-yaml-packages,代碼行數:75,代碼來源:MiscTask.ts

示例5: join

export const getEntryAndOutput = (target: Target, command: Command) => {
  const entry: Entry = {
    index: project.ws.srcEntry
  };

  const output: StrictOutput = {
    publicPath: project.ws.publicPath,
    path: join(process.cwd(), project.ws.distDir),
    filename: '[name].js',
    // removes tabs (better for multiline strings)
    sourcePrefix: ''
  };

  // command specific config
  if (command === 'build -p') {
    output.path = join(process.cwd(), project.ws.distReleaseDir);
  } else if (command === 'unit') {
    let pattern: string[] = [];
    if (project.ws.testsPattern) {
      pattern = Array.isArray(project.ws.testsPattern)
        ? project.ws.testsPattern
        : [project.ws.testsPattern];
    }
    entry.index = globby.sync([project.ws.unitEntry, ...pattern]);
    output.path = join(process.cwd(), project.ws.distTestsDir);
  } else if (command === 'e2e') {
    entry.index = project.ws.e2eEntry;
    output.path = join(process.cwd(), project.ws.distTestsDir);
  }

  // target specific config
  if (target === 'browser') {
    output.libraryTarget = 'umd';
    output.library = project.name;
  } else if (target === 'spa') {
    output.libraryTarget = 'umd'; // is this needed?
  } else if (target === 'node') {
    const currentEntry = Array.isArray(entry.index)
      ? entry.index
      : [entry.index as string];
    entry.index = [nodeSourceMapEntry, ...currentEntry];
    output.libraryTarget = 'commonjs2';
  }

  // special cases
  if (target === 'spa' && command === 'build -p') {
    output.filename = '[name].[chunkhash].js';
    output.chunkFilename = '[name].[chunkhash].lazy.js';
  }

  return { entry, output };
};
開發者ID:Mercateo,項目名稱:ws,代碼行數:52,代碼來源:options.ts

示例6: findMatchingFiles

  /**
   *  find matching files based on the given path or glob
   *
   * @param {string} patterns - glob pattern(s) or relative path
   * @param {boolean} [isGlob] - pass true to treat the path as a glob
   * @param {Object} [globOptions] - options to pass to globby
   * @returns {Array<string>} files
   */
  static findMatchingFiles(patterns: string | Array<string>, {isGlob, globOptions}: {
    isGlob: boolean,
    globOptions: Object,
  }): Array<string> {

    // Try to treat the patterns as globs first
    if (globby.hasMagic(patterns) || Array.isArray(patterns) || isGlob) {
      return globby.sync(patterns, globOptions);
    }

    // Fallback to the legacy implementation for non-glob patterns to avoid code breaks
    return Context.walkDirSync(patterns);
  }
開發者ID:yruan,項目名稱:inceptum,代碼行數:21,代碼來源:Context.ts

示例7: getConfigFilePath

(() => {
  const configFilePath = getConfigFilePath();
  const workingDirectory = path.dirname(configFilePath);

  const config = require(configFilePath);

  if (config.outDir === undefined) {
    throw new Error('Invalid config: must specify an outDir.');
  }

  const sourcePaths = globby.sync(config.src, { cwd: workingDirectory })
    .map(file => path.normalize(path.join(workingDirectory, file)));

  const outputItems = generateOutput(sourcePaths, config.options);
  writeOutput(workingDirectory, config, outputItems);
})();
開發者ID:vintage-software,項目名稱:vstack-typescript-generator,代碼行數:16,代碼來源:tsgen-cli.ts

示例8: parseContentSync

const parseAndReportFiles = (fileGlobs: string[], program: ProgramArgs): void => {
    // Get all files and their resolved globs
    const files = globby.sync(fileGlobs, {
        cwd: process.cwd(),
        ignore: program.ignore || [],
        onlyFiles: true,
        deep: true,
        unique: true,
        matchBase: true,
    });

    if (!files || !files.length) {
        console.log(logSymbols.warning, 'No files found for parsing');
        process.exit(1);
    }

    // Parallel read all of the given files
    mapLimit(
        files,
        CONCURRENCY_LIMIT,
        (file, cb) => readFile(resolve(process.cwd(), file), 'utf8', cb),
        (err, results: string[]) => {
            if (err) {
                console.log(err);
                process.exit(1);
            }
            const todos = results
                .map(function(content: string, index: number) {
                    return parseContentSync(content, program, files[index]);
                })
                // filter files without any parsed content
                .filter(item => item && item.length > 0)
                .reduce((items, item) => items.concat(item), []);

            outputTodos(todos, program);
        }
    );
};
開發者ID:pgilad,項目名稱:leasot,代碼行數:38,代碼來源:cli.ts

示例9: sync

    ${chalk.dim('Run JPEGmini.app over every JPG in current directory')}
    imageoptim --jpegmini --no-imageoptim '**/*.jpg' '**/*.jpeg'

    ${chalk.dim('Run ImageOptim.app over every image in a specific directory')}
    imageoptim '~/Desktop'
    `.trimRight()
  );
});

program.parse(process.argv);

if (process.platform !== 'darwin') {
  console.log('imageoptim-cli is macOS only');
}

const filePaths = sync(patterns.map((pattern) => pattern.replace('~', homedir())));
const supportedFilePaths = filePaths.filter(isSupported(SUPPORTED_FILE_TYPES)).map((filePath) => ({
  source: filePath,
  tmp: join(TMPDIR, filePath)
}));

cli({
  enabled: {
    color: program.color === true,
    imageAlpha: program.imagealpha === true,
    imageOptim: program.imageoptim === true,
    jpegMini: program.jpegmini === true,
    quit: program.quit === true,
    stats: program.stats === true
  },
  files: {
開發者ID:JamieMason,項目名稱:ImageOptim-CLI,代碼行數:31,代碼來源:imageoptim.ts

示例10: function

export default function() {
  const files: string[] = globby.sync('src/Components/AutoImport/**/*.tsx');

  log(files);
  const lib = globby.sync('types/**/*.d.ts');
  const program = ts.createProgram(files.concat(lib), compilerOptions);
  const checker = program.getTypeChecker();
  const symbol_cache = new Map<ts.Symbol, Definition>();
  // const t_cache = new WeakSet();

  const types: { type: ts.Type | null; fileName: string }[] = [];
  for (const sourceFile of program.getSourceFiles()) {
    if (
      !sourceFile.isDeclarationFile &&
      files.some(f => sourceFile.fileName.indexOf(f) > -1)
    ) {
      ts.forEachChild(sourceFile, visit);
    }
  }
  const schema = oneOf(types);
  log(JSON.stringify(schema, undefined, 2));
  return {
    code: `module.exports = {schema:${JSON.stringify(schema)}}`,
    contextDependencies: files,
    cacheable: true,
  };
  // console.log(JSON.stringify(oneOf(types), undefined, 2));

  function extractProps(node: ts.Node) {
    const typeName = node
      .getSourceFile()
      .fileName.replace(/src\/Components\/AutoImport\/(.*).tsx?/, '$1');
    const t = checker.getTypeAtLocation(node);
    if (t.isClassOrInterface()) {
      const props = checker.getTypeAtLocation(node).getProperty('props');
      if (props) {
        types.push({
          type: checker.getTypeOfSymbolAtLocation(
            props,
            props.valueDeclaration!,
          ),
          fileName: typeName,
        });
      }
    }
    const sign = checker.getSignaturesOfType(t, ts.SignatureKind.Call);
    sign.forEach(s => {
      types.push({
        type: s.parameters[0]
          ? checker.getTypeAtLocation(s.parameters[0].valueDeclaration!)
          : null,
        fileName: typeName,
      });
    });
  }
  function visit(node: ts.Node) {
    if (isNodeDefaultExported(node)) {
      extractProps(node);
      return;
    }
    if (ts.isExportAssignment(node)) {
      extractProps(node.expression);
      return;
    }
  }

  function isNodeDefaultExported(node: ts.Node): boolean {
    return (
      (ts.getCombinedModifierFlags(node as ts.Declaration) &
        ts.ModifierFlags.ExportDefault) !==
      0
    );
  }

  /*
  Types to Schema
  */
  function oneOf(
    types: { type: ts.Type | null; fileName: string }[],
  ): Definition {
    const defs: { [k: string]: Definition } = {};
    defs.components = {
      oneOf: types.map(t => {
        return {
          type: 'object',
          required: ['type', 'props'],
          properties: {
            type: {
              type: 'string',
              enum: [t.fileName],
            },
            props:
              t.type !== null
                ? serializeType(t.type)
                : { type: 'object', additionalProperties: false },
          },
        };
      }),
      defaultSnippets: [
        {
//.........這裏部分代碼省略.........
開發者ID:Heigvd,項目名稱:Wegas,代碼行數:101,代碼來源:page-schema.build.ts


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