@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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { access, chmod, mkdir, readdir, readFile, writeFile, } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import git from "isomorphic-git";
|
|
6
|
+
import * as p from "@clack/prompts";
|
|
7
|
+
import { createFsAssetTree } from "../asset/asset-tree.js";
|
|
8
|
+
import { walkAssetDir } from "../asset/walker.js";
|
|
9
|
+
import { emptyEvalContext } from "../core/eval-context.js";
|
|
10
|
+
import { getMessage } from "../i18n/index.js";
|
|
11
|
+
import { detectLocale } from "./locale-detect.js";
|
|
12
|
+
import { readSettingsSafe } from "./settings-io.js";
|
|
13
|
+
const MANAGED_MARKER = "@accel-cli-managed";
|
|
14
|
+
const HOOKS_PATH = ".githooks";
|
|
15
|
+
const HOOK_FILE_REL = ".githooks/pre-commit";
|
|
16
|
+
const ASSETS_GITHOOKS_ROOT = fileURLToPath(new URL("../../assets/githooks", import.meta.url));
|
|
17
|
+
const readFileSafe = async (filePath) => {
|
|
18
|
+
try {
|
|
19
|
+
return await readFile(filePath, "utf-8");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const listForeignFiles = async (hooksDir) => {
|
|
26
|
+
const foreign = [];
|
|
27
|
+
for (const entry of await readdir(hooksDir, { withFileTypes: true })) {
|
|
28
|
+
if (!entry.isFile()) {
|
|
29
|
+
foreign.push(entry.name);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const content = await readFileSafe(join(hooksDir, entry.name));
|
|
33
|
+
if (content === null || !content.includes(MANAGED_MARKER)) {
|
|
34
|
+
foreign.push(entry.name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return foreign;
|
|
38
|
+
};
|
|
39
|
+
export const syncGitHooks = async (projectDir) => {
|
|
40
|
+
const settings = await readSettingsSafe(projectDir);
|
|
41
|
+
if (settings?.gitHooks === false)
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
await access(join(projectDir, ".git"));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const locale = settings?.locale ?? detectLocale();
|
|
50
|
+
const tree = createFsAssetTree(ASSETS_GITHOOKS_ROOT);
|
|
51
|
+
const entries = await walkAssetDir(tree, emptyEvalContext({ locale }));
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const destPath = join(projectDir, entry.relativePath);
|
|
54
|
+
const existing = await readFileSafe(destPath);
|
|
55
|
+
if (existing !== null && !existing.includes(MANAGED_MARKER)) {
|
|
56
|
+
p.log.warning(getMessage("warning.gitHooksUserFile", locale, {
|
|
57
|
+
path: entry.relativePath,
|
|
58
|
+
}));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const content = (await tree.readFile(entry.sourceRelPath)).replace(/\r\n/g, "\n");
|
|
62
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
63
|
+
await writeFile(destPath, content, "utf-8");
|
|
64
|
+
if (entry.relativePath === HOOK_FILE_REL) {
|
|
65
|
+
await chmod(destPath, 0o755);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const current = (await git.getConfig({
|
|
69
|
+
fs,
|
|
70
|
+
dir: projectDir,
|
|
71
|
+
path: "core.hooksPath",
|
|
72
|
+
}));
|
|
73
|
+
if (current === undefined) {
|
|
74
|
+
const foreign = await listForeignFiles(join(projectDir, HOOKS_PATH));
|
|
75
|
+
if (foreign.length > 0) {
|
|
76
|
+
p.log.warning(getMessage("warning.gitHooksForeignFiles", locale, {
|
|
77
|
+
files: foreign.join(", "),
|
|
78
|
+
}));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
await git.setConfig({
|
|
82
|
+
fs,
|
|
83
|
+
dir: projectDir,
|
|
84
|
+
path: "core.hooksPath",
|
|
85
|
+
value: HOOKS_PATH,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else if (current !== HOOKS_PATH) {
|
|
89
|
+
p.log.warning(getMessage("warning.gitHooksPathConflict", locale, { current }));
|
|
90
|
+
}
|
|
91
|
+
};
|
package/dist/utils/mcp-sync.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFile, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
4
4
|
import { persistCredentials } from "./credentials.js";
|
|
5
|
+
import { syncGitHooks } from "./githooks-sync.js";
|
|
5
6
|
import { readSettingsSafe } from "./settings-io.js";
|
|
6
7
|
const AUTHORIZATION_HEADER = "Authorization";
|
|
7
8
|
export const matchesEndpoint = (url, endpoint) => {
|
|
@@ -94,4 +95,9 @@ export const persistCredentialsAndSyncMcp = async (projectDir, creds) => {
|
|
|
94
95
|
}
|
|
95
96
|
catch {
|
|
96
97
|
}
|
|
98
|
+
try {
|
|
99
|
+
await syncGitHooks(projectDir);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
}
|
|
97
103
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { diff3Merge } from "node-diff3";
|
|
2
|
+
export const mergeFile = async (base, ours, theirs) => {
|
|
3
|
+
const regions = diff3Merge(ours.split("\n"), base.split("\n"), theirs.split("\n"), {
|
|
4
|
+
excludeFalseConflicts: true,
|
|
5
|
+
stringSeparator: "\n",
|
|
6
|
+
});
|
|
7
|
+
let conflicted = false;
|
|
8
|
+
const lines = [];
|
|
9
|
+
for (const region of regions) {
|
|
10
|
+
if (region.ok) {
|
|
11
|
+
lines.push(...region.ok);
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (region.conflict) {
|
|
15
|
+
conflicted = true;
|
|
16
|
+
lines.push("<<<<<<< ours", ...region.conflict.a, "=======", ...region.conflict.b, ">>>>>>> theirs");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { content: lines.join("\n"), conflicted };
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intra-mart/accel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-dev.202607170346",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI tool for intra-mart Accel Platform development",
|
|
6
6
|
"author": "NTT DATA INTRAMART",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"accel": "./dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"assets"
|
|
23
24
|
],
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=24.0.0"
|
|
@@ -34,22 +35,20 @@
|
|
|
34
35
|
"test:unit": "vitest run tests/unit",
|
|
35
36
|
"test:e2e": "vitest run tests/e2e",
|
|
36
37
|
"test:watch": "vitest",
|
|
37
|
-
"typecheck": "tsc --noEmit"
|
|
38
|
-
"prepublishOnly": "tsc"
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@clack/prompts": "^1.4.0",
|
|
42
42
|
"@intra-mart/catalog": "0.1.0-dev.202606250213",
|
|
43
43
|
"citty": "^0.1.6",
|
|
44
44
|
"fast-xml-parser": "^5.2.0",
|
|
45
|
-
"
|
|
45
|
+
"isomorphic-git": "^1.38.6",
|
|
46
|
+
"node-diff3": "^3.2.1",
|
|
46
47
|
"remark-parse": "^11.0.0",
|
|
47
|
-
"remark-stringify": "^11.0.0",
|
|
48
48
|
"semver": "^7.7.1",
|
|
49
49
|
"smol-toml": "^1.6.1",
|
|
50
|
-
"
|
|
51
|
-
"unified": "^11.0.5"
|
|
52
|
-
"unist-util-visit": "^5.0.0"
|
|
50
|
+
"undici": "^8.5.0",
|
|
51
|
+
"unified": "^11.0.5"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
54
|
"@types/node": "^24",
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { mkdir, rm, readdir } from "node:fs/promises";
|
|
3
|
-
import { extractTarGz, createTempDir } from "../utils/archive.js";
|
|
4
|
-
import { downloadFile } from "../utils/https.js";
|
|
5
|
-
export const createGitHubAssetProvider = (repoUrl, ref) => {
|
|
6
|
-
let tmpDir = null;
|
|
7
|
-
return {
|
|
8
|
-
fetch: async () => {
|
|
9
|
-
tmpDir = await createTempDir("accel-assets-");
|
|
10
|
-
const archivePath = join(tmpDir, "assets.tar.gz");
|
|
11
|
-
const extractDir = join(tmpDir, "repo");
|
|
12
|
-
await mkdir(extractDir, { recursive: true });
|
|
13
|
-
const base = repoUrl.replace(/\/+$/, "");
|
|
14
|
-
const archiveUrl = `${base}/archive/${ref}.tar.gz`;
|
|
15
|
-
try {
|
|
16
|
-
await downloadFile(archiveUrl, archivePath);
|
|
17
|
-
}
|
|
18
|
-
catch (err) {
|
|
19
|
-
const reason = err instanceof Error ? err.message : String(err);
|
|
20
|
-
throw new Error(`Failed to fetch the asset repository from ${archiveUrl}. Check the URL and ref: ${reason}`);
|
|
21
|
-
}
|
|
22
|
-
await extractTarGz(archivePath, extractDir);
|
|
23
|
-
const entries = await readdir(extractDir, { withFileTypes: true });
|
|
24
|
-
const dirs = entries.filter((e) => e.isDirectory());
|
|
25
|
-
if (dirs.length !== 1) {
|
|
26
|
-
throw new Error(`Unexpected tarball structure (top-level directory count: ${dirs.length}).`);
|
|
27
|
-
}
|
|
28
|
-
return join(extractDir, dirs[0].name);
|
|
29
|
-
},
|
|
30
|
-
cleanup: async () => {
|
|
31
|
-
if (tmpDir) {
|
|
32
|
-
await rm(tmpDir, { recursive: true, force: true }).catch(() => { });
|
|
33
|
-
tmpDir = null;
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { mkdir, rm } from "node:fs/promises";
|
|
3
|
-
import { extractTarGz, createTempDir } from "../utils/archive.js";
|
|
4
|
-
import { downloadFile } from "../utils/https.js";
|
|
5
|
-
export const createLocalAssetProvider = (serverUrl) => {
|
|
6
|
-
let tmpDir = null;
|
|
7
|
-
return {
|
|
8
|
-
fetch: async () => {
|
|
9
|
-
tmpDir = await createTempDir("accel-assets-");
|
|
10
|
-
const archivePath = join(tmpDir, "assets.tar.gz");
|
|
11
|
-
const extractDir = join(tmpDir, "repo");
|
|
12
|
-
await mkdir(extractDir, { recursive: true });
|
|
13
|
-
await downloadFile(`${serverUrl}/archive`, archivePath);
|
|
14
|
-
await extractTarGz(archivePath, extractDir);
|
|
15
|
-
return extractDir;
|
|
16
|
-
},
|
|
17
|
-
cleanup: async () => {
|
|
18
|
-
if (tmpDir) {
|
|
19
|
-
await rm(tmpDir, { recursive: true, force: true }).catch(() => { });
|
|
20
|
-
tmpDir = null;
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
package/dist/utils/archive.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const extractTarGz: (archivePath: string, destDir: string) => Promise<void>;
|
|
2
|
-
export declare const createTarGz: (sourceDir: string, destPath: string, entries?: string[]) => Promise<void>;
|
|
3
|
-
export declare const createTempDir: (prefix?: string) => Promise<string>;
|
package/dist/utils/archive.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { extract, create } from "tar";
|
|
2
|
-
import { mkdtemp } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
export const extractTarGz = async (archivePath, destDir) => {
|
|
6
|
-
await extract({
|
|
7
|
-
file: archivePath,
|
|
8
|
-
cwd: destDir,
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
export const createTarGz = async (sourceDir, destPath, entries) => {
|
|
12
|
-
await create({
|
|
13
|
-
gzip: true,
|
|
14
|
-
file: destPath,
|
|
15
|
-
cwd: sourceDir,
|
|
16
|
-
}, entries ?? ["."]);
|
|
17
|
-
};
|
|
18
|
-
export const createTempDir = async (prefix = "accel-") => {
|
|
19
|
-
return mkdtemp(join(tmpdir(), prefix));
|
|
20
|
-
};
|
package/dist/utils/https.d.ts
DELETED
package/dist/utils/https.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { get as httpGet } from "node:http";
|
|
2
|
-
import { get as httpsGet } from "node:https";
|
|
3
|
-
import { createWriteStream } from "node:fs";
|
|
4
|
-
const MAX_REDIRECTS = 5;
|
|
5
|
-
export const isInsecureRedirect = (from, location) => {
|
|
6
|
-
if (!from.startsWith("https:"))
|
|
7
|
-
return false;
|
|
8
|
-
return new URL(location, from).protocol === "http:";
|
|
9
|
-
};
|
|
10
|
-
export const downloadFile = (url, destPath, redirectsLeft = MAX_REDIRECTS) => {
|
|
11
|
-
const requester = url.startsWith("http:") ? httpGet : httpsGet;
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
requester(url, (response) => {
|
|
14
|
-
const status = response.statusCode ?? 0;
|
|
15
|
-
const location = response.headers.location;
|
|
16
|
-
if (status >= 300 && status < 400 && location) {
|
|
17
|
-
response.resume();
|
|
18
|
-
if (redirectsLeft <= 0) {
|
|
19
|
-
reject(new Error(`Too many redirects when downloading from ${url}`));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (isInsecureRedirect(url, location)) {
|
|
23
|
-
reject(new Error(`Refusing insecure https→http redirect from ${url} to ${location}`));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const nextUrl = new URL(location, url).toString();
|
|
27
|
-
downloadFile(nextUrl, destPath, redirectsLeft - 1).then(resolve, reject);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (status !== 200) {
|
|
31
|
-
response.resume();
|
|
32
|
-
reject(new Error(`HTTP ${status} when downloading from ${url}`));
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const file = createWriteStream(destPath);
|
|
36
|
-
response.pipe(file);
|
|
37
|
-
file.on("finish", () => file.close(() => resolve()));
|
|
38
|
-
file.on("error", (err) => {
|
|
39
|
-
file.close();
|
|
40
|
-
reject(err);
|
|
41
|
-
});
|
|
42
|
-
}).on("error", reject);
|
|
43
|
-
});
|
|
44
|
-
};
|