@dcdavidev/spellbookx 0.0.0-stage → 0.3.1

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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -2
  3. package/dist/cli.d.ts +6 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +7 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/init.d.ts +17 -0
  8. package/dist/commands/init.d.ts.map +1 -0
  9. package/dist/commands/init.js +310 -0
  10. package/dist/commands/init.js.map +1 -0
  11. package/dist/context.d.ts +55 -0
  12. package/dist/context.d.ts.map +1 -0
  13. package/dist/context.js +39 -0
  14. package/dist/context.js.map +1 -0
  15. package/dist/index.d.ts +25 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +18 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lefthook.d.ts +24 -0
  20. package/dist/lefthook.d.ts.map +1 -0
  21. package/dist/lefthook.js +91 -0
  22. package/dist/lefthook.js.map +1 -0
  23. package/dist/merge/editorconfig.d.ts +25 -0
  24. package/dist/merge/editorconfig.d.ts.map +1 -0
  25. package/dist/merge/editorconfig.js +123 -0
  26. package/dist/merge/editorconfig.js.map +1 -0
  27. package/dist/merge/json.d.ts +21 -0
  28. package/dist/merge/json.d.ts.map +1 -0
  29. package/dist/merge/json.js +189 -0
  30. package/dist/merge/json.js.map +1 -0
  31. package/dist/merge/lines.d.ts +13 -0
  32. package/dist/merge/lines.d.ts.map +1 -0
  33. package/dist/merge/lines.js +36 -0
  34. package/dist/merge/lines.js.map +1 -0
  35. package/dist/merge/types.d.ts +23 -0
  36. package/dist/merge/types.d.ts.map +1 -0
  37. package/dist/merge/types.js +5 -0
  38. package/dist/merge/types.js.map +1 -0
  39. package/dist/merge/yaml.d.ts +26 -0
  40. package/dist/merge/yaml.d.ts.map +1 -0
  41. package/dist/merge/yaml.js +163 -0
  42. package/dist/merge/yaml.js.map +1 -0
  43. package/dist/output.d.ts +43 -0
  44. package/dist/output.d.ts.map +1 -0
  45. package/dist/output.js +39 -0
  46. package/dist/output.js.map +1 -0
  47. package/dist/package-manager.d.ts +53 -0
  48. package/dist/package-manager.d.ts.map +1 -0
  49. package/dist/package-manager.js +85 -0
  50. package/dist/package-manager.js.map +1 -0
  51. package/dist/pnpm-workspace.d.ts +33 -0
  52. package/dist/pnpm-workspace.d.ts.map +1 -0
  53. package/dist/pnpm-workspace.js +73 -0
  54. package/dist/pnpm-workspace.js.map +1 -0
  55. package/dist/run.d.ts +30 -0
  56. package/dist/run.d.ts.map +1 -0
  57. package/dist/run.js +83 -0
  58. package/dist/run.js.map +1 -0
  59. package/dist/tools.d.ts +135 -0
  60. package/dist/tools.d.ts.map +1 -0
  61. package/dist/tools.js +254 -0
  62. package/dist/tools.js.map +1 -0
  63. package/dist/tsconfig.tsbuildinfo +1 -0
  64. package/package.json +76 -3
  65. package/skills/spellbookx/SKILL.md +93 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sources":["../../src/merge/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,KAAK,GAAG,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,KAClB,MAAM,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file Shared types of the configuration file mergers.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../src/merge/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file Deep merge of YAML files, such as `lefthook.yml`.
3
+ *
4
+ * The existing file is edited as a YAML document, so its comments and order
5
+ * are kept:
6
+ *
7
+ * - Mappings are merged key by key, and missing keys are added at the end.
8
+ * - In a list of mappings with a `name`, such as the jobs of a Lefthook hook,
9
+ * an item is matched by its name and merged; an item with a new name is added
10
+ * at the end.
11
+ * - Other lists get the incoming items that they do not contain yet.
12
+ * - A different value is replaced only with `force`.
13
+ */
14
+ import type { Merge } from './types.js';
15
+ /**
16
+ * Deep merges an incoming YAML file into an existing one.
17
+ * @param existing - The content of the file that the project already has.
18
+ * @param incoming - The content of the file from the package.
19
+ * @param options - How to resolve conflicts.
20
+ * @param options.force - Whether the incoming value replaces a different
21
+ * existing value.
22
+ * @returns The merged content.
23
+ * @throws {Error} When a file is not valid YAML or does not hold a mapping.
24
+ */
25
+ export declare const mergeYaml: Merge;
26
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.d.ts","sources":["../../src/merge/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAeH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAqJxC;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,EAAE,KAgBvB,CAAC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * @file Deep merge of YAML files, such as `lefthook.yml`.
3
+ *
4
+ * The existing file is edited as a YAML document, so its comments and order
5
+ * are kept:
6
+ *
7
+ * - Mappings are merged key by key, and missing keys are added at the end.
8
+ * - In a list of mappings with a `name`, such as the jobs of a Lefthook hook,
9
+ * an item is matched by its name and merged; an item with a new name is added
10
+ * at the end.
11
+ * - Other lists get the incoming items that they do not contain yet.
12
+ * - A different value is replaced only with `force`.
13
+ */
14
+ import { isDeepStrictEqual } from 'node:util';
15
+ import { isMap, isScalar, isSeq, parseDocument, Scalar, visit, } from 'yaml';
16
+ /**
17
+ * Checks whether a value is a plain object (not an array and not `null`).
18
+ * @param value - The value to check.
19
+ * @returns `true` if `value` is a plain object.
20
+ */
21
+ function isObject(value) {
22
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
23
+ }
24
+ /**
25
+ * Parses a YAML text.
26
+ * @param text - The YAML source.
27
+ * @param label - The name of the text, used in the error message.
28
+ * @returns The parsed document.
29
+ * @throws {Error} When the text is not valid YAML.
30
+ */
31
+ function parseYaml(text, label) {
32
+ const document = parseDocument(text);
33
+ const [error] = document.errors;
34
+ if (error)
35
+ throw new Error(`${label} is not valid YAML: ${error.message}`);
36
+ return document;
37
+ }
38
+ /**
39
+ * Finds the quoting style that most strings of a document use.
40
+ * @param document - The existing document.
41
+ * @returns `QUOTE_SINGLE` or `QUOTE_DOUBLE` when most strings are quoted that
42
+ * way, or `undefined` for plain strings.
43
+ */
44
+ function quoteStyleOf(document) {
45
+ const counts = new Map();
46
+ visit(document, {
47
+ Scalar(key, node) {
48
+ // Keys are almost always plain, so only values tell the style.
49
+ if (key === 'key' || typeof node.value !== 'string')
50
+ return;
51
+ const style = node.type === Scalar.QUOTE_SINGLE || node.type === Scalar.QUOTE_DOUBLE
52
+ ? node.type
53
+ : undefined;
54
+ counts.set(style, (counts.get(style) ?? 0) + 1);
55
+ },
56
+ });
57
+ let best;
58
+ let bestCount = 0;
59
+ for (const [style, count] of counts) {
60
+ if (count > bestCount)
61
+ [best, bestCount] = [style, count];
62
+ }
63
+ return best;
64
+ }
65
+ /**
66
+ * Creates a node for new data, with the quoting style of the document.
67
+ * @param document - The existing document.
68
+ * @param value - The data of the new node.
69
+ * @param style - The quoting style of the strings.
70
+ * @returns The new node.
71
+ */
72
+ function createNode(document, value, style) {
73
+ const node = document.createNode(value);
74
+ if (style) {
75
+ visit(node, {
76
+ Scalar(key, scalar) {
77
+ if (key !== 'key' && typeof scalar.value === 'string') {
78
+ scalar.type = style;
79
+ }
80
+ },
81
+ });
82
+ }
83
+ return node;
84
+ }
85
+ /**
86
+ * Reads the `name` of a list item.
87
+ * @param node - A list item of the existing document.
88
+ * @returns The name, or `undefined` if the item is not a mapping with a name.
89
+ */
90
+ function nameOf(node) {
91
+ return isMap(node) ? node.get('name') : undefined;
92
+ }
93
+ /**
94
+ * Merges incoming data into a node of the existing document.
95
+ * @param document - The existing document, used to create new nodes.
96
+ * @param node - The node of the existing document to update.
97
+ * @param incoming - The data from the incoming file.
98
+ * @param isForced - Whether a different value is replaced.
99
+ * @param style - The quoting style of new strings.
100
+ * @returns The node to keep at that place: `node` itself, or a new node when
101
+ * a different value is replaced.
102
+ */
103
+ function mergeNode(document, node, incoming, isForced, style) {
104
+ if (isMap(node) && isObject(incoming)) {
105
+ for (const [key, value] of Object.entries(incoming)) {
106
+ const current = node.get(key, true);
107
+ if (current === undefined) {
108
+ node.set(key, createNode(document, value, style));
109
+ continue;
110
+ }
111
+ const merged = mergeNode(document, current, value, isForced, style);
112
+ if (merged !== current)
113
+ node.set(key, merged);
114
+ }
115
+ return node;
116
+ }
117
+ if (isSeq(node) && Array.isArray(incoming)) {
118
+ for (const item of incoming) {
119
+ const name = isObject(item) ? item.name : undefined;
120
+ const match = name === undefined
121
+ ? undefined
122
+ : node.items.find((current) => nameOf(current) === name);
123
+ if (match) {
124
+ mergeNode(document, match, item, isForced, style);
125
+ continue;
126
+ }
127
+ const present = node.items.some((current) => isDeepStrictEqual(current.toJSON(), item));
128
+ if (!present)
129
+ node.add(createNode(document, item, style));
130
+ }
131
+ return node;
132
+ }
133
+ const current = isScalar(node) ? node.value : node.toJSON();
134
+ return isForced && !isDeepStrictEqual(current, incoming)
135
+ ? createNode(document, incoming, style)
136
+ : node;
137
+ }
138
+ /**
139
+ * Deep merges an incoming YAML file into an existing one.
140
+ * @param existing - The content of the file that the project already has.
141
+ * @param incoming - The content of the file from the package.
142
+ * @param options - How to resolve conflicts.
143
+ * @param options.force - Whether the incoming value replaces a different
144
+ * existing value.
145
+ * @returns The merged content.
146
+ * @throws {Error} When a file is not valid YAML or does not hold a mapping.
147
+ */
148
+ export const mergeYaml = (existing, incoming, { force }) => {
149
+ const next = parseYaml(incoming, 'the package file').toJS();
150
+ if (existing.trim() === '')
151
+ return incoming;
152
+ const document = parseYaml(existing, 'the existing file');
153
+ if (!isMap(document.contents)) {
154
+ throw new Error('the existing file does not hold a YAML mapping');
155
+ }
156
+ // Long values stay on one line, as Lefthook commands usually are.
157
+ const options = { lineWidth: 0 };
158
+ const before = document.toString(options);
159
+ mergeNode(document, document.contents, next, force, quoteStyleOf(document));
160
+ const after = document.toString(options);
161
+ return after === before ? existing : after;
162
+ };
163
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.js","sources":["../../src/merge/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAEL,KAAK,EACL,QAAQ,EACR,KAAK,EAEL,aAAa,EACb,MAAM,EACN,KAAK,GACN,MAAM,MAAM,CAAC;AAId;;;;GAIG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,IAAY,EAAE,KAAa;IAC5C,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,IAAI,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3E,OAAO,QAAQ,CAAC;AAClB,CAAC;AAOD;;;;;GAKG;AACH,SAAS,YAAY,CAAC,QAAkB;IACtC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7C,KAAK,CAAC,QAAQ,EAAE;QACd,MAAM,CAAC,GAAG,EAAE,IAAI;YACd,+DAA+D;YAC/D,IAAI,GAAG,KA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,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,kEAAkE;IAClE,MAAM,OAAO,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1C,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAEzC,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7C,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @file Colored, emoji-prefixed messages of the commands.
3
+ */
4
+ import type { ChalkInstance } from 'chalk';
5
+ /**
6
+ * The kinds of messages.
7
+ */
8
+ export type MessageKind = 'install' | 'created' | 'merged' | 'overwrote' | 'kept' | 'skipped' | 'done' | 'error';
9
+ /**
10
+ * The emoji and the color of a kind of message.
11
+ */
12
+ export interface MessageStyle {
13
+ /**
14
+ * The emoji written before the message.
15
+ */
16
+ emoji: string;
17
+ /**
18
+ * The chalk color of the message.
19
+ */
20
+ color: 'cyan' | 'green' | 'yellow' | 'gray' | 'magenta' | 'red';
21
+ }
22
+ /**
23
+ * The emoji and the color of each kind of message.
24
+ */
25
+ export declare const MESSAGE_STYLES: Readonly<Record<MessageKind, MessageStyle>>;
26
+ /**
27
+ * Formats a message as one line: the emoji and the colored text.
28
+ * @param chalk - The chalk instance that colors the text.
29
+ * @param kind - Decides the emoji and the color.
30
+ * @param text - The message. It can hold text already styled with `chalk`, such
31
+ * as a bold file name.
32
+ * @returns The line, with a final newline.
33
+ */
34
+ export declare function formatMessage(chalk: ChalkInstance, kind: MessageKind, text: string): string;
35
+ /**
36
+ * Formats a help text: the `Usage:`, `Commands:`, `Tools:` and `Options:`
37
+ * headings are bold.
38
+ * @param chalk - The chalk instance that colors the text.
39
+ * @param text - A help text, such as the one of `spellbookx` or of `init`.
40
+ * @returns The formatted help text.
41
+ */
42
+ export declare function formatHelp(chalk: ChalkInstance, text: string): string;
43
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC;CACjE;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAStE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,GACX,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIrE"}
package/dist/output.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @file Colored, emoji-prefixed messages of the commands.
3
+ */
4
+ /**
5
+ * The emoji and the color of each kind of message.
6
+ */
7
+ export const MESSAGE_STYLES = {
8
+ install: { emoji: '📦', color: 'cyan' },
9
+ created: { emoji: '✨', color: 'green' },
10
+ merged: { emoji: '🔀', color: 'green' },
11
+ overwrote: { emoji: '♻️', color: 'yellow' },
12
+ kept: { emoji: '👌', color: 'gray' },
13
+ skipped: { emoji: '⏭️', color: 'yellow' },
14
+ done: { emoji: '🪄', color: 'magenta' },
15
+ error: { emoji: '❌', color: 'red' },
16
+ };
17
+ /**
18
+ * Formats a message as one line: the emoji and the colored text.
19
+ * @param chalk - The chalk instance that colors the text.
20
+ * @param kind - Decides the emoji and the color.
21
+ * @param text - The message. It can hold text already styled with `chalk`, such
22
+ * as a bold file name.
23
+ * @returns The line, with a final newline.
24
+ */
25
+ export function formatMessage(chalk, kind, text) {
26
+ const { emoji, color } = MESSAGE_STYLES[kind];
27
+ return `${emoji} ${chalk[color](text)}\n`;
28
+ }
29
+ /**
30
+ * Formats a help text: the `Usage:`, `Commands:`, `Tools:` and `Options:`
31
+ * headings are bold.
32
+ * @param chalk - The chalk instance that colors the text.
33
+ * @param text - A help text, such as the one of `spellbookx` or of `init`.
34
+ * @returns The formatted help text.
35
+ */
36
+ export function formatHelp(chalk, text) {
37
+ return text.replaceAll(/^(?:Usage|Commands|Tools|Options):/gm, (heading) => chalk.bold(heading));
38
+ }
39
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;GAEG;AA+BH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAgD;IACzE,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IACvC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;IACvC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE;IACvC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC3C,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;IACpC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE;IACzC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE;IACvC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE;CACpC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAoB,EACpB,IAAiB,EACjB,IAAY;IAEZ,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9C,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAoB,EAAE,IAAY;IAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,sCAAsC,EAAE,CAAC,OAAO,EAAE,EAAE,CACzE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CACpB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file Builds the command that installs development dependencies with the
3
+ * package manager of the project.
4
+ */
5
+ import { type WorkspacePackageManager } from '@dcdavidev/shared-spells/discover-workspace-scopes';
6
+ /**
7
+ * A program and its arguments.
8
+ */
9
+ export interface Command {
10
+ /**
11
+ * The program to run, for example `pnpm`.
12
+ */
13
+ command: string;
14
+ /**
15
+ * The arguments of the program.
16
+ */
17
+ args: string[];
18
+ }
19
+ /**
20
+ * Finds the package manager of the project in `cwd`.
21
+ * @param cwd - The project folder.
22
+ * @returns The package manager, or `npm` if none is detected.
23
+ */
24
+ export declare function getPackageManager(cwd: string): WorkspacePackageManager;
25
+ /**
26
+ * Builds the command that installs development dependencies.
27
+ * @param manager - The package manager.
28
+ * @param dependencies - The packages to install.
29
+ * @param cwd - The project folder. In the root of a pnpm workspace, `-w` is
30
+ * added so that pnpm installs the packages there.
31
+ * @returns The command to run.
32
+ */
33
+ export declare function getInstallCommand(manager: WorkspacePackageManager, dependencies: readonly string[], cwd: string): Command;
34
+ /**
35
+ * Builds the command that runs a binary installed in the project.
36
+ * @param manager - The package manager.
37
+ * @param args - The binary and its arguments, for example
38
+ * `['lefthook', 'install']`.
39
+ * @returns The command to run, for example `pnpm exec lefthook install`.
40
+ */
41
+ export declare function getExecCommand(manager: WorkspacePackageManager, args: readonly string[]): Command;
42
+ /**
43
+ * Builds the command that runs a `package.json` script.
44
+ * @param manager - The package manager.
45
+ * @param script - The name of the script, for example `lint`.
46
+ * @returns The command to run, for example `pnpm run lint`.
47
+ */
48
+ export declare function getRunCommand(manager: WorkspacePackageManager, script: string): Command;
49
+ /**
50
+ * The lock file that each package manager writes.
51
+ */
52
+ export declare const LOCK_FILES: Readonly<Record<WorkspacePackageManager, string>>;
53
+ //# sourceMappingURL=package-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.d.ts","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAEtE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,uBAAuB,EAChC,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,GAAG,EAAE,MAAM,GACV,OAAO,CAmBT;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,uBAAuB,EAChC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,OAAO,CAeT;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAET;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAKxE,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @file Builds the command that installs development dependencies with the
3
+ * package manager of the project.
4
+ */
5
+ import { existsSync } from 'node:fs';
6
+ import path from 'node:path';
7
+ import { detectPackageManager, } from '@dcdavidev/shared-spells/discover-workspace-scopes';
8
+ /**
9
+ * Finds the package manager of the project in `cwd`.
10
+ * @param cwd - The project folder.
11
+ * @returns The package manager, or `npm` if none is detected.
12
+ */
13
+ export function getPackageManager(cwd) {
14
+ return detectPackageManager(cwd)?.manager ?? 'npm';
15
+ }
16
+ /**
17
+ * Builds the command that installs development dependencies.
18
+ * @param manager - The package manager.
19
+ * @param dependencies - The packages to install.
20
+ * @param cwd - The project folder. In the root of a pnpm workspace, `-w` is
21
+ * added so that pnpm installs the packages there.
22
+ * @returns The command to run.
23
+ */
24
+ export function getInstallCommand(manager, dependencies, cwd) {
25
+ switch (manager) {
26
+ case 'pnpm': {
27
+ const workspaceRoot = existsSync(path.join(cwd, 'pnpm-workspace.yaml'));
28
+ return {
29
+ command: 'pnpm',
30
+ args: ['add', '-D', ...(workspaceRoot ? ['-w'] : []), ...dependencies],
31
+ };
32
+ }
33
+ case 'yarn': {
34
+ return { command: 'yarn', args: ['add', '-D', ...dependencies] };
35
+ }
36
+ case 'bun': {
37
+ return { command: 'bun', args: ['add', '-d', ...dependencies] };
38
+ }
39
+ case 'npm': {
40
+ return { command: 'npm', args: ['install', '-D', ...dependencies] };
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Builds the command that runs a binary installed in the project.
46
+ * @param manager - The package manager.
47
+ * @param args - The binary and its arguments, for example
48
+ * `['lefthook', 'install']`.
49
+ * @returns The command to run, for example `pnpm exec lefthook install`.
50
+ */
51
+ export function getExecCommand(manager, args) {
52
+ switch (manager) {
53
+ case 'pnpm': {
54
+ return { command: 'pnpm', args: ['exec', ...args] };
55
+ }
56
+ case 'yarn': {
57
+ return { command: 'yarn', args: [...args] };
58
+ }
59
+ case 'bun': {
60
+ return { command: 'bunx', args: [...args] };
61
+ }
62
+ case 'npm': {
63
+ return { command: 'npx', args: ['--no', ...args] };
64
+ }
65
+ }
66
+ }
67
+ /**
68
+ * Builds the command that runs a `package.json` script.
69
+ * @param manager - The package manager.
70
+ * @param script - The name of the script, for example `lint`.
71
+ * @returns The command to run, for example `pnpm run lint`.
72
+ */
73
+ export function getRunCommand(manager, script) {
74
+ return { command: manager, args: ['run', script] };
75
+ }
76
+ /**
77
+ * The lock file that each package manager writes.
78
+ */
79
+ export const LOCK_FILES = {
80
+ pnpm: 'pnpm-lock.yaml',
81
+ yarn: 'yarn.lock',
82
+ bun: 'bun.lock',
83
+ npm: 'package-lock.json',
84
+ };
85
+ //# sourceMappingURL=package-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.js","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,oBAAoB,GAErB,MAAM,oDAAoD,CAAC;AAgB5D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,OAAO,oBAAoB,CAAC,GAAG,CAAC,EAAE,OAAO,IAAI,KAAK,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAgC,EAChC,YAA+B,EAC/B,GAAW;IAEX,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,aAAa,GAAG,UA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CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QAC9C,CAAC;QACD,KAAK,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAgC,EAChC,MAAc;IAEd,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsD;IAC3E,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,WAAW;IACjB,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,mBAAmB;CACzB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file Settings that some tools need in `pnpm-workspace.yaml`, such as the
3
+ * `publicHoistPattern` that lets Prettier find its plugins.
4
+ */
5
+ /**
6
+ * The name of the pnpm workspace file.
7
+ */
8
+ export declare const PNPM_WORKSPACE_FILE = "pnpm-workspace.yaml";
9
+ /**
10
+ * pnpm settings that hold lists, such as `publicHoistPattern`, with the
11
+ * items that a tool needs.
12
+ */
13
+ export type PnpmListSettings = Readonly<Record<string, readonly string[]>>;
14
+ /**
15
+ * Finds the `pnpm-workspace.yaml` that applies to a folder: the first one in
16
+ * the folder or in a parent folder.
17
+ * @param cwd - The project folder.
18
+ * @returns The path of the file, or of a new file in `cwd` if there is none.
19
+ */
20
+ export declare function findPnpmWorkspace(cwd: string): string;
21
+ /**
22
+ * Adds the missing items of list settings to a `pnpm-workspace.yaml`. The
23
+ * comments and formatting of the file are kept, and a missing setting is
24
+ * added at the end, after a blank line.
25
+ * @param text - The content of the file, or `''` for a new file.
26
+ * @param settings - The settings and the items that they must contain.
27
+ * @returns The updated content. It is equal to `text` when nothing had to
28
+ * change.
29
+ * @throws {Error} When the file is not valid YAML, does not hold a mapping,
30
+ * or holds a setting that is not a list.
31
+ */
32
+ export declare function mergePnpmSettings(text: string, settings: PnpmListSettings): string;
33
+ //# sourceMappingURL=pnpm-workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pnpm-workspace.d.ts","sources":["../src/pnpm-workspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH;;GAEG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;AAE3E;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAYrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,gBAAgB,GACzB,MAAM,CAwCR"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @file Settings that some tools need in `pnpm-workspace.yaml`, such as the
3
+ * `publicHoistPattern` that lets Prettier find its plugins.
4
+ */
5
+ import { existsSync } from 'node:fs';
6
+ import path from 'node:path';
7
+ import { Document, isMap, isSeq, parseDocument, Scalar } from 'yaml';
8
+ /**
9
+ * The name of the pnpm workspace file.
10
+ */
11
+ export const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
12
+ /**
13
+ * Finds the `pnpm-workspace.yaml` that applies to a folder: the first one in
14
+ * the folder or in a parent folder.
15
+ * @param cwd - The project folder.
16
+ * @returns The path of the file, or of a new file in `cwd` if there is none.
17
+ */
18
+ export function findPnpmWorkspace(cwd) {
19
+ let dir = path.resolve(cwd);
20
+ for (;;) {
21
+ const file = path.join(dir, PNPM_WORKSPACE_FILE);
22
+ if (existsSync(file))
23
+ return file;
24
+ const parent = path.dirname(dir);
25
+ if (parent === dir)
26
+ return path.join(path.resolve(cwd), PNPM_WORKSPACE_FILE);
27
+ dir = parent;
28
+ }
29
+ }
30
+ /**
31
+ * Adds the missing items of list settings to a `pnpm-workspace.yaml`. The
32
+ * comments and formatting of the file are kept, and a missing setting is
33
+ * added at the end, after a blank line.
34
+ * @param text - The content of the file, or `''` for a new file.
35
+ * @param settings - The settings and the items that they must contain.
36
+ * @returns The updated content. It is equal to `text` when nothing had to
37
+ * change.
38
+ * @throws {Error} When the file is not valid YAML, does not hold a mapping,
39
+ * or holds a setting that is not a list.
40
+ */
41
+ export function mergePnpmSettings(text, settings) {
42
+ const document = text.trim() === '' ? new Document({}) : parseDocument(text);
43
+ const [error] = document.errors;
44
+ if (error)
45
+ throw new Error(`${PNPM_WORKSPACE_FILE} is not valid YAML: ${error.message}`);
46
+ const { contents } = document;
47
+ if (!isMap(contents)) {
48
+ throw new Error(`${PNPM_WORKSPACE_FILE} does not hold a mapping`);
49
+ }
50
+ let isChanged = false;
51
+ for (const [key, items] of Object.entries(settings)) {
52
+ const current = contents.get(key, true);
53
+ if (current === undefined) {
54
+ const name = new Scalar(key);
55
+ name.spaceBefore = contents.items.length > 0;
56
+ contents.add(document.createPair(name, [...items]));
57
+ isChanged = true;
58
+ continue;
59
+ }
60
+ if (!isSeq(current)) {
61
+ throw new Error(`${key} in ${PNPM_WORKSPACE_FILE} is not a list`);
62
+ }
63
+ const present = new Set(current.toJSON());
64
+ for (const item of items) {
65
+ if (present.has(item))
66
+ continue;
67
+ current.add(document.createNode(item));
68
+ isChanged = true;
69
+ }
70
+ }
71
+ return isChanged ? document.toString({ singleQuote: true }) : text;
72
+ }
73
+ //# sourceMappingURL=pnpm-workspace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pnpm-workspace.js","sources":["../src/pnpm-workspace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,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,30 @@
1
+ /**
2
+ * @file Argument parsing and dispatch for the `spellbookx` command.
3
+ */
4
+ import { type Context } from './context.js';
5
+ /**
6
+ * Name of the command, as installed by the package.
7
+ */
8
+ export declare const COMMAND_NAME = "spellbookx";
9
+ /**
10
+ * Short alias of the command.
11
+ */
12
+ export declare const COMMAND_ALIAS = "sbx";
13
+ /**
14
+ * Text printed by `spellbookx --help`.
15
+ */
16
+ export declare const HELP_TEXT: string;
17
+ /**
18
+ * Reads the version of the package from its `package.json`.
19
+ * @returns The version, for example `1.2.3`.
20
+ */
21
+ export declare function getVersion(): string;
22
+ /**
23
+ * Runs the command with the given arguments.
24
+ * @param args - The arguments, without the Node.js and script paths.
25
+ * @param context - The environment: the working folder, where to write the
26
+ * output and how to run other programs.
27
+ * @returns The exit code: `0` on success, `1` on an error.
28
+ */
29
+ export declare function run(args: readonly string[], context?: Context): number;
30
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,cAAc,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,aAAa,QAAQ,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAavB,CAAC;AASF;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAMnC;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CACjB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,GAAE,OAA0B,GAClC,MAAM,CAiCR"}