コード例 #1
0
ファイル: build.js プロジェクト: easystatic/easystatic
/**
 * Builds a distributable version of the static site from source files.
 */
async function build({ baseDir, buildDir, assetsDir, base, production }) {
  log(`build({ baseDir: '${baseDir}' })`);
  await scaffold({ baseDir, assetsDir });

  // Clean up the output directory
  log('remove', path.resolve(baseDir, buildDir));
  await fs.removeDir(path.resolve(baseDir, buildDir));

  // Load information about the project from GitHub API and NPM Registry.
  // For example, the number of stars on GitHub, package version on NPM etc.
  const data = await info({ baseDir });

  // https://github.com/isaacs/node-glob#options
  const opts = { cwd: path.resolve(process.cwd(), baseDir) };

  // Get the list of Markdown files in the source folder
  let files = await glob(['**/*.md', `!${buildDir}/**`, `!${assetsDir}/**`], opts);

  // Compile *.md files and copy them to dist/*.html
  await Promise.all(files.map(file => new Promise(async (resolve, reject) => {
    try {
      // Resolve URL path from a filename:
      //   - index.md       -> /
      //   - privacy.md     -> /privacy
      //   - about/index.md -> /about
      //   - about/team.md  -> /about/team
      const pathname = `/${file}`.replace(/(\/index)?\.md$/, '') || '/';
      // Generate HTML markup from a Markdown file
      const contents = await compile.md(path.join(baseDir, file), {
        baseDir,
        assetsDir,
        production,
        data: { ...data, base, path: pathname, file }, // data variables for EJS template(s)
      });
      // Resolve the output filename:
      //   - /index.md       -> /dist/index.html
      //   - /about/index.md -> /dist/about/index.html
      const filename = path.resolve(baseDir, path.join(buildDir, file.replace(/\.md$/, '.html')));
      log('create', filename);
      await fs.createDir(path.dirname(filename));
      await fs.writeFile(filename, contents, 'utf-8');
      resolve();
    } catch (err) {
      reject(err);
    }
  })));

  // Bundle and minimize all the CSS files that a referenced in assets/main.css and
  // save the resulting bundle to dist/main.css
  const css = await compile.css('/main.css', { baseDir, assetsDir, production });
  await fs.writeFile(path.resolve(baseDir, path.join(buildDir, 'main.css')), css, 'utf-8');

  // Copy the remaining assets from the assets folder to dist.
  opts.cwd = path.resolve(opts.cwd, assetsDir);
  files = await glob(['**/*.*', '!**/*.{md,ejs,css}'], opts);
  await Promise.all(files.map(file => cp(
    path.resolve(baseDir, assetsDir, file),
    path.resolve(baseDir, buildDir, file)
  )));
}
コード例 #2
0
ファイル: git-diff.js プロジェクト: valsun2016/apfe-cli
async function searchGitFile (dir) {
  let deps = 10
  while (!(await globby('.git', { cwd: dir })).length && deps > 0) {
    dir = path.resolve(dir, '..')
    --deps
  }

  if (!(await globby('.git', { cwd: dir })).length) {
    throw new Error('Could not find .git file')
  } else {
    return path.resolve(dir)
  }
}
コード例 #3
0
ファイル: gulpfile.babel.js プロジェクト: DaBs/PokeSniffer
gulp.task('javascript', () => {

  const bundledStream = through();

  bundledStream
    .pipe(source('main.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    /*.pipe(uglify())
      .on('error', gutil.log)*/
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./www/js'))
    .pipe(reload({stream: true}));

  globby(['./src/**/*.vue', './src/main.js']).then(function(entries) {
    const b = browserify({
      entries: entries,
      debug: true,
      transform: [vueify, babelify]
    });

    b.on('update', function() {
      b.bundle().pipe(bundledStream);
    });
    b.bundle().pipe(bundledStream);
  }).catch(function(err) {
    bundledStream.emit('error', err);
  });

  gulp.src('./src/vendor/**/*.js')
    .pipe(gulp.dest('./www/js/vendor'));

  return bundledStream;
});
コード例 #4
0
const matchToFs = (pattern, num = 1, opts = {}) => new Promise((resolve, reject) => {
  if (_.isNull(num) || _.isUndefined(num)) num = (len) => len !== 0

  let _num
  if (_.isNumber(num)) _num = (len) => len === num
  if (_.isFunction(num)) _num = num

  opts = Object.assign({}, { realpath: true }, opts)

  globby(pattern, opts)
  .then((paths) => {
    // You could expect 0 matches with a custom `num` function if desired
    if (_num(paths.length)) {
      // Turn one item arrays into just the item
      if (paths.length === 1) paths = paths[0]
      // Else, resolve with array of paths
      return resolve(paths)
    } else {
      // TODO more descriptive error message if num was a number
      reject(`No matches found for pattern ${chalk.magenta(pattern)} in ${opts.cwd || process.cwd()}`)
    }
  })
  .catch((err) => {
    console.log('math-to-fs error: ', err)
    reject(err)
  })
})
コード例 #5
0
ファイル: index.js プロジェクト: 1031Hiko/Original-App-Order
module.exports = function (patterns, opts) {
	opts = objectAssign({}, opts);

	var force = opts.force;
	delete opts.force;

	var dryRun = opts.dryRun;
	delete opts.dryRun;

	return globby(patterns, opts).then(function (files) {
		return Promise.all(files.map(function (file) {
			if (!force) {
				safeCheck(file);
			}

			file = path.resolve(opts.cwd || '', file);

			if (dryRun) {
				return Promise.resolve(file);
			}

			return rimrafP(file).then(function () {
				return file;
			});
		}));
	});
};
コード例 #6
0
ファイル: generate-menus.js プロジェクト: nayan1247/site
function getDirectories() {
  const docsPath = config.siteDocsPath + '/**'
  const not = '!**/*.*'
  return globby([docsPath, not]).then(paths => {
    return paths
  })
}
コード例 #7
0
ファイル: gulpfile.js プロジェクト: ying123/cesium
 .then(function () {
     return globby(['Source/Workers/cesiumWorkerBootstrapper.js',
         'Source/Workers/transferTypedArrayTest.js',
         'Source/ThirdParty/Workers/*.js',
         // Files are already minified, don't optimize
         '!Source/ThirdParty/Workers/draco*.js']);
 })
コード例 #8
0
module.exports = function resolveGlob(id, base, opts) {
    var prefix = opts.prefix;
    var extensions = opts.extensions;
    var paths = [base].concat(opts.path);
    var patterns = [];
    var prefixedId = prefix ? addPrefix(id, prefix) : null;

    paths.forEach(function (p) {
        [''].concat(extensions).forEach(function (ext) {
            if (prefix) {
                patterns.push(path.resolve(p, prefixedId + ext));
            }
            patterns.push(path.resolve(p, id + ext));
        });
    });

    return globby(patterns).then(function (files) {
        return files.filter(function (file) {
            return hasExtensions(file, extensions) &&
                (!prefix || hasPrefix(file, prefix));
        }).map(function (file) {
            return path.normalize(file);
        });
    });
};
コード例 #9
0
ファイル: questions.js プロジェクト: dequelabs/axe-core
const validateGetRuleName = async input => {
	const ruleName = input.toLowerCase();
	// 1) check if valid name
	if (!isValidName(ruleName)) {
		throw new Error(
			'RULE name should not be empty and can only contain alphabets and dashes.'
		);
	}
	// 2) ensure no rule filename overlaps
	if (fs.existsSync(`${directories.rules}/${ruleName}.json`)) {
		throw new Error(`RULE name conflicts with an existing rule's filename.`);
	}
	// 3) ensure no rule id overlaps
	const ruleSpecs = await globby(directories.rules, {
		expandDirectories: { extensions: ['json'] }
	});
	const axeRulesIds = ruleSpecs.reduce((out, specPath) => {
		const spec = require(specPath);
		out.push(spec.id);
		return out;
	}, []);
	if (axeRulesIds.includes(ruleName)) {
		throw new Error('Rule ID already exists.');
	}
	return true;
};
コード例 #10
0
gulp.task('build_prod_script', function () {
    var bundledStream = through();

    bundledStream
        .pipe(source('app.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({loadMaps: true}))
        .pipe(gulp.dest('./client/dist/js/'))
        .pipe(uglify())
        .pipe(rename({ suffix: '.min' }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./client/dist/js/'));

    globby(['./client/src/js/*.js'], function(err, entries) {
        if (err) {
            bundledStream.emit('error', err);
            return;
        }

        var b = browserify({
            entries: entries,
            debug: true,
            transform: [babelify]
        });

        b.bundle().pipe(bundledStream);
    });

    return bundledStream;
});
コード例 #11
0
ファイル: prettier.js プロジェクト: Daniel15/prettier
function eachFilename(patterns, callback) {
  if (ignoreNodeModules) {
    patterns = patterns.concat(ignoreNodeModulesGlobs);
  }

  return globby(patterns, globOptions)
    .then(filePaths => {
      if (filePaths.length === 0) {
        console.error(
          "No matching files. Patterns tried: " + patterns.join(" ")
        );
        process.exitCode = 2;
        return;
      }

      filePaths.forEach(filePath => {
        return callback(filePath);
      });
    })
    .catch(err => {
      console.error(
        "Unable to expand glob patterns: " + patterns.join(" ") + "\n" + err
      );
      // Don't exit the process if one pattern failed
      process.exitCode = 2;
    });
}
コード例 #12
0
ファイル: gulpfile.js プロジェクト: igemuoftATG/wiki2016
gulp.task('browserify', () => {
  globby([globs.libJS], (err, entries) => {
    if (err) {
      gutil.log()
      return
    }

    const b = browserify({
      entries,
      extensions: ['.js'],
      debug: true,
      // transform: [babelify]
    })

    const combined = combiner.obj([
      b.bundle(),
      source('bundle.js'),
      buffer(),
      sourcemaps.init({ loadMaps: true }),
      sourcemaps.write('./maps'),
      gulp.dest(dests.dev.js)
    ])

    combined.on('error', gutil.log)

    return combined
  })
})
コード例 #13
0
gulp.task('build_dev_script', function () {
    var bundledStream = through();

    bundledStream
        .pipe(source('app.js'))
        .pipe(buffer())
        .pipe(gulp.dest('./client/dist/js/'))
        .pipe(livereload());

    globby(['./client/src/js/*.js'], function(err, entries) {
        if (err) {
            bundledStream.emit('error', err);
            return;
        }

        var b = browserify({
            entries: entries,
            transform: [babelify]
        });

        b.bundle().pipe(bundledStream);
    });

    return bundledStream;
});
コード例 #14
0
ファイル: build.js プロジェクト: Xalior/nocca
function copyStatic () {

    return $globby([
        './src/*.html',
        './src/*.ico'
    ]).then(function (files) {

        var deferreds = [];

        files.forEach(function (file) {

            var promise = $q.nfcall($fs.readFile, file)
                .then(function (buffer) {

                    return $q.nfcall($fs.writeFile, $path.resolve('./ui', $path.basename(file)), buffer);

                });

            deferreds.push(promise);

        });

        return $q.all(deferreds);

    });

}
コード例 #15
0
gulp.task('build-js', function () {
    // gulp expects tasks to return a stream, so we create one here.
    var bundledStream = through();

    bundledStream
    // turns the output bundle stream into a stream containing
    // the normal attributes gulp plugins expect.
        .pipe(source('cytube-enhanced.js'))
        .pipe(buffer())
        // Add gulp plugins to the pipeline here.
        .pipe(gulp.dest('./build/ru'))
        .pipe(rename('cytube-enhanced.min.js'))
        .pipe(uglify({mangle: false, preserveComments: ''}))
        .pipe(gulp.dest('./build/ru'));

    // "globby" replaces the normal "gulp.src" as Browserify
    // creates it's own readable stream.
    globby(jsFilesGlob, function(err, entries) {
        // ensure any errors from globby are handled
        if (err) {
            bundledStream.emit('error', err);
            return;
        }

        // create the Browserify instance.
        var b = browserify({entries: entries});

        // pipe the Browserify stream into the stream we created earlier
        // this starts our gulp pipeline.
        b.bundle().pipe(bundledStream);
    });

    // finally, we return the stream, so gulp knows when this task is done.
    return bundledStream;
});
コード例 #16
0
ファイル: prepare.js プロジェクト: mochamaddani/vuepress
async function resolveComponents (sourceDir) {
  const componentDir = path.resolve(sourceDir, '.vuepress/components')
  if (!fs.existsSync(componentDir)) {
    return
  }
  return sort(await globby(['**/*.vue'], { cwd: componentDir }))
}
コード例 #17
0
ファイル: fix-export.js プロジェクト: tscanlin/tocbot
globby(`out/**/page`).then((files) => {
  const folder = files[0]
  const newFolder = folder.split('/page').join(prefix)
  console.log('Copying: ', folder, newFolder)
  fs.copySync(folder, newFolder)
  fs.moveSync(newFolder, folder + prefix)
  globby(folder + prefix + '/**/*.js').then((editFiles) => {
    console.log(editFiles)
    editFiles.forEach((file) => {
      fs.readFile(file, 'utf8', function (err, data) {
        if (err) {
          return console.log(err)
        }

        const newString = "window.__NEXT_REGISTER_PAGE('" + prefix
        const rootPathString = "window.__NEXT_REGISTER_PAGE('/'"

        let result = data
        if (data.indexOf(newString) === -1 && data.indexOf(rootPathString) === -1) {
          result = data.replace(/window.__NEXT_REGISTER_PAGE\(\'/g, newString)
        } else if (data.indexOf(rootPathString) > -1) {
          // If it's the index page then don't leave the trailing slash.
          result = data.replace(/window.__NEXT_REGISTER_PAGE\(\'\/\'/g, newString + "'")
        }

        fs.writeFile(file, result, 'utf8', function (err) {
          if (err) return console.log(err)
        })
      })
    })
  }).catch((e) => {
    console.log(e)
  })
  return files
}).catch((e) => {
コード例 #18
0
ファイル: globs.js プロジェクト: avajs/ava
const findFiles = async (cwd, patterns) => {
	const files = await globby(patterns, {
		absolute: true,
		brace: true,
		case: false,
		cwd,
		dot: false,
		expandDirectories: false,
		extglob: true,
		followSymlinkedDirectories: true,
		gitignore: false,
		globstar: true,
		ignore: defaultIgnorePatterns,
		matchBase: false,
		onlyFiles: true,
		stats: false,
		unique: true
	});

	// `globby` returns slashes even on Windows. Normalize here so the file
	// paths are consistently platform-accurate as tests are run.
	if (process.platform === 'win32') {
		return files.map(file => path.normalize(file));
	}

	return files;
};
コード例 #19
0
/**
 * Requires multiple modules using glob patterns. Supports exclusions.
 *
 * @type {Function}
 * @param {String|Array.<String>|Function|*} patterns A glob string, array of
 *   glob strings, or a function that will return either. If not a string or
 *   an array, value will be returned as-is.
 * @param {Object=} options Options for `globby` module and callbacks.
 * @param {Boolean=} options.bustCache Whether to force the reload of modules by deleting them from the cache.
 * @param {Function=} options.mapper Custom mapper.
 * @param {Function=} options.reducer Custom reducer.
 * @param {Function=} options.keygen Custom key generator.
 * @param {Function(?String, Object)} callback
 * @return {Null}
 */
function requireGlob(patterns, options, callback) {
	// Make `options` optional
	if (arguments.length === 2) {
		callback = options;
		options = null;
	}

	options = normalizeOptions(options);
	patterns = normalizePatterns(patterns, options);

	// If patterns isn't a glob, act as a pass-through
	if (!isGlob(patterns)) {
		callback(null, patterns);
		return;
	}

	globby(patterns, options, function (err, paths) {
		try {
			// istanbul ignore if
			if (err) {
				throw err;
			}

			callback(null, normalizePaths(paths, options));
		}
		catch (e) {
			// istanbul ignore next
			callback(e);
		}
	});
}
コード例 #20
0
 func: function (cb) {
   // options is optional
   globby(pattern, globOptions, function (err, files) {
     if (err) {
       return cb(err);
     }
     _.forEach(files,function (filename) {
       var extension;
       if (minimatch(filename, '**/*.+(html|js|sjs|scss)')) {
         extension = _.last(filename.split('.'));
         console.log('Looking up "' + filename + '" information');
         var fileContents = fs.readFileSync('./' + filename, 'utf8');
         var operation;
         var regx = /Copyright (\d{4})-(\d{4}) MarkLogic Corporation/g;
         var match = regx.exec(fileContents);
         if (match) {
           operation = 'Updated';
           // update existing copyright text
           fileContents = fileContents
             .replace(regx, copyright);
         }
         else {
           operation = 'Added';
           // add complete copyright text
           fileContents = copyrightText[extension] + fileContents;
         }
         fs.writeFileSync('./' + filename, fileContents);
         console.log(operation + ' copyright to: ' + filename);
       }
     });
   });
   cb();
 }
コード例 #21
0
gulp.task('browserify', function () {

	var bundledStream = through()
		.pipe(buffer());

	globby("./assets/browserify/[^_]*.js").then(function(entries) {
		var stream = merge(entries.map(function(entry) {
			var file = entry.split('/').pop();

			return browserify({
					entries: [entry],
					debug: true
				})
				.bundle()
				.pipe(source(file))

				// create .js file
				.pipe(rename({ extname: '.js' }))
				.pipe(gulp.dest('./assets/js'))

				// create .min.js file
				.pipe(streamify(uglify()))
				.pipe(rename({ extname: '.min.js' }))
				.pipe(gulp.dest('./assets/js'));
		}));

		stream
			.pipe(bundledStream);
	}).catch(function(err) {});

	return bundledStream;
});
コード例 #22
0
var _filesMap = function(input, cb) {
  var data = input;

  globby(data).then(function(fileList) {
    cb(fileList);
  });
};
コード例 #23
0
ファイル: index.js プロジェクト: rlugojr/xo
exports.lintFiles = (patterns, opts) => {
	opts = optionsManager.preprocess(opts);

	if (patterns.length === 0) {
		patterns = '**/*';
	}

	return globby(patterns, {ignore: opts.ignores}).then(paths => {
		// filter out unwanted file extensions
		// for silly users that don't specify an extension in the glob pattern
		paths = paths.filter(x => {
			// Remove dot before the actual extension
			const ext = path.extname(x).replace('.', '');
			return opts.extensions.indexOf(ext) !== -1;
		});

		if (!(opts.overrides && opts.overrides.length > 0)) {
			return runEslint(paths, opts);
		}

		const overrides = opts.overrides;
		delete opts.overrides;

		const grouped = optionsManager.groupConfigs(paths, opts, overrides);

		return mergeReports(grouped.map(data => runEslint(data.paths, data.opts)));
	});
};
コード例 #24
0
ファイル: gulpfile.js プロジェクト: mozcmcgill/testpilot
gulp.task('scripts', shouldLint('js-lint', 'lint'), function scriptsTask() {
  const bundledStream = through();

  // this part runs second
  bundledStream
    .pipe(source('app.js'))
    .pipe(buffer())
    .pipe(gulpif(IS_DEBUG, sourcemaps.init({loadMaps: true})))
     // don't uglify in development. eases build chain debugging
    .pipe(gulpif(!IS_DEBUG, uglify()))
    .on('error', gutil.log)
    .pipe(gulpif(IS_DEBUG, sourcemaps.write('./')))
    .pipe(gulp.dest(DEST_PATH + 'app/'));

  // this part runs first, then pipes to bundledStream
  globby([SRC_PATH + 'app/**/*.js']).then(function gatherFiles(entries) {
    const b = browserify({
      entries: entries,
      debug: IS_DEBUG,
      fullPaths: IS_DEBUG,
      transform: [babelify]
    });
    b.bundle()
      .pipe(bundledStream);
  }, function onGlobbyError(err) {
    return bundledStream.emit('error', err);
  });

  return bundledStream;
});
コード例 #25
0
ファイル: utils.js プロジェクト: YurySolovyov/museeks
const fetchCover = async (trackPath) => {
    if(!trackPath) {
        return null;
    }

    const stream = fs.createReadStream(trackPath);

    const data = await musicmetadataAsync(stream);

    if(data.picture[0]) { // If cover in id3
        return parseBase64(data.picture[0].format, data.picture[0].data.toString('base64'));
    }

    // scan folder for any cover image
    const folder = path.dirname(trackPath);
    const pattern = path.join(folder, '*');
    const matches = await globby(pattern, { nodir: true, follow: false });

    return matches.find((elem) => {
        const parsedPath = path.parse(elem);

        return ['album', 'albumart', 'folder', 'cover'].includes(parsedPath.name.toLowerCase())
            && ['.png', '.jpg', '.bmp', '.gif'].includes(parsedPath.ext.toLowerCase()) ;
    });
};
コード例 #26
0
ファイル: index.js プロジェクト: binocarlos/guilder
function runCopy(srcFolder, glob, destFolder, emitter, processPath, done, sync){
	if(typeof(glob)=='string'){
		glob = [glob]
	}
	processPath = processPath || function(path){
		return path
	}
	globby(glob, {
		cwd:srcFolder
	}, function(err, files){

		files = files.filter(function(f){
			return f.match(/\.\w+$/)
		})
		
		async.forEach(files, function(file, nextFile){

			emitter('copy: ' + file)

			var fileSrc = path.join(srcFolder, file)
			var fileDest = path.join(destFolder, processPath(file))

			if(sync){
				cpFile.sync(fileSrc, fileDest);
				nextFile();
			}else{
				cpFile(fileSrc, fileDest, nextFile);
			}

		}, done)

	})
}
コード例 #27
0
ファイル: index.js プロジェクト: AlexPenkin/Messenger
exports.lintFiles = function (patterns, opts) {
	opts = optionsManager.preprocess(opts);

	if (patterns.length === 0) {
		patterns = '**/*.{js,jsx}';
	}

	return globby(patterns, {ignore: opts.ignores}).then(function (paths) {
		// when users are silly and don't specify an extension in the glob pattern
		paths = paths.filter(function (x) {
			var ext = path.extname(x);
			return ext === '.js' || ext === '.jsx';
		});

		if (!(opts.overrides && opts.overrides.length)) {
			return runEslint(paths, opts);
		}

		var overrides = opts.overrides;
		delete opts.overrides;

		var grouped = optionsManager.groupConfigs(paths, opts, overrides);

		return mergeReports(grouped.map(function (data) {
			return runEslint(data.paths, data.opts);
		}));
	});
};
コード例 #28
0
ファイル: gulpfile.js プロジェクト: sld/Planamp
gulp.task('images', ['clean'], function() {
    globby(source.images, function (err, paths) {
        gulp.src(paths)
            .pipe(gulp.dest(build.images))
            .pipe(imagemin())
    });
});
コード例 #29
0
 .then(function() {
     return globby(['Source/Workers/*.js',
                    '!Source/Workers/cesiumWorkerBootstrapper.js',
                    '!Source/Workers/transferTypedArrayTest.js',
                    '!Source/Workers/createTaskProcessorWorker.js',
                    '!Source/ThirdParty/Workers/*.js']);
 })
コード例 #30
0
ファイル: add-element.js プロジェクト: atomproject/browser
let createNewElement = Q.async(function* (el) {
  let repo = 'polymerelements/seed-element';
  // download and extrac the seed-element
  let repoPath = yield utils.extractGhRepo(repo, '.', el.name);
  el.install = repoPath;

  yield fs.removeTree(path.resolve(repoPath, '.github'));

  let replacePaths = yield globby([`${repoPath}/**`], {nodir: true});

  // replace the text `seed-element` with the name of the new element
  yield Promise.all(replacePaths.map(Q.async(function*(p) {
    let content = yield fs.read(p);
    let ccName = utils.toCamelCase(el.name);

    content = content.replace(/seedElement/g, ccName);
    content = content.replace(/seed-element/g, el.name);

    yield fs.write(p, content);
  })));

  let fromPath = path.resolve(repoPath, 'seed-element.html');
  let toPath = path.resolve(repoPath, `${el.name}.html`);
  // rename the paths to the new name
  yield fs.rename(fromPath, toPath);

  return el;
});