hereby 1.0.6 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +7 -3
- package/dist/cli/parseArgs.js +7 -0
- package/dist/cli/runner.js +38 -5
- package/dist/cli/utils.js +6 -0
- package/dist/index.d.ts +5 -3
- package/package.json +7 -7
- package/dist/runner.js +0 -44
package/dist/cli/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { formatTasks } from "./formatTasks.js";
|
|
|
5
5
|
import { findHerebyfile, loadHerebyfile } from "./loadHerebyfile.js";
|
|
6
6
|
import { getUsage, parseArgs } from "./parseArgs.js";
|
|
7
7
|
import { reexec } from "./reexec.js";
|
|
8
|
-
import {
|
|
8
|
+
import { Runner } from "./runner.js";
|
|
9
9
|
import { ExitCodeError, simplifyPath, UserError } from "./utils.js";
|
|
10
10
|
export async function main(d) {
|
|
11
11
|
try {
|
|
@@ -35,6 +35,10 @@ async function mainWorker(d) {
|
|
|
35
35
|
if (await reexec(d, herebyfilePath)) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
+
if (args.version) {
|
|
39
|
+
d.log(`hereby ${d.version}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
38
42
|
d.chdir(path.dirname(herebyfilePath));
|
|
39
43
|
d.log(`Using ${simplifyPath(herebyfilePath)}`);
|
|
40
44
|
const herebyfile = await loadHerebyfile(herebyfilePath);
|
|
@@ -44,7 +48,7 @@ async function mainWorker(d) {
|
|
|
44
48
|
}
|
|
45
49
|
const tasks = selectTasks(herebyfile, args.run);
|
|
46
50
|
try {
|
|
47
|
-
const runner = new
|
|
51
|
+
const runner = new Runner(d);
|
|
48
52
|
await runner.runTasks(...tasks);
|
|
49
53
|
}
|
|
50
54
|
catch (e) {
|
|
@@ -66,7 +70,7 @@ export function selectTasks(herebyfile, taskNames) {
|
|
|
66
70
|
let message = `Task "${name}" does not exist or is not exported in the Herebyfile.`;
|
|
67
71
|
const candidate = closest(name, Array.from(allTasks.keys()));
|
|
68
72
|
if (distance(name, candidate) < name.length * 0.4) {
|
|
69
|
-
message += ` Did you mean "${candidate}
|
|
73
|
+
message += ` Did you mean "${candidate}"?`;
|
|
70
74
|
}
|
|
71
75
|
throw new UserError(message);
|
|
72
76
|
}
|
package/dist/cli/parseArgs.js
CHANGED
|
@@ -10,6 +10,7 @@ export function parseArgs(argv) {
|
|
|
10
10
|
{ name: "herebyfile", type: String },
|
|
11
11
|
{ name: "tasks", alias: "T", type: Boolean },
|
|
12
12
|
{ name: "help", alias: "h", type: Boolean },
|
|
13
|
+
{ name: "version", type: Boolean },
|
|
13
14
|
], {
|
|
14
15
|
argv,
|
|
15
16
|
stopAtFirstUnknown: true,
|
|
@@ -19,6 +20,7 @@ export function parseArgs(argv) {
|
|
|
19
20
|
run: options["run"],
|
|
20
21
|
herebyfile: options["herebyfile"],
|
|
21
22
|
printTasks: options["tasks"],
|
|
23
|
+
version: options["version"],
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
export function getUsage() {
|
|
@@ -53,6 +55,11 @@ export function getUsage() {
|
|
|
53
55
|
alias: "T",
|
|
54
56
|
type: Boolean,
|
|
55
57
|
},
|
|
58
|
+
{
|
|
59
|
+
name: "version",
|
|
60
|
+
description: "Print the current hereby version.",
|
|
61
|
+
type: Boolean,
|
|
62
|
+
},
|
|
56
63
|
],
|
|
57
64
|
},
|
|
58
65
|
{
|
package/dist/cli/runner.js
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
-
import
|
|
4
|
-
export class
|
|
5
|
-
constructor(d) {
|
|
6
|
-
|
|
3
|
+
import pLimit from "p-limit";
|
|
4
|
+
export class Runner {
|
|
5
|
+
constructor(d, limiter) {
|
|
6
|
+
this._addedTasks = new WeakMap();
|
|
7
7
|
this._errored = false;
|
|
8
8
|
this._startTimes = new WeakMap();
|
|
9
|
+
this._limiter = limiter ?? pLimit(d.numCPUs);
|
|
9
10
|
this._d = d;
|
|
10
11
|
}
|
|
12
|
+
async runTasks(...tasks) {
|
|
13
|
+
await Promise.all(tasks.map((task) => {
|
|
14
|
+
const cached = this._addedTasks.get(task);
|
|
15
|
+
if (cached) {
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
const promise = this._runTask(task);
|
|
19
|
+
this._addedTasks.set(task, promise);
|
|
20
|
+
return promise;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
async _runTask(task) {
|
|
24
|
+
const { dependencies, run } = task.options;
|
|
25
|
+
if (dependencies) {
|
|
26
|
+
await this.runTasks(...dependencies);
|
|
27
|
+
}
|
|
28
|
+
if (!run) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return this._limiter(async () => {
|
|
32
|
+
try {
|
|
33
|
+
this.onTaskStart(task);
|
|
34
|
+
await run();
|
|
35
|
+
this.onTaskFinish(task);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
this.onTaskError(task, e);
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
11
43
|
onTaskStart(task) {
|
|
12
44
|
this._startTimes.set(task, Date.now());
|
|
13
45
|
if (this._errored) {
|
|
@@ -27,7 +59,8 @@ export class CLIRunner extends Runner {
|
|
|
27
59
|
return; // Skip logging.
|
|
28
60
|
}
|
|
29
61
|
this._errored = true;
|
|
30
|
-
|
|
62
|
+
const took = Date.now() - checkDefined(this._startTimes.get(task));
|
|
63
|
+
this._d.error(`Error in ${chalk.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`);
|
|
31
64
|
}
|
|
32
65
|
}
|
|
33
66
|
function checkDefined(value) {
|
package/dist/cli/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
1
2
|
import os from "os";
|
|
2
3
|
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
3
5
|
export function taskSorter(a, b) {
|
|
4
6
|
return stringSorter(a.options.name, b.options.name);
|
|
5
7
|
}
|
|
@@ -40,6 +42,9 @@ export async function real() {
|
|
|
40
42
|
const { default: foregroundChild } = await import("foreground-child");
|
|
41
43
|
const { resolve } = await import("import-meta-resolve");
|
|
42
44
|
const { default: prettyMilliseconds } = await import("pretty-ms");
|
|
45
|
+
const packageJsonPath = fileURLToPath(await resolve("hereby/package.json", import.meta.url));
|
|
46
|
+
const packageJson = await fs.readFile(packageJsonPath, "utf-8");
|
|
47
|
+
const { version } = JSON.parse(packageJson);
|
|
43
48
|
/* eslint-disable no-restricted-globals */
|
|
44
49
|
return {
|
|
45
50
|
log: console.log,
|
|
@@ -55,6 +60,7 @@ export async function real() {
|
|
|
55
60
|
process.exitCode = code;
|
|
56
61
|
},
|
|
57
62
|
numCPUs: os.cpus().length,
|
|
63
|
+
version,
|
|
58
64
|
foregroundChild,
|
|
59
65
|
resolve,
|
|
60
66
|
prettyMilliseconds,
|
package/dist/index.d.ts
CHANGED
|
@@ -14,11 +14,13 @@ export interface TaskOptions {
|
|
|
14
14
|
* A list of tasks that must has been run to completion before
|
|
15
15
|
* this task can execute.
|
|
16
16
|
*/
|
|
17
|
-
dependencies?: Task[] | undefined;
|
|
17
|
+
dependencies?: readonly Task[] | undefined;
|
|
18
18
|
/**
|
|
19
|
-
* A function to execute when this task is run.
|
|
19
|
+
* A function to execute when this task is run. If this function
|
|
20
|
+
* returns a promise, the task will not be marked as finished until
|
|
21
|
+
* that promise resolves.
|
|
20
22
|
*/
|
|
21
|
-
run?: (() => void |
|
|
23
|
+
run?: (() => void) | (() => PromiseLike<void>) | undefined;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* A hereby Task. To get an instance, call `test`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hereby",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A simple task runner",
|
|
5
5
|
"repository": "github:jakebailey/hereby",
|
|
6
6
|
"type": "module",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"@tsconfig/node14": "^1.0.3",
|
|
53
53
|
"@types/command-line-args": "^5.2.0",
|
|
54
54
|
"@types/command-line-usage": "^5.0.2",
|
|
55
|
-
"@types/node": "^14.18.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
55
|
+
"@types/node": "^14.18.30",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.38.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.38.0",
|
|
58
58
|
"ava": "^4.3.3",
|
|
59
59
|
"c8": "^7.12.0",
|
|
60
|
-
"eslint": "^8.
|
|
60
|
+
"eslint": "^8.24.0",
|
|
61
61
|
"eslint-config-prettier": "^8.5.0",
|
|
62
62
|
"eslint-plugin-ava": "^13.2.0",
|
|
63
63
|
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
64
64
|
"execa": "^6.1.0",
|
|
65
65
|
"moq.ts": "^9.0.2",
|
|
66
66
|
"prettier": "^2.7.1",
|
|
67
|
-
"release-it": "^15.4.
|
|
67
|
+
"release-it": "^15.4.2",
|
|
68
68
|
"rimraf": "^3.0.2",
|
|
69
69
|
"tempy": "^3.0.0",
|
|
70
70
|
"typescript": "~4.8.3"
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"tagName": "v${version}"
|
|
108
108
|
},
|
|
109
109
|
"hooks": {
|
|
110
|
-
"before:init": "npm run test"
|
|
110
|
+
"before:init": "npm run build && npm run test"
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
package/dist/runner.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import pLimit from "p-limit";
|
|
2
|
-
export class Runner {
|
|
3
|
-
constructor(options) {
|
|
4
|
-
this._addedTasks = new WeakMap();
|
|
5
|
-
this._limiter = (fn) => fn();
|
|
6
|
-
const concurrency = options?.concurrency;
|
|
7
|
-
if (concurrency !== undefined) {
|
|
8
|
-
this._limiter = pLimit(concurrency);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
async runTasks(...tasks) {
|
|
12
|
-
await Promise.all(tasks.map((task) => {
|
|
13
|
-
const cached = this._addedTasks.get(task);
|
|
14
|
-
if (cached) {
|
|
15
|
-
return cached;
|
|
16
|
-
}
|
|
17
|
-
const promise = this._runTask(task);
|
|
18
|
-
this._addedTasks.set(task, promise);
|
|
19
|
-
return promise;
|
|
20
|
-
}));
|
|
21
|
-
}
|
|
22
|
-
async _runTask(task) {
|
|
23
|
-
this.onTaskAdd?.(task);
|
|
24
|
-
const { dependencies, run } = task.options;
|
|
25
|
-
if (dependencies) {
|
|
26
|
-
await this.runTasks(...dependencies);
|
|
27
|
-
}
|
|
28
|
-
if (!run) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
return this._limiter(async () => {
|
|
32
|
-
try {
|
|
33
|
-
this.onTaskStart?.(task);
|
|
34
|
-
await run();
|
|
35
|
-
this.onTaskFinish?.(task);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
this.onTaskError?.(task, e);
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=runner.js.map
|