hereby 1.1.0 → 1.3.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.
@@ -2,19 +2,22 @@ import chalk from "chalk";
2
2
  import commandLineUsage from "command-line-usage";
3
3
  import { stringSorter, taskSorter } from "./utils.js";
4
4
  export function formatTasks(tasks, defaultTask) {
5
- tasks = tasks.slice(0).sort(taskSorter);
5
+ tasks = tasks
6
+ .slice(0)
7
+ .filter((task) => !task.options.hiddenFromTaskList)
8
+ .sort(taskSorter);
6
9
  const sections = [];
7
10
  sections.push({
8
11
  header: "Available tasks",
9
12
  content: tasks.map((task) => {
10
- const blueName = chalk.blue(task.options.name);
11
- const name = task !== defaultTask ? blueName : `${blueName} (default)`;
13
+ const name = task !== defaultTask ? chalk.blue(task.options.name) : `${chalk.green(task.options.name)} (default)`;
12
14
  const descriptionParts = [];
13
15
  if (task.options.description) {
14
16
  descriptionParts.push(task.options.description);
15
17
  }
16
18
  if (task.options.dependencies && task.options.dependencies.length > 0) {
17
19
  const deps = task.options.dependencies
20
+ .filter((task) => !task.options.hiddenFromTaskList)
18
21
  .map((task) => task.options.name)
19
22
  .sort(stringSorter)
20
23
  .map((v) => chalk.blue(v));
package/dist/cli/index.js CHANGED
@@ -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);
@@ -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
  }
@@ -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
  {
@@ -59,7 +59,8 @@ export class Runner {
59
59
  return; // Skip logging.
60
60
  }
61
61
  this._errored = true;
62
- this._d.error(`Error in ${chalk.red(task.options.name)}\n${e}`);
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}`);
63
64
  }
64
65
  }
65
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
@@ -21,6 +21,10 @@ export interface TaskOptions {
21
21
  * that promise resolves.
22
22
  */
23
23
  run?: (() => void) | (() => PromiseLike<void>) | undefined;
24
+ /**
25
+ * If true, this task will be hidden from `hereby --tasks`.
26
+ */
27
+ hiddenFromTaskList?: boolean | undefined;
24
28
  }
25
29
  /**
26
30
  * 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.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "A simple task runner",
5
5
  "repository": "github:jakebailey/hereby",
6
6
  "type": "module",
@@ -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
  }