turbo-gulp
Version:
Gulp tasks to boost high-quality projects.
29 lines (28 loc) • 862 B
JavaScript
import { Minimatch } from "minimatch";
import { asString, join } from "../utils/matcher";
/**
* Return a list of sources, prefixed by "from"
*/
export function getSources({ files, from }) {
return files.map((val) => asString(join(from, new Minimatch(val))));
}
export function copy(gulp, options) {
return gulp
.src(getSources(options), { base: options.from })
.pipe(gulp.dest(options.to));
}
/**
* Generate a task to copy files from one directory to an other.
*/
export function generateTask(gulp, options) {
const task = function () {
return copy(gulp, options);
};
task.displayName = "_copy";
return task;
}
export function watch(gulp, options) {
const buildTask = generateTask(gulp, options);
const sources = getSources(options);
return gulp.watch(sources, { cwd: options.from }, buildTask);
}