How to use glob - 10 common examples

To help you get started, we’ve selected a few glob examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 104corp / espack / lib / api / __tests__ / index.spec.js View on Github external
import HtmlWebpackPlugin from 'html-webpack-plugin';
import espack from '../index';
import webpackConfig from '../../webpack.config';
import CSSExtractPlugin from '../plugins/CSSExtractPlugin';
import EventCallbackPlugin from '../plugins/EventCallbackPlugin';
import { setConfigOptions, OUTPUT_FILE_NAME, INFO_CHUNK_NAME } from '../../config';
import presetStage from '../../babel/preset-stage';

jest.unmock('../../config');
jest.mock('fs-extra');
jest.mock('glob');
jest.unmock('webpack');
jest.mock('mini-css-extract-plugin');
jest.mock('uglifyjs-webpack-plugin');

require('glob').__setMockFiles([ // eslint-disable-line no-underscore-dangle, global-require
  'src/pages/index.js',
]);

global.console.log = jest.fn();
const Api = espack.constructor;
jest.spyOn(Api, 'log');


describe('API 需要先提供 config 驗證', () => {
  beforeEach(() => {
    setConfigOptions({
      dev: false,
      dropConsole: false,
      port: '8888',
      viewsFolder: '.',
      staticFolder: '.',
github zerkalica / reactive-di / test / tests.js View on Github external
global.window = win

const hasOwnProperty = {}.hasOwnProperty

function propagateToGlobal(window: Object) {
    for (let key in window) { // eslint-disable-line
        if (hasOwnProperty.call(window, key) && !(key in global)) {
            global[key] = window[key]
        }
    }
}

propagateToGlobal(win)


glob.sync(__dirname + '/spec/**/*.js').forEach((file) => require(file)) // eslint-disable-line
github 104corp / espack / lib / __tests__ / webpack.base.config.spec.js View on Github external
beforeEach(() => {
    require('glob').__setMockFiles([ // eslint-disable-line no-underscore-dangle, global-require
      'src/pages/index.js',
    ]);
  });
github cs-education / classTranscribe / archive / utility_scripts / import.js View on Github external
*
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var fs = require("fs");

require("glob").glob("../captions/first/*.json", function (er, files) {
  console.log (files)
  files.forEach(function (filename) {
    var file = fs.readFileSync(filename).toString();
    console.log("// Part " + filename.split("Part_")[1].split("-")[0]);
    console.log(file + ",");
  });
});

require("glob").glob("../captions/second/*.json", function (er, files) {
  console.log (files)
  files.forEach(function (filename) {
    var file = fs.readFileSync(filename).toString();
    console.log("// Part " + filename.split("Part_")[1].split("-")[0]);
    console.log(file + ",");
  });
});
github ballerina-attic / composer / modules / distribution / pre-build.js View on Github external
function prepareService() {
    // search for service jar
    let foundFiles = glob.sync(serviceBuild);

    if(foundFiles.length !== 1) {
        console.error('Error while searching for service build file.');
    }

    fs.createReadStream(foundFiles[0]).pipe(fs.createWriteStream(path.join(__dirname, 'workspace-service.jar')));
}
github assetgraph / assetgraph / lib / AssetConfigResolver.js View on Github external
['catch'](cb);
    }
    if (typeof assetConfig === 'string') {
        if (/^\//.test(assetConfig) && /^file:/.test(fromUrl) && /^file:/.test(that.root)) {
            assetConfig = {url: that.root + assetConfig.substr(1)};
        } else {
            assetConfig = {url: urlTools.resolveUrl(fromUrl, assetConfig)};
        }
    }
    if (assetConfig.url) {
        var protocol = assetConfig.url.substr(0, assetConfig.url.indexOf(':')),
            pathname = assetConfig.url.replace(/^\w+:(?:\/\/)?/, ""); // Strip protocol and two leading slashes if present
        if (protocol === 'file') {
            if (/[\*\?]/.test(pathname)) {
                // Expand wildcard, then expand each resulting url
                return glob.glob(pathname, error.passToFunction(cb, function (fsPaths) {
                    if (!fsPaths.length) {
                        cb(new Error("AssetGraph.resolveAssetConfig: Wildcard " + pathname + " expanded to nothing"));
                    } else {
                        that.resolve(fsPaths.map(function (fsPath) {
                            return 'file://' + fsPath;
                        }), fromUrl, cb);
                    }
                }));
            }
            assetConfig.rawSrcProxy = function (cb) {
                fs.readFile(pathname, null, cb);
            };
        } else if (protocol === 'http' || protocol === 'https') {
            assetConfig.rawSrcProxy = function (cb) {
                request({
                    url: assetConfig.url,
github aerogear / graphback / src / schema / SchemaGenerator.ts View on Github external
private registerPartials() {
    const partialsPath = join(__dirname, `partials`);
    const templates = new GlobSync('./*.handlebars', { cwd: partialsPath });
    templates.found.forEach((path: string) => {
      logger.debug("Adding new partial", path);
      // tslint:disable-next-line:no-any
      let name: any = basename(path).split('.');
      if (name.length > 0) {
        name = name[0];
      }
      const location = join(partialsPath, path);
      const content = readFileSync(location, { encoding: "UTF8" });
      handlebars.registerPartial(name, content);
    });
  }
}
github google / pulito / webpack.common.js View on Github external
function pageFinder(dir, webpack_config, minifyOutput) {
  // Look at all sub-directories of dir and if a directory contains
  // both a -demo.html and -demo.js file then add the corresponding
  // entry points and Html plugins to the config.

  // Find all the dirs below 'dir'.
  const pagesDir = path.resolve(dir, 'pages');
  // Look for all *.js files, for each one look for a matching .html file.
  // Emit into config.
  //
  const pagesJS = glob.sync(pagesDir + '/*.js');

  pagesJS.forEach(pageJS => {
    // Look for both a .js and .html file in the directory.
    // Strip off ".js" from end and replace with ".html".
    let pageHTML = pageJS.replace(/\.js$/, '.html');
    if (!fs.existsSync(pageHTML)) {
      console.log("WARNING: A page needs both a *.js and a *.html file.");
      return
    }

    let baseHTML = basename(pageHTML);
    let name = basename(pageJS, '.js');
    webpack_config.entry[name] = pageJS;
    let opts = {
      filename: baseHTML,
      template: pageHTML,
github google / skia-buildbot / pulito / webpack.common.js View on Github external
function pageFinder(dir, webpack_config) {
  // Look at all sub-directories of dir and if a directory contains
  // both a -demo.html and -demo.js file then add the corresponding
  // entry points and Html plugins to the config.

  // Find all the dirs below 'dir'.
  const pagesDir = path.resolve(dir, 'pages');
  // Look for all *.js files, for each one look for a matching .html file.
  // Emit into config.
  //
  const pagesJS = glob.sync(pagesDir + '/*.js');

  pagesJS.forEach(pageJS => {
    // Look for both a .js and .html file in the directory.
    // Strip off ".js" from end and replace with ".html".
    let pageHTML = pageJS.replace(/\.js$/, '.html');
    if (!fs.existsSync(pageHTML)) {
      console.log("WARNING: A page needs both a *.js and a *.html file.");
      return
    }

    let baseHTML = basename(pageHTML);
    let name = basename(pageJS, '.js');
    webpack_config.entry[name] = pageJS;
    webpack_config.plugins.push(
      new HtmlWebpackPlugin({
        filename: baseHTML,
github eva-org / eva-core / app / base_plugin / FindApp / index.js View on Github external
if (isMac) {
      config.patterns = ['/Applications/**.app', `${os.homedir()}/Downloads/**.**`]
      config.command = 'open '
    } else if (isWindows) {
      config.patterns = ['C:/ProgramData/Microsoft/Windows/Start Menu/Programs/**.lnk']
      config.command = ''
    } else if (isLinux) {
      // TODO linux support. Pull request needed.
    } else {
      logger.error('Not support current system.')
    }
    saveConfig('findApp', config)
  }

  for (const pattern of config.patterns) {
    await glob.promise(pattern, (err, file) => {
      if (err) {
        logger.error(err)
        return
      }
      files = files.concat(file.toString().split(',').filter(() => true))
    })
  }

  //加载缓存
  const cacheFileExist = fs.existsSync(cachePath)
  files.forEach(file => {
    searchCache[file] = 0
  })
  if (cacheFileExist) {
    Object.assign(searchCache, JSON.parse(fs.readFileSync(cachePath).toString()))
  } else {