forked from kriasoft/graphql-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.js
More file actions
36 lines (33 loc) · 1001 Bytes
/
task.js
File metadata and controls
36 lines (33 loc) · 1001 Bytes
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
/**
* Copyright © 2016-present Kriasoft.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
/*
* Minimalistic script runner. Usage example:
*
* node tools/db.js migrate
* Starting 'db-migrate'...
* Finished 'db-migrate' in 25ms
*/
function run(task, action, ...args) {
const command = process.argv[2];
const taskName =
command && !command.startsWith('-') ? `${task}-${command}` : task;
const start = new Date();
process.stdout.write(`Starting '${taskName}'...\n`);
return Promise.resolve()
.then(() => action(...args))
.then(
() => {
process.stdout.write(
`Finished '${taskName}' after ${new Date().getTime() -
start.getTime()}ms\n`,
);
},
err => process.stderr.write(`${err.stack}\n`),
);
}
process.nextTick(() => require.main.exports());
module.exports = (task, action) => run.bind(undefined, task, action);