@platforma-sdk/block-tools 2.11.2 → 2.11.3
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/bin/run.js +9 -5
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +12 -12
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +740 -930
- package/dist/cli.mjs.map +1 -1
- package/dist/cmd/build-meta.d.ts +2 -9
- package/dist/cmd/build-model.d.ts +2 -10
- package/dist/cmd/list-overview-snapshots.d.ts +2 -9
- package/dist/cmd/mark-stable.d.ts +2 -13
- package/dist/cmd/pack.d.ts +2 -9
- package/dist/cmd/publish.d.ts +2 -12
- package/dist/cmd/refresh-registry.d.ts +2 -9
- package/dist/cmd/restore-overview-from-snapshot.d.ts +2 -10
- package/dist/cmd/structure/check.d.ts +2 -10
- package/dist/cmd/structure/init.d.ts +2 -18
- package/dist/cmd/structure/refresh.d.ts +10 -11
- package/dist/cmd/update-deps.d.ts +2 -6
- package/dist/cmd/upload-package-v1.d.ts +2 -14
- package/dist/config-DpfTzcgG.mjs.map +1 -1
- package/dist/config-xxVy3IQR.js.map +1 -1
- package/dist/registry_v1/config_schema.d.ts +7 -7
- package/dist/registry_v1/flags.d.ts +2 -4
- package/dist/structure/cli/run-structure.d.ts +1 -1
- package/dist/v2/registry/schema_public.d.ts +3600 -3600
- package/package.json +4 -19
- package/src/cli.test.ts +56 -0
- package/src/cli.ts +50 -0
- package/src/cmd/build-meta.ts +11 -22
- package/src/cmd/build-model.ts +16 -33
- package/src/cmd/list-overview-snapshots.ts +24 -28
- package/src/cmd/mark-stable.ts +35 -55
- package/src/cmd/pack.ts +11 -22
- package/src/cmd/publish.ts +35 -49
- package/src/cmd/refresh-registry.ts +22 -26
- package/src/cmd/restore-overview-from-snapshot.ts +24 -34
- package/src/cmd/structure/check.ts +19 -28
- package/src/cmd/structure/init.ts +40 -47
- package/src/cmd/structure/refresh.ts +45 -36
- package/src/cmd/update-deps.ts +22 -12
- package/src/cmd/upload-package-v1.ts +42 -60
- package/src/registry_v1/flags.ts +7 -7
- package/src/structure/cli/run-structure.ts +2 -2
- package/src/v2/model/content_conversion.ts +0 -1
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -6
- package/dist/cmd/index.d.ts +0 -28
- package/src/cmd/index.ts +0 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/block-tools",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.3",
|
|
4
4
|
"description": "Utility to manipulate Platforma Blocks and Block Registry",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"bin": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@aws-sdk/client-s3": "3.859.0",
|
|
27
27
|
"@inquirer/prompts": "^7.0.1",
|
|
28
|
-
"@oclif/core": "^4.0.37",
|
|
29
28
|
"canonicalize": "~2.1.0",
|
|
29
|
+
"commander": "^15.0.0",
|
|
30
30
|
"lru-cache": "^11.2.2",
|
|
31
31
|
"mime-types": "^2.1.35",
|
|
32
32
|
"tar": "^7.4.3",
|
|
@@ -35,12 +35,11 @@
|
|
|
35
35
|
"zod": "~3.25.76",
|
|
36
36
|
"@milaboratories/pl-http": "1.2.4",
|
|
37
37
|
"@milaboratories/pl-model-middle-layer": "1.30.8",
|
|
38
|
+
"@milaboratories/pl-model-backend": "1.4.8",
|
|
38
39
|
"@milaboratories/pl-model-common": "1.46.2",
|
|
39
|
-
"@milaboratories/ts-helpers": "1.8.3",
|
|
40
40
|
"@milaboratories/resolve-helper": "1.1.3",
|
|
41
41
|
"@platforma-sdk/blocks-deps-updater": "2.2.0",
|
|
42
|
-
"@milaboratories/ts-helpers
|
|
43
|
-
"@milaboratories/pl-model-backend": "1.4.8"
|
|
42
|
+
"@milaboratories/ts-helpers": "1.8.3"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
@@ -48,7 +47,6 @@
|
|
|
48
47
|
"@types/node": "~24.5.2",
|
|
49
48
|
"@types/semver": "^7.7.0",
|
|
50
49
|
"@vitest/coverage-istanbul": "^4.1.3",
|
|
51
|
-
"oclif": "^4.16.2",
|
|
52
50
|
"oxfmt": "0.35.0",
|
|
53
51
|
"rollup-plugin-node-externals": "^8.0.0",
|
|
54
52
|
"semver": "^7.7.2",
|
|
@@ -57,24 +55,11 @@
|
|
|
57
55
|
"vite-plugin-dts": "^4.5.3",
|
|
58
56
|
"vitest": "^4.1.3",
|
|
59
57
|
"@milaboratories/build-configs": "2.0.0",
|
|
60
|
-
"@milaboratories/oclif-index": "1.1.1",
|
|
61
58
|
"@milaboratories/ts-configs": "1.2.3",
|
|
62
59
|
"@milaboratories/ts-builder": "1.5.2"
|
|
63
60
|
},
|
|
64
|
-
"oclif": {
|
|
65
|
-
"bin": "block-tools",
|
|
66
|
-
"commands": {
|
|
67
|
-
"identifier": "COMMANDS",
|
|
68
|
-
"strategy": "explicit",
|
|
69
|
-
"target": "./dist/cli.js"
|
|
70
|
-
},
|
|
71
|
-
"dirname": "block-tools",
|
|
72
|
-
"topicSeparator": " "
|
|
73
|
-
},
|
|
74
61
|
"scripts": {
|
|
75
|
-
"oclif:index": "oclif-index --commands-root=./src/cmd/ --index-file=./src/cmd/index.ts && node --run fmt",
|
|
76
62
|
"build": "vite build",
|
|
77
|
-
"readme": "oclif readme",
|
|
78
63
|
"test": "vitest run --coverage",
|
|
79
64
|
"do-pack": "rm -f *.tgz && pnpm pack && mv *.tgz package.tgz",
|
|
80
65
|
"formatter:check": "ts-builder formatter --check",
|
package/src/cli.test.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import type { Command } from "commander";
|
|
3
|
+
import { buildProgram } from "./cli";
|
|
4
|
+
|
|
5
|
+
function subcommand(cmd: Command, name: string): Command {
|
|
6
|
+
const c = cmd.commands.find((x) => x.name() === name);
|
|
7
|
+
if (!c) throw new Error(`subcommand "${name}" not found`);
|
|
8
|
+
return c;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function longNames(cmd: Command): string[] {
|
|
12
|
+
return cmd.options.map((o) => o.long ?? o.short ?? o.name());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("block-tools CLI structure", () => {
|
|
16
|
+
const program = buildProgram();
|
|
17
|
+
|
|
18
|
+
it("exposes the full command surface (10 commands + structure topic)", () => {
|
|
19
|
+
expect(program.commands.map((c) => c.name()).sort()).toEqual([
|
|
20
|
+
"build-meta",
|
|
21
|
+
"build-model",
|
|
22
|
+
"list-overview-snapshots",
|
|
23
|
+
"mark-stable",
|
|
24
|
+
"pack",
|
|
25
|
+
"publish",
|
|
26
|
+
"refresh-registry",
|
|
27
|
+
"restore-overview-from-snapshot",
|
|
28
|
+
"structure",
|
|
29
|
+
"update-deps",
|
|
30
|
+
"upload-package-v1",
|
|
31
|
+
]);
|
|
32
|
+
expect(
|
|
33
|
+
subcommand(program, "structure")
|
|
34
|
+
.commands.map((c) => c.name())
|
|
35
|
+
.sort(),
|
|
36
|
+
).toEqual(["check", "init", "refresh"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("preserves key flags + env bindings", () => {
|
|
40
|
+
const publish = subcommand(program, "publish");
|
|
41
|
+
const pnames = longNames(publish);
|
|
42
|
+
for (const f of ["--registry", "--manifest", "--version-override", "--refresh", "--unstable"]) {
|
|
43
|
+
expect(pnames).toContain(f);
|
|
44
|
+
}
|
|
45
|
+
// --no-refresh negation and PL_REGISTRY env preserved
|
|
46
|
+
expect(pnames).toContain("--no-refresh");
|
|
47
|
+
expect(publish.options.find((o) => o.long === "--registry")?.envVar).toBe("PL_REGISTRY");
|
|
48
|
+
|
|
49
|
+
// structure init keeps its positional [path] and the with/no-software pair
|
|
50
|
+
const init = subcommand(subcommand(program, "structure"), "init");
|
|
51
|
+
const inames = longNames(init);
|
|
52
|
+
expect(inames).toContain("--with-software");
|
|
53
|
+
expect(inames).toContain("--no-software");
|
|
54
|
+
expect(init.registeredArguments.map((a) => a.name())).toContain("path");
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { buildMetaCommand } from "./cmd/build-meta";
|
|
3
|
+
import { buildModelCommand } from "./cmd/build-model";
|
|
4
|
+
import { packCommand } from "./cmd/pack";
|
|
5
|
+
import { publishCommand } from "./cmd/publish";
|
|
6
|
+
import { refreshRegistryCommand } from "./cmd/refresh-registry";
|
|
7
|
+
import { markStableCommand } from "./cmd/mark-stable";
|
|
8
|
+
import { updateDepsCommand } from "./cmd/update-deps";
|
|
9
|
+
import { listOverviewSnapshotsCommand } from "./cmd/list-overview-snapshots";
|
|
10
|
+
import { restoreOverviewFromSnapshotCommand } from "./cmd/restore-overview-from-snapshot";
|
|
11
|
+
import { uploadPackageV1Command } from "./cmd/upload-package-v1";
|
|
12
|
+
import { structureCheckCommand } from "./cmd/structure/check";
|
|
13
|
+
import { structureInitCommand } from "./cmd/structure/init";
|
|
14
|
+
import { structureRefreshCommand } from "./cmd/structure/refresh";
|
|
15
|
+
|
|
16
|
+
// `packageRoot` is the package install root (the dir containing `src/` and
|
|
17
|
+
// `bin/`); the `structure` commands resolve their templates under it. bin/run.js
|
|
18
|
+
// passes it in; defaults to cwd for tests/introspection.
|
|
19
|
+
export function buildProgram(packageRoot: string = process.cwd()): Command {
|
|
20
|
+
const program = new Command();
|
|
21
|
+
program
|
|
22
|
+
.name("block-tools")
|
|
23
|
+
.description("Utility to manipulate Platforma Blocks and Block Registry");
|
|
24
|
+
|
|
25
|
+
program.addCommand(buildMetaCommand());
|
|
26
|
+
program.addCommand(buildModelCommand());
|
|
27
|
+
program.addCommand(packCommand());
|
|
28
|
+
program.addCommand(publishCommand());
|
|
29
|
+
program.addCommand(refreshRegistryCommand());
|
|
30
|
+
program.addCommand(markStableCommand());
|
|
31
|
+
program.addCommand(updateDepsCommand(packageRoot));
|
|
32
|
+
program.addCommand(listOverviewSnapshotsCommand());
|
|
33
|
+
program.addCommand(restoreOverviewFromSnapshotCommand());
|
|
34
|
+
program.addCommand(uploadPackageV1Command());
|
|
35
|
+
|
|
36
|
+
// `structure` subcommands: check | init | refresh.
|
|
37
|
+
const structure = new Command("structure").description(
|
|
38
|
+
"Manage block scaffolding against the canonical structure (check / init / refresh)",
|
|
39
|
+
);
|
|
40
|
+
structure.addCommand(structureCheckCommand(packageRoot));
|
|
41
|
+
structure.addCommand(structureInitCommand(packageRoot));
|
|
42
|
+
structure.addCommand(structureRefreshCommand(packageRoot));
|
|
43
|
+
program.addCommand(structure);
|
|
44
|
+
|
|
45
|
+
return program;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function run(argv: string[], packageRoot: string): Promise<void> {
|
|
49
|
+
await buildProgram(packageRoot).parseAsync(argv);
|
|
50
|
+
}
|
package/src/cmd/build-meta.ts
CHANGED
|
@@ -1,32 +1,19 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { loadPackDescriptionRaw } from "../v2";
|
|
5
5
|
import { embedBlockPackMetaAbsoluteBase64, resolveBlockPackMeta } from "../v2/model/block_meta";
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
export function buildMetaCommand(): Command {
|
|
8
|
+
const cmd = new Command("build-meta").description(
|
|
9
9
|
"Extracts meta information from blocks package.json and outputs meta.json with embedded binary " +
|
|
10
|
-
|
|
10
|
+
"and textual information linked from the meta section.",
|
|
11
|
+
);
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
char: "i",
|
|
15
|
-
summary: "input module path",
|
|
16
|
-
helpValue: "<path>",
|
|
17
|
-
default: ".",
|
|
18
|
-
}),
|
|
13
|
+
cmd.option("-i, --modulePath <path>", "input module path", ".");
|
|
14
|
+
cmd.requiredOption("-o, --destination <path>", "output meta.json file");
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
char: "o",
|
|
22
|
-
summary: "output meta.json file",
|
|
23
|
-
helpValue: "<path>",
|
|
24
|
-
required: true,
|
|
25
|
-
}),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
public async run(): Promise<void> {
|
|
29
|
-
const { flags } = await this.parse(BuildMeta);
|
|
16
|
+
cmd.action(async (flags) => {
|
|
30
17
|
const modulePath = path.resolve(flags.modulePath);
|
|
31
18
|
const descriptionRaw = await loadPackDescriptionRaw(modulePath);
|
|
32
19
|
const metaEmbedded = await embedBlockPackMetaAbsoluteBase64(
|
|
@@ -34,5 +21,7 @@ export default class BuildMeta extends Command {
|
|
|
34
21
|
);
|
|
35
22
|
|
|
36
23
|
await fs.promises.writeFile(path.resolve(flags.destination), JSON.stringify(metaEmbedded));
|
|
37
|
-
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return cmd;
|
|
38
27
|
}
|
package/src/cmd/build-model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
@@ -13,44 +13,26 @@ async function getFileContent(path: string) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
"Extracts and outputs block model JSON from pre-built block model module"
|
|
16
|
+
export function buildModelCommand(): Command {
|
|
17
|
+
const cmd = new Command("build-model").description(
|
|
18
|
+
"Extracts and outputs block model JSON from pre-built block model module",
|
|
19
|
+
);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
cmd.option("-i, --modulePath <path>", "input module path", ".");
|
|
22
|
+
cmd.option(
|
|
23
|
+
"-b, --sourceBundle <path>",
|
|
24
|
+
"bundled model code to embed into the model for callback-based rendering to work",
|
|
25
|
+
"./dist/bundle.js",
|
|
26
|
+
);
|
|
27
|
+
cmd.option("-o, --destination <path>", "output model file", "./dist/model.json");
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
char: "b",
|
|
30
|
-
summary: "bundled model code to embed into the model for callback-based rendering to work",
|
|
31
|
-
helpValue: "<path>",
|
|
32
|
-
default: "./dist/bundle.js",
|
|
33
|
-
}),
|
|
34
|
-
|
|
35
|
-
destination: Flags.string({
|
|
36
|
-
char: "o",
|
|
37
|
-
summary: "output model file",
|
|
38
|
-
helpValue: "<path>",
|
|
39
|
-
default: "./dist/model.json",
|
|
40
|
-
}),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
public async run(): Promise<void> {
|
|
44
|
-
const { flags } = await this.parse(BuildModel);
|
|
29
|
+
cmd.action(async (flags) => {
|
|
45
30
|
const modulePath = path.resolve(flags.modulePath); // i.e. folder with package.json file
|
|
46
|
-
// eslint-disable-next-line prefer-const, @typescript-eslint/no-unsafe-assignment
|
|
47
31
|
let { model, platforma } = require(modulePath);
|
|
48
32
|
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
50
33
|
if (!model) model = platforma;
|
|
51
34
|
if (!model) throw new Error('"model" export not found');
|
|
52
35
|
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
54
36
|
const { config } = model;
|
|
55
37
|
|
|
56
38
|
if (!config)
|
|
@@ -64,7 +46,6 @@ export default class BuildModel extends Command {
|
|
|
64
46
|
|
|
65
47
|
const code = await getFileContent(flags.sourceBundle);
|
|
66
48
|
if (code !== undefined) {
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
68
49
|
config.code = {
|
|
69
50
|
type: "plain",
|
|
70
51
|
content: code,
|
|
@@ -72,5 +53,7 @@ export default class BuildModel extends Command {
|
|
|
72
53
|
}
|
|
73
54
|
|
|
74
55
|
await fs.promises.writeFile(path.resolve(flags.destination), JSON.stringify(config));
|
|
75
|
-
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return cmd;
|
|
76
59
|
}
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
import { Command,
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
2
|
import { BlockRegistryV2 } from "../v2/registry/registry";
|
|
3
3
|
import { storageByUrl } from "../io/storage";
|
|
4
|
-
import {
|
|
4
|
+
import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export function listOverviewSnapshotsCommand(): Command {
|
|
7
|
+
const cmd = new Command("list-overview-snapshots").description(
|
|
8
|
+
"List all available global overview snapshots in the registry",
|
|
9
|
+
);
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
registry
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
required: true,
|
|
16
|
-
}),
|
|
11
|
+
cmd.addOption(
|
|
12
|
+
new Option("-r, --registry <address>", "full address of the registry")
|
|
13
|
+
.env("PL_REGISTRY")
|
|
14
|
+
.makeOptionMandatory(),
|
|
15
|
+
);
|
|
16
|
+
cmd.option("--json", "output in JSON format", false);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
default: false,
|
|
21
|
-
}),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
public async run(): Promise<void> {
|
|
25
|
-
const { flags } = await this.parse(ListOverviewSnapshots);
|
|
18
|
+
cmd.action(async (flags) => {
|
|
19
|
+
const logger = new ConsoleLoggerAdapter();
|
|
26
20
|
const storage = storageByUrl(flags.registry);
|
|
27
|
-
const registry = new BlockRegistryV2(storage,
|
|
21
|
+
const registry = new BlockRegistryV2(storage, logger);
|
|
28
22
|
|
|
29
23
|
const snapshots = await registry.listGlobalOverviewSnapshots();
|
|
30
24
|
|
|
31
25
|
if (flags.json) {
|
|
32
|
-
|
|
26
|
+
logger.info(JSON.stringify(snapshots, null, 2));
|
|
33
27
|
} else {
|
|
34
28
|
if (snapshots.length === 0) {
|
|
35
|
-
|
|
29
|
+
logger.info("No snapshots found.");
|
|
36
30
|
} else {
|
|
37
|
-
|
|
31
|
+
logger.info(`Found ${snapshots.length} snapshot(s):\n`);
|
|
38
32
|
for (const snapshot of snapshots) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
logger.info(` ${snapshot.timestamp}`);
|
|
34
|
+
logger.info(` Path: ${snapshot.path}`);
|
|
35
|
+
logger.info("");
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
|
-
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return cmd;
|
|
46
42
|
}
|
package/src/cmd/mark-stable.ts
CHANGED
|
@@ -1,67 +1,47 @@
|
|
|
1
|
-
import { Command,
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
2
|
import { BlockRegistryV2, loadPackDescriptionRaw } from "../v2";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { overrideDescriptionVersion, StableChannel } from "@milaboratories/pl-model-middle-layer";
|
|
5
5
|
import { storageByUrl } from "../io";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
summary: "full address of the registry",
|
|
35
|
-
helpValue: "<address>",
|
|
36
|
-
env: "PL_REGISTRY",
|
|
37
|
-
required: true,
|
|
38
|
-
}),
|
|
39
|
-
|
|
40
|
-
refresh: Flags.boolean({
|
|
41
|
-
summary: "refresh repository after adding the package",
|
|
42
|
-
default: true,
|
|
43
|
-
allowNo: true,
|
|
44
|
-
env: "PL_REGISTRY_REFRESH",
|
|
45
|
-
}),
|
|
46
|
-
|
|
47
|
-
unmark: Flags.boolean({
|
|
48
|
-
summary:
|
|
49
|
-
'reverses meaning of this command, flag can be used to remove "stable" flag from the package',
|
|
50
|
-
default: false,
|
|
51
|
-
}),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
public async run(): Promise<void> {
|
|
55
|
-
const { flags } = await this.parse(MarkStable);
|
|
6
|
+
import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
|
|
7
|
+
|
|
8
|
+
export function markStableCommand(): Command {
|
|
9
|
+
const cmd = new Command("mark-stable").description("Mark target block stable");
|
|
10
|
+
|
|
11
|
+
cmd.option("-i, --modulePath <path>", "input module path", ".");
|
|
12
|
+
cmd.addOption(
|
|
13
|
+
new Option("-c, --channel <channel name>", "custom channel").default(StableChannel).hideHelp(),
|
|
14
|
+
);
|
|
15
|
+
cmd.option("-v, --version-override <path>", "override package version");
|
|
16
|
+
cmd.addOption(
|
|
17
|
+
new Option("-r, --registry <address>", "full address of the registry")
|
|
18
|
+
.env("PL_REGISTRY")
|
|
19
|
+
.makeOptionMandatory(),
|
|
20
|
+
);
|
|
21
|
+
cmd.addOption(
|
|
22
|
+
new Option("--refresh", "refresh repository after adding the package")
|
|
23
|
+
.default(true)
|
|
24
|
+
.env("PL_REGISTRY_REFRESH"),
|
|
25
|
+
);
|
|
26
|
+
cmd.option("--no-refresh", "do not refresh repository after adding the package");
|
|
27
|
+
cmd.option(
|
|
28
|
+
"--unmark",
|
|
29
|
+
'reverses meaning of this command, flag can be used to remove "stable" flag from the package',
|
|
30
|
+
false,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
cmd.action(async (flags) => {
|
|
56
34
|
let description = await loadPackDescriptionRaw(path.resolve(flags.modulePath));
|
|
57
|
-
if (flags
|
|
58
|
-
description = overrideDescriptionVersion(description, flags
|
|
35
|
+
if (flags.versionOverride)
|
|
36
|
+
description = overrideDescriptionVersion(description, flags.versionOverride);
|
|
59
37
|
const storage = storageByUrl(flags.registry);
|
|
60
|
-
const registry = new BlockRegistryV2(storage, new
|
|
38
|
+
const registry = new BlockRegistryV2(storage, new ConsoleLoggerAdapter());
|
|
61
39
|
|
|
62
40
|
if (flags.unmark) await registry.removePackageFromChannel(description.id, flags.channel);
|
|
63
41
|
else await registry.addPackageToChannel(description.id, flags.channel);
|
|
64
42
|
|
|
65
43
|
if (flags.refresh) await registry.updateIfNeeded();
|
|
66
|
-
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return cmd;
|
|
67
47
|
}
|
package/src/cmd/pack.ts
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import { Command
|
|
1
|
+
import { Command } from "commander";
|
|
2
2
|
import { loadPackDescription } from "../v2/source_package";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { buildBlockPackDist } from "../v2/build_dist";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
6
|
+
export function packCommand(): Command {
|
|
7
|
+
const cmd = new Command("pack").description(
|
|
8
8
|
"Builds block pack and outputs a block pack manifest consolidating all " +
|
|
9
|
-
|
|
9
|
+
"references assets into a single folder",
|
|
10
|
+
);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
char: "i",
|
|
14
|
-
summary: "input module path",
|
|
15
|
-
helpValue: "<path>",
|
|
16
|
-
default: ".",
|
|
17
|
-
}),
|
|
12
|
+
cmd.option("-i, --modulePath <path>", "input module path", ".");
|
|
13
|
+
cmd.option("-o, --destinationPath <path>", "output folder", "./block-pack");
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
char: "o",
|
|
21
|
-
summary: "output folder",
|
|
22
|
-
helpValue: "<path>",
|
|
23
|
-
default: "./block-pack",
|
|
24
|
-
}),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
public async run(): Promise<void> {
|
|
28
|
-
const { flags } = await this.parse(PackBlock);
|
|
15
|
+
cmd.action(async (flags) => {
|
|
29
16
|
const description = await loadPackDescription(path.resolve(flags.modulePath));
|
|
30
17
|
await buildBlockPackDist(description, path.resolve(flags.destinationPath));
|
|
31
|
-
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return cmd;
|
|
32
21
|
}
|
package/src/cmd/publish.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Command,
|
|
1
|
+
import { Command, Option } from "commander";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
|
|
4
4
|
import { ManifestFileName } from "../v2/registry/schema_public";
|
|
5
5
|
import {
|
|
6
6
|
BlockPackManifest,
|
|
@@ -35,47 +35,32 @@ function simpleDeepMerge<T extends Record<string, unknown>>(
|
|
|
35
35
|
return result as T;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
"Publishes the block package and refreshes the registry (for v2 block-pack schema)"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
summary: "refresh repository after adding the package",
|
|
65
|
-
default: true,
|
|
66
|
-
allowNo: true,
|
|
67
|
-
env: "PL_REGISTRY_REFRESH",
|
|
68
|
-
}),
|
|
69
|
-
|
|
70
|
-
unstable: Flags.boolean({
|
|
71
|
-
summary: "do not add the published package to stable channel",
|
|
72
|
-
default: false,
|
|
73
|
-
env: "PL_PUBLISH_UNSTABLE",
|
|
74
|
-
}),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
public async run(): Promise<void> {
|
|
78
|
-
const { flags } = await this.parse(Publish);
|
|
38
|
+
export function publishCommand(): Command {
|
|
39
|
+
const cmd = new Command("publish").description(
|
|
40
|
+
"Publishes the block package and refreshes the registry (for v2 block-pack schema)",
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
cmd.addOption(
|
|
44
|
+
new Option("-r, --registry <address>", "full address of the registry")
|
|
45
|
+
.env("PL_REGISTRY")
|
|
46
|
+
.makeOptionMandatory(),
|
|
47
|
+
);
|
|
48
|
+
cmd.option("-m, --manifest <path>", "manifest file path", `./block-pack/${ManifestFileName}`);
|
|
49
|
+
cmd.option("-v, --version-override <path>", "override package version");
|
|
50
|
+
cmd.addOption(
|
|
51
|
+
new Option("--refresh", "refresh repository after adding the package")
|
|
52
|
+
.default(true)
|
|
53
|
+
.env("PL_REGISTRY_REFRESH"),
|
|
54
|
+
);
|
|
55
|
+
cmd.option("--no-refresh", "do not refresh repository after adding the package");
|
|
56
|
+
cmd.addOption(
|
|
57
|
+
new Option("--unstable", "do not add the published package to stable channel")
|
|
58
|
+
.default(false)
|
|
59
|
+
.env("PL_PUBLISH_UNSTABLE"),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
cmd.action(async (flags) => {
|
|
63
|
+
const logger = new ConsoleLoggerAdapter();
|
|
79
64
|
|
|
80
65
|
const manifestPath = path.resolve(flags.manifest);
|
|
81
66
|
const rawManifest = JSON.parse(
|
|
@@ -89,23 +74,24 @@ export default class Publish extends Command {
|
|
|
89
74
|
);
|
|
90
75
|
const manifestRoot = path.dirname(manifestPath);
|
|
91
76
|
|
|
92
|
-
|
|
77
|
+
logger.info(`Manifest root = ${manifestRoot}`);
|
|
93
78
|
|
|
94
|
-
if (flags
|
|
95
|
-
manifest = overrideManifestVersion(manifest, flags["version-override"]);
|
|
79
|
+
if (flags.versionOverride) manifest = overrideManifestVersion(manifest, flags.versionOverride);
|
|
96
80
|
|
|
97
81
|
const storage = storageByUrl(flags.registry);
|
|
98
|
-
const registry = new BlockRegistryV2(storage,
|
|
82
|
+
const registry = new BlockRegistryV2(storage, logger);
|
|
99
83
|
|
|
100
84
|
await registry.publishPackage(manifest, async (file) =>
|
|
101
85
|
Buffer.from(await fs.promises.readFile(path.resolve(manifestRoot, file))),
|
|
102
86
|
);
|
|
103
87
|
|
|
104
88
|
if (!flags.unstable) {
|
|
105
|
-
|
|
89
|
+
logger.info(`Adding package to ${StableChannel} channel...`);
|
|
106
90
|
await registry.addPackageToChannel(manifest.description.id, StableChannel);
|
|
107
91
|
}
|
|
108
92
|
|
|
109
93
|
if (flags.refresh) await registry.updateIfNeeded();
|
|
110
|
-
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return cmd;
|
|
111
97
|
}
|