@intra-mart/accel 0.3.0 → 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 +50 -7
- package/dist/i18n/ja.js +50 -7
- package/dist/i18n/zh_CN.js +50 -7
- 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
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
intra-mart Accel Platform (iAP) 開発プロジェクトの作成・管理を行うCLIツール。
|
|
4
4
|
|
|
5
|
-
コーディングエージェント(Claude Code、Codex、GitHub Copilot)向けのスキルファイルやインストラクションなどの資材を、資材リポジトリから取得しプロジェクトに配備します。
|
|
6
|
-
|
|
7
5
|
## 必要環境
|
|
8
6
|
|
|
9
7
|
- 以下のいずれかのパッケージマネージャ(`--package-manager` で選択、デフォルト: Bun)
|
|
@@ -11,7 +9,6 @@ intra-mart Accel Platform (iAP) 開発プロジェクトの作成・管理を行
|
|
|
11
9
|
- [npm](https://www.npmjs.com/)
|
|
12
10
|
- [Yarn](https://classic.yarnpkg.com/) (classic v1)
|
|
13
11
|
- [pnpm](https://pnpm.io/)
|
|
14
|
-
- Git(`--no-git-init` を指定しない場合)
|
|
15
12
|
|
|
16
13
|
## インストール
|
|
17
14
|
|
|
@@ -70,8 +67,8 @@ accel init my-project \
|
|
|
70
67
|
| `--non-interactive` | boolean | 非対話モード(このモードでは `project-name` が必須) | `false` |
|
|
71
68
|
| `--no-git-init` | boolean | git initをスキップ | `false`(git initする) |
|
|
72
69
|
| `--skip-install` | boolean | 依存インストールをスキップ | `false` |
|
|
73
|
-
| `--asset-server-url` | string | 資材を取得する
|
|
74
|
-
| `--asset-ref` | string |
|
|
70
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ。デフォルトの取得先を上書き) | `https://github.com/accelplatform/skills` |
|
|
71
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグ | `experiment` |
|
|
75
72
|
|
|
76
73
|
### `accel attach`
|
|
77
74
|
|
|
@@ -111,8 +108,50 @@ accel attach --non-interactive --accelplatform-version 2026-spring
|
|
|
111
108
|
| `--overwrite` | boolean | 既存ファイルの上書き確認を行わず、全て上書きする | `false`(対話で確認 / 非対話ではスキップ) |
|
|
112
109
|
| `--non-interactive` | boolean | 非対話モード | `false` |
|
|
113
110
|
| `--skip-install` | boolean | 依存インストールをスキップ | `false` |
|
|
114
|
-
| `--asset-server-url` | string | 資材を取得する
|
|
115
|
-
| `--asset-ref` | string |
|
|
111
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ。デフォルトの取得先を上書き) | `https://github.com/accelplatform/skills` |
|
|
112
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグ | `experiment` |
|
|
113
|
+
|
|
114
|
+
### `accel update`
|
|
115
|
+
|
|
116
|
+
配備済みの資材を資材リポジトリの最新版へ更新します。
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
cd my-project
|
|
120
|
+
accel update
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- ユーザーが編集したファイルの内容は保持されます。編集箇所と資材の更新が重なった場合はコンフリクトマーカー(git と同じ `<<<<<<<` 形式)が挿入されるので、該当ファイルを手動で解決してください。コンフリクトの発生は正常終了扱いで、終了時に対象ファイルの一覧が表示されます。
|
|
124
|
+
- 対話モードでは、最初に**既存の設定を利用するか**を確認します(デフォルト: Yes)。利用する場合は各設定の再入力をスキップし、現在の設定(CLIオプションの指定があればその値で上書き)のまま更新に進みます。再入力を選んだ場合は、iAPバージョン・モジュール・機能・エージェントなどの設定を**現在値を初期値として**変更できます。
|
|
125
|
+
- 既存の設定に不正な値やカタログとの不整合がある場合は、対象の項目と理由を通知した上で再入力になります(確認はスキップ)。
|
|
126
|
+
- 非対話モードでは `init` と同じオプションで変更を指定でき、未指定の項目は現在の設定を維持します。
|
|
127
|
+
- IM-Juggling プロジェクトとの連携は、設定の再入力時に IM-Juggling プロジェクトのプロンプトを空にして確定するか、`--juggling-project ""`(空文字)を指定すると解除できます。
|
|
128
|
+
- `--asset-server-url` / `--asset-ref` で取得元のリポジトリ・ブランチを変更できます(リポジトリの移転やブランチ再編への追従)。変更した取得元は記録され、以降の update の既定になります。
|
|
129
|
+
- 配備時のコミットが取得できない場合(資材リポジトリの履歴書き換え等)も、ユーザー編集を失わないフォールバックモードで更新を続行できます。対話モードでは確認の上で続行し、非対話モードでは `--allow-missing-base` の指定時のみ続行します(対話モードでも同フラグ指定時は確認を省略します)。
|
|
130
|
+
- 未コミットの変更がある状態での実行は推奨しません(警告が表示されます)。update 前のコミットを推奨します。
|
|
131
|
+
|
|
132
|
+
#### 非対話モード
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
accel update --non-interactive
|
|
136
|
+
|
|
137
|
+
# モジュール構成も同時に変更する場合
|
|
138
|
+
accel update --non-interactive --module im_workflow,im_activiti
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### オプション一覧
|
|
142
|
+
|
|
143
|
+
`init` と同じ設定系オプション(`--accelplatform-version`, `--module`, `--feature`, `--agent`, `--locale`, `--name`, `--artifact-id`, `--group`, `--project-version`, `--description`, `--database`, `--javascript`, `--juggling-project`, `--package-manager`)を受け付けます。**未指定の項目は現在の設定を維持します。**
|
|
144
|
+
|
|
145
|
+
| オプション | 型 | 説明 | デフォルト |
|
|
146
|
+
|---|---|---|---|
|
|
147
|
+
| `--non-interactive` | boolean | 非対話モード | `false` |
|
|
148
|
+
| `--skip-install` | boolean | 更新後の install / build をスキップ | `false` |
|
|
149
|
+
| `--asset-server-url` | string | 資材を取得するgitリポジトリのURL(HTTP(S) のみ)を変更する。変更は記録され、以降の既定になる | 記録済みのURL |
|
|
150
|
+
| `--asset-ref` | string | 資材リポジトリから取得するブランチ/タグを変更する。変更は記録され、以降の既定になる | 記録済みのref |
|
|
151
|
+
| `--allow-missing-base` | boolean | 配備時のコミットが取得できない場合にフォールバックモードで続行する | `false` |
|
|
152
|
+
| `--keep-edited` | boolean | フォールバックモード時、編集済みファイルを保持してスキップする(コンフリクトマーカーを入れない)。`--allow-missing-base` とセットで指定 | `false` |
|
|
153
|
+
|
|
154
|
+
> **Note**: `update` は git ソース(既定の GitHub リポジトリ等)から配備されたプロジェクトでのみ利用できます。`--asset-source`(ローカルディレクトリ)から配備したプロジェクトや、旧バージョンのCLIで作成されたプロジェクトでは利用できません。
|
|
116
155
|
|
|
117
156
|
### `accel detach`
|
|
118
157
|
|
|
@@ -183,7 +222,8 @@ accel deploy
|
|
|
183
222
|
- `.accel/credentials.json` に値を保存/更新したタイミングで、プロジェクト内の MCP 設定ファイルにも API キーを自動反映します(詳細は後述「[MCP 設定の自動同期](#mcp-設定の自動同期)」)。非対話モードでは `credentials.json` を保存しないため MCP 同期も発生しません。
|
|
184
223
|
- 既存のステージング環境を一覧から選択します(ステージングは iAP 側で事前に作成しておく必要があります)。
|
|
185
224
|
- デプロイ対象の zip は、`.accel/settings.json` の `artifactId` と `projectVersion` から `<artifactId>-<projectVersion>.zip` を `./target/` 配下で特定し、見つかれば自動選択します。見つからない場合は `./target/` 配下の zip を一覧から選択します(単一なら自動選択)。
|
|
186
|
-
-
|
|
225
|
+
- ビルド成果物とは別に管理している共通の imm など、**追加のアーカイブファイル**(`.imm` / `.zip`)を `--additional-file` で複数指定できます。複数ファイルは送信順に展開され、同一パスのエントリは後勝ちで上書きされます。デフォルトの順番は「`--additional-file` の指定順 → ビルド成果物(最後)」で、`--additional-file` を指定した場合はデプロイ前に順番の確認・変更ができます。
|
|
226
|
+
- いずれの場合もデプロイ実行前に、デプロイするファイルの一覧(送信順)を含む最終確認を行います。
|
|
187
227
|
- デプロイ成功後、ステージング詳細画面への自動ログイン付きURL(有効期限60分)が iAP から返ってきた場合は、結果と共に表示します。
|
|
188
228
|
- デプロイ成功後、iAP からテナント環境セットアップ設定が返ってきた場合は、対話的にテナント環境セットアップの実行を提案します:
|
|
189
229
|
1. セットアップ設定の情報を表示
|
|
@@ -205,6 +245,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
205
245
|
--endpoint https://example.com/imart \
|
|
206
246
|
--staging-id my-staging \
|
|
207
247
|
--file ./target/my-app-1.0.0.zip \
|
|
248
|
+
--additional-file ./libs/common-master.imm \
|
|
208
249
|
--description "CI deploy"
|
|
209
250
|
```
|
|
210
251
|
|
|
@@ -214,6 +255,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
214
255
|
- デプロイ対象 zip:
|
|
215
256
|
- `--file` を指定した場合はそのパス(`./target/` 配下に限定しません)を使います。ファイルが存在しなければエラー終了します。
|
|
216
257
|
- `--file` 未指定の場合は対話モードと同じ自動特定(`<artifactId>-<projectVersion>.zip` 完全一致)を試みます。**自動特定できない場合**(settings 無し/完全一致無し/複数候補)は `--file` 指定が必要な旨を表示してエラー終了します。`./target/` に zip が 1 件も無い場合は、ビルド未実行の旨(`mvn package` 等の実行を促す)を表示してエラー終了します。
|
|
258
|
+
- `--additional-file` は任意です。指定した場合は各パスの存在・拡張子(`.imm` / `.zip`)・重複を検証し、違反があればエラー終了します。デプロイ順は「`--additional-file` の指定順 → ビルド成果物(最後)」で固定です(順番確認プロンプトは出しません)。
|
|
217
259
|
- `--description` は任意です。最終確認プロンプトは出さず、即デプロイします。
|
|
218
260
|
- **テナント環境セットアップは実行しません**(対話が必要なため)。自動ログイン付きURLはデプロイ結果に含めて表示します。
|
|
219
261
|
- フラグ/環境変数で渡した接続情報は **`.accel/credentials.json` に保存しません**(CIランナーにシークレット情報を残さないため)。
|
|
@@ -226,6 +268,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
226
268
|
| `--api-key` | string | OAuth Bearerトークン(**環境変数 `ACCEL_API_KEY` 推奨**) | 保存値 / 対話で入力 |
|
|
227
269
|
| `--staging-id` | string | デプロイ先ステージングID(**非対話モードでは必須**) | 対話で一覧選択 |
|
|
228
270
|
| `--file` | string | デプロイする zip のパス(`./target/` 配下に限定しない) | 自動特定 / 対話で選択 |
|
|
271
|
+
| `--additional-file` | string(複数指定可) | 追加でデプロイするアーカイブファイルのパス(`.imm` / `.zip`。指定順にビルド成果物より先に展開) | なし |
|
|
229
272
|
| `--description` | string | デプロイメントの説明 | `""` |
|
|
230
273
|
| `--non-interactive` | boolean | 非対話モード(プロンプトを出さず、失敗時は非0終了) | `false` |
|
|
231
274
|
|
|
@@ -262,7 +305,7 @@ ACCEL_API_KEY=*** accel deploy \
|
|
|
262
305
|
|
|
263
306
|
該当エントリの `Authorization` キーのみが上書きされます。同じヘッダテーブル内の他のキーは保持されます。
|
|
264
307
|
|
|
265
|
-
####
|
|
308
|
+
#### 同期タイミング
|
|
266
309
|
|
|
267
310
|
- `accel login`(対話・非対話の両方、検証成功時)
|
|
268
311
|
- `accel deploy`(対話モードでの初回入力時/再入力ループの成功時)
|
|
@@ -307,8 +350,8 @@ my-project/
|
|
|
307
350
|
└── .git/
|
|
308
351
|
```
|
|
309
352
|
|
|
310
|
-
- `.accel/settings.json` — プロジェクト設定。git
|
|
311
|
-
- `.accel/hashsum.txt` — 配備ファイルのハッシュ。`detach`
|
|
353
|
+
- `.accel/settings.json` — プロジェクト設定。git管理対象、手動編集可。資材リポジトリのURL・ref・配備時のコミットSHA(`assetSource`)を記録し、`accel update` が参照
|
|
354
|
+
- `.accel/hashsum.txt` — 配備ファイルのハッシュ。`update` / `detach` 時のユーザー編集検出に使用
|
|
312
355
|
- `.accel/credentials.json` — iAP接続情報(endpoint / APIキー)。`accel deploy` 初回実行時に生成。APIキーを含むため `.gitignore` 対象(git管理対象外)
|
|
313
356
|
|
|
314
357
|
`credentials.json` の保存/更新時には、エージェント別の MCP 設定ファイル(`.mcp.json` / `.codex/config.toml` / `.vscode/mcp.json` のうち、存在し、かつ `agents` に含まれるエージェントのもの)に対しても API キーが反映されます。詳細は「[MCP 設定の自動同期](#mcp-設定の自動同期)」を参照してください。
|
|
@@ -317,4 +360,4 @@ my-project/
|
|
|
317
360
|
|
|
318
361
|
選択可能なiAPバージョン・モジュール・機能は、同梱のマスタデータパッケージ `@intra-mart/catalog` のカタログに基づきます(2025 Spring / 8.0.37 以降)。バージョンは `2026-spring` のようなリリースID形式で指定します。新しいリリースへの対応はカタログの更新によって行われます。
|
|
319
362
|
|
|
320
|
-
CLI
|
|
363
|
+
CLIに渡された値および対話で入力された値はバリデーションされます。対話で入力した値が違反する場合は再入力を促し、CLIオプションで渡した値が違反する場合は(対話モードでも)エラーメッセージを表示して終了します。`--artifact-id` / `--group` / `--project-version` は Maven の命名規約に従う必要があります。
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { listFilesUnder } from "../utils/fs-list.js";
|
|
4
|
+
export const createFsAssetTree = (rootDir) => ({
|
|
5
|
+
listFiles: () => listFilesUnder(rootDir),
|
|
6
|
+
readFile: (relPath) => readFile(join(rootDir, relPath), "utf-8"),
|
|
7
|
+
});
|
package/dist/asset/deployer.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { AssetProvider, AccelSettings, HashsumEntry } from "../core/types.js";
|
|
2
|
+
export { getInstallCmds } from "./installer.js";
|
|
2
3
|
export type OverwriteDecision = "overwrite" | "skip";
|
|
3
4
|
export type ExistingFileHandler = (relativePath: string) => Promise<OverwriteDecision>;
|
|
4
5
|
export type ProgressCallbacks = {
|
|
5
6
|
onFetchStart?: () => void;
|
|
7
|
+
onDownloadStart?: () => void;
|
|
6
8
|
onSectionDeploy?: (section: string, files: string[]) => void;
|
|
7
9
|
onInstallStart?: (command: string) => void;
|
|
8
10
|
onBuildStart?: (command: string) => void;
|
|
@@ -22,6 +24,5 @@ export type DeployResult = {
|
|
|
22
24
|
skippedFiles: string[];
|
|
23
25
|
overwrittenFiles: string[];
|
|
24
26
|
};
|
|
25
|
-
export declare const getInstallCmds: (packageManager: string) => string[];
|
|
26
27
|
export declare const ROOT_SECTION = "(root)";
|
|
27
28
|
export declare const deployAssets: (options: DeployOptions) => Promise<DeployResult>;
|
package/dist/asset/deployer.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { writeFile, mkdir, stat } from "node:fs/promises";
|
|
2
2
|
import { join, dirname, resolve, sep } from "node:path";
|
|
3
3
|
import { buildEvalContext } from "../core/eval-context.js";
|
|
4
4
|
import { walkAssetRepo } from "./walker.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { applyForeachReplacements } from "./foreach-replacement.js";
|
|
5
|
+
import { renderAssetContent } from "./renderer.js";
|
|
6
|
+
import { runInstallBuild } from "./installer.js";
|
|
8
7
|
import { computeSha1 } from "../utils/hash.js";
|
|
9
8
|
import { writeSettings, writeHashsum } from "../utils/settings-io.js";
|
|
10
|
-
|
|
9
|
+
export { getInstallCmds } from "./installer.js";
|
|
11
10
|
const fileExists = async (path) => {
|
|
12
11
|
try {
|
|
13
12
|
await stat(path);
|
|
@@ -17,6 +16,10 @@ const fileExists = async (path) => {
|
|
|
17
16
|
return false;
|
|
18
17
|
}
|
|
19
18
|
};
|
|
19
|
+
const dirnamePosix = (p) => {
|
|
20
|
+
const idx = p.lastIndexOf("/");
|
|
21
|
+
return idx === -1 ? "" : p.slice(0, idx);
|
|
22
|
+
};
|
|
20
23
|
const isWithinDir = (parentDir, candidate) => {
|
|
21
24
|
const parent = resolve(parentDir);
|
|
22
25
|
const target = resolve(candidate);
|
|
@@ -25,19 +28,6 @@ const isWithinDir = (parentDir, candidate) => {
|
|
|
25
28
|
const prefix = parent.endsWith(sep) ? parent : parent + sep;
|
|
26
29
|
return target.startsWith(prefix);
|
|
27
30
|
};
|
|
28
|
-
export const getInstallCmds = (packageManager) => {
|
|
29
|
-
switch (packageManager) {
|
|
30
|
-
case "npm":
|
|
31
|
-
return ["npm ci", "npm run build"];
|
|
32
|
-
case "yarn":
|
|
33
|
-
return ["yarn install --frozen-lockfile", "yarn run build"];
|
|
34
|
-
case "pnpm":
|
|
35
|
-
return ["pnpm install --frozen-lockfile", "pnpm run build"];
|
|
36
|
-
case "bun":
|
|
37
|
-
default:
|
|
38
|
-
return ["bun ci", "bun run build"];
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
31
|
const collectReplacements = (entry) => {
|
|
42
32
|
if (!entry.meta?.replacements)
|
|
43
33
|
return [];
|
|
@@ -58,9 +48,28 @@ export const deployAssets = async (options) => {
|
|
|
58
48
|
try {
|
|
59
49
|
progress?.onFetchStart?.();
|
|
60
50
|
const repoDir = await provider.fetch();
|
|
51
|
+
const tree = {
|
|
52
|
+
listFiles: () => provider.listFiles(),
|
|
53
|
+
readFile: (relPath) => provider.readFile(relPath),
|
|
54
|
+
};
|
|
61
55
|
const semver = settings.accelplatformVersion.semver;
|
|
62
56
|
const context = buildEvalContext(settings);
|
|
63
|
-
const
|
|
57
|
+
const allEntries = await walkAssetRepo(tree, semver, context);
|
|
58
|
+
const entries = allEntries.filter((entry) => {
|
|
59
|
+
if (!isWithinDir(projectDir, join(projectDir, entry.relativePath))) {
|
|
60
|
+
console.warn(`Warning: skipping asset with path escaping project directory: ${entry.relativePath}`);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (!isWithinDir(repoDir, resolve(repoDir, entry.sourceRelPath))) {
|
|
64
|
+
console.warn(`Warning: skipping asset with source path escaping asset repo: ${entry.sourceRelPath}`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
progress?.onDownloadStart?.();
|
|
70
|
+
await provider.materialize([
|
|
71
|
+
...new Set(entries.map((e) => dirnamePosix(e.sourceRelPath))),
|
|
72
|
+
]);
|
|
64
73
|
const deployedFiles = [];
|
|
65
74
|
const hashEntries = [];
|
|
66
75
|
const deployedAssets = {};
|
|
@@ -80,14 +89,6 @@ export const deployAssets = async (options) => {
|
|
|
80
89
|
progress.onSectionDeploy(section, sectionFiles);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
|
-
if (!isWithinDir(projectDir, destPath)) {
|
|
84
|
-
console.warn(`Warning: skipping asset with path escaping project directory: ${targetPath}`);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (!isWithinDir(repoDir, entry.sourcePath)) {
|
|
88
|
-
console.warn(`Warning: skipping asset with source path escaping asset repo: ${entry.sourcePath}`);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
92
|
const exists = await fileExists(destPath);
|
|
92
93
|
if (exists) {
|
|
93
94
|
let decision = "overwrite";
|
|
@@ -103,23 +104,8 @@ export const deployAssets = async (options) => {
|
|
|
103
104
|
}
|
|
104
105
|
overwrittenFiles.push(targetPath);
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
if (replacements.length > 0) {
|
|
109
|
-
const foreachReplacements = replacements.filter((r) => r.type === "foreach");
|
|
110
|
-
if (foreachReplacements.length > 0) {
|
|
111
|
-
content = applyForeachReplacements(content, foreachReplacements, context);
|
|
112
|
-
}
|
|
113
|
-
if (targetPath.endsWith(".md")) {
|
|
114
|
-
content = processMarkdown(content, replacements, context);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const regexReplacements = replacements.filter((r) => r.type === "regex");
|
|
118
|
-
if (regexReplacements.length > 0) {
|
|
119
|
-
content = applyRegexReplacements(content, regexReplacements, context);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
107
|
+
const raw = await tree.readFile(entry.sourceRelPath);
|
|
108
|
+
const content = renderAssetContent(raw, targetPath, collectReplacements(entry), context);
|
|
123
109
|
await mkdir(dirname(destPath), { recursive: true });
|
|
124
110
|
await writeFile(destPath, content, "utf-8");
|
|
125
111
|
const sha1 = computeSha1(content);
|
|
@@ -130,26 +116,13 @@ export const deployAssets = async (options) => {
|
|
|
130
116
|
}
|
|
131
117
|
const updatedSettings = {
|
|
132
118
|
...settings,
|
|
119
|
+
assetSource: provider.sourceInfo(),
|
|
133
120
|
deployedAssets,
|
|
134
121
|
};
|
|
135
122
|
await writeSettings(projectDir, updatedSettings);
|
|
136
123
|
await writeHashsum(projectDir, hashEntries);
|
|
137
124
|
if (!noInstall) {
|
|
138
|
-
|
|
139
|
-
progress?.onInstallStart?.(installCmd);
|
|
140
|
-
try {
|
|
141
|
-
execSync(installCmd, { cwd: projectDir, stdio: "pipe" });
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
console.warn(`Warning: install command failed: ${installCmd} in ${projectDir}`);
|
|
145
|
-
}
|
|
146
|
-
progress?.onBuildStart?.(buildCmd);
|
|
147
|
-
try {
|
|
148
|
-
execSync(buildCmd, { cwd: projectDir, stdio: "pipe" });
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
console.warn(`Warning: build command failed: ${buildCmd} in ${projectDir}`);
|
|
152
|
-
}
|
|
125
|
+
runInstallBuild(projectDir, settings.packageManager, progress);
|
|
153
126
|
}
|
|
154
127
|
return { deployedFiles, hashEntries, skippedFiles, overwrittenFiles };
|
|
155
128
|
}
|
|
@@ -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: (dirs: 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,198 @@
|
|
|
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 prefetchedMetaDirs = new Map();
|
|
22
|
+
const withHint = (message, cause) => {
|
|
23
|
+
if (isGitAuthError(cause)) {
|
|
24
|
+
return `${message}\n${getMessage("error.gitAuthHint", locale)}`;
|
|
25
|
+
}
|
|
26
|
+
if (isGitServerUnsupportedError(cause)) {
|
|
27
|
+
return `${message}\n${getMessage("error.gitServerUnsupported", locale)}`;
|
|
28
|
+
}
|
|
29
|
+
return message;
|
|
30
|
+
};
|
|
31
|
+
const requireRepo = () => {
|
|
32
|
+
if (!store || !commit) {
|
|
33
|
+
throw new Error("GitAssetProvider used before fetch()");
|
|
34
|
+
}
|
|
35
|
+
return { store, commit };
|
|
36
|
+
};
|
|
37
|
+
const fetchMissingBlobs = async (oids) => {
|
|
38
|
+
const { store } = requireRepo();
|
|
39
|
+
const missing = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
for (const oid of oids) {
|
|
42
|
+
if (seen.has(oid))
|
|
43
|
+
continue;
|
|
44
|
+
seen.add(oid);
|
|
45
|
+
if (!(await store.hasObject(oid)))
|
|
46
|
+
missing.push(oid);
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < missing.length; i += MAX_WANTS_PER_REQUEST) {
|
|
49
|
+
const pack = await fetchPack(repoUrl, missing.slice(i, i + MAX_WANTS_PER_REQUEST));
|
|
50
|
+
await store.writePack(pack, `blobs-${packSeq++}`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const topDirOf = (relPath) => {
|
|
54
|
+
const slash = relPath.indexOf("/");
|
|
55
|
+
return slash === -1 ? "" : relPath.slice(0, slash);
|
|
56
|
+
};
|
|
57
|
+
const ensureMetasPrefetched = async (oid, topDir) => {
|
|
58
|
+
let dirs = prefetchedMetaDirs.get(oid);
|
|
59
|
+
if (!dirs) {
|
|
60
|
+
dirs = new Set();
|
|
61
|
+
prefetchedMetaDirs.set(oid, dirs);
|
|
62
|
+
}
|
|
63
|
+
if (dirs.has(topDir))
|
|
64
|
+
return;
|
|
65
|
+
const { store } = requireRepo();
|
|
66
|
+
const prefix = topDir === "" ? "" : `${topDir}/`;
|
|
67
|
+
const entries = await store.listBlobEntries(oid);
|
|
68
|
+
const metaOids = entries
|
|
69
|
+
.filter((e) => e.path.startsWith(prefix) &&
|
|
70
|
+
(e.path === `${prefix}${META_FILENAME}` ||
|
|
71
|
+
e.path.endsWith(`/${META_FILENAME}`)))
|
|
72
|
+
.map((e) => e.oid);
|
|
73
|
+
await fetchMissingBlobs(metaOids);
|
|
74
|
+
dirs.add(topDir);
|
|
75
|
+
};
|
|
76
|
+
const readFileAt = async (oid, relPath) => {
|
|
77
|
+
const { store } = requireRepo();
|
|
78
|
+
try {
|
|
79
|
+
return await store.readBlobAtPath(oid, relPath);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (!isGitObjectMissingError(err))
|
|
83
|
+
throw err;
|
|
84
|
+
if (relPath === META_FILENAME || relPath.endsWith(`/${META_FILENAME}`)) {
|
|
85
|
+
await ensureMetasPrefetched(oid, topDirOf(relPath));
|
|
86
|
+
return store.readBlobAtPath(oid, relPath);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`File content is not materialized (materialize() must be called first): ${relPath}`);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const materializeAt = async (oid, dirs) => {
|
|
92
|
+
if (dirs.length === 0)
|
|
93
|
+
return;
|
|
94
|
+
const { store } = requireRepo();
|
|
95
|
+
const prefixes = [
|
|
96
|
+
...new Set(dirs.map((d) => (d === "" || d === "." ? "" : `${d}/`))),
|
|
97
|
+
];
|
|
98
|
+
const entries = await store.listBlobEntries(oid);
|
|
99
|
+
const targets = entries
|
|
100
|
+
.filter((e) => prefixes.some((p) => e.path.startsWith(p)))
|
|
101
|
+
.map((e) => e.oid);
|
|
102
|
+
await fetchMissingBlobs(targets);
|
|
103
|
+
};
|
|
104
|
+
const listFilesAt = async (oid) => {
|
|
105
|
+
const { store } = requireRepo();
|
|
106
|
+
return (await store.listBlobEntries(oid)).map((e) => e.path);
|
|
107
|
+
};
|
|
108
|
+
const fetchTreesFor = async (oid, label) => {
|
|
109
|
+
const { store } = requireRepo();
|
|
110
|
+
const pack = await fetchPack(repoUrl, [oid], {
|
|
111
|
+
deepenOne: true,
|
|
112
|
+
filterBlobNone: true,
|
|
113
|
+
});
|
|
114
|
+
await store.writePack(pack, label);
|
|
115
|
+
const entries = await store.listBlobEntries(oid);
|
|
116
|
+
const rootMetaOids = entries
|
|
117
|
+
.filter((e) => {
|
|
118
|
+
const parts = e.path.split("/");
|
|
119
|
+
return ((parts.length === 1 && parts[0] === META_FILENAME) ||
|
|
120
|
+
(parts.length === 2 && parts[1] === META_FILENAME));
|
|
121
|
+
})
|
|
122
|
+
.map((e) => e.oid);
|
|
123
|
+
await fetchMissingBlobs(rootMetaOids);
|
|
124
|
+
};
|
|
125
|
+
const commitTreeOf = (oid) => ({
|
|
126
|
+
listFiles: () => listFilesAt(oid),
|
|
127
|
+
readFile: (relPath) => readFileAt(oid, relPath),
|
|
128
|
+
materialize: (dirs) => materializeAt(oid, dirs),
|
|
129
|
+
});
|
|
130
|
+
const provider = {
|
|
131
|
+
fetch: async () => {
|
|
132
|
+
if (!isHttpUrl(repoUrl)) {
|
|
133
|
+
throw new Error(getMessage("error.gitUrlUnsupported", locale, { url: repoUrl }));
|
|
134
|
+
}
|
|
135
|
+
store = await createObjectStore();
|
|
136
|
+
try {
|
|
137
|
+
const caps = await fetchCapabilities(repoUrl);
|
|
138
|
+
assertServerSupported(repoUrl, caps);
|
|
139
|
+
const resolved = await resolveRef(repoUrl, ref);
|
|
140
|
+
if (!resolved) {
|
|
141
|
+
throw new Error(`ref not found on server: ${ref}`);
|
|
142
|
+
}
|
|
143
|
+
commit = resolved.oid;
|
|
144
|
+
await fetchTreesFor(commit, "trees-head");
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
148
|
+
throw new Error(withHint(`Failed to fetch the asset repository from ${repoUrl} (ref: ${ref}). Check the URL and ref: ${reason}`, err));
|
|
149
|
+
}
|
|
150
|
+
return store.dir;
|
|
151
|
+
},
|
|
152
|
+
listFiles: () => {
|
|
153
|
+
const { commit: oid } = requireRepo();
|
|
154
|
+
return listFilesAt(oid);
|
|
155
|
+
},
|
|
156
|
+
readFile: (relPath) => {
|
|
157
|
+
const { commit: oid } = requireRepo();
|
|
158
|
+
return readFileAt(oid, relPath);
|
|
159
|
+
},
|
|
160
|
+
materialize: (dirs) => {
|
|
161
|
+
const { commit: oid } = requireRepo();
|
|
162
|
+
return materializeAt(oid, dirs);
|
|
163
|
+
},
|
|
164
|
+
cleanup: async () => {
|
|
165
|
+
if (store) {
|
|
166
|
+
await store.cleanup();
|
|
167
|
+
store = null;
|
|
168
|
+
commit = null;
|
|
169
|
+
prefetchedMetaDirs.clear();
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
sourceInfo: () => ({
|
|
173
|
+
type: "git",
|
|
174
|
+
url: repoUrl,
|
|
175
|
+
ref,
|
|
176
|
+
commit,
|
|
177
|
+
}),
|
|
178
|
+
asTree: () => {
|
|
179
|
+
const { commit: oid } = requireRepo();
|
|
180
|
+
return commitTreeOf(oid);
|
|
181
|
+
},
|
|
182
|
+
openCommit: async (sha) => {
|
|
183
|
+
requireRepo();
|
|
184
|
+
if (!isValidOid(sha)) {
|
|
185
|
+
throw new Error(`Invalid commit SHA recorded in settings: ${JSON.stringify(sha)}`);
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
await fetchTreesFor(sha, `trees-${sha.slice(0, 7)}`);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
192
|
+
throw new Error(withHint(`Failed to fetch commit ${sha} from ${repoUrl} (history may have been rewritten): ${reason}`, err));
|
|
193
|
+
}
|
|
194
|
+
return commitTreeOf(sha);
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
return provider;
|
|
198
|
+
};
|
|
@@ -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";
|