-
Notifications
You must be signed in to change notification settings - Fork 2
Helper functions
Paths
Config
Merge
Glob generator helper
const getPaths = require('@videinfra/example-website-builder/lib/get-path');Return path configuration object
getPaths.getPathConfig(); // => {'src': '...', 'dest': '...', 'html': {'src': '...', 'dest': '...'}, ...}Returns task source path or paths, absolute paths.
If a task has a single source path, then returns a string, if a task has multiple source paths then returns an array of paths.
getPaths.getSourcePath('html');
// => '/www/my-project/html/src/html'
getPaths.getSourcePath('html', 'foo', 'bar', 'baz.html');
// => '/www/my-project/html/src/html/foo/bar/baz.html'
getPaths.getSourcePath('example', 'baz.html');
// => ['/www/my-project/html/src/example-1/baz.html', '/www/my-project/html/src/example-2/baz.html']Returns task source paths. Same as getSourcePath but always returns an array of paths even if there is a single path.
Returns task destination path
getPaths.getDestPath('html'); // => 'public'
getPaths.getDestPath('html', 'foo', 'bar', 'baz.html'); // => '/www/my-project/public/foo/bar/baz.html'Returns a path relative to the project folder. Project folder is a folder from which "builder" command is called.
getPaths.getProjectPath(); // => '/www/my-project'
getPaths.getProjectPath('example/hello', 'world.txt'); // => '/www/my-project/example/hello/world.txt'Returns a path relative to the builderfolder. Builder folder is a @videinfra/example-website-builder package folder.
getPaths.getBuilderPath();
// => '/www/my-project/node_modules/@videinfra/example-website-builder'
getPaths.getBuilderPath('example/hello', 'world.txt');
// => '/www/my-project/node_modules/@videinfra/example-website-builder/example/hello/world.txt'const getConfig = require('@videinfra/example-website-builder/lib/get-config');Returns full config, including all tasks, paths and preprocess functions
getConfig.getConfig(); // => {'paths': {...}, 'tasks': {...}, 'preprocess': {...}, 'html': {...}, 'stylesheets': {...}, ...}Returns a value from config object by path
getConfig.getTaskConfig('javascripts', 'webpack' 'resolve'); // => {alias:{}}const merge = require('@videinfra/example-website-builder/lib/merge');Merge source objects into dest objects recursively. Uses lodash/merge but with support for merging arrays
merge({'a': ['b'], 'c': {'d': 1}}, {'a': ['e'], 'c': {'e': 2}, 'f': 3);
// => {'a': ['b', 'e'], 'c': {'d': 1, 'e': 2}, 'f': 3}Helper to create globs and normalize for different operating systems.
const glob = require('@videinfra/example-website-builder/lib/globs-helper');Creates a helper object with paths
glob.paths(getConfig.getSourcePaths('html')); // => [GlobObject] instanceOutputs paths from all GlobObjects as array
glob.generate(
glob.paths(getConfig.getSourcePaths('html')).allFiles(),
glob.paths(getConfig.getSourcePaths('data')).allFiles()
);
// => ['/www/my-project/html/src/html/**/*', '/www/my-project/html/src/data/**/*']Returns an array of paths
glob.paths(getConfig.getSourcePaths('html')).generate();
// => ['/www/my-project/html/src/html']Add recursively additional paths
glob.paths(getConfig.getSourcePaths('html')).paths(['a', 'b']).generate();
// => ['/www/my-project/html/src/html/a', '/www/my-project/html/src/html/b']Adds a wildcard to match all files for the paths
glob.paths(getConfig.getSourcePaths('html')).allFiles().generate();
// => ['/www/my-project/html/src/html/**/*']Adds file extensions to the paths
glob.paths(getConfig.getSourcePaths('html')).filesWithExtensions(['jpg']).generate();
// => ['/www/my-project/html/src/html/**/*.jpg']
glob.paths(getConfig.getSourcePaths('html')).filesWithExtensions(['jpg', 'png']).generate();
// => ['/www/my-project/html/src/html/**/*.{jpg,png}']Adds all paths to the ignore list, meaning that gulp.src won't be matching those files
glob.paths(getConfig.getSourcePaths('html')).allFiles().ignore().generate();
// => ['!/www/my-project/html/src/html/**/*']Runs array .map functions on all paths.
function addHelloWorld (path, index) {
return path + '/hello-world';
}
glob.paths(getConfig.getSourcePaths('html')).map(addHelloWorld).generate();
// => ['/www/my-project/html/src/html/hello-world']