@intra-mart/accel 0.3.1 → 0.4.0-dev.202607140628
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/README.md +55 -12
- package/dist/asset/asset-tree.d.ts +5 -0
- package/dist/asset/asset-tree.js +7 -0
- package/dist/asset/deployer.d.ts +2 -1
- package/dist/asset/deployer.js +32 -59
- package/dist/asset/file-provider.js +19 -18
- package/dist/asset/git-provider.d.ts +14 -0
- package/dist/asset/git-provider.js +198 -0
- package/dist/asset/installer.d.ts +6 -0
- package/dist/asset/installer.js +31 -0
- package/dist/asset/renderer.d.ts +2 -0
- package/dist/asset/renderer.js +22 -0
- package/dist/asset/types.d.ts +1 -1
- package/dist/asset/updater.d.ts +52 -0
- package/dist/asset/updater.js +301 -0
- package/dist/asset/walker.d.ts +3 -2
- package/dist/asset/walker.js +67 -45
- package/dist/commands/asset-provider.d.ts +7 -0
- package/dist/commands/asset-provider.js +9 -0
- package/dist/commands/attach.d.ts +0 -4
- package/dist/commands/attach.js +11 -20
- package/dist/commands/deploy.d.ts +11 -6
- package/dist/commands/deploy.js +77 -23
- package/dist/commands/init.d.ts +0 -4
- package/dist/commands/init.js +11 -20
- package/dist/commands/update.d.ts +86 -0
- package/dist/commands/update.js +438 -0
- package/dist/core/constants.d.ts +3 -3
- package/dist/core/constants.js +4 -2
- package/dist/core/types.d.ts +11 -0
- package/dist/deploy/api-client.d.ts +6 -2
- package/dist/deploy/api-client.js +8 -4
- package/dist/deploy/deploy-files.d.ts +20 -0
- package/dist/deploy/deploy-files.js +37 -0
- package/dist/git/errors.d.ts +6 -0
- package/dist/git/errors.js +9 -0
- package/dist/git/http.d.ts +3 -0
- package/dist/git/http.js +58 -0
- package/dist/git/object-store.d.ts +13 -0
- package/dist/git/object-store.js +79 -0
- package/dist/git/pkt-line.d.ts +13 -0
- package/dist/git/pkt-line.js +41 -0
- package/dist/git/smart-http.d.ts +18 -0
- package/dist/git/smart-http.js +109 -0
- package/dist/i18n/en.js +49 -6
- package/dist/i18n/ja.js +49 -6
- package/dist/i18n/zh_CN.js +49 -6
- package/dist/index.js +4 -1
- package/dist/interactive/progress.js +1 -0
- package/dist/interactive/prompts.d.ts +7 -1
- package/dist/interactive/prompts.js +63 -64
- package/dist/markdown/section-replacement.js +34 -8
- package/dist/utils/args.d.ts +1 -0
- package/dist/utils/args.js +4 -0
- package/dist/utils/fs-list.d.ts +1 -0
- package/dist/utils/fs-list.js +11 -0
- package/dist/utils/merge-file.d.ts +6 -0
- package/dist/utils/merge-file.js +20 -0
- package/package.json +6 -8
- package/dist/asset/github-provider.d.ts +0 -2
- package/dist/asset/github-provider.js +0 -37
- package/dist/asset/local-provider.d.ts +0 -2
- package/dist/asset/local-provider.js +0 -24
- package/dist/utils/archive.d.ts +0 -3
- package/dist/utils/archive.js +0 -20
- package/dist/utils/https.d.ts +0 -2
- package/dist/utils/https.js +0 -44
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
|
+
import type { AssetTree } from "./asset-tree.js";
|
|
3
|
+
import type { MergeFn } from "../utils/merge-file.js";
|
|
4
|
+
export type RenderedAsset = {
|
|
5
|
+
relativePath: string;
|
|
6
|
+
content: string;
|
|
7
|
+
version: string;
|
|
8
|
+
sha1: string;
|
|
9
|
+
};
|
|
10
|
+
export type RenderedPlan = Map<string, RenderedAsset>;
|
|
11
|
+
export declare const buildRenderedPlan: (tree: AssetTree, settings: AccelSettings, materialize?: (dirs: string[]) => Promise<void>) => Promise<RenderedPlan>;
|
|
12
|
+
export type FileState = {
|
|
13
|
+
relativePath: string;
|
|
14
|
+
base: RenderedAsset | null;
|
|
15
|
+
theirs: RenderedAsset | null;
|
|
16
|
+
oursContent: string | null;
|
|
17
|
+
recorded: HashsumEntry | null;
|
|
18
|
+
};
|
|
19
|
+
export type UpdateOutcome = "up-to-date" | "updated" | "kept-edited" | "merged" | "conflict" | "kept-deleted" | "redeployed" | "removed" | "kept-warn" | "added" | "adopted" | "redeployed-warn" | "skipped-edited";
|
|
20
|
+
export type UpdateAction = {
|
|
21
|
+
relativePath: string;
|
|
22
|
+
op: "none" | "write" | "delete";
|
|
23
|
+
outcome: UpdateOutcome;
|
|
24
|
+
content?: string;
|
|
25
|
+
record: HashsumEntry | "keep" | "remove";
|
|
26
|
+
};
|
|
27
|
+
export declare const collectFileStates: (projectDir: string, basePlan: RenderedPlan, theirsPlan: RenderedPlan, recorded: HashsumEntry[]) => Promise<FileState[]>;
|
|
28
|
+
export declare const classifyFile: (state: FileState, merge: MergeFn) => Promise<UpdateAction>;
|
|
29
|
+
export declare const classifyFileFallback: (state: FileState, merge: MergeFn, keepEdited: boolean) => Promise<UpdateAction>;
|
|
30
|
+
export declare const classifyAll: (states: FileState[], merge: MergeFn, fallback?: {
|
|
31
|
+
keepEdited: boolean;
|
|
32
|
+
}) => Promise<UpdateAction[]>;
|
|
33
|
+
export type UpdateSummary = {
|
|
34
|
+
updated: string[];
|
|
35
|
+
merged: string[];
|
|
36
|
+
keptEdited: string[];
|
|
37
|
+
keptDeleted: string[];
|
|
38
|
+
deleted: string[];
|
|
39
|
+
redeployed: string[];
|
|
40
|
+
added: string[];
|
|
41
|
+
adopted: string[];
|
|
42
|
+
conflicts: string[];
|
|
43
|
+
warnings: string[];
|
|
44
|
+
redeployedWarn: string[];
|
|
45
|
+
skippedEdited: string[];
|
|
46
|
+
changedFileCount: number;
|
|
47
|
+
};
|
|
48
|
+
export declare const applyUpdateActions: (projectDir: string, actions: UpdateAction[]) => Promise<UpdateSummary>;
|
|
49
|
+
export declare const buildUpdatedRecords: (oldEntries: HashsumEntry[], actions: UpdateAction[]) => {
|
|
50
|
+
hashEntries: HashsumEntry[];
|
|
51
|
+
deployedAssets: Record<string, string>;
|
|
52
|
+
};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { buildEvalContext } from "../core/eval-context.js";
|
|
4
|
+
import { walkAssetRepo } from "./walker.js";
|
|
5
|
+
import { renderAssetContent } from "./renderer.js";
|
|
6
|
+
import { computeSha1 } from "../utils/hash.js";
|
|
7
|
+
const dirnamePosix = (p) => {
|
|
8
|
+
const idx = p.lastIndexOf("/");
|
|
9
|
+
return idx === -1 ? "" : p.slice(0, idx);
|
|
10
|
+
};
|
|
11
|
+
const isSafeRelPath = (p) => !p.startsWith("/") && !p.split("/").includes("..");
|
|
12
|
+
export const buildRenderedPlan = async (tree, settings, materialize) => {
|
|
13
|
+
const context = buildEvalContext(settings);
|
|
14
|
+
const entries = await walkAssetRepo(tree, settings.accelplatformVersion.semver, context);
|
|
15
|
+
const safeEntries = entries.filter((entry) => {
|
|
16
|
+
if (!isSafeRelPath(entry.relativePath) || !isSafeRelPath(entry.sourceRelPath)) {
|
|
17
|
+
console.warn(`Warning: skipping asset with unsafe path: ${entry.relativePath} (source: ${entry.sourceRelPath})`);
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
22
|
+
if (materialize) {
|
|
23
|
+
await materialize([
|
|
24
|
+
...new Set(safeEntries.map((e) => dirnamePosix(e.sourceRelPath))),
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
const plan = new Map();
|
|
28
|
+
for (const entry of safeEntries) {
|
|
29
|
+
const raw = await tree.readFile(entry.sourceRelPath);
|
|
30
|
+
const content = renderAssetContent(raw, entry.relativePath, entry.meta?.replacements ?? [], context);
|
|
31
|
+
plan.set(entry.relativePath, {
|
|
32
|
+
relativePath: entry.relativePath,
|
|
33
|
+
content,
|
|
34
|
+
version: entry.meta?.version ?? "0.0.0",
|
|
35
|
+
sha1: computeSha1(content),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return plan;
|
|
39
|
+
};
|
|
40
|
+
export const collectFileStates = async (projectDir, basePlan, theirsPlan, recorded) => {
|
|
41
|
+
const recordedMap = new Map(recorded.map((e) => [e.filePath, e]));
|
|
42
|
+
const keys = new Set([
|
|
43
|
+
...basePlan.keys(),
|
|
44
|
+
...theirsPlan.keys(),
|
|
45
|
+
...recordedMap.keys(),
|
|
46
|
+
]);
|
|
47
|
+
const states = [];
|
|
48
|
+
for (const key of [...keys].sort()) {
|
|
49
|
+
const theirs = theirsPlan.get(key) ?? null;
|
|
50
|
+
const rec = recordedMap.get(key) ?? null;
|
|
51
|
+
if (!theirs && !rec)
|
|
52
|
+
continue;
|
|
53
|
+
let oursContent = null;
|
|
54
|
+
try {
|
|
55
|
+
oursContent = await readFile(join(projectDir, key), "utf-8");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
oursContent = null;
|
|
59
|
+
}
|
|
60
|
+
states.push({
|
|
61
|
+
relativePath: key,
|
|
62
|
+
base: basePlan.get(key) ?? null,
|
|
63
|
+
theirs,
|
|
64
|
+
oursContent,
|
|
65
|
+
recorded: rec,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return states;
|
|
69
|
+
};
|
|
70
|
+
export const classifyFile = async (state, merge) => {
|
|
71
|
+
const { relativePath, base, theirs, oursContent, recorded } = state;
|
|
72
|
+
if (recorded) {
|
|
73
|
+
if (!theirs) {
|
|
74
|
+
if (oursContent === null) {
|
|
75
|
+
return { relativePath, op: "none", outcome: "removed", record: "remove" };
|
|
76
|
+
}
|
|
77
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
78
|
+
if (edited) {
|
|
79
|
+
return { relativePath, op: "none", outcome: "kept-warn", record: "remove" };
|
|
80
|
+
}
|
|
81
|
+
return { relativePath, op: "delete", outcome: "removed", record: "remove" };
|
|
82
|
+
}
|
|
83
|
+
const theirsRecord = {
|
|
84
|
+
filePath: relativePath,
|
|
85
|
+
version: theirs.version,
|
|
86
|
+
sha1: theirs.sha1,
|
|
87
|
+
};
|
|
88
|
+
const upstreamChanged = base?.content !== theirs.content;
|
|
89
|
+
if (oursContent === null) {
|
|
90
|
+
if (!upstreamChanged) {
|
|
91
|
+
return { relativePath, op: "none", outcome: "kept-deleted", record: "keep" };
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
relativePath,
|
|
95
|
+
op: "write",
|
|
96
|
+
outcome: "redeployed",
|
|
97
|
+
content: theirs.content,
|
|
98
|
+
record: theirsRecord,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
102
|
+
if (!edited) {
|
|
103
|
+
if (!upstreamChanged) {
|
|
104
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
relativePath,
|
|
108
|
+
op: "write",
|
|
109
|
+
outcome: "updated",
|
|
110
|
+
content: theirs.content,
|
|
111
|
+
record: theirsRecord,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (!upstreamChanged) {
|
|
115
|
+
return { relativePath, op: "none", outcome: "kept-edited", record: "keep" };
|
|
116
|
+
}
|
|
117
|
+
const result = await merge(base?.content ?? "", oursContent, theirs.content);
|
|
118
|
+
return {
|
|
119
|
+
relativePath,
|
|
120
|
+
op: "write",
|
|
121
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
122
|
+
content: result.content,
|
|
123
|
+
record: theirsRecord,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (!theirs) {
|
|
127
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
128
|
+
}
|
|
129
|
+
const theirsRecord = {
|
|
130
|
+
filePath: relativePath,
|
|
131
|
+
version: theirs.version,
|
|
132
|
+
sha1: theirs.sha1,
|
|
133
|
+
};
|
|
134
|
+
if (oursContent === null) {
|
|
135
|
+
return {
|
|
136
|
+
relativePath,
|
|
137
|
+
op: "write",
|
|
138
|
+
outcome: "added",
|
|
139
|
+
content: theirs.content,
|
|
140
|
+
record: theirsRecord,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (oursContent === theirs.content) {
|
|
144
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
145
|
+
}
|
|
146
|
+
const result = await merge("", oursContent, theirs.content);
|
|
147
|
+
return {
|
|
148
|
+
relativePath,
|
|
149
|
+
op: "write",
|
|
150
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
151
|
+
content: result.content,
|
|
152
|
+
record: theirsRecord,
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export const classifyFileFallback = async (state, merge, keepEdited) => {
|
|
156
|
+
const { relativePath, theirs, oursContent, recorded } = state;
|
|
157
|
+
if (!recorded || !theirs) {
|
|
158
|
+
return classifyFile(state, merge);
|
|
159
|
+
}
|
|
160
|
+
const theirsRecord = {
|
|
161
|
+
filePath: relativePath,
|
|
162
|
+
version: theirs.version,
|
|
163
|
+
sha1: theirs.sha1,
|
|
164
|
+
};
|
|
165
|
+
if (oursContent === null) {
|
|
166
|
+
return {
|
|
167
|
+
relativePath,
|
|
168
|
+
op: "write",
|
|
169
|
+
outcome: "redeployed-warn",
|
|
170
|
+
content: theirs.content,
|
|
171
|
+
record: theirsRecord,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
175
|
+
if (!edited) {
|
|
176
|
+
if (oursContent === theirs.content) {
|
|
177
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: theirsRecord };
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
relativePath,
|
|
181
|
+
op: "write",
|
|
182
|
+
outcome: "updated",
|
|
183
|
+
content: theirs.content,
|
|
184
|
+
record: theirsRecord,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (oursContent === theirs.content) {
|
|
188
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
189
|
+
}
|
|
190
|
+
if (keepEdited) {
|
|
191
|
+
return { relativePath, op: "none", outcome: "skipped-edited", record: theirsRecord };
|
|
192
|
+
}
|
|
193
|
+
const result = await merge("", oursContent, theirs.content);
|
|
194
|
+
return {
|
|
195
|
+
relativePath,
|
|
196
|
+
op: "write",
|
|
197
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
198
|
+
content: result.content,
|
|
199
|
+
record: theirsRecord,
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
export const classifyAll = async (states, merge, fallback) => {
|
|
203
|
+
const actions = [];
|
|
204
|
+
for (const state of states) {
|
|
205
|
+
actions.push(fallback
|
|
206
|
+
? await classifyFileFallback(state, merge, fallback.keepEdited)
|
|
207
|
+
: await classifyFile(state, merge));
|
|
208
|
+
}
|
|
209
|
+
return actions;
|
|
210
|
+
};
|
|
211
|
+
export const applyUpdateActions = async (projectDir, actions) => {
|
|
212
|
+
const summary = {
|
|
213
|
+
updated: [],
|
|
214
|
+
merged: [],
|
|
215
|
+
keptEdited: [],
|
|
216
|
+
keptDeleted: [],
|
|
217
|
+
deleted: [],
|
|
218
|
+
redeployed: [],
|
|
219
|
+
added: [],
|
|
220
|
+
adopted: [],
|
|
221
|
+
conflicts: [],
|
|
222
|
+
warnings: [],
|
|
223
|
+
redeployedWarn: [],
|
|
224
|
+
skippedEdited: [],
|
|
225
|
+
changedFileCount: 0,
|
|
226
|
+
};
|
|
227
|
+
for (const action of actions) {
|
|
228
|
+
const destPath = join(projectDir, action.relativePath);
|
|
229
|
+
if (action.op === "write") {
|
|
230
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
231
|
+
await writeFile(destPath, action.content ?? "", "utf-8");
|
|
232
|
+
summary.changedFileCount++;
|
|
233
|
+
}
|
|
234
|
+
else if (action.op === "delete") {
|
|
235
|
+
await unlink(destPath).catch(() => { });
|
|
236
|
+
summary.changedFileCount++;
|
|
237
|
+
}
|
|
238
|
+
switch (action.outcome) {
|
|
239
|
+
case "updated":
|
|
240
|
+
summary.updated.push(action.relativePath);
|
|
241
|
+
break;
|
|
242
|
+
case "merged":
|
|
243
|
+
summary.merged.push(action.relativePath);
|
|
244
|
+
break;
|
|
245
|
+
case "conflict":
|
|
246
|
+
summary.conflicts.push(action.relativePath);
|
|
247
|
+
break;
|
|
248
|
+
case "kept-edited":
|
|
249
|
+
summary.keptEdited.push(action.relativePath);
|
|
250
|
+
break;
|
|
251
|
+
case "kept-deleted":
|
|
252
|
+
summary.keptDeleted.push(action.relativePath);
|
|
253
|
+
break;
|
|
254
|
+
case "removed":
|
|
255
|
+
if (action.op === "delete") {
|
|
256
|
+
summary.deleted.push(action.relativePath);
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case "kept-warn":
|
|
260
|
+
summary.warnings.push(action.relativePath);
|
|
261
|
+
break;
|
|
262
|
+
case "redeployed":
|
|
263
|
+
summary.redeployed.push(action.relativePath);
|
|
264
|
+
break;
|
|
265
|
+
case "redeployed-warn":
|
|
266
|
+
summary.redeployedWarn.push(action.relativePath);
|
|
267
|
+
break;
|
|
268
|
+
case "skipped-edited":
|
|
269
|
+
summary.skippedEdited.push(action.relativePath);
|
|
270
|
+
break;
|
|
271
|
+
case "added":
|
|
272
|
+
summary.added.push(action.relativePath);
|
|
273
|
+
break;
|
|
274
|
+
case "adopted":
|
|
275
|
+
summary.adopted.push(action.relativePath);
|
|
276
|
+
break;
|
|
277
|
+
case "up-to-date":
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return summary;
|
|
282
|
+
};
|
|
283
|
+
export const buildUpdatedRecords = (oldEntries, actions) => {
|
|
284
|
+
const map = new Map(oldEntries.map((e) => [e.filePath, e]));
|
|
285
|
+
for (const action of actions) {
|
|
286
|
+
if (action.record === "keep")
|
|
287
|
+
continue;
|
|
288
|
+
if (action.record === "remove") {
|
|
289
|
+
map.delete(action.relativePath);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
map.set(action.relativePath, action.record);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const hashEntries = [...map.values()].sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
296
|
+
const deployedAssets = {};
|
|
297
|
+
for (const entry of hashEntries) {
|
|
298
|
+
deployedAssets[entry.filePath] = entry.version;
|
|
299
|
+
}
|
|
300
|
+
return { hashEntries, deployedAssets };
|
|
301
|
+
};
|
package/dist/asset/walker.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { MetaJson, EvalContext } from "../core/types.js";
|
|
2
|
+
import type { AssetTree } from "./asset-tree.js";
|
|
2
3
|
export type AssetEntry = {
|
|
3
|
-
|
|
4
|
+
sourceRelPath: string;
|
|
4
5
|
relativePath: string;
|
|
5
6
|
meta: MetaJson | null;
|
|
6
7
|
};
|
|
7
|
-
export declare const walkAssetRepo: (
|
|
8
|
+
export declare const walkAssetRepo: (tree: AssetTree, targetSemver: string, context: EvalContext) => Promise<AssetEntry[]>;
|
package/dist/asset/walker.js
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
-
import { join, relative, dirname, sep } from "node:path";
|
|
3
1
|
import { evaluateCondition } from "../core/condition-evaluator.js";
|
|
4
2
|
import { emptyEvalContext } from "../core/eval-context.js";
|
|
5
|
-
const toPosixPath = (p) => sep === "/" ? p : p.split(sep).join("/");
|
|
6
3
|
const META_FILE = "_meta.json";
|
|
7
|
-
const
|
|
4
|
+
const joinPosix = (...parts) => parts.filter((p) => p !== "").join("/");
|
|
5
|
+
const dirnamePosix = (p) => {
|
|
6
|
+
const idx = p.lastIndexOf("/");
|
|
7
|
+
return idx === -1 ? "" : p.slice(0, idx);
|
|
8
|
+
};
|
|
9
|
+
const buildVirtualTree = (files) => {
|
|
10
|
+
const tree = new Map();
|
|
11
|
+
const ensureDir = (dir) => {
|
|
12
|
+
let node = tree.get(dir);
|
|
13
|
+
if (!node) {
|
|
14
|
+
node = { files: new Set(), subdirs: new Set() };
|
|
15
|
+
tree.set(dir, node);
|
|
16
|
+
}
|
|
17
|
+
return node;
|
|
18
|
+
};
|
|
19
|
+
ensureDir("");
|
|
20
|
+
for (const file of files) {
|
|
21
|
+
const parts = file.split("/");
|
|
22
|
+
let dir = "";
|
|
23
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
24
|
+
ensureDir(dir).subdirs.add(parts[i]);
|
|
25
|
+
dir = joinPosix(dir, parts[i]);
|
|
26
|
+
}
|
|
27
|
+
ensureDir(dir).files.add(parts[parts.length - 1]);
|
|
28
|
+
}
|
|
29
|
+
return tree;
|
|
30
|
+
};
|
|
31
|
+
const readMetaJson = async (tree, vtree, dir) => {
|
|
32
|
+
if (!vtree.get(dir)?.files.has(META_FILE))
|
|
33
|
+
return null;
|
|
8
34
|
try {
|
|
9
|
-
const content = await readFile(
|
|
35
|
+
const content = await tree.readFile(joinPosix(dir, META_FILE));
|
|
10
36
|
const parsed = JSON.parse(content);
|
|
11
37
|
if (!parsed.type) {
|
|
12
38
|
parsed.type = "directory";
|
|
@@ -23,21 +49,20 @@ const resolveRenameRule = (rules, context, dir) => {
|
|
|
23
49
|
for (const rule of rules) {
|
|
24
50
|
if (evaluateCondition(rule.condition, context)) {
|
|
25
51
|
return {
|
|
26
|
-
|
|
52
|
+
sourceRelPath: joinPosix(dir, rule.from),
|
|
27
53
|
targetName: rule.to,
|
|
28
54
|
};
|
|
29
55
|
}
|
|
30
56
|
}
|
|
31
57
|
return null;
|
|
32
58
|
};
|
|
33
|
-
const findMatchingVersionDirs = async (
|
|
34
|
-
const
|
|
59
|
+
const findMatchingVersionDirs = async (tree, vtree, targetSemver) => {
|
|
60
|
+
const root = vtree.get("");
|
|
61
|
+
if (!root)
|
|
62
|
+
return [];
|
|
35
63
|
const matched = [];
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
continue;
|
|
39
|
-
const dirPath = join(repoDir, entry.name);
|
|
40
|
-
const meta = await readMetaJson(dirPath);
|
|
64
|
+
for (const name of [...root.subdirs].sort()) {
|
|
65
|
+
const meta = await readMetaJson(tree, vtree, name);
|
|
41
66
|
if (!meta) {
|
|
42
67
|
continue;
|
|
43
68
|
}
|
|
@@ -46,69 +71,64 @@ const findMatchingVersionDirs = async (repoDir, targetSemver) => {
|
|
|
46
71
|
accelplatformVersion: { label: "", semver: targetSemver },
|
|
47
72
|
});
|
|
48
73
|
if (evaluateCondition(meta.conditions, context)) {
|
|
49
|
-
matched.push(
|
|
74
|
+
matched.push(name);
|
|
50
75
|
}
|
|
51
76
|
}
|
|
52
77
|
}
|
|
53
78
|
return matched;
|
|
54
79
|
};
|
|
55
|
-
const walkDirectory = async (dir, baseDir, parentMeta, context) => {
|
|
80
|
+
const walkDirectory = async (tree, vtree, dir, baseDir, parentMeta, context) => {
|
|
56
81
|
const entries = [];
|
|
57
|
-
const
|
|
58
|
-
|
|
82
|
+
const node = vtree.get(dir);
|
|
83
|
+
if (!node)
|
|
84
|
+
return entries;
|
|
85
|
+
const ownMeta = await readMetaJson(tree, vtree, dir);
|
|
59
86
|
const effectiveMeta = ownMeta ?? parentMeta;
|
|
60
87
|
if (ownMeta?.conditions) {
|
|
61
88
|
if (!evaluateCondition(ownMeta.conditions, context)) {
|
|
62
89
|
return [];
|
|
63
90
|
}
|
|
64
91
|
}
|
|
92
|
+
const relativeOf = (p) => p === baseDir ? "" : p.slice(baseDir.length + 1);
|
|
65
93
|
if (ownMeta?.type === "file") {
|
|
66
|
-
const parentRelative =
|
|
94
|
+
const parentRelative = relativeOf(dirnamePosix(dir));
|
|
67
95
|
if (ownMeta.rename && ownMeta.rename.length > 0) {
|
|
68
96
|
const resolved = resolveRenameRule(ownMeta.rename, context, dir);
|
|
69
97
|
if (!resolved)
|
|
70
98
|
return [];
|
|
71
|
-
const targetPath = parentRelative
|
|
72
|
-
? join(parentRelative, resolved.targetName)
|
|
73
|
-
: resolved.targetName;
|
|
74
99
|
entries.push({
|
|
75
|
-
|
|
76
|
-
relativePath:
|
|
100
|
+
sourceRelPath: resolved.sourceRelPath,
|
|
101
|
+
relativePath: joinPosix(parentRelative, resolved.targetName),
|
|
77
102
|
meta: effectiveMeta,
|
|
78
103
|
});
|
|
79
104
|
}
|
|
80
105
|
else {
|
|
81
|
-
for (const
|
|
82
|
-
if (
|
|
106
|
+
for (const name of [...node.files].sort()) {
|
|
107
|
+
if (name === META_FILE)
|
|
83
108
|
continue;
|
|
84
|
-
if (!entry.isFile())
|
|
85
|
-
continue;
|
|
86
|
-
const fullPath = join(dir, entry.name);
|
|
87
|
-
const targetPath = parentRelative
|
|
88
|
-
? join(parentRelative, entry.name)
|
|
89
|
-
: entry.name;
|
|
90
109
|
entries.push({
|
|
91
|
-
|
|
92
|
-
relativePath:
|
|
110
|
+
sourceRelPath: joinPosix(dir, name),
|
|
111
|
+
relativePath: joinPosix(parentRelative, name),
|
|
93
112
|
meta: effectiveMeta,
|
|
94
113
|
});
|
|
95
114
|
}
|
|
96
115
|
}
|
|
97
116
|
return entries;
|
|
98
117
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (
|
|
118
|
+
const childNames = [...new Set([...node.files, ...node.subdirs])].sort();
|
|
119
|
+
for (const name of childNames) {
|
|
120
|
+
if (name === META_FILE) {
|
|
102
121
|
continue;
|
|
103
122
|
}
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
const fullPath = joinPosix(dir, name);
|
|
124
|
+
if (node.subdirs.has(name)) {
|
|
125
|
+
const children = await walkDirectory(tree, vtree, fullPath, baseDir, effectiveMeta, context);
|
|
106
126
|
entries.push(...children);
|
|
107
127
|
}
|
|
108
|
-
else
|
|
128
|
+
else {
|
|
109
129
|
entries.push({
|
|
110
|
-
|
|
111
|
-
relativePath:
|
|
130
|
+
sourceRelPath: fullPath,
|
|
131
|
+
relativePath: relativeOf(fullPath),
|
|
112
132
|
meta: effectiveMeta,
|
|
113
133
|
});
|
|
114
134
|
}
|
|
@@ -131,12 +151,14 @@ const deduplicateByPath = (entries) => {
|
|
|
131
151
|
}
|
|
132
152
|
return [...byPath.values()];
|
|
133
153
|
};
|
|
134
|
-
export const walkAssetRepo = async (
|
|
135
|
-
const
|
|
154
|
+
export const walkAssetRepo = async (tree, targetSemver, context) => {
|
|
155
|
+
const files = await tree.listFiles();
|
|
156
|
+
const vtree = buildVirtualTree(files);
|
|
157
|
+
const versionDirs = await findMatchingVersionDirs(tree, vtree, targetSemver);
|
|
136
158
|
const allEntries = [];
|
|
137
159
|
for (const versionDir of versionDirs) {
|
|
138
|
-
const meta = await readMetaJson(versionDir);
|
|
139
|
-
const entries = await walkDirectory(versionDir, versionDir, meta, context);
|
|
160
|
+
const meta = await readMetaJson(tree, vtree, versionDir);
|
|
161
|
+
const entries = await walkDirectory(tree, vtree, versionDir, versionDir, meta, context);
|
|
140
162
|
allEntries.push(...entries);
|
|
141
163
|
}
|
|
142
164
|
return deduplicateByPath(allEntries);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AssetProvider } from "../core/types.js";
|
|
2
|
+
export type AssetProviderArgs = {
|
|
3
|
+
assetSource?: string;
|
|
4
|
+
assetServerUrl?: string;
|
|
5
|
+
assetRef?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const selectAssetProvider: (args: AssetProviderArgs, locale: string) => Promise<AssetProvider>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DEFAULT_ASSET_REPO_URL, DEFAULT_ASSET_REF, } from "../core/constants.js";
|
|
2
|
+
import { createFileAssetProvider } from "../asset/file-provider.js";
|
|
3
|
+
import { createGitAssetProvider } from "../asset/git-provider.js";
|
|
4
|
+
export const selectAssetProvider = async (args, locale) => {
|
|
5
|
+
if (args.assetSource) {
|
|
6
|
+
return createFileAssetProvider(args.assetSource);
|
|
7
|
+
}
|
|
8
|
+
return createGitAssetProvider(args.assetServerUrl ?? DEFAULT_ASSET_REPO_URL, args.assetRef ?? DEFAULT_ASSET_REF, { locale });
|
|
9
|
+
};
|
package/dist/commands/attach.js
CHANGED
|
@@ -2,12 +2,10 @@ import { defineCommand } from "citty";
|
|
|
2
2
|
import * as p from "@clack/prompts";
|
|
3
3
|
import { stat } from "node:fs/promises";
|
|
4
4
|
import { basename, join } from "node:path";
|
|
5
|
-
import { CLI_VERSION
|
|
5
|
+
import { CLI_VERSION } from "../core/constants.js";
|
|
6
6
|
import { runPrompts } from "../interactive/prompts.js";
|
|
7
7
|
import { deployAssets, } from "../asset/deployer.js";
|
|
8
|
-
import {
|
|
9
|
-
import { createFileAssetProvider } from "../asset/file-provider.js";
|
|
10
|
-
import { createGitHubAssetProvider } from "../asset/github-provider.js";
|
|
8
|
+
import { selectAssetProvider } from "./asset-provider.js";
|
|
11
9
|
import { getMessage } from "../i18n/index.js";
|
|
12
10
|
import { detectLocale } from "../utils/locale-detect.js";
|
|
13
11
|
import { printSummary } from "../interactive/summary.js";
|
|
@@ -92,19 +90,15 @@ export const attachCommand = defineCommand({
|
|
|
92
90
|
},
|
|
93
91
|
"asset-server-url": {
|
|
94
92
|
type: "string",
|
|
95
|
-
description: "
|
|
93
|
+
description: "Git repository URL to fetch assets from (overrides the default repository)",
|
|
96
94
|
},
|
|
97
95
|
"asset-ref": {
|
|
98
96
|
type: "string",
|
|
99
|
-
description: "Git
|
|
97
|
+
description: "Git branch/tag to fetch from the asset repository. Default: experiment",
|
|
100
98
|
},
|
|
101
99
|
"asset-source": {
|
|
102
100
|
type: "string",
|
|
103
|
-
description: "(debug) Local asset source
|
|
104
|
-
},
|
|
105
|
-
"debug-server-url": {
|
|
106
|
-
type: "string",
|
|
107
|
-
description: "(debug) Local asset server URL serving GET /archive",
|
|
101
|
+
description: "(debug) Local asset source directory",
|
|
108
102
|
},
|
|
109
103
|
},
|
|
110
104
|
run: async ({ args }) => {
|
|
@@ -170,18 +164,15 @@ export const attachCommand = defineCommand({
|
|
|
170
164
|
javascript: resolved.javascript,
|
|
171
165
|
locale: resolved.locale,
|
|
172
166
|
packageManager: resolved.packageManager,
|
|
173
|
-
jugglingProject: resolved.jugglingProject,
|
|
167
|
+
jugglingProject: resolved.jugglingProject ?? null,
|
|
174
168
|
deployedAssets: {},
|
|
175
169
|
};
|
|
176
|
-
const assetSource = args["asset-source"];
|
|
177
|
-
const debugServerUrl = args["debug-server-url"];
|
|
178
|
-
const provider = assetSource
|
|
179
|
-
? createFileAssetProvider(assetSource)
|
|
180
|
-
: debugServerUrl
|
|
181
|
-
? createLocalAssetProvider(debugServerUrl)
|
|
182
|
-
: createGitHubAssetProvider(args["asset-server-url"] ??
|
|
183
|
-
DEFAULT_ASSET_REPO_URL, args["asset-ref"] ?? DEFAULT_ASSET_REF);
|
|
184
170
|
const isInteractive = !args["non-interactive"];
|
|
171
|
+
const provider = await selectAssetProvider({
|
|
172
|
+
assetSource: args["asset-source"],
|
|
173
|
+
assetServerUrl: args["asset-server-url"],
|
|
174
|
+
assetRef: args["asset-ref"],
|
|
175
|
+
}, locale);
|
|
185
176
|
const overwriteFlag = args.overwrite;
|
|
186
177
|
if (isInteractive) {
|
|
187
178
|
printSummary(settings, projectDir, locale);
|