@venizia/vulcan 0.4.9-0 → 0.4.9-2

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 (141) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +2 -2
  3. package/base/hooks/codex-guards.ts +15 -5
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +4 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +5 -6
  8. package/base/hooks/guard-remote-hosts.ts +6 -7
  9. package/base/hooks/guard-scripting.ts +5 -6
  10. package/base/hooks/guard-writes.ts +8 -9
  11. package/base/hooks/post-tool.ts +2 -2
  12. package/base/hooks/prompt-submit.ts +2 -2
  13. package/base/hooks/session-start.ts +3 -3
  14. package/base/hooks/stop.ts +2 -2
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/skills/docs-update/SKILL.md +4 -2
  17. package/base/skills/visualize-work/SKILL.md +9 -0
  18. package/package.json +3 -3
  19. package/src/agents/atlas-block.ts +43 -43
  20. package/src/agents/codex-hooks.ts +45 -43
  21. package/src/agents/detect.ts +19 -16
  22. package/src/agents/exclude.ts +96 -97
  23. package/src/agents/hooks-json.ts +38 -36
  24. package/src/agents/local.ts +46 -43
  25. package/src/agents/prompt.ts +45 -42
  26. package/src/agents/render.ts +201 -195
  27. package/src/agents/resolve.ts +133 -134
  28. package/src/agents/table.ts +12 -8
  29. package/src/commands/add.command.ts +2 -2
  30. package/src/commands/agents.command.ts +11 -17
  31. package/src/commands/clean.command.ts +6 -6
  32. package/src/commands/doctor.command.ts +4 -4
  33. package/src/commands/init.command.ts +12 -8
  34. package/src/commands/preset.command.ts +2 -2
  35. package/src/commands/profile.command.ts +42 -49
  36. package/src/commands/sync.command.ts +109 -111
  37. package/src/commands/upgrade.command.ts +80 -75
  38. package/src/commands/visualize.command.ts +7 -13
  39. package/src/commands/x.command.ts +55 -50
  40. package/src/common/format.ts +23 -21
  41. package/src/common/json.ts +8 -5
  42. package/src/common/layout-folder.ts +94 -91
  43. package/src/common/paths.ts +14 -12
  44. package/src/config/loader.ts +52 -49
  45. package/src/config/packages.ts +14 -11
  46. package/src/config/schema.ts +3 -3
  47. package/src/create/add-app.ts +519 -509
  48. package/src/create/add-lib.ts +237 -240
  49. package/src/create/bunfig.ts +26 -23
  50. package/src/create/checks.ts +36 -34
  51. package/src/create/diff.ts +21 -23
  52. package/src/create/dockerignore.ts +26 -24
  53. package/src/create/files.ts +7 -5
  54. package/src/create/init-monorepo.ts +75 -80
  55. package/src/create/lib-preset.ts +59 -63
  56. package/src/create/manifest-json.ts +10 -4
  57. package/src/create/names.ts +217 -210
  58. package/src/create/next.ts +26 -23
  59. package/src/create/plan.ts +15 -12
  60. package/src/create/preset-diff.ts +301 -303
  61. package/src/create/preset-menu.ts +38 -32
  62. package/src/create/preset.ts +202 -197
  63. package/src/create/process.ts +79 -72
  64. package/src/create/scratch.ts +48 -49
  65. package/src/create/workspace.ts +404 -396
  66. package/src/doctor/checks.ts +1027 -1014
  67. package/src/doctor/makefile.ts +17 -13
  68. package/src/doctor/runner.ts +88 -118
  69. package/src/doctor/skills.ts +97 -95
  70. package/src/doctor/tags.ts +42 -37
  71. package/src/hooks/codex-patch.ts +25 -22
  72. package/src/hooks/command-view.ts +44 -39
  73. package/src/hooks/decision.ts +37 -37
  74. package/src/hooks/guard-git.ts +51 -49
  75. package/src/hooks/guard-manifest.ts +58 -55
  76. package/src/hooks/guard-outside.ts +93 -91
  77. package/src/hooks/guard-package.ts +82 -79
  78. package/src/hooks/guard-scripting.ts +19 -14
  79. package/src/hooks/guard-writes.ts +154 -149
  80. package/src/hooks/owner-reply.ts +127 -127
  81. package/src/hooks/post-tool.ts +94 -93
  82. package/src/hooks/project-guards.ts +65 -62
  83. package/src/hooks/project-tmp.ts +27 -24
  84. package/src/hooks/remote-hosts.ts +153 -130
  85. package/src/hooks/session-digest.ts +98 -101
  86. package/src/hooks/shell.ts +509 -499
  87. package/src/hooks/subagent-card.ts +11 -7
  88. package/src/hooks/trusted-scripts.ts +106 -104
  89. package/src/init/scaffold.ts +135 -132
  90. package/src/local/clean.ts +38 -36
  91. package/src/local/format.ts +21 -17
  92. package/src/local/scan.ts +144 -138
  93. package/src/manifest/render.ts +110 -104
  94. package/src/owner/card.ts +51 -46
  95. package/src/owner/profile.ts +99 -93
  96. package/src/owner/reply-switch.ts +9 -6
  97. package/src/owner/shape.ts +71 -69
  98. package/src/owner/survey.ts +173 -171
  99. package/src/owner/view.ts +62 -59
  100. package/src/owner/violations.ts +119 -123
  101. package/src/rules/base.ts +15 -11
  102. package/src/rules/parser.ts +39 -32
  103. package/src/rules/slots.ts +8 -6
  104. package/src/signals/claims.ts +30 -28
  105. package/src/signals/classify.ts +38 -33
  106. package/src/signals/loop.ts +39 -37
  107. package/src/signals/state.ts +79 -81
  108. package/src/skills/frontmatter.ts +28 -28
  109. package/src/sync/agent-files.ts +217 -199
  110. package/src/sync/agent-removal.ts +56 -59
  111. package/src/sync/atlas-block.ts +45 -43
  112. package/src/sync/base-rules.ts +32 -30
  113. package/src/sync/claude-launch.ts +36 -34
  114. package/src/sync/exclude.ts +77 -69
  115. package/src/sync/local-choice.ts +50 -47
  116. package/src/sync/planner.ts +59 -61
  117. package/src/sync/prune.ts +52 -48
  118. package/src/sync/settings.ts +166 -167
  119. package/src/ui/capability.ts +12 -7
  120. package/src/ui/keyboard.ts +38 -38
  121. package/src/ui/prompt.ts +79 -77
  122. package/src/visualize/assets.ts +33 -24
  123. package/src/visualize/charts.ts +179 -176
  124. package/src/visualize/compare-css.ts +3 -2
  125. package/src/visualize/compare-render.ts +9 -7
  126. package/src/visualize/diagrams.ts +189 -174
  127. package/src/visualize/grid-span.ts +34 -0
  128. package/src/visualize/icons.ts +7 -5
  129. package/src/visualize/kinds-render.ts +50 -45
  130. package/src/visualize/kinds-validate.ts +12 -10
  131. package/src/visualize/labels.ts +21 -17
  132. package/src/visualize/layout.ts +112 -97
  133. package/src/visualize/page.ts +92 -104
  134. package/src/visualize/render.ts +143 -140
  135. package/src/visualize/sections.ts +395 -384
  136. package/src/visualize/sources.ts +2 -2
  137. package/src/visualize/theme.ts +12 -10
  138. package/src/visualize/validate.ts +13 -9
  139. package/src/wiki/anchors.ts +38 -36
  140. package/src/wiki/command.ts +4 -4
  141. package/src/wiki/source-links.ts +46 -44
@@ -1,5 +1,5 @@
1
1
  import { OFFICIAL_PRESETS, OfficialPresets } from '@venizia/vulcan-atlas';
2
- import { promptSelect, promptText } from '../ui/index.ts';
2
+ import { TerminalPrompt } from '../ui/index.ts';
3
3
 
4
4
  const ANOTHER_PRESET = ':another-preset';
5
5
 
@@ -10,36 +10,42 @@ interface IKnownPreset {
10
10
  summary: string;
11
11
  }
12
12
 
13
- /**
14
- * What a menu offers for `--preset`: the presets the project recorded, then the official ones it has
15
- * not used yet (the one list atlas answers `presets` from), then a text input for any other package
16
- * or `file:` path. null when the user cancelled.
17
- */
18
- export const askPresetSpec = async (opts: { recorded: IKnownPreset[] }): Promise<string | null> => {
19
- const used = new Set(opts.recorded.map((entry) => OfficialPresets.idOf({ spec: entry.spec })));
20
- const picked = await promptSelect({
21
- message: 'Which preset?',
22
- choices: [
23
- ...opts.recorded.map((entry) => ({
24
- value: entry.spec,
25
- label: entry.spec,
26
- hint: `${entry.side}: ${entry.summary}`,
27
- })),
28
- ...OFFICIAL_PRESETS.filter((entry) => !used.has(entry.id)).map((entry) => ({
29
- value: entry.id,
30
- label: entry.id,
31
- hint: `official, ${entry.side} (app or lib)`,
32
- })),
33
- { value: ANOTHER_PRESET, label: 'Another preset...', hint: 'a package name or file:<path>' },
34
- ],
35
- });
13
+ export class PresetMenu {
14
+ /**
15
+ * What a menu offers for `--preset`: the presets the project recorded, then the official ones it has
16
+ * not used yet (the one list atlas answers `presets` from), then a text input for any other package
17
+ * or `file:` path. null when the user cancelled.
18
+ */
19
+ static async askSpec(opts: { recorded: IKnownPreset[] }): Promise<string | null> {
20
+ const used = new Set(opts.recorded.map((entry) => OfficialPresets.idOf({ spec: entry.spec })));
21
+ const picked = await TerminalPrompt.promptSelect({
22
+ message: 'Which preset?',
23
+ choices: [
24
+ ...opts.recorded.map((entry) => ({
25
+ value: entry.spec,
26
+ label: entry.spec,
27
+ hint: `${entry.side}: ${entry.summary}`,
28
+ })),
29
+ ...OFFICIAL_PRESETS.filter((entry) => !used.has(entry.id)).map((entry) => ({
30
+ value: entry.id,
31
+ label: entry.id,
32
+ hint: `official, ${entry.side} (app or lib)`,
33
+ })),
34
+ {
35
+ value: ANOTHER_PRESET,
36
+ label: 'Another preset...',
37
+ hint: 'a package name or file:<path>',
38
+ },
39
+ ],
40
+ });
36
41
 
37
- if (picked !== ANOTHER_PRESET) {
38
- return picked;
39
- }
42
+ if (picked !== ANOTHER_PRESET) {
43
+ return picked;
44
+ }
40
45
 
41
- return promptText({
42
- message: 'Preset (a package name, or file:<path>)',
43
- validate: (value) => (value.trim() === '' ? 'a package name, or file:<path>' : undefined),
44
- });
45
- };
46
+ return TerminalPrompt.promptText({
47
+ message: 'Preset (a package name, or file:<path>)',
48
+ validate: (value) => (value.trim() === '' ? 'a package name, or file:<path>' : undefined),
49
+ });
50
+ }
51
+ }
@@ -11,7 +11,7 @@ import {
11
11
  } from 'node:fs';
12
12
  import { basename, dirname, join, resolve } from 'node:path';
13
13
  import { z } from 'zod';
14
- import { readProperty } from '../common/index.ts';
14
+ import { JsonValue } from '../common/index.ts';
15
15
  import { AppSides, CreateConstants, PresetPath } from './common/index.ts';
16
16
  import type { ILocatedPreset, IPresetSpec, TAppSide, TPresetResult } from './common/index.ts';
17
17
 
@@ -79,247 +79,252 @@ const resolveInside = (opts: { root: string; from: string; path: string }): stri
79
79
  return resolved;
80
80
  };
81
81
 
82
- /** A file's text when it is UTF-8 without a NUL byte; undefined for anything else, which is data and is copied as it is. */
83
- export const decodeText = (opts: { content: Buffer }): string | undefined => {
84
- if (opts.content.includes(0)) {
85
- return undefined;
82
+ export class Preset {
83
+ /** Text gets its tokens replaced; anything else is copied as it is. */
84
+ private static substituteTokens(opts: {
85
+ content: Buffer;
86
+ tokens: Record<string, string>;
87
+ }): Buffer {
88
+ const text = Preset.decodeText({ content: opts.content });
89
+
90
+ return text === undefined
91
+ ? opts.content
92
+ : Buffer.from(text.replace(TOKEN, (match, key: string) => opts.tokens[key] ?? match));
86
93
  }
87
94
 
88
- try {
89
- return UTF8.decode(opts.content);
90
- } catch {
91
- return undefined;
95
+ /** A file's text when it is UTF-8 without a NUL byte; undefined for anything else, which is data and is copied as it is. */
96
+ static decodeText(opts: { content: Buffer }): string | undefined {
97
+ if (opts.content.includes(0)) {
98
+ return undefined;
99
+ }
100
+
101
+ try {
102
+ return UTF8.decode(opts.content);
103
+ } catch {
104
+ return undefined;
105
+ }
92
106
  }
93
- };
94
107
 
95
- /** Text gets its tokens replaced; anything else is copied as it is. */
96
- const substituteTokens = (opts: { content: Buffer; tokens: Record<string, string> }): Buffer => {
97
- const text = decodeText({ content: opts.content });
108
+ static parseSpec(opts: { value: string; cwd: string }): IPresetSpec {
109
+ if (opts.value.startsWith(CreateConstants.PRESET_FILE_PREFIX)) {
110
+ const path = opts.value.slice(CreateConstants.PRESET_FILE_PREFIX.length);
98
111
 
99
- return text === undefined
100
- ? opts.content
101
- : Buffer.from(text.replace(TOKEN, (match, key: string) => opts.tokens[key] ?? match));
102
- };
112
+ return { range: `${CreateConstants.PRESET_FILE_PREFIX}${resolve(opts.cwd, path)}` };
113
+ }
103
114
 
104
- export const parsePresetSpec = (opts: { value: string; cwd: string }): IPresetSpec => {
105
- if (opts.value.startsWith(CreateConstants.PRESET_FILE_PREFIX)) {
106
- const path = opts.value.slice(CreateConstants.PRESET_FILE_PREFIX.length);
115
+ // The version separator is the last '@' that is not the scope's leading one.
116
+ const at = opts.value.lastIndexOf('@');
117
+ const [name, range] =
118
+ at > 0 ? [opts.value.slice(0, at), opts.value.slice(at + 1)] : [opts.value, 'latest'];
119
+ const packageName = name.startsWith('@') ? name : `${CreateConstants.PRESET_SCOPE}${name}`;
107
120
 
108
- return { range: `${CreateConstants.PRESET_FILE_PREFIX}${resolve(opts.cwd, path)}` };
121
+ return { packageName, range };
109
122
  }
110
123
 
111
- // The version separator is the last '@' that is not the scope's leading one.
112
- const at = opts.value.lastIndexOf('@');
113
- const [name, range] =
114
- at > 0 ? [opts.value.slice(0, at), opts.value.slice(at + 1)] : [opts.value, 'latest'];
115
- const packageName = name.startsWith('@') ? name : `${CreateConstants.PRESET_SCOPE}${name}`;
124
+ static readJson(opts: { file: string }): Record<string, unknown> | undefined {
125
+ if (!existsSync(opts.file)) {
126
+ return undefined;
127
+ }
116
128
 
117
- return { packageName, range };
118
- };
129
+ try {
130
+ return JSON.parse(readFileSync(opts.file, 'utf8'));
131
+ } catch (error) {
132
+ console.error(
133
+ `[Preset.readJson] ${opts.file} | ${error instanceof Error ? error.message : String(error)}`,
134
+ );
119
135
 
120
- export const readJson = (opts: { file: string }): Record<string, unknown> | undefined => {
121
- if (!existsSync(opts.file)) {
122
- return undefined;
136
+ return undefined;
137
+ }
123
138
  }
124
139
 
125
- try {
126
- return JSON.parse(readFileSync(opts.file, 'utf8'));
127
- } catch (error) {
128
- console.error(
129
- `[readJson] ${opts.file} | ${error instanceof Error ? error.message : String(error)}`,
130
- );
131
-
132
- return undefined;
133
- }
134
- };
140
+ static locate(opts: { spec: IPresetSpec; root: string }): TPresetResult {
141
+ const packageRoot =
142
+ opts.spec.packageName === undefined
143
+ ? opts.spec.range.slice(CreateConstants.PRESET_FILE_PREFIX.length)
144
+ : join(opts.root, 'node_modules', opts.spec.packageName);
145
+ const manifest = Preset.readJson({ file: join(packageRoot, 'package.json') });
135
146
 
136
- export const locatePreset = (opts: { spec: IPresetSpec; root: string }): TPresetResult => {
137
- const packageRoot =
138
- opts.spec.packageName === undefined
139
- ? opts.spec.range.slice(CreateConstants.PRESET_FILE_PREFIX.length)
140
- : join(opts.root, 'node_modules', opts.spec.packageName);
141
- const manifest = readJson({ file: join(packageRoot, 'package.json') });
147
+ if (manifest === undefined) {
148
+ return { ok: false, error: `no package at ${packageRoot} - was it installed?` };
149
+ }
142
150
 
143
- if (manifest === undefined) {
144
- return { ok: false, error: `no package at ${packageRoot} - was it installed?` };
145
- }
151
+ const packageName = String(manifest.name);
152
+ const packageVersion = String(manifest.version);
153
+ const shown = `${packageName}@${packageVersion}`;
154
+ const vulcan = manifest[CreateConstants.PRESET_FIELD];
155
+ const oldKeys = ['preset', 'lib'].filter(
156
+ (key) => JsonValue.readProperty({ value: vulcan, key }) !== undefined,
157
+ );
146
158
 
147
- const packageName = String(manifest.name);
148
- const packageVersion = String(manifest.version);
149
- const shown = `${packageName}@${packageVersion}`;
150
- const vulcan = manifest[CreateConstants.PRESET_FIELD];
151
- const oldKeys = ['preset', 'lib'].filter(
152
- (key) => readProperty({ value: vulcan, key }) !== undefined,
153
- );
154
-
155
- // No fallback to the keys before `presets`: say what the contract is now.
156
- if (oldKeys.length > 0) {
157
- return {
158
- ok: false,
159
- error: `${shown} uses the old keys "vulcan": { ${oldKeys.map((key) => `"${key}"`).join(', ')} }; the contract is now "vulcan": { "presets": { "app": "./path/preset.json", "lib": "./path/lib.json" } }`,
160
- };
161
- }
159
+ // No fallback to the keys before `presets`: say what the contract is now.
160
+ if (oldKeys.length > 0) {
161
+ return {
162
+ ok: false,
163
+ error: `${shown} uses the old keys "vulcan": { ${oldKeys.map((key) => `"${key}"`).join(', ')} }; the contract is now "vulcan": { "presets": { "app": "./path/preset.json", "lib": "./path/lib.json" } }`,
164
+ };
165
+ }
162
166
 
163
- const presets = readProperty({ value: vulcan, key: 'presets' });
164
- const field = readProperty({ value: presets, key: 'app' });
165
- const libField = readProperty({ value: presets, key: 'lib' });
166
- const sharedField = readProperty({ value: presets, key: 'shared' });
167
-
168
- if (typeof field !== 'string') {
169
- return {
170
- ok: false,
171
- error:
172
- typeof libField === 'string'
173
- ? `${shown}: vulcan.presets.lib needs vulcan.presets.app: a lib-only package is not supported`
174
- : `${shown} ships no VULCAN preset (no "vulcan": { "presets": { "app" } } in its package.json)`,
175
- };
176
- }
167
+ const presets = JsonValue.readProperty({ value: vulcan, key: 'presets' });
168
+ const field = JsonValue.readProperty({ value: presets, key: 'app' });
169
+ const libField = JsonValue.readProperty({ value: presets, key: 'lib' });
170
+ const sharedField = JsonValue.readProperty({ value: presets, key: 'shared' });
171
+
172
+ if (typeof field !== 'string') {
173
+ return {
174
+ ok: false,
175
+ error:
176
+ typeof libField === 'string'
177
+ ? `${shown}: vulcan.presets.lib needs vulcan.presets.app: a lib-only package is not supported`
178
+ : `${shown} ships no VULCAN preset (no "vulcan": { "presets": { "app" } } in its package.json)`,
179
+ };
180
+ }
177
181
 
178
- const presetFile = resolveInside({ root: packageRoot, from: packageRoot, path: field });
182
+ const presetFile = resolveInside({ root: packageRoot, from: packageRoot, path: field });
179
183
 
180
- if (presetFile === undefined) {
181
- return {
182
- ok: false,
183
- error: `${shown}: vulcan.presets.app ${field} points outside the package`,
184
- };
185
- }
184
+ if (presetFile === undefined) {
185
+ return {
186
+ ok: false,
187
+ error: `${shown}: vulcan.presets.app ${field} points outside the package`,
188
+ };
189
+ }
186
190
 
187
- const raw = readJson({ file: presetFile });
191
+ const raw = Preset.readJson({ file: presetFile });
188
192
 
189
- if (raw === undefined) {
190
- return { ok: false, error: `${shown}: ${field} is missing or not JSON` };
191
- }
193
+ if (raw === undefined) {
194
+ return { ok: false, error: `${shown}: ${field} is missing or not JSON` };
195
+ }
192
196
 
193
- if (raw.presetVersion !== CreateConstants.PRESET_VERSION) {
194
- return {
195
- ok: false,
196
- error: `${shown} has preset version ${String(raw.presetVersion)}; this VULCAN reads version ${CreateConstants.PRESET_VERSION} - upgrade @venizia/vulcan`,
197
- };
198
- }
197
+ if (raw.presetVersion !== CreateConstants.PRESET_VERSION) {
198
+ return {
199
+ ok: false,
200
+ error: `${shown} has preset version ${String(raw.presetVersion)}; this VULCAN reads version ${CreateConstants.PRESET_VERSION} - upgrade @venizia/vulcan`,
201
+ };
202
+ }
199
203
 
200
- const parsed = PRESET_SCHEMA.safeParse(raw);
204
+ const parsed = PRESET_SCHEMA.safeParse(raw);
201
205
 
202
- if (!parsed.success) {
203
- const issues = parsed.error.issues
204
- .map((issue) => `${issue.path.join('.')} ${issue.message}`)
205
- .join('; ');
206
+ if (!parsed.success) {
207
+ const issues = parsed.error.issues
208
+ .map((issue) => `${issue.path.join('.')} ${issue.message}`)
209
+ .join('; ');
206
210
 
207
- return { ok: false, error: `${shown}: ${field}: ${issues}` };
208
- }
211
+ return { ok: false, error: `${shown}: ${field}: ${issues}` };
212
+ }
209
213
 
210
- const filesFolder = resolveInside({
211
- root: packageRoot,
212
- from: dirname(presetFile),
213
- path: parsed.data.files,
214
- });
214
+ const filesFolder = resolveInside({
215
+ root: packageRoot,
216
+ from: dirname(presetFile),
217
+ path: parsed.data.files,
218
+ });
215
219
 
216
- if (filesFolder === undefined) {
217
- return {
218
- ok: false,
219
- error: `${shown}: ${field}: files ${parsed.data.files} points outside the package`,
220
- };
221
- }
220
+ if (filesFolder === undefined) {
221
+ return {
222
+ ok: false,
223
+ error: `${shown}: ${field}: files ${parsed.data.files} points outside the package`,
224
+ };
225
+ }
222
226
 
223
- const preset = { ...parsed.data, files: filesFolder };
224
- const libFile =
225
- typeof libField === 'string'
226
- ? resolveInside({ root: packageRoot, from: packageRoot, path: libField })
227
- : undefined;
227
+ const preset = { ...parsed.data, files: filesFolder };
228
+ const libFile =
229
+ typeof libField === 'string'
230
+ ? resolveInside({ root: packageRoot, from: packageRoot, path: libField })
231
+ : undefined;
232
+
233
+ if (typeof libField === 'string' && libFile === undefined) {
234
+ return {
235
+ ok: false,
236
+ error: `${shown}: vulcan.presets.lib ${libField} points outside the package`,
237
+ };
238
+ }
228
239
 
229
- if (typeof libField === 'string' && libFile === undefined) {
230
- return {
231
- ok: false,
232
- error: `${shown}: vulcan.presets.lib ${libField} points outside the package`,
233
- };
234
- }
240
+ const sharedFile =
241
+ typeof sharedField === 'string'
242
+ ? resolveInside({ root: packageRoot, from: packageRoot, path: sharedField })
243
+ : undefined;
235
244
 
236
- const sharedFile =
237
- typeof sharedField === 'string'
238
- ? resolveInside({ root: packageRoot, from: packageRoot, path: sharedField })
239
- : undefined;
245
+ if (typeof sharedField === 'string' && sharedFile === undefined) {
246
+ return {
247
+ ok: false,
248
+ error: `${shown}: vulcan.presets.shared ${sharedField} points outside the package`,
249
+ };
250
+ }
240
251
 
241
- if (typeof sharedField === 'string' && sharedFile === undefined) {
242
- return {
243
- ok: false,
244
- error: `${shown}: vulcan.presets.shared ${sharedField} points outside the package`,
252
+ const located: ILocatedPreset = {
253
+ preset,
254
+ ...(libFile === undefined ? {} : { libFile }),
255
+ ...(sharedFile === undefined ? {} : { sharedFile }),
256
+ packageRoot,
257
+ packageName,
258
+ packageVersion,
245
259
  };
260
+
261
+ return { ok: true, located };
246
262
  }
247
263
 
248
- const located: ILocatedPreset = {
249
- preset,
250
- ...(libFile === undefined ? {} : { libFile }),
251
- ...(sharedFile === undefined ? {} : { sharedFile }),
252
- packageRoot,
253
- packageName,
254
- packageVersion,
255
- };
264
+ /**
265
+ * Every file the preset makes, as the app would get it: the dotfile names, the tokens replaced, symlinks
266
+ * skipped. Nothing is written: `Preset.copyFiles` writes what this returns, and `preset diff` compares it.
267
+ */
268
+ static renderFiles(opts: {
269
+ located: ILocatedPreset;
270
+ tokens: Record<string, string>;
271
+ /** The folder to render when it is not the app's: a lib preset's own. */
272
+ files?: string;
273
+ }): IRenderedPresetFile[] {
274
+ const rendered: IRenderedPresetFile[] = [];
275
+ const files = opts.files ?? opts.located.preset.files;
276
+
277
+ for (const path of new Glob('**/*').scanSync({ cwd: files, dot: true })) {
278
+ const source = join(files, path);
279
+
280
+ // A link could point at any file on the machine; only real files belong to the preset.
281
+ if (lstatSync(source).isSymbolicLink()) {
282
+ continue;
283
+ }
256
284
 
257
- return { ok: true, located };
258
- };
285
+ const name = basename(path);
259
286
 
260
- /** One file a preset makes: where it lands in the app, what it holds once its tokens are replaced, its mode. */
261
- export interface IRenderedPresetFile {
262
- path: string;
263
- content: Buffer;
264
- mode: number;
265
- }
266
-
267
- /**
268
- * Every file the preset makes, as the app would get it: the dotfile names, the tokens replaced, symlinks
269
- * skipped. Nothing is written: `copyPresetFiles` writes what this returns, and `preset diff` compares it.
270
- */
271
- export const renderPresetFiles = (opts: {
272
- located: ILocatedPreset;
273
- tokens: Record<string, string>;
274
- /** The folder to render when it is not the app's: a lib preset's own. */
275
- files?: string;
276
- }): IRenderedPresetFile[] => {
277
- const rendered: IRenderedPresetFile[] = [];
278
- const files = opts.files ?? opts.located.preset.files;
279
-
280
- for (const path of new Glob('**/*').scanSync({ cwd: files, dot: true })) {
281
- const source = join(files, path);
282
-
283
- // A link could point at any file on the machine; only real files belong to the preset.
284
- if (lstatSync(source).isSymbolicLink()) {
285
- continue;
287
+ rendered.push({
288
+ path: CreateConstants.PRESET_DOTFILE_NAMES.includes(name)
289
+ ? join(dirname(path), `.${name.slice(1)}`)
290
+ : path,
291
+ content: Preset.substituteTokens({ content: readFileSync(source), tokens: opts.tokens }),
292
+ mode: statSync(source).mode,
293
+ });
286
294
  }
287
295
 
288
- const name = basename(path);
289
-
290
- rendered.push({
291
- path: CreateConstants.PRESET_DOTFILE_NAMES.includes(name)
292
- ? join(dirname(path), `.${name.slice(1)}`)
293
- : path,
294
- content: substituteTokens({ content: readFileSync(source), tokens: opts.tokens }),
295
- mode: statSync(source).mode,
296
- });
296
+ return rendered;
297
297
  }
298
298
 
299
- return rendered;
300
- };
299
+ static copyFiles(opts: {
300
+ located: ILocatedPreset;
301
+ target: string;
302
+ tokens: Record<string, string>;
303
+ /** The folder to copy when it is not the app's: a lib preset's own. */
304
+ files?: string;
305
+ }): string[] {
306
+ const written: string[] = [];
301
307
 
302
- export const copyPresetFiles = (opts: {
303
- located: ILocatedPreset;
304
- target: string;
305
- tokens: Record<string, string>;
306
- /** The folder to copy when it is not the app's: a lib preset's own. */
307
- files?: string;
308
- }): string[] => {
309
- const written: string[] = [];
308
+ for (const file of Preset.renderFiles(opts)) {
309
+ const destination = join(opts.target, file.path);
310
310
 
311
- for (const file of renderPresetFiles(opts)) {
312
- const destination = join(opts.target, file.path);
311
+ mkdirSync(dirname(destination), { recursive: true });
312
+ writeFileSync(destination, file.content);
313
313
 
314
- mkdirSync(dirname(destination), { recursive: true });
315
- writeFileSync(destination, file.content);
314
+ if (file.mode & EXECUTABLE_BITS) {
315
+ chmodSync(destination, file.mode & PERMISSION_BITS);
316
+ }
316
317
 
317
- if (file.mode & EXECUTABLE_BITS) {
318
- chmodSync(destination, file.mode & PERMISSION_BITS);
318
+ written.push(file.path);
319
319
  }
320
320
 
321
- written.push(file.path);
321
+ return written;
322
322
  }
323
+ }
323
324
 
324
- return written;
325
- };
325
+ /** One file a preset makes: where it lands in the app, what it holds once its tokens are replaced, its mode. */
326
+ export interface IRenderedPresetFile {
327
+ path: string;
328
+ content: Buffer;
329
+ mode: number;
330
+ }