turbo-gulp
Version:
Gulp tasks to boost high-quality projects.
32 lines (31 loc) • 1.39 kB
JavaScript
import { posix as posixPath } from "path";
import { DEFAULT_PROJECT_TSC_OPTIONS, mergeTscOptionsJson } from "../options/tsc";
import { writeJsonFile } from "../utils/project";
export function generateTask(gulp, options) {
const compilerOptions = mergeTscOptionsJson(DEFAULT_PROJECT_TSC_OPTIONS, options.compilerOptions);
const task = async function () {
return writeJsonFile(options.tsconfigJson, { compilerOptions });
};
task.displayName = getTaskName();
return task;
}
export function getTaskName() {
return ":tsconfig.json";
}
export function registerTask(gulp, project) {
if (project.typescript === undefined || project.typescript.tsconfigJson === undefined) {
throw new Error("Cannot register project tsconfigJson task, missing required properties options");
}
const subTasks = [];
for (const tsconfigPath of project.typescript.tsconfigJson) {
const tsconfigJson = posixPath.join(project.root, tsconfigPath);
const compilerOptions = project.typescript.compilerOptions;
const subTask = generateTask(gulp, { tsconfigJson, compilerOptions });
subTask.displayName = `_tsconfig.json:${tsconfigPath}`;
subTasks.push(subTask);
}
const mainTask = gulp.parallel(...subTasks);
mainTask.displayName = getTaskName();
gulp.task(mainTask.displayName, mainTask);
return mainTask;
}