forked from mouseless/prebuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { readFileSync } from "fs";
import { join, dirname } from "path";
import YAML from "yaml";
import * as builtInTasks from "./tasks/index.js";
import * as log from "./tasks/utils/log.js";
/**
* Runs tasks configured in .yml file
*
* @async
* @param {String} configPath Path of the prebuild configuration file
* @param {Module} options Run options parameter
* @param {Module} options.customTasks Custom module for user defined tasks
*
* @returns {Promise}
*/
export async function run(configPath,
{ customTasks } = { customTasks: {} }
) {
process.setMaxListeners(0);
const configDir = dirname(configPath);
const config = YAML.parse(readFileSync(configPath, "utf8"));
const projectRoot = join(configDir, config.projectRoot);
process.chdir(projectRoot);
Object.assign(log.settings, config.log);
const tasks = { ...builtInTasks, ...customTasks };
for (const task of config.tasks) {
const [name] = Object.keys(task);
const parameters = task[name];
await tasks[name](parameters);
}
}