@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.
- package/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +2 -2
- package/base/hooks/codex-guards.ts +15 -5
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +4 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +5 -6
- package/base/hooks/guard-remote-hosts.ts +6 -7
- package/base/hooks/guard-scripting.ts +5 -6
- package/base/hooks/guard-writes.ts +8 -9
- package/base/hooks/post-tool.ts +2 -2
- package/base/hooks/prompt-submit.ts +2 -2
- package/base/hooks/session-start.ts +3 -3
- package/base/hooks/stop.ts +2 -2
- package/base/hooks/subagent-start.ts +2 -2
- package/base/skills/docs-update/SKILL.md +4 -2
- package/base/skills/visualize-work/SKILL.md +9 -0
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +45 -43
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +96 -97
- package/src/agents/hooks-json.ts +38 -36
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +201 -195
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +4 -4
- package/src/commands/init.command.ts +12 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +42 -49
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +80 -75
- package/src/commands/visualize.command.ts +7 -13
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +94 -91
- package/src/common/paths.ts +14 -12
- package/src/config/loader.ts +52 -49
- package/src/config/packages.ts +14 -11
- package/src/config/schema.ts +3 -3
- package/src/create/add-app.ts +519 -509
- package/src/create/add-lib.ts +237 -240
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +75 -80
- package/src/create/lib-preset.ts +59 -63
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +26 -23
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +301 -303
- package/src/create/preset-menu.ts +38 -32
- package/src/create/preset.ts +202 -197
- package/src/create/process.ts +79 -72
- package/src/create/scratch.ts +48 -49
- package/src/create/workspace.ts +404 -396
- package/src/doctor/checks.ts +1027 -1014
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -118
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +42 -37
- package/src/hooks/codex-patch.ts +25 -22
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/decision.ts +37 -37
- package/src/hooks/guard-git.ts +51 -49
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +93 -91
- package/src/hooks/guard-package.ts +82 -79
- package/src/hooks/guard-scripting.ts +19 -14
- package/src/hooks/guard-writes.ts +154 -149
- package/src/hooks/owner-reply.ts +127 -127
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +65 -62
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +153 -130
- package/src/hooks/session-digest.ts +98 -101
- package/src/hooks/shell.ts +509 -499
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +106 -104
- package/src/init/scaffold.ts +135 -132
- package/src/local/clean.ts +38 -36
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +144 -138
- package/src/manifest/render.ts +110 -104
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +99 -93
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +71 -69
- package/src/owner/survey.ts +173 -171
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/rules/base.ts +15 -11
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +38 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +79 -81
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +56 -59
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +36 -34
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +59 -61
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +166 -167
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +38 -38
- package/src/ui/prompt.ts +79 -77
- package/src/visualize/assets.ts +33 -24
- package/src/visualize/charts.ts +179 -176
- package/src/visualize/compare-css.ts +3 -2
- package/src/visualize/compare-render.ts +9 -7
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +7 -5
- package/src/visualize/kinds-render.ts +50 -45
- package/src/visualize/kinds-validate.ts +12 -10
- package/src/visualize/labels.ts +21 -17
- package/src/visualize/layout.ts +112 -97
- package/src/visualize/page.ts +92 -104
- package/src/visualize/render.ts +143 -140
- package/src/visualize/sections.ts +395 -384
- package/src/visualize/sources.ts +2 -2
- package/src/visualize/theme.ts +12 -10
- package/src/visualize/validate.ts +13 -9
- package/src/wiki/anchors.ts +38 -36
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +46 -44
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OFFICIAL_PRESETS, OfficialPresets } from '@venizia/vulcan-atlas';
|
|
2
|
-
import {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
if (picked !== ANOTHER_PRESET) {
|
|
43
|
+
return picked;
|
|
44
|
+
}
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|
package/src/create/preset.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
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 {
|
|
121
|
+
return { packageName, range };
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
return undefined;
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
123
138
|
}
|
|
124
139
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
182
|
+
const presetFile = resolveInside({ root: packageRoot, from: packageRoot, path: field });
|
|
179
183
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
191
|
+
const raw = Preset.readJson({ file: presetFile });
|
|
188
192
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
if (raw === undefined) {
|
|
194
|
+
return { ok: false, error: `${shown}: ${field} is missing or not JSON` };
|
|
195
|
+
}
|
|
192
196
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
204
|
+
const parsed = PRESET_SCHEMA.safeParse(raw);
|
|
201
205
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
if (!parsed.success) {
|
|
207
|
+
const issues = parsed.error.issues
|
|
208
|
+
.map((issue) => `${issue.path.join('.')} ${issue.message}`)
|
|
209
|
+
.join('; ');
|
|
206
210
|
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
return { ok: false, error: `${shown}: ${field}: ${issues}` };
|
|
212
|
+
}
|
|
209
213
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
const filesFolder = resolveInside({
|
|
215
|
+
root: packageRoot,
|
|
216
|
+
from: dirname(presetFile),
|
|
217
|
+
path: parsed.data.files,
|
|
218
|
+
});
|
|
215
219
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
};
|
|
234
|
-
}
|
|
240
|
+
const sharedFile =
|
|
241
|
+
typeof sharedField === 'string'
|
|
242
|
+
? resolveInside({ root: packageRoot, from: packageRoot, path: sharedField })
|
|
243
|
+
: undefined;
|
|
235
244
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
258
|
-
};
|
|
285
|
+
const name = basename(path);
|
|
259
286
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
303
|
-
|
|
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
|
-
|
|
312
|
-
|
|
311
|
+
mkdirSync(dirname(destination), { recursive: true });
|
|
312
|
+
writeFileSync(destination, file.content);
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
if (file.mode & EXECUTABLE_BITS) {
|
|
315
|
+
chmodSync(destination, file.mode & PERMISSION_BITS);
|
|
316
|
+
}
|
|
316
317
|
|
|
317
|
-
|
|
318
|
-
chmodSync(destination, file.mode & PERMISSION_BITS);
|
|
318
|
+
written.push(file.path);
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
written
|
|
321
|
+
return written;
|
|
322
322
|
}
|
|
323
|
+
}
|
|
323
324
|
|
|
324
|
-
|
|
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
|
+
}
|