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
29 lines (26 loc) · 1019 Bytes
/
task.js
File metadata and controls
29 lines (26 loc) · 1019 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
/**
* Node.js API Starter Kit (https://reactstarter.com/nodejs)
*
* Copyright © 2016-present Kriasoft, LLC. All rights reserved.
*
* 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 scripts/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);