@kubohiroya/sb3-toolchain 0.20.0 → 0.22.0
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/CHANGELOG.md +9 -0
- package/README.ja.md +15 -1
- package/README.md +15 -1
- package/dist/clean-up-sb3.d.ts +14 -0
- package/dist/clean-up-sb3.js +63 -0
- package/dist/clean-up-sb3.js.map +1 -0
- package/dist/cli.d.ts +14 -2
- package/dist/cli.js +80 -1
- package/dist/cli.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/extension-digest-inventory.d.ts +104 -0
- package/dist/extension-digest-inventory.js +319 -0
- package/dist/extension-digest-inventory.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -1
- package/dist/turbowarp-clean-up.d.ts +3 -1
- package/dist/turbowarp-clean-up.js +149 -37
- package/dist/turbowarp-clean-up.js.map +1 -1
- package/docs/extension-digests.md +83 -0
- package/docs/index.html +10 -2
- package/docs/ja/extension-digests.md +81 -0
- package/docs/ja/workflows.md +17 -0
- package/docs/workflows.md +20 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.22.0 - 2026-11-08
|
|
4
|
+
|
|
5
|
+
- feat(release): sync version references in a release:prepare script (#85)
|
|
6
|
+
- feat(sb3): 既存の SB3 のブロック配置を整理する (#82)
|
|
7
|
+
|
|
8
|
+
## 0.21.0 - 2026-11-07
|
|
9
|
+
|
|
10
|
+
- SB3 の検査で、機能拡張のダイジェストと保持形式を確認できるようにした(#79)。
|
|
11
|
+
|
|
3
12
|
## 0.20.0 - 2026-10-29
|
|
4
13
|
|
|
5
14
|
- Kamishibai作品SB3のRuntimeバンドルとBlock Scriptを一括更新する `extensions replace-sb3` とJavaScript APIを追加。
|
package/README.ja.md
CHANGED
|
@@ -14,9 +14,12 @@ Scratch 3およびTurboWarpの`.sb3`プロジェクトを、Gitで差分を確
|
|
|
14
14
|
- 埋め込みJavaScriptを置き換える前に、バージョン付き機能拡張APIマニフェストを任意で比較
|
|
15
15
|
- 元のJavaScriptを削除せず、複数の機能拡張を1つの権限単位へ静的にbundleし、展開ソースまたは
|
|
16
16
|
bundle済みSB3から復元
|
|
17
|
+
- 各機能拡張の固定SHA-256、保持形式、保持バイト数、作品のURI、および複数の作品が共有するdigestを、
|
|
18
|
+
ブラウザーの保存状態を読まず、何も取得せずに出力
|
|
17
19
|
- ZIPエントリ順、タイムスタンプ、圧縮設定を固定した決定的ビルド
|
|
18
20
|
- 展開済みbase sourceを変更せず、JSON/YAML build manifestからsprite、backdrop、costume、soundを追加
|
|
19
21
|
- 全ターゲットのスクリプトをTurboWarp風の決定的な「きれいにする」配置へ任意で整理
|
|
22
|
+
- `clean-up` で既存の SB3 内のスクリプトを整理し、別ファイルに保存
|
|
20
23
|
- import時に未コミットのGit変更を保護
|
|
21
24
|
- トランザクションによる置換とロールバックで既存出力を保護
|
|
22
25
|
- CLIとJavaScript APIの両方を提供
|
|
@@ -31,7 +34,7 @@ Scratch 3およびTurboWarpの`.sb3`プロジェクトを、Gitで差分を確
|
|
|
31
34
|
再現可能なインストールのため、検証済みのnpmバージョンを固定します。
|
|
32
35
|
|
|
33
36
|
```bash
|
|
34
|
-
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.
|
|
37
|
+
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.22.0
|
|
35
38
|
```
|
|
36
39
|
|
|
37
40
|
## クイックスタート
|
|
@@ -53,6 +56,13 @@ sb3-toolchain extensions replace-sb3 input.sb3 --output updated.sb3
|
|
|
53
56
|
|
|
54
57
|
提供元の指定方法、保持するデータ、検証と制限は[SB3の機能拡張更新](docs/ja/sb3-extension-replacement.md)を参照してください。
|
|
55
58
|
|
|
59
|
+
ブラウザーの機能拡張キャッシュと照合するため、手元のSB3が機能拡張について述べていることを一覧します。
|
|
60
|
+
何も取得せず、ブラウザーの保存状態も読みません。
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
sb3-toolchain extensions digests one.sb3 two.sb3
|
|
64
|
+
```
|
|
65
|
+
|
|
56
66
|
プロジェクトリポジトリに推奨する信頼できる唯一の情報源、再import、置換保護、機能拡張更新、CIの
|
|
57
67
|
ワークフローについては、[`docs/ja/workflows.md`](docs/ja/workflows.md)を参照してください。
|
|
58
68
|
|
|
@@ -68,6 +78,7 @@ import {
|
|
|
68
78
|
extensionIntegrity,
|
|
69
79
|
extensionStatus,
|
|
70
80
|
importSb3,
|
|
81
|
+
inventoryExtensionDigests,
|
|
71
82
|
migrateExtensionId,
|
|
72
83
|
planExtensionIdMigration,
|
|
73
84
|
syncExtensions,
|
|
@@ -96,6 +107,8 @@ const {archive} = await createDeterministicSb3('app', {cleanUpBlocks: true});
|
|
|
96
107
|
const integrity = extensionIntegrity(await readFile('app/extensions/example.js'));
|
|
97
108
|
|
|
98
109
|
const statuses = await extensionStatus('app');
|
|
110
|
+
// 読み取り専用です。SB3中のURLにはアクセスせず、ブラウザーの保存状態も読みません。
|
|
111
|
+
const inventory = await inventoryExtensionDigests(['dist/project.sb3']);
|
|
99
112
|
const migration = await planExtensionIdMigration({
|
|
100
113
|
sourceDirectory: 'app',
|
|
101
114
|
fromId: 'oldId',
|
|
@@ -146,6 +159,7 @@ await unbundleSb3({
|
|
|
146
159
|
- [`docs/ja/extension-id-migration.md`](docs/ja/extension-id-migration.md): プロジェクトで使用中の機能拡張IDの移行
|
|
147
160
|
- [`docs/ja/extension-api-compatibility.md`](docs/ja/extension-api-compatibility.md): 機能拡張更新時の任意の静的API互換性検査
|
|
148
161
|
- [`docs/ja/extension-bundles.md`](docs/ja/extension-bundles.md): 静的bundle、共有依存を持つ明示選択のmodule統合ビルド、可逆的なunbundle
|
|
162
|
+
- [`docs/ja/extension-digests.md`](docs/ja/extension-digests.md): 機能拡張のdigest、4つの保持形式、作品のURI、共有されるdigest
|
|
149
163
|
|
|
150
164
|
## 開発
|
|
151
165
|
|
package/README.md
CHANGED
|
@@ -14,10 +14,13 @@ expanded sources and rebuilding bit-for-bit identical SB3 files from the same in
|
|
|
14
14
|
- Optionally compare versioned extension API manifests before replacing embedded JavaScript
|
|
15
15
|
- Statically bundle multiple extensions into one permission unit without deleting their original
|
|
16
16
|
JavaScript, then restore them from either the expanded source or the bundled SB3
|
|
17
|
+
- Report every extension's pinned SHA-256, retention form, held size, and the project URI, and
|
|
18
|
+
which digests several projects share, without reading browser storage or fetching anything
|
|
17
19
|
- Produce deterministic builds with fixed ZIP entry order, timestamps, and compression settings
|
|
18
20
|
- Add sprites, backdrops, costumes, and sounds from an optional JSON or YAML build manifest without
|
|
19
21
|
modifying the expanded base source
|
|
20
22
|
- Optionally lay out every target's scripts in a deterministic TurboWarp-style cleaned arrangement
|
|
23
|
+
- Rearrange scripts in an existing SB3 and save a separate copy with `clean-up`
|
|
21
24
|
- Protect uncommitted Git changes when importing
|
|
22
25
|
- Protect existing output through transactional replacement and rollback
|
|
23
26
|
- Provide both a CLI and a JavaScript API
|
|
@@ -32,7 +35,7 @@ expanded sources and rebuilding bit-for-bit identical SB3 files from the same in
|
|
|
32
35
|
Pin the verified npm version for reproducible installation.
|
|
33
36
|
|
|
34
37
|
```bash
|
|
35
|
-
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.
|
|
38
|
+
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.22.0
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
## Quick start
|
|
@@ -55,6 +58,13 @@ sb3-toolchain extensions replace-sb3 input.sb3 --output updated.sb3
|
|
|
55
58
|
See the [replacement guide (Japanese)](docs/ja/sb3-extension-replacement.md) for local donors,
|
|
56
59
|
preserved story data, validation, and limits.
|
|
57
60
|
|
|
61
|
+
List what the SB3s on hand say about their extensions, to compare a browser's extension cache
|
|
62
|
+
against. Nothing is fetched, and no browser storage is read.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
sb3-toolchain extensions digests one.sb3 two.sb3
|
|
66
|
+
```
|
|
67
|
+
|
|
58
68
|
See [`docs/workflows.md`](docs/workflows.md) for the recommended source-of-truth, re-import,
|
|
59
69
|
replacement protection, extension update, and CI workflows for a project repository.
|
|
60
70
|
|
|
@@ -70,6 +80,7 @@ import {
|
|
|
70
80
|
extensionIntegrity,
|
|
71
81
|
extensionStatus,
|
|
72
82
|
importSb3,
|
|
83
|
+
inventoryExtensionDigests,
|
|
73
84
|
migrateExtensionId,
|
|
74
85
|
planExtensionIdMigration,
|
|
75
86
|
syncExtensions,
|
|
@@ -98,6 +109,8 @@ const {archive} = await createDeterministicSb3('app', {cleanUpBlocks: true});
|
|
|
98
109
|
const integrity = extensionIntegrity(await readFile('app/extensions/example.js'));
|
|
99
110
|
|
|
100
111
|
const statuses = await extensionStatus('app');
|
|
112
|
+
// Read-only: no URL in an SB3 is contacted and no browser storage is read.
|
|
113
|
+
const inventory = await inventoryExtensionDigests(['dist/project.sb3']);
|
|
101
114
|
const migration = await planExtensionIdMigration({
|
|
102
115
|
sourceDirectory: 'app',
|
|
103
116
|
fromId: 'oldId',
|
|
@@ -150,6 +163,7 @@ await unbundleSb3({
|
|
|
150
163
|
- [`docs/extension-id-migration.md`](docs/extension-id-migration.md): migration of extension IDs already used by a project
|
|
151
164
|
- [`docs/extension-api-compatibility.md`](docs/extension-api-compatibility.md) ([日本語](docs/ja/extension-api-compatibility.md)): opt-in static API compatibility checks for extension updates
|
|
152
165
|
- [`docs/extension-bundles.md`](docs/extension-bundles.md): static bundling, opt-in module builds with shared dependencies, and reversible unbundling
|
|
166
|
+
- [`docs/extension-digests.md`](docs/extension-digests.md) ([日本語](docs/ja/extension-digests.md)): extension digests, the four retention forms, project URIs, and shared digests
|
|
153
167
|
|
|
154
168
|
## Development
|
|
155
169
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WriteSb3ArchiveOptions, WriteSb3ArchiveResult } from './build';
|
|
2
|
+
import { TargetCleanUpResult } from './turbowarp-clean-up';
|
|
3
|
+
export interface CleanUpSb3Options extends Omit<WriteSb3ArchiveOptions, 'archive'> {
|
|
4
|
+
inputPath: string;
|
|
5
|
+
}
|
|
6
|
+
export interface CleanUpSb3ArchiveResult extends TargetCleanUpResult {
|
|
7
|
+
archive: Uint8Array;
|
|
8
|
+
targetCount: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CleanUpSb3Result extends WriteSb3ArchiveResult, Omit<CleanUpSb3ArchiveResult, 'archive'> {
|
|
11
|
+
}
|
|
12
|
+
/** Rearranges an SB3 archive without extracting its entries to disk. */
|
|
13
|
+
export declare function cleanUpSb3Archive(original: Uint8Array): CleanUpSb3ArchiveResult;
|
|
14
|
+
export declare function cleanUpSb3({ confirmReplace, inputPath, outputPath, yes, }: CleanUpSb3Options): Promise<CleanUpSb3Result>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { assert } from "./assert.js";
|
|
2
|
+
import { validateArchiveEntryName } from "./archive.js";
|
|
3
|
+
import { cleanUpTurboWarpBlocks } from "./turbowarp-clean-up.js";
|
|
4
|
+
import { fixedZipTimestamp } from "./source.js";
|
|
5
|
+
import { writeSb3Archive } from "./build.js";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
8
|
+
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
9
|
+
//#region src/clean-up-sb3.ts
|
|
10
|
+
/** Rearranges an SB3 archive without extracting its entries to disk. */
|
|
11
|
+
function cleanUpSb3Archive(original) {
|
|
12
|
+
const names = /* @__PURE__ */ new Set();
|
|
13
|
+
const entries = unzipSync(original, { filter: ({ name }) => {
|
|
14
|
+
validateArchiveEntryName(name);
|
|
15
|
+
assert(name !== "__proto__", "Unsupported SB3 archive entry: __proto__");
|
|
16
|
+
assert(!names.has(name), `Duplicate SB3 archive entry: ${name}`);
|
|
17
|
+
names.add(name);
|
|
18
|
+
return true;
|
|
19
|
+
} });
|
|
20
|
+
assert(Object.hasOwn(entries, "project.json"), "SB3 archive does not contain project.json.");
|
|
21
|
+
const { project, ...counts } = cleanUpTurboWarpBlocks(JSON.parse(strFromU8(entries["project.json"])), { compact: true });
|
|
22
|
+
if (counts.movedScriptCount === 0) return {
|
|
23
|
+
archive: original,
|
|
24
|
+
...counts
|
|
25
|
+
};
|
|
26
|
+
entries["project.json"] = strToU8(`${JSON.stringify(project)}\n`);
|
|
27
|
+
return {
|
|
28
|
+
archive: zipSync(entries, {
|
|
29
|
+
level: 6,
|
|
30
|
+
mtime: fixedZipTimestamp
|
|
31
|
+
}),
|
|
32
|
+
...counts
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function cleanUpSb3({ confirmReplace, inputPath, outputPath, yes }) {
|
|
36
|
+
const input = path.resolve(inputPath);
|
|
37
|
+
const output = path.resolve(outputPath);
|
|
38
|
+
assert(path.extname(input).toLowerCase() === ".sb3", `Expected an .sb3 file: ${input}`);
|
|
39
|
+
assert(input !== output, "Output must differ from the input SB3 path.");
|
|
40
|
+
const inputStats = await lstat(input);
|
|
41
|
+
assert(inputStats.isFile(), `Expected a regular SB3 file: ${input}`);
|
|
42
|
+
const outputStats = await lstat(output).catch((error) => {
|
|
43
|
+
if (error.code === "ENOENT") return void 0;
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
assert(!outputStats || outputStats.isFile(), `Expected a regular SB3 output file: ${output}`);
|
|
47
|
+
assert(!outputStats || outputStats.ino !== inputStats.ino || outputStats.dev !== inputStats.dev, "Output must differ from the input SB3 path.");
|
|
48
|
+
const { archive, ...counts } = cleanUpSb3Archive(await readFile(input));
|
|
49
|
+
const written = await writeSb3Archive({
|
|
50
|
+
archive,
|
|
51
|
+
confirmReplace,
|
|
52
|
+
outputPath: output,
|
|
53
|
+
yes
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
...counts,
|
|
57
|
+
...written
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { cleanUpSb3, cleanUpSb3Archive };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=clean-up-sb3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean-up-sb3.js","names":[],"sources":["../src/clean-up-sb3.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {lstat, readFile} from 'node:fs/promises';\nimport path from 'node:path';\n\nimport {strFromU8, strToU8, unzipSync, zipSync} from 'fflate';\n\nimport {validateArchiveEntryName} from './archive';\nimport {assert} from './assert';\nimport {writeSb3Archive} from './build';\nimport type {WriteSb3ArchiveOptions, WriteSb3ArchiveResult} from './build';\nimport {fixedZipTimestamp} from './source';\nimport {cleanUpTurboWarpBlocks} from './turbowarp-clean-up';\nimport type {TargetCleanUpResult} from './turbowarp-clean-up';\nimport type {ProjectJson} from './types';\n\nexport interface CleanUpSb3Options extends Omit<WriteSb3ArchiveOptions, 'archive'> {\n inputPath: string;\n}\n\nexport interface CleanUpSb3ArchiveResult extends TargetCleanUpResult {\n archive: Uint8Array;\n targetCount: number;\n}\n\nexport interface CleanUpSb3Result\n extends WriteSb3ArchiveResult, Omit<CleanUpSb3ArchiveResult, 'archive'> {}\n\n/** Rearranges an SB3 archive without extracting its entries to disk. */\nexport function cleanUpSb3Archive(original: Uint8Array): CleanUpSb3ArchiveResult {\n const names = new Set<string>();\n const entries = unzipSync(original, {\n filter: ({name}) => {\n validateArchiveEntryName(name);\n assert(name !== '__proto__', 'Unsupported SB3 archive entry: __proto__');\n assert(!names.has(name), `Duplicate SB3 archive entry: ${name}`);\n names.add(name);\n return true;\n },\n });\n assert(Object.hasOwn(entries, 'project.json'), 'SB3 archive does not contain project.json.');\n const {project, ...counts} = cleanUpTurboWarpBlocks(\n JSON.parse(strFromU8(entries['project.json'])) as ProjectJson,\n {compact: true},\n );\n\n if (counts.movedScriptCount === 0) return {archive: original, ...counts};\n\n entries['project.json'] = strToU8(`${JSON.stringify(project)}\\n`);\n return {archive: zipSync(entries, {level: 6, mtime: fixedZipTimestamp}), ...counts};\n}\n\nexport async function cleanUpSb3({\n confirmReplace,\n inputPath,\n outputPath,\n yes,\n}: CleanUpSb3Options): Promise<CleanUpSb3Result> {\n const input = path.resolve(inputPath);\n const output = path.resolve(outputPath);\n assert(path.extname(input).toLowerCase() === '.sb3', `Expected an .sb3 file: ${input}`);\n assert(input !== output, 'Output must differ from the input SB3 path.');\n const inputStats = await lstat(input);\n assert(inputStats.isFile(), `Expected a regular SB3 file: ${input}`);\n const outputStats = await lstat(output).catch((error: unknown) => {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined;\n throw error;\n });\n assert(!outputStats || outputStats.isFile(), `Expected a regular SB3 output file: ${output}`);\n assert(\n !outputStats || outputStats.ino !== inputStats.ino || outputStats.dev !== inputStats.dev,\n 'Output must differ from the input SB3 path.',\n );\n\n const {archive, ...counts} = cleanUpSb3Archive(await readFile(input));\n const written = await writeSb3Archive({archive, confirmReplace, outputPath: output, yes});\n return {...counts, ...written};\n}\n"],"mappings":";;;;;;;;;;AA6BA,SAAgB,kBAAkB,UAA+C;CAC/E,MAAM,wBAAQ,IAAI,IAAY;CAC9B,MAAM,UAAU,UAAU,UAAU,EAClC,SAAS,EAAC,WAAU;EAClB,yBAAyB,IAAI;EAC7B,OAAO,SAAS,aAAa,0CAA0C;EACvE,OAAO,CAAC,MAAM,IAAI,IAAI,GAAG,gCAAgC,MAAM;EAC/D,MAAM,IAAI,IAAI;EACd,OAAO;CACT,EACF,CAAC;CACD,OAAO,OAAO,OAAO,SAAS,cAAc,GAAG,4CAA4C;CAC3F,MAAM,EAAC,SAAS,GAAG,WAAU,uBAC3B,KAAK,MAAM,UAAU,QAAQ,eAAe,CAAC,GAC7C,EAAC,SAAS,KAAI,CAChB;CAEA,IAAI,OAAO,qBAAqB,GAAG,OAAO;EAAC,SAAS;EAAU,GAAG;CAAM;CAEvE,QAAQ,kBAAkB,QAAQ,GAAG,KAAK,UAAU,OAAO,EAAE,GAAG;CAChE,OAAO;EAAC,SAAS,QAAQ,SAAS;GAAC,OAAO;GAAG,OAAO;EAAiB,CAAC;EAAG,GAAG;CAAM;AACpF;AAEA,eAAsB,WAAW,EAC/B,gBACA,WACA,YACA,OAC+C;CAC/C,MAAM,QAAQ,KAAK,QAAQ,SAAS;CACpC,MAAM,SAAS,KAAK,QAAQ,UAAU;CACtC,OAAO,KAAK,QAAQ,KAAK,CAAC,CAAC,YAAY,MAAM,QAAQ,0BAA0B,OAAO;CACtF,OAAO,UAAU,QAAQ,6CAA6C;CACtE,MAAM,aAAa,MAAM,MAAM,KAAK;CACpC,OAAO,WAAW,OAAO,GAAG,gCAAgC,OAAO;CACnE,MAAM,cAAc,MAAM,MAAM,MAAM,CAAC,CAAC,OAAO,UAAmB;EAChE,IAAK,MAAgC,SAAS,UAAU,OAAO,KAAA;EAC/D,MAAM;CACR,CAAC;CACD,OAAO,CAAC,eAAe,YAAY,OAAO,GAAG,uCAAuC,QAAQ;CAC5F,OACE,CAAC,eAAe,YAAY,QAAQ,WAAW,OAAO,YAAY,QAAQ,WAAW,KACrF,6CACF;CAEA,MAAM,EAAC,SAAS,GAAG,WAAU,kBAAkB,MAAM,SAAS,KAAK,CAAC;CACpE,MAAM,UAAU,MAAM,gBAAgB;EAAC;EAAS;EAAgB,YAAY;EAAQ;CAAG,CAAC;CACxF,OAAO;EAAC,GAAG;EAAQ,GAAG;CAAO;AAC/B"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export interface BuildCliOptions {
|
|
|
28
28
|
sourceDirectory: string;
|
|
29
29
|
yes: boolean;
|
|
30
30
|
}
|
|
31
|
+
export interface CleanUpCliOptions {
|
|
32
|
+
command: 'clean-up';
|
|
33
|
+
inputPath: string;
|
|
34
|
+
outputPath: string;
|
|
35
|
+
yes: boolean;
|
|
36
|
+
}
|
|
31
37
|
export interface ExtensionsStatusCliOptions {
|
|
32
38
|
action: 'status';
|
|
33
39
|
command: 'extensions';
|
|
@@ -80,6 +86,12 @@ export interface ExtensionsUnbundleArchiveCliOptions {
|
|
|
80
86
|
outputPath: string;
|
|
81
87
|
yes: boolean;
|
|
82
88
|
}
|
|
89
|
+
export interface ExtensionsDigestsCliOptions {
|
|
90
|
+
action: 'digests';
|
|
91
|
+
command: 'extensions';
|
|
92
|
+
inputPaths: string[];
|
|
93
|
+
json: boolean;
|
|
94
|
+
}
|
|
83
95
|
export interface ExtensionsReplaceSb3CliOptions {
|
|
84
96
|
action: 'replace-sb3';
|
|
85
97
|
command: 'extensions';
|
|
@@ -88,8 +100,8 @@ export interface ExtensionsReplaceSb3CliOptions {
|
|
|
88
100
|
outputPath: string;
|
|
89
101
|
yes: boolean;
|
|
90
102
|
}
|
|
91
|
-
export type ExtensionsCliOptions = ExtensionsReplaceSb3CliOptions | ExtensionsStatusCliOptions | ExtensionsMutationCliOptions | ExtensionsMigrateIdCliOptions | ExtensionsBundleCliOptions | ExtensionsUnbundleSourceCliOptions | ExtensionsUnbundleArchiveCliOptions;
|
|
92
|
-
export type CliOptions = HelpCliOptions | VersionCliOptions | ImportCliOptions | CheckCliOptions | BuildCliOptions | ExtensionsCliOptions;
|
|
103
|
+
export type ExtensionsCliOptions = ExtensionsDigestsCliOptions | ExtensionsReplaceSb3CliOptions | ExtensionsStatusCliOptions | ExtensionsMutationCliOptions | ExtensionsMigrateIdCliOptions | ExtensionsBundleCliOptions | ExtensionsUnbundleSourceCliOptions | ExtensionsUnbundleArchiveCliOptions;
|
|
104
|
+
export type CliOptions = HelpCliOptions | VersionCliOptions | ImportCliOptions | CheckCliOptions | BuildCliOptions | CleanUpCliOptions | ExtensionsCliOptions;
|
|
93
105
|
export interface RunCliOptions {
|
|
94
106
|
fetch?: FetchImplementation;
|
|
95
107
|
log?: (message: string) => void;
|
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,12 @@ import { assert } from "./assert.js";
|
|
|
2
2
|
import { validateExtensionBundleMetadata } from "./extension-bundle-metadata.js";
|
|
3
3
|
import { createDeterministicSb3, validateSb3Source } from "./source.js";
|
|
4
4
|
import { buildSb3 } from "./build.js";
|
|
5
|
+
import { cleanUpSb3 } from "./clean-up-sb3.js";
|
|
5
6
|
import { packageVersion } from "./constants.js";
|
|
6
7
|
import { importSb3 } from "./import.js";
|
|
7
8
|
import { unbundleSb3 } from "./extension-bundle-archive.js";
|
|
8
9
|
import { bundleExtensions, unbundleExtensions } from "./extension-bundle-configuration.js";
|
|
10
|
+
import { formatExtensionDigestInventory, inventoryExtensionDigests } from "./extension-digest-inventory.js";
|
|
9
11
|
import { migrateExtensionId } from "./extension-id-migration.js";
|
|
10
12
|
import { replaceSb3Extensions } from "./extension-sb3-replacement.js";
|
|
11
13
|
import { extensionStatus, syncExtensions, updateExtensions } from "./extension-sync.js";
|
|
@@ -18,6 +20,8 @@ function usage() {
|
|
|
18
20
|
sb3-toolchain import INPUT.sb3 --output SOURCE_DIR [--yes] [--discard-local-changes]
|
|
19
21
|
sb3-toolchain check SOURCE_DIR [--project-assets MANIFEST.json] [--allow-asset-root DIR ...]
|
|
20
22
|
sb3-toolchain build SOURCE_DIR --output OUTPUT.sb3 [--project-assets MANIFEST.json] [--allow-asset-root DIR ...] [--clean-up-blocks] [--yes]
|
|
23
|
+
sb3-toolchain clean-up INPUT.sb3 --output OUTPUT.sb3 [--yes]
|
|
24
|
+
sb3-toolchain extensions digests INPUT.sb3 [INPUT.sb3 ...] [--json]
|
|
21
25
|
sb3-toolchain extensions replace-sb3 INPUT.sb3 [--from DONOR.sb3] --output OUTPUT.sb3 [--yes]
|
|
22
26
|
sb3-toolchain extensions status SOURCE_DIR
|
|
23
27
|
sb3-toolchain extensions sync SOURCE_DIR [--yes]
|
|
@@ -31,6 +35,7 @@ Commands:
|
|
|
31
35
|
import Expand an SB3 into Git-friendly source files.
|
|
32
36
|
check Validate an expanded SB3 source directory.
|
|
33
37
|
build Build a deterministic SB3 from expanded sources.
|
|
38
|
+
clean-up Arrange scripts in a more compact layout and write a separate SB3.
|
|
34
39
|
extensions Inspect, restore, or update managed embedded extensions.
|
|
35
40
|
|
|
36
41
|
Build layout cleanup:
|
|
@@ -44,6 +49,15 @@ Project asset additions:
|
|
|
44
49
|
backdrops, costumes, and sounds only to the generated SB3. Input files are confined to the
|
|
45
50
|
manifest directory unless --allow-asset-root explicitly permits another root.
|
|
46
51
|
|
|
52
|
+
Extension digests:
|
|
53
|
+
extensions digests reads each SB3's own manifest and reports every extension's ID,
|
|
54
|
+
pinned SHA-256, source form (remote-non-cacheable, remote-cacheable, embedded-file,
|
|
55
|
+
embedded-data), held byte size, and the project URI that names the cache bucket. Given
|
|
56
|
+
several SB3s it also reports which digests more than one project names. Nothing is
|
|
57
|
+
fetched and no browser storage is read: an extension cache belongs to an origin and a
|
|
58
|
+
browser profile, so only the browser can list it, and an unresolved project URI never
|
|
59
|
+
means an absent project.
|
|
60
|
+
|
|
47
61
|
Kamishibai SB3 replacement:
|
|
48
62
|
extensions replace-sb3 replaces the runtime bundle and Block Script in INPUT.sb3.
|
|
49
63
|
Omitting --from downloads the published block SB3 from the official samples site
|
|
@@ -89,6 +103,32 @@ function parseImportArguments(arguments_) {
|
|
|
89
103
|
yes
|
|
90
104
|
};
|
|
91
105
|
}
|
|
106
|
+
function parseCleanUpArguments(arguments_) {
|
|
107
|
+
let inputPath;
|
|
108
|
+
let outputPath;
|
|
109
|
+
let yes = false;
|
|
110
|
+
for (let index = 0; index < arguments_.length; index += 1) {
|
|
111
|
+
const argument = arguments_[index];
|
|
112
|
+
if (argument === "--output") {
|
|
113
|
+
assert(!outputPath, "--output may only be specified once.");
|
|
114
|
+
outputPath = path.resolve(takeValue(arguments_, index, "--output"));
|
|
115
|
+
index += 1;
|
|
116
|
+
} else if (argument === "--yes") yes = true;
|
|
117
|
+
else {
|
|
118
|
+
assert(!argument.startsWith("-"), `Unknown option: ${argument}`);
|
|
119
|
+
assert(!inputPath, "Only one input SB3 may be specified.");
|
|
120
|
+
inputPath = path.resolve(argument);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
assert(inputPath, "The clean-up command requires INPUT.sb3.");
|
|
124
|
+
assert(outputPath, "The clean-up command requires --output OUTPUT.sb3.");
|
|
125
|
+
return {
|
|
126
|
+
command: "clean-up",
|
|
127
|
+
inputPath,
|
|
128
|
+
outputPath,
|
|
129
|
+
yes
|
|
130
|
+
};
|
|
131
|
+
}
|
|
92
132
|
function parseCheckArguments(arguments_) {
|
|
93
133
|
const allowedAssetRoots = [];
|
|
94
134
|
let projectAssetsPath;
|
|
@@ -356,6 +396,25 @@ function parseExtensionUnbundleArguments(arguments_) {
|
|
|
356
396
|
yes
|
|
357
397
|
};
|
|
358
398
|
}
|
|
399
|
+
function parseExtensionDigestsArguments(arguments_) {
|
|
400
|
+
const inputPaths = [];
|
|
401
|
+
let json = false;
|
|
402
|
+
for (let index = 0; index < arguments_.length; index += 1) {
|
|
403
|
+
const argument = arguments_[index];
|
|
404
|
+
if (argument === "--json") json = true;
|
|
405
|
+
else {
|
|
406
|
+
assert(!argument.startsWith("-"), `Unknown option: ${argument}`);
|
|
407
|
+
inputPaths.push(path.resolve(argument));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
assert(inputPaths.length > 0, "The extensions digests command requires at least one INPUT.sb3.");
|
|
411
|
+
return {
|
|
412
|
+
action: "digests",
|
|
413
|
+
command: "extensions",
|
|
414
|
+
inputPaths,
|
|
415
|
+
json
|
|
416
|
+
};
|
|
417
|
+
}
|
|
359
418
|
function parseExtensionReplaceSb3Arguments(arguments_) {
|
|
360
419
|
let fromPath;
|
|
361
420
|
let inputPath;
|
|
@@ -391,7 +450,8 @@ function parseExtensionReplaceSb3Arguments(arguments_) {
|
|
|
391
450
|
}
|
|
392
451
|
function parseExtensionsArguments(arguments_) {
|
|
393
452
|
const [action, ...actionArguments] = arguments_;
|
|
394
|
-
assert(action === "replace-sb3" || action === "bundle" || action === "migrate-id" || action === "status" || action === "sync" || action === "unbundle" || action === "update", "The extensions command requires status, sync, update, migrate-id, bundle, unbundle, or replace-sb3.");
|
|
453
|
+
assert(action === "digests" || action === "replace-sb3" || action === "bundle" || action === "migrate-id" || action === "status" || action === "sync" || action === "unbundle" || action === "update", "The extensions command requires status, digests, sync, update, migrate-id, bundle, unbundle, or replace-sb3.");
|
|
454
|
+
if (action === "digests") return parseExtensionDigestsArguments(actionArguments);
|
|
395
455
|
if (action === "replace-sb3") return parseExtensionReplaceSb3Arguments(actionArguments);
|
|
396
456
|
if (action === "status") {
|
|
397
457
|
assert(actionArguments.length === 1 && !actionArguments[0].startsWith("-"), "The extensions status command requires exactly one SOURCE_DIR.");
|
|
@@ -415,6 +475,7 @@ function parseCliArguments(arguments_) {
|
|
|
415
475
|
if (command === "import") return parseImportArguments(commandArguments);
|
|
416
476
|
if (command === "check") return parseCheckArguments(commandArguments);
|
|
417
477
|
if (command === "build") return parseBuildArguments(commandArguments);
|
|
478
|
+
if (command === "clean-up") return parseCleanUpArguments(commandArguments);
|
|
418
479
|
if (command === "extensions") return parseExtensionsArguments(commandArguments);
|
|
419
480
|
throw new Error(`Unknown command: ${command}`);
|
|
420
481
|
}
|
|
@@ -515,7 +576,25 @@ async function runCli(arguments_, { fetch: fetchImplementation = globalThis.fetc
|
|
|
515
576
|
if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);
|
|
516
577
|
return;
|
|
517
578
|
}
|
|
579
|
+
if (options.command === "clean-up") {
|
|
580
|
+
const result = await cleanUpSb3({
|
|
581
|
+
...options,
|
|
582
|
+
confirmReplace: confirmBuildReplacement
|
|
583
|
+
});
|
|
584
|
+
log(`${result.changed ? "Wrote" : "Already up to date"}: ${result.outputPath} (${result.movedScriptCount}/${result.scriptCount} scripts moved across ${result.targetCount} targets).`);
|
|
585
|
+
if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
518
588
|
if (options.command === "extensions") {
|
|
589
|
+
if (options.action === "digests") {
|
|
590
|
+
const inventory = await inventoryExtensionDigests(options.inputPaths);
|
|
591
|
+
if (options.json) {
|
|
592
|
+
log(`${JSON.stringify(inventory, null, 2)}`);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
for (const line of formatExtensionDigestInventory(inventory)) log(line);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
519
598
|
if (options.action === "replace-sb3") {
|
|
520
599
|
const result = await replaceSb3Extensions({
|
|
521
600
|
confirmReplace: confirmBuildReplacement,
|