hereby 1.11.1 → 1.12.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.
@@ -1,29 +1,57 @@
1
- import commandLineUsage from "command-line-usage";
2
1
  import pc from "picocolors";
2
+ import Wordwrap from "wordwrapjs";
3
3
  import { compareTaskNames } from "./utils.js";
4
- export function formatTasks(format, tasks, defaultTask) {
4
+ export function formatTasks(format, tasks, defaultTask, columns) {
5
5
  const visibleTasks = [...tasks].filter(isTaskVisible).sort(compareTaskNames);
6
6
  if (format === "simple") {
7
7
  return visibleTasks.map((task) => task.options.name).join("\n");
8
8
  }
9
- return commandLineUsage({
10
- header: "Available tasks",
11
- content: visibleTasks.map((task) => {
12
- var _a;
13
- const name = task === defaultTask
14
- ? `${pc.green(task.options.name)} (default)`
15
- : pc.blue(task.options.name);
16
- let descriptionParts = task.options.description ? [task.options.description] : undefined;
17
- const deps = (_a = task.options.dependencies) === null || _a === void 0 ? void 0 : _a.filter(isTaskVisible).sort(compareTaskNames);
18
- if (deps === null || deps === void 0 ? void 0 : deps.length) {
19
- const depNames = deps.map((task) => pc.blue(task.options.name));
20
- (descriptionParts !== null && descriptionParts !== void 0 ? descriptionParts : (descriptionParts = [])).push(`Depends on: ${depNames.join(", ")}`);
21
- }
22
- return { name, description: descriptionParts === null || descriptionParts === void 0 ? void 0 : descriptionParts.join("\n") };
23
- }),
9
+ const names = visibleTasks.map((task) => task === defaultTask ? `${pc.green(task.options.name)} (default)` : pc.blue(task.options.name));
10
+ const descriptions = visibleTasks.map((task) => {
11
+ var _a, _b;
12
+ let parts = task.options.description ? [task.options.description] : undefined;
13
+ const deps = (_a = task.options.dependencies) === null || _a === void 0 ? void 0 : _a.filter(isTaskVisible).sort(compareTaskNames);
14
+ if (deps === null || deps === void 0 ? void 0 : deps.length) {
15
+ const depNames = deps.map((task) => pc.blue(task.options.name));
16
+ (parts !== null && parts !== void 0 ? parts : (parts = [])).push(`Depends on: ${depNames.join(", ")}`);
17
+ }
18
+ return (_b = parts === null || parts === void 0 ? void 0 : parts.join("\n")) !== null && _b !== void 0 ? _b : "";
24
19
  });
20
+ // There's a 2 space indent plus 3 spaces between columns, hence take away 5
21
+ // padding spaces from the available width
22
+ const maxTotalWidth = columns - 5;
23
+ const maxNameWidth = Math.max(...names.map(visibleLength));
24
+ // Check the name doesn't take up more than half the space
25
+ const nameWidth = Math.min(maxNameWidth, maxTotalWidth >> 1);
26
+ const descriptionWidth = maxTotalWidth - nameWidth;
27
+ const formatted = names.map((name, i) => formatAsColumns(" ", name, nameWidth, descriptions[i], descriptionWidth));
28
+ return `
29
+ ${pc.bold(pc.underline("Available tasks"))}
30
+
31
+ ${formatted.join("")}`;
25
32
  }
26
33
  function isTaskVisible(task) {
27
34
  return !task.options.hiddenFromTaskList;
28
35
  }
36
+ function formatAsColumns(indent, leftText, leftWidth, rightText, rightWidth) {
37
+ const leftLines = wrapText(leftText, leftWidth);
38
+ const rightLines = wrapText(rightText, rightWidth);
39
+ const maxLines = Math.max(leftLines.length, rightLines.length);
40
+ let result = "";
41
+ for (let i = 0; i < maxLines; i++) {
42
+ const leftPart = leftLines[i] || "";
43
+ const rightPart = rightLines[i] || "";
44
+ const paddedLeft = leftPart.padEnd(leftWidth, " ");
45
+ result += `${indent}${paddedLeft} ${rightPart}\n`;
46
+ }
47
+ return result;
48
+ }
49
+ // eslint-disable-next-line no-control-regex
50
+ const ANSI_REGEX = /\u001B\[([0-9]{1,2})m/g;
51
+ function visibleLength(str) {
52
+ return str.replace(ANSI_REGEX, "").length;
53
+ }
54
+ function wrapText(text, maxWidth) {
55
+ return Wordwrap.lines(text, { width: maxWidth, break: true });
56
+ }
29
57
  //# sourceMappingURL=formatTasks.js.map
package/dist/cli/index.js CHANGED
@@ -42,7 +42,7 @@ async function mainWorker(d) {
42
42
  d.chdir(path.dirname(herebyfilePath));
43
43
  const herebyfile = await loadHerebyfile(herebyfilePath);
44
44
  if (args.printTasks) {
45
- d.log(formatTasks(args.printTasks, herebyfile.tasks.values(), herebyfile.defaultTask));
45
+ d.log(formatTasks(args.printTasks, herebyfile.tasks.values(), herebyfile.defaultTask, d.columns()));
46
46
  return;
47
47
  }
48
48
  const tasks = await selectTasks(d, herebyfile, herebyfilePath, args.run);
@@ -1,5 +1,5 @@
1
- import commandLineUsage from "command-line-usage";
2
1
  import minimist from "minimist";
2
+ import pc from "picocolors";
3
3
  export function parseArgs(argv) {
4
4
  let parseUnknownAsTask = true;
5
5
  const options = minimist(argv, {
@@ -21,54 +21,29 @@ export function parseArgs(argv) {
21
21
  };
22
22
  }
23
23
  export function getUsage() {
24
- const usage = commandLineUsage([
25
- {
26
- header: "hereby",
27
- content: "A simple task runner.",
28
- },
29
- {
30
- header: "Synopsis",
31
- content: "$ hereby <task>",
32
- },
33
- {
34
- header: "Options",
35
- optionList: [
36
- {
37
- name: "help",
38
- description: "Display this usage guide.",
39
- alias: "h",
40
- type: Boolean,
41
- },
42
- {
43
- name: "herebyfile",
44
- description: "A path to a Herebyfile. Optional.",
45
- type: String,
46
- defaultOption: true,
47
- typeLabel: "{underline path}",
48
- },
49
- {
50
- name: "tasks",
51
- description: "Print a listing of the available tasks.",
52
- alias: "T",
53
- type: Boolean,
54
- },
55
- {
56
- name: "version",
57
- description: "Print the current hereby version.",
58
- type: Boolean,
59
- },
60
- ],
61
- },
62
- {
63
- header: "Example usage",
64
- content: [
65
- "$ hereby build",
66
- "$ hereby build lint",
67
- "$ hereby test --skip someTest --lint=false",
68
- "$ hereby --tasks",
69
- ],
70
- },
71
- ]);
72
- return usage;
24
+ const header = (text) => pc.bold(pc.underline(text));
25
+ return `
26
+ ${header("hereby")}
27
+
28
+ A simple task runner.
29
+
30
+ ${header("Synopsis")}
31
+
32
+ $ hereby <task>
33
+
34
+ ${header("Options")}
35
+
36
+ ${pc.bold("-h, --help")} Display this usage guide.
37
+ ${pc.bold("--herebyfile")} ${pc.underline("path")} A path to a Herebyfile. Optional.
38
+ ${pc.bold("-T, --tasks")} Print a listing of the available tasks.
39
+ ${pc.bold("--version")} Print the current hereby version.
40
+
41
+ ${header("Example usage")}
42
+
43
+ $ hereby build
44
+ $ hereby build lint
45
+ $ hereby test --skip someTest --lint=false
46
+ $ hereby --tasks
47
+ `;
73
48
  }
74
49
  //# sourceMappingURL=parseArgs.js.map
package/dist/cli/utils.js CHANGED
@@ -38,6 +38,7 @@ export async function real() {
38
38
  const { default: prettyMilliseconds } = await import("pretty-ms");
39
39
  /* eslint-disable no-restricted-globals */
40
40
  return {
41
+ columns: () => process.stdout.isTTY && process.stdout.columns || 80,
41
42
  log: console.log,
42
43
  error: console.error,
43
44
  // eslint-disable-next-line @typescript-eslint/unbound-method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hereby",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "A simple task runner",
5
5
  "repository": "github:jakebailey/hereby",
6
6
  "type": "module",
@@ -39,38 +39,36 @@
39
39
  "./dist/index.d.ts"
40
40
  ],
41
41
  "dependencies": {
42
- "command-line-usage": "^6.1.3",
43
42
  "fastest-levenshtein": "^1.0.16",
44
43
  "minimist": "^1.2.8",
45
44
  "picocolors": "^1.1.0",
46
- "pretty-ms": "^8.0.0"
45
+ "pretty-ms": "^8.0.0",
46
+ "wordwrapjs": "^5.1.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@ava/typescript": "^3.0.1",
50
- "@changesets/cli": "^2.29.7",
51
- "@codspeed/tinybench-plugin": "^4.0.1",
52
- "@fast-check/ava": "2.0.1",
53
- "@tsconfig/node12": "^12.1.5",
54
- "@types/command-line-usage": "^5.0.4",
50
+ "@changesets/cli": "^2.29.8",
51
+ "@eslint/js": "^10.0.1",
52
+ "@tsconfig/node12": "^12.1.7",
55
53
  "@types/minimist": "^1.2.5",
56
- "@types/node": "^24.7.2",
54
+ "@types/node": "^25.2.3",
57
55
  "@types/tmp": "^0.2.6",
56
+ "@types/wordwrapjs": "^5.1.2",
58
57
  "ava": "~5.0.1",
59
58
  "c8": "^10.1.3",
60
- "dprint": "^0.50.2",
61
- "eslint": "^9.37.0",
62
- "eslint-plugin-ava": "^15.1.0",
59
+ "dprint": "^0.51.1",
60
+ "eslint": "^10.0.0",
61
+ "eslint-plugin-ava": "^16.0.0",
63
62
  "eslint-plugin-simple-import-sort": "^12.1.1",
64
- "eslint-plugin-unicorn": "^61.0.2",
63
+ "eslint-plugin-unicorn": "^63.0.0",
65
64
  "execa": "^6.1.0",
66
- "globals": "^16.4.0",
65
+ "globals": "^17.3.0",
67
66
  "monocart-coverage-reports": "^2.12.9",
68
67
  "moq.ts": "^10.1.0",
69
68
  "rimraf": "^5.0.10",
70
- "tinybench": "~2.8.0",
71
69
  "tmp": "0.2.1",
72
70
  "typescript": "^5.9.3",
73
- "typescript-eslint": "^8.46.0"
71
+ "typescript-eslint": "^8.56.0"
74
72
  },
75
73
  "overrides": {
76
74
  "ava": {