@intra-mart/accel 0.3.1 → 0.4.0-dev.202607170346
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 +72 -12
- package/assets/githooks/.githooks/.gitattributes +2 -0
- package/assets/githooks/.githooks/pre-commit/_meta.json +24 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_en +268 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_ja +255 -0
- package/assets/githooks/.githooks/pre-commit/pre-commit_zh_CN +255 -0
- 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 +28 -59
- package/dist/asset/file-provider.js +19 -18
- package/dist/asset/git-provider.d.ts +14 -0
- package/dist/asset/git-provider.js +163 -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 +297 -0
- package/dist/asset/walker.d.ts +4 -2
- package/dist/asset/walker.js +74 -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 +448 -0
- package/dist/core/constants.d.ts +3 -3
- package/dist/core/constants.js +4 -2
- package/dist/core/types.d.ts +13 -1
- 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 +53 -6
- package/dist/i18n/ja.js +53 -6
- package/dist/i18n/zh_CN.js +53 -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/githooks-sync.d.ts +1 -0
- package/dist/utils/githooks-sync.js +91 -0
- package/dist/utils/mcp-sync.js +6 -0
- package/dist/utils/merge-file.d.ts +6 -0
- package/dist/utils/merge-file.js +20 -0
- package/package.json +8 -9
- 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
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { stat
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { createFsAssetTree } from "./asset-tree.js";
|
|
4
4
|
export const createFileAssetProvider = (sourcePath) => {
|
|
5
|
-
|
|
5
|
+
const absPath = resolve(sourcePath);
|
|
6
|
+
const tree = createFsAssetTree(absPath);
|
|
6
7
|
return {
|
|
7
8
|
fetch: async () => {
|
|
8
|
-
const st = await stat(
|
|
9
|
-
if (st
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
tmpDir = await createTempDir("accel-assets-");
|
|
13
|
-
const extractDir = join(tmpDir, "repo");
|
|
14
|
-
await mkdir(extractDir, { recursive: true });
|
|
15
|
-
await extractTarGz(sourcePath, extractDir);
|
|
16
|
-
return extractDir;
|
|
17
|
-
},
|
|
18
|
-
cleanup: async () => {
|
|
19
|
-
if (tmpDir) {
|
|
20
|
-
await rm(tmpDir, { recursive: true, force: true }).catch(() => { });
|
|
21
|
-
tmpDir = null;
|
|
9
|
+
const st = await stat(absPath).catch(() => null);
|
|
10
|
+
if (!st?.isDirectory()) {
|
|
11
|
+
throw new Error(`Asset source is not a directory: ${absPath}`);
|
|
22
12
|
}
|
|
13
|
+
return absPath;
|
|
23
14
|
},
|
|
15
|
+
listFiles: () => tree.listFiles(),
|
|
16
|
+
materialize: async () => { },
|
|
17
|
+
readFile: (relPath) => tree.readFile(relPath),
|
|
18
|
+
cleanup: async () => { },
|
|
19
|
+
sourceInfo: () => ({
|
|
20
|
+
type: "directory",
|
|
21
|
+
url: absPath,
|
|
22
|
+
ref: null,
|
|
23
|
+
commit: null,
|
|
24
|
+
}),
|
|
24
25
|
};
|
|
25
26
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AssetProvider } from "../core/types.js";
|
|
2
|
+
export type CommitTree = {
|
|
3
|
+
listFiles: () => Promise<string[]>;
|
|
4
|
+
readFile: (relPath: string) => Promise<string>;
|
|
5
|
+
materialize: (files: string[]) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export type GitAssetProvider = AssetProvider & {
|
|
8
|
+
asTree: () => CommitTree;
|
|
9
|
+
openCommit: (sha: string) => Promise<CommitTree>;
|
|
10
|
+
};
|
|
11
|
+
export type GitAssetProviderOptions = {
|
|
12
|
+
locale?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const createGitAssetProvider: (repoUrl: string, ref: string, options?: GitAssetProviderOptions) => GitAssetProvider;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { getMessage } from "../i18n/index.js";
|
|
2
|
+
import { isGitAuthError, isGitObjectMissingError, isGitServerUnsupportedError, } from "../git/errors.js";
|
|
3
|
+
import { createObjectStore } from "../git/object-store.js";
|
|
4
|
+
import { assertServerSupported, fetchCapabilities, fetchPack, isValidOid, resolveRef, } from "../git/smart-http.js";
|
|
5
|
+
const MAX_WANTS_PER_REQUEST = 1000;
|
|
6
|
+
const META_FILENAME = "_meta.json";
|
|
7
|
+
const isHttpUrl = (url) => {
|
|
8
|
+
try {
|
|
9
|
+
const parsed = new URL(url);
|
|
10
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const createGitAssetProvider = (repoUrl, ref, options = {}) => {
|
|
17
|
+
const { locale = "en" } = options;
|
|
18
|
+
let store = null;
|
|
19
|
+
let commit = null;
|
|
20
|
+
let packSeq = 0;
|
|
21
|
+
const withHint = (message, cause) => {
|
|
22
|
+
if (isGitAuthError(cause)) {
|
|
23
|
+
return `${message}\n${getMessage("error.gitAuthHint", locale)}`;
|
|
24
|
+
}
|
|
25
|
+
if (isGitServerUnsupportedError(cause)) {
|
|
26
|
+
return `${message}\n${getMessage("error.gitServerUnsupported", locale)}`;
|
|
27
|
+
}
|
|
28
|
+
return message;
|
|
29
|
+
};
|
|
30
|
+
const requireRepo = () => {
|
|
31
|
+
if (!store || !commit) {
|
|
32
|
+
throw new Error("GitAssetProvider used before fetch()");
|
|
33
|
+
}
|
|
34
|
+
return { store, commit };
|
|
35
|
+
};
|
|
36
|
+
const fetchMissingBlobs = async (oids) => {
|
|
37
|
+
const { store } = requireRepo();
|
|
38
|
+
const missing = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const oid of oids) {
|
|
41
|
+
if (seen.has(oid))
|
|
42
|
+
continue;
|
|
43
|
+
seen.add(oid);
|
|
44
|
+
if (!(await store.hasObject(oid)))
|
|
45
|
+
missing.push(oid);
|
|
46
|
+
}
|
|
47
|
+
for (let i = 0; i < missing.length; i += MAX_WANTS_PER_REQUEST) {
|
|
48
|
+
const pack = await fetchPack(repoUrl, missing.slice(i, i + MAX_WANTS_PER_REQUEST));
|
|
49
|
+
await store.writePack(pack, `blobs-${packSeq++}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const readFileAt = async (oid, relPath) => {
|
|
53
|
+
const { store } = requireRepo();
|
|
54
|
+
try {
|
|
55
|
+
return await store.readBlobAtPath(oid, relPath);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (!isGitObjectMissingError(err))
|
|
59
|
+
throw err;
|
|
60
|
+
throw new Error(`File content is not materialized (materialize() must be called first): ${relPath}`);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const materializeAt = async (oid, files) => {
|
|
64
|
+
if (files.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
const { store } = requireRepo();
|
|
67
|
+
const entries = await store.listBlobEntries(oid);
|
|
68
|
+
const oidByPath = new Map(entries.map((e) => [e.path, e.oid]));
|
|
69
|
+
const targets = files
|
|
70
|
+
.map((f) => oidByPath.get(f))
|
|
71
|
+
.filter((o) => o !== undefined);
|
|
72
|
+
await fetchMissingBlobs(targets);
|
|
73
|
+
};
|
|
74
|
+
const listFilesAt = async (oid) => {
|
|
75
|
+
const { store } = requireRepo();
|
|
76
|
+
return (await store.listBlobEntries(oid)).map((e) => e.path);
|
|
77
|
+
};
|
|
78
|
+
const fetchTreesFor = async (oid, label) => {
|
|
79
|
+
const { store } = requireRepo();
|
|
80
|
+
const pack = await fetchPack(repoUrl, [oid], {
|
|
81
|
+
deepenOne: true,
|
|
82
|
+
filterBlobNone: true,
|
|
83
|
+
});
|
|
84
|
+
await store.writePack(pack, label);
|
|
85
|
+
const entries = await store.listBlobEntries(oid);
|
|
86
|
+
const metaOids = entries
|
|
87
|
+
.filter((e) => e.path === META_FILENAME || e.path.endsWith(`/${META_FILENAME}`))
|
|
88
|
+
.map((e) => e.oid);
|
|
89
|
+
await fetchMissingBlobs(metaOids);
|
|
90
|
+
};
|
|
91
|
+
const commitTreeOf = (oid) => ({
|
|
92
|
+
listFiles: () => listFilesAt(oid),
|
|
93
|
+
readFile: (relPath) => readFileAt(oid, relPath),
|
|
94
|
+
materialize: (files) => materializeAt(oid, files),
|
|
95
|
+
});
|
|
96
|
+
const provider = {
|
|
97
|
+
fetch: async () => {
|
|
98
|
+
if (!isHttpUrl(repoUrl)) {
|
|
99
|
+
throw new Error(getMessage("error.gitUrlUnsupported", locale, { url: repoUrl }));
|
|
100
|
+
}
|
|
101
|
+
store = await createObjectStore();
|
|
102
|
+
try {
|
|
103
|
+
const caps = await fetchCapabilities(repoUrl);
|
|
104
|
+
assertServerSupported(repoUrl, caps);
|
|
105
|
+
const resolved = await resolveRef(repoUrl, ref);
|
|
106
|
+
if (!resolved) {
|
|
107
|
+
throw new Error(`ref not found on server: ${ref}`);
|
|
108
|
+
}
|
|
109
|
+
commit = resolved.oid;
|
|
110
|
+
await fetchTreesFor(commit, "trees-head");
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
114
|
+
throw new Error(withHint(`Failed to fetch the asset repository from ${repoUrl} (ref: ${ref}). Check the URL and ref: ${reason}`, err));
|
|
115
|
+
}
|
|
116
|
+
return store.dir;
|
|
117
|
+
},
|
|
118
|
+
listFiles: () => {
|
|
119
|
+
const { commit: oid } = requireRepo();
|
|
120
|
+
return listFilesAt(oid);
|
|
121
|
+
},
|
|
122
|
+
readFile: (relPath) => {
|
|
123
|
+
const { commit: oid } = requireRepo();
|
|
124
|
+
return readFileAt(oid, relPath);
|
|
125
|
+
},
|
|
126
|
+
materialize: (files) => {
|
|
127
|
+
const { commit: oid } = requireRepo();
|
|
128
|
+
return materializeAt(oid, files);
|
|
129
|
+
},
|
|
130
|
+
cleanup: async () => {
|
|
131
|
+
if (store) {
|
|
132
|
+
await store.cleanup();
|
|
133
|
+
store = null;
|
|
134
|
+
commit = null;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
sourceInfo: () => ({
|
|
138
|
+
type: "git",
|
|
139
|
+
url: repoUrl,
|
|
140
|
+
ref,
|
|
141
|
+
commit,
|
|
142
|
+
}),
|
|
143
|
+
asTree: () => {
|
|
144
|
+
const { commit: oid } = requireRepo();
|
|
145
|
+
return commitTreeOf(oid);
|
|
146
|
+
},
|
|
147
|
+
openCommit: async (sha) => {
|
|
148
|
+
requireRepo();
|
|
149
|
+
if (!isValidOid(sha)) {
|
|
150
|
+
throw new Error(`Invalid commit SHA recorded in settings: ${JSON.stringify(sha)}`);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
await fetchTreesFor(sha, `trees-${sha.slice(0, 7)}`);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
157
|
+
throw new Error(withHint(`Failed to fetch commit ${sha} from ${repoUrl} (history may have been rewritten): ${reason}`, err));
|
|
158
|
+
}
|
|
159
|
+
return commitTreeOf(sha);
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
return provider;
|
|
163
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type InstallProgress = {
|
|
2
|
+
onInstallStart?: (command: string) => void;
|
|
3
|
+
onBuildStart?: (command: string) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare const getInstallCmds: (packageManager: string) => string[];
|
|
6
|
+
export declare const runInstallBuild: (projectDir: string, packageManager: string, progress?: InstallProgress) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
export const getInstallCmds = (packageManager) => {
|
|
3
|
+
switch (packageManager) {
|
|
4
|
+
case "npm":
|
|
5
|
+
return ["npm ci", "npm run build"];
|
|
6
|
+
case "yarn":
|
|
7
|
+
return ["yarn install --frozen-lockfile", "yarn run build"];
|
|
8
|
+
case "pnpm":
|
|
9
|
+
return ["pnpm install --frozen-lockfile", "pnpm run build"];
|
|
10
|
+
case "bun":
|
|
11
|
+
default:
|
|
12
|
+
return ["bun ci", "bun run build"];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const runInstallBuild = (projectDir, packageManager, progress) => {
|
|
16
|
+
const [installCmd, buildCmd] = getInstallCmds(packageManager);
|
|
17
|
+
progress?.onInstallStart?.(installCmd);
|
|
18
|
+
try {
|
|
19
|
+
execSync(installCmd, { cwd: projectDir, stdio: "pipe" });
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
console.warn(`Warning: install command failed: ${installCmd} in ${projectDir}`);
|
|
23
|
+
}
|
|
24
|
+
progress?.onBuildStart?.(buildCmd);
|
|
25
|
+
try {
|
|
26
|
+
execSync(buildCmd, { cwd: projectDir, stdio: "pipe" });
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
console.warn(`Warning: build command failed: ${buildCmd} in ${projectDir}`);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { processMarkdown } from "../markdown/processor.js";
|
|
2
|
+
import { applyRegexReplacements } from "./regex-replacement.js";
|
|
3
|
+
import { applyForeachReplacements } from "./foreach-replacement.js";
|
|
4
|
+
export const renderAssetContent = (raw, targetPath, replacements, context) => {
|
|
5
|
+
let content = raw;
|
|
6
|
+
if (replacements.length === 0)
|
|
7
|
+
return content;
|
|
8
|
+
const foreachReplacements = replacements.filter((r) => r.type === "foreach");
|
|
9
|
+
if (foreachReplacements.length > 0) {
|
|
10
|
+
content = applyForeachReplacements(content, foreachReplacements, context);
|
|
11
|
+
}
|
|
12
|
+
if (targetPath.endsWith(".md")) {
|
|
13
|
+
content = processMarkdown(content, replacements, context);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const regexReplacements = replacements.filter((r) => r.type === "regex");
|
|
17
|
+
if (regexReplacements.length > 0) {
|
|
18
|
+
content = applyRegexReplacements(content, regexReplacements, context);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return content;
|
|
22
|
+
};
|
package/dist/asset/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type { AssetProvider } from "../core/types.js";
|
|
1
|
+
export type { AssetProvider, AssetSourceInfo } from "../core/types.js";
|
|
@@ -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?: (files: 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,297 @@
|
|
|
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 isSafeRelPath = (p) => !p.startsWith("/") && !p.split("/").includes("..");
|
|
8
|
+
export const buildRenderedPlan = async (tree, settings, materialize) => {
|
|
9
|
+
const context = buildEvalContext(settings);
|
|
10
|
+
const entries = await walkAssetRepo(tree, settings.accelplatformVersion.semver, context);
|
|
11
|
+
const safeEntries = entries.filter((entry) => {
|
|
12
|
+
if (!isSafeRelPath(entry.relativePath) || !isSafeRelPath(entry.sourceRelPath)) {
|
|
13
|
+
console.warn(`Warning: skipping asset with unsafe path: ${entry.relativePath} (source: ${entry.sourceRelPath})`);
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
if (materialize) {
|
|
19
|
+
await materialize([
|
|
20
|
+
...new Set(safeEntries.map((e) => e.sourceRelPath)),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
const plan = new Map();
|
|
24
|
+
for (const entry of safeEntries) {
|
|
25
|
+
const raw = await tree.readFile(entry.sourceRelPath);
|
|
26
|
+
const content = renderAssetContent(raw, entry.relativePath, entry.meta?.replacements ?? [], context);
|
|
27
|
+
plan.set(entry.relativePath, {
|
|
28
|
+
relativePath: entry.relativePath,
|
|
29
|
+
content,
|
|
30
|
+
version: entry.meta?.version ?? "0.0.0",
|
|
31
|
+
sha1: computeSha1(content),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return plan;
|
|
35
|
+
};
|
|
36
|
+
export const collectFileStates = async (projectDir, basePlan, theirsPlan, recorded) => {
|
|
37
|
+
const recordedMap = new Map(recorded.map((e) => [e.filePath, e]));
|
|
38
|
+
const keys = new Set([
|
|
39
|
+
...basePlan.keys(),
|
|
40
|
+
...theirsPlan.keys(),
|
|
41
|
+
...recordedMap.keys(),
|
|
42
|
+
]);
|
|
43
|
+
const states = [];
|
|
44
|
+
for (const key of [...keys].sort()) {
|
|
45
|
+
const theirs = theirsPlan.get(key) ?? null;
|
|
46
|
+
const rec = recordedMap.get(key) ?? null;
|
|
47
|
+
if (!theirs && !rec)
|
|
48
|
+
continue;
|
|
49
|
+
let oursContent = null;
|
|
50
|
+
try {
|
|
51
|
+
oursContent = await readFile(join(projectDir, key), "utf-8");
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
oursContent = null;
|
|
55
|
+
}
|
|
56
|
+
states.push({
|
|
57
|
+
relativePath: key,
|
|
58
|
+
base: basePlan.get(key) ?? null,
|
|
59
|
+
theirs,
|
|
60
|
+
oursContent,
|
|
61
|
+
recorded: rec,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return states;
|
|
65
|
+
};
|
|
66
|
+
export const classifyFile = async (state, merge) => {
|
|
67
|
+
const { relativePath, base, theirs, oursContent, recorded } = state;
|
|
68
|
+
if (recorded) {
|
|
69
|
+
if (!theirs) {
|
|
70
|
+
if (oursContent === null) {
|
|
71
|
+
return { relativePath, op: "none", outcome: "removed", record: "remove" };
|
|
72
|
+
}
|
|
73
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
74
|
+
if (edited) {
|
|
75
|
+
return { relativePath, op: "none", outcome: "kept-warn", record: "remove" };
|
|
76
|
+
}
|
|
77
|
+
return { relativePath, op: "delete", outcome: "removed", record: "remove" };
|
|
78
|
+
}
|
|
79
|
+
const theirsRecord = {
|
|
80
|
+
filePath: relativePath,
|
|
81
|
+
version: theirs.version,
|
|
82
|
+
sha1: theirs.sha1,
|
|
83
|
+
};
|
|
84
|
+
const upstreamChanged = base?.content !== theirs.content;
|
|
85
|
+
if (oursContent === null) {
|
|
86
|
+
if (!upstreamChanged) {
|
|
87
|
+
return { relativePath, op: "none", outcome: "kept-deleted", record: "keep" };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
relativePath,
|
|
91
|
+
op: "write",
|
|
92
|
+
outcome: "redeployed",
|
|
93
|
+
content: theirs.content,
|
|
94
|
+
record: theirsRecord,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
98
|
+
if (!edited) {
|
|
99
|
+
if (!upstreamChanged) {
|
|
100
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
relativePath,
|
|
104
|
+
op: "write",
|
|
105
|
+
outcome: "updated",
|
|
106
|
+
content: theirs.content,
|
|
107
|
+
record: theirsRecord,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (!upstreamChanged) {
|
|
111
|
+
return { relativePath, op: "none", outcome: "kept-edited", record: "keep" };
|
|
112
|
+
}
|
|
113
|
+
const result = await merge(base?.content ?? "", oursContent, theirs.content);
|
|
114
|
+
return {
|
|
115
|
+
relativePath,
|
|
116
|
+
op: "write",
|
|
117
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
118
|
+
content: result.content,
|
|
119
|
+
record: theirsRecord,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (!theirs) {
|
|
123
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: "keep" };
|
|
124
|
+
}
|
|
125
|
+
const theirsRecord = {
|
|
126
|
+
filePath: relativePath,
|
|
127
|
+
version: theirs.version,
|
|
128
|
+
sha1: theirs.sha1,
|
|
129
|
+
};
|
|
130
|
+
if (oursContent === null) {
|
|
131
|
+
return {
|
|
132
|
+
relativePath,
|
|
133
|
+
op: "write",
|
|
134
|
+
outcome: "added",
|
|
135
|
+
content: theirs.content,
|
|
136
|
+
record: theirsRecord,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (oursContent === theirs.content) {
|
|
140
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
141
|
+
}
|
|
142
|
+
const result = await merge("", oursContent, theirs.content);
|
|
143
|
+
return {
|
|
144
|
+
relativePath,
|
|
145
|
+
op: "write",
|
|
146
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
147
|
+
content: result.content,
|
|
148
|
+
record: theirsRecord,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
export const classifyFileFallback = async (state, merge, keepEdited) => {
|
|
152
|
+
const { relativePath, theirs, oursContent, recorded } = state;
|
|
153
|
+
if (!recorded || !theirs) {
|
|
154
|
+
return classifyFile(state, merge);
|
|
155
|
+
}
|
|
156
|
+
const theirsRecord = {
|
|
157
|
+
filePath: relativePath,
|
|
158
|
+
version: theirs.version,
|
|
159
|
+
sha1: theirs.sha1,
|
|
160
|
+
};
|
|
161
|
+
if (oursContent === null) {
|
|
162
|
+
return {
|
|
163
|
+
relativePath,
|
|
164
|
+
op: "write",
|
|
165
|
+
outcome: "redeployed-warn",
|
|
166
|
+
content: theirs.content,
|
|
167
|
+
record: theirsRecord,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const edited = computeSha1(oursContent) !== recorded.sha1;
|
|
171
|
+
if (!edited) {
|
|
172
|
+
if (oursContent === theirs.content) {
|
|
173
|
+
return { relativePath, op: "none", outcome: "up-to-date", record: theirsRecord };
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
relativePath,
|
|
177
|
+
op: "write",
|
|
178
|
+
outcome: "updated",
|
|
179
|
+
content: theirs.content,
|
|
180
|
+
record: theirsRecord,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (oursContent === theirs.content) {
|
|
184
|
+
return { relativePath, op: "none", outcome: "adopted", record: theirsRecord };
|
|
185
|
+
}
|
|
186
|
+
if (keepEdited) {
|
|
187
|
+
return { relativePath, op: "none", outcome: "skipped-edited", record: theirsRecord };
|
|
188
|
+
}
|
|
189
|
+
const result = await merge("", oursContent, theirs.content);
|
|
190
|
+
return {
|
|
191
|
+
relativePath,
|
|
192
|
+
op: "write",
|
|
193
|
+
outcome: result.conflicted ? "conflict" : "merged",
|
|
194
|
+
content: result.content,
|
|
195
|
+
record: theirsRecord,
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
export const classifyAll = async (states, merge, fallback) => {
|
|
199
|
+
const actions = [];
|
|
200
|
+
for (const state of states) {
|
|
201
|
+
actions.push(fallback
|
|
202
|
+
? await classifyFileFallback(state, merge, fallback.keepEdited)
|
|
203
|
+
: await classifyFile(state, merge));
|
|
204
|
+
}
|
|
205
|
+
return actions;
|
|
206
|
+
};
|
|
207
|
+
export const applyUpdateActions = async (projectDir, actions) => {
|
|
208
|
+
const summary = {
|
|
209
|
+
updated: [],
|
|
210
|
+
merged: [],
|
|
211
|
+
keptEdited: [],
|
|
212
|
+
keptDeleted: [],
|
|
213
|
+
deleted: [],
|
|
214
|
+
redeployed: [],
|
|
215
|
+
added: [],
|
|
216
|
+
adopted: [],
|
|
217
|
+
conflicts: [],
|
|
218
|
+
warnings: [],
|
|
219
|
+
redeployedWarn: [],
|
|
220
|
+
skippedEdited: [],
|
|
221
|
+
changedFileCount: 0,
|
|
222
|
+
};
|
|
223
|
+
for (const action of actions) {
|
|
224
|
+
const destPath = join(projectDir, action.relativePath);
|
|
225
|
+
if (action.op === "write") {
|
|
226
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
227
|
+
await writeFile(destPath, action.content ?? "", "utf-8");
|
|
228
|
+
summary.changedFileCount++;
|
|
229
|
+
}
|
|
230
|
+
else if (action.op === "delete") {
|
|
231
|
+
await unlink(destPath).catch(() => { });
|
|
232
|
+
summary.changedFileCount++;
|
|
233
|
+
}
|
|
234
|
+
switch (action.outcome) {
|
|
235
|
+
case "updated":
|
|
236
|
+
summary.updated.push(action.relativePath);
|
|
237
|
+
break;
|
|
238
|
+
case "merged":
|
|
239
|
+
summary.merged.push(action.relativePath);
|
|
240
|
+
break;
|
|
241
|
+
case "conflict":
|
|
242
|
+
summary.conflicts.push(action.relativePath);
|
|
243
|
+
break;
|
|
244
|
+
case "kept-edited":
|
|
245
|
+
summary.keptEdited.push(action.relativePath);
|
|
246
|
+
break;
|
|
247
|
+
case "kept-deleted":
|
|
248
|
+
summary.keptDeleted.push(action.relativePath);
|
|
249
|
+
break;
|
|
250
|
+
case "removed":
|
|
251
|
+
if (action.op === "delete") {
|
|
252
|
+
summary.deleted.push(action.relativePath);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
case "kept-warn":
|
|
256
|
+
summary.warnings.push(action.relativePath);
|
|
257
|
+
break;
|
|
258
|
+
case "redeployed":
|
|
259
|
+
summary.redeployed.push(action.relativePath);
|
|
260
|
+
break;
|
|
261
|
+
case "redeployed-warn":
|
|
262
|
+
summary.redeployedWarn.push(action.relativePath);
|
|
263
|
+
break;
|
|
264
|
+
case "skipped-edited":
|
|
265
|
+
summary.skippedEdited.push(action.relativePath);
|
|
266
|
+
break;
|
|
267
|
+
case "added":
|
|
268
|
+
summary.added.push(action.relativePath);
|
|
269
|
+
break;
|
|
270
|
+
case "adopted":
|
|
271
|
+
summary.adopted.push(action.relativePath);
|
|
272
|
+
break;
|
|
273
|
+
case "up-to-date":
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return summary;
|
|
278
|
+
};
|
|
279
|
+
export const buildUpdatedRecords = (oldEntries, actions) => {
|
|
280
|
+
const map = new Map(oldEntries.map((e) => [e.filePath, e]));
|
|
281
|
+
for (const action of actions) {
|
|
282
|
+
if (action.record === "keep")
|
|
283
|
+
continue;
|
|
284
|
+
if (action.record === "remove") {
|
|
285
|
+
map.delete(action.relativePath);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
map.set(action.relativePath, action.record);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const hashEntries = [...map.values()].sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
292
|
+
const deployedAssets = {};
|
|
293
|
+
for (const entry of hashEntries) {
|
|
294
|
+
deployedAssets[entry.filePath] = entry.version;
|
|
295
|
+
}
|
|
296
|
+
return { hashEntries, deployedAssets };
|
|
297
|
+
};
|
package/dist/asset/walker.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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
|
|
8
|
+
export declare const walkAssetDir: (tree: AssetTree, context: EvalContext) => Promise<AssetEntry[]>;
|
|
9
|
+
export declare const walkAssetRepo: (tree: AssetTree, targetSemver: string, context: EvalContext) => Promise<AssetEntry[]>;
|