@platforma-sdk/block-tools 2.11.1 → 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.
Files changed (48) hide show
  1. package/bin/run.js +9 -5
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.js +12 -12
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +740 -930
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/cmd/build-meta.d.ts +2 -9
  8. package/dist/cmd/build-model.d.ts +2 -10
  9. package/dist/cmd/list-overview-snapshots.d.ts +2 -9
  10. package/dist/cmd/mark-stable.d.ts +2 -13
  11. package/dist/cmd/pack.d.ts +2 -9
  12. package/dist/cmd/publish.d.ts +2 -12
  13. package/dist/cmd/refresh-registry.d.ts +2 -9
  14. package/dist/cmd/restore-overview-from-snapshot.d.ts +2 -10
  15. package/dist/cmd/structure/check.d.ts +2 -10
  16. package/dist/cmd/structure/init.d.ts +2 -18
  17. package/dist/cmd/structure/refresh.d.ts +10 -11
  18. package/dist/cmd/update-deps.d.ts +2 -6
  19. package/dist/cmd/upload-package-v1.d.ts +2 -14
  20. package/dist/config-DpfTzcgG.mjs.map +1 -1
  21. package/dist/config-xxVy3IQR.js.map +1 -1
  22. package/dist/registry_v1/config_schema.d.ts +7 -7
  23. package/dist/registry_v1/flags.d.ts +2 -4
  24. package/dist/structure/cli/run-structure.d.ts +1 -1
  25. package/dist/v2/registry/schema_public.d.ts +3600 -3600
  26. package/package.json +7 -22
  27. package/src/cli.test.ts +56 -0
  28. package/src/cli.ts +50 -0
  29. package/src/cmd/build-meta.ts +11 -22
  30. package/src/cmd/build-model.ts +16 -33
  31. package/src/cmd/list-overview-snapshots.ts +24 -28
  32. package/src/cmd/mark-stable.ts +35 -55
  33. package/src/cmd/pack.ts +11 -22
  34. package/src/cmd/publish.ts +35 -49
  35. package/src/cmd/refresh-registry.ts +22 -26
  36. package/src/cmd/restore-overview-from-snapshot.ts +24 -34
  37. package/src/cmd/structure/check.ts +19 -28
  38. package/src/cmd/structure/init.ts +40 -47
  39. package/src/cmd/structure/refresh.ts +45 -36
  40. package/src/cmd/update-deps.ts +22 -12
  41. package/src/cmd/upload-package-v1.ts +42 -60
  42. package/src/registry_v1/flags.ts +7 -7
  43. package/src/structure/cli/run-structure.ts +2 -2
  44. package/src/v2/model/content_conversion.ts +0 -1
  45. package/bin/dev.cmd +0 -3
  46. package/bin/dev.js +0 -6
  47. package/dist/cmd/index.d.ts +0 -28
  48. 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.1",
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",
@@ -34,13 +34,12 @@
34
34
  "yaml": "^2.8.0",
35
35
  "zod": "~3.25.76",
36
36
  "@milaboratories/pl-http": "1.2.4",
37
+ "@milaboratories/pl-model-middle-layer": "1.30.8",
37
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
- "@milaboratories/pl-model-middle-layer": "1.30.7",
41
- "@milaboratories/ts-helpers-oclif": "1.1.42",
40
+ "@milaboratories/resolve-helper": "1.1.3",
42
41
  "@platforma-sdk/blocks-deps-updater": "2.2.0",
43
- "@milaboratories/resolve-helper": "1.1.3"
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
- "@milaboratories/ts-builder": "1.5.2",
62
- "@milaboratories/ts-configs": "1.2.3"
63
- },
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": " "
58
+ "@milaboratories/ts-configs": "1.2.3",
59
+ "@milaboratories/ts-builder": "1.5.2"
73
60
  },
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",
@@ -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
+ }
@@ -1,32 +1,19 @@
1
- import { Command, Flags } from "@oclif/core";
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 default class BuildMeta extends Command {
8
- static override description =
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
- "and textual information linked from the meta section.";
10
+ "and textual information linked from the meta section.",
11
+ );
11
12
 
12
- static flags = {
13
- modulePath: Flags.string({
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
- destination: Flags.string({
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
  }
@@ -1,4 +1,4 @@
1
- import { Command, Flags } from "@oclif/core";
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 default class BuildModel extends Command {
17
- static override description =
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
- static flags = {
21
- modulePath: Flags.string({
22
- char: "i",
23
- summary: "input module path",
24
- helpValue: "<path>",
25
- default: ".",
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
- sourceBundle: Flags.string({
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, Flags } from "@oclif/core";
1
+ import { Command, Option } from "commander";
2
2
  import { BlockRegistryV2 } from "../v2/registry/registry";
3
3
  import { storageByUrl } from "../io/storage";
4
- import { OclifLoggerAdapter } from "@milaboratories/ts-helpers-oclif";
4
+ import { ConsoleLoggerAdapter } from "@milaboratories/ts-helpers";
5
5
 
6
- export default class ListOverviewSnapshots extends Command {
7
- static description = "List all available global overview snapshots in the registry";
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
- static flags = {
10
- registry: Flags.string({
11
- char: "r",
12
- summary: "full address of the registry",
13
- helpValue: "<address>",
14
- env: "PL_REGISTRY",
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
- json: Flags.boolean({
19
- summary: "output in JSON format",
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, new OclifLoggerAdapter(this));
21
+ const registry = new BlockRegistryV2(storage, logger);
28
22
 
29
23
  const snapshots = await registry.listGlobalOverviewSnapshots();
30
24
 
31
25
  if (flags.json) {
32
- this.log(JSON.stringify(snapshots, null, 2));
26
+ logger.info(JSON.stringify(snapshots, null, 2));
33
27
  } else {
34
28
  if (snapshots.length === 0) {
35
- this.log("No snapshots found.");
29
+ logger.info("No snapshots found.");
36
30
  } else {
37
- this.log(`Found ${snapshots.length} snapshot(s):\n`);
31
+ logger.info(`Found ${snapshots.length} snapshot(s):\n`);
38
32
  for (const snapshot of snapshots) {
39
- this.log(` ${snapshot.timestamp}`);
40
- this.log(` Path: ${snapshot.path}`);
41
- this.log("");
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
  }
@@ -1,67 +1,47 @@
1
- import { Command, Flags } from "@oclif/core";
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 { OclifLoggerAdapter } from "@milaboratories/ts-helpers-oclif";
7
-
8
- export default class MarkStable extends Command {
9
- static description = "Mark target block stable";
10
-
11
- static flags = {
12
- modulePath: Flags.string({
13
- char: "i",
14
- summary: "input module path",
15
- helpValue: "<path>",
16
- default: ".",
17
- }),
18
-
19
- channel: Flags.string({
20
- char: "c",
21
- hidden: true,
22
- summary: "custom channel",
23
- helpValue: "<channel name>",
24
- default: StableChannel,
25
- }),
26
-
27
- "version-override": Flags.file({
28
- char: "v",
29
- summary: "override package version",
30
- }),
31
-
32
- registry: Flags.string({
33
- char: "r",
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["version-override"])
58
- description = overrideDescriptionVersion(description, flags["version-override"]);
35
+ if (flags.versionOverride)
36
+ description = overrideDescriptionVersion(description, flags.versionOverride);
59
37
  const storage = storageByUrl(flags.registry);
60
- const registry = new BlockRegistryV2(storage, new OclifLoggerAdapter(this));
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, Flags } from "@oclif/core";
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 default class PackBlock extends Command {
7
- static description =
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
- "references assets into a single folder";
9
+ "references assets into a single folder",
10
+ );
10
11
 
11
- static flags = {
12
- modulePath: Flags.string({
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
- destinationPath: Flags.string({
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
  }
@@ -1,6 +1,6 @@
1
- import { Command, Flags } from "@oclif/core";
1
+ import { Command, Option } from "commander";
2
2
  import fs from "node:fs";
3
- import { OclifLoggerAdapter } from "@milaboratories/ts-helpers-oclif";
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 default class Publish extends Command {
39
- static description =
40
- "Publishes the block package and refreshes the registry (for v2 block-pack schema)";
41
-
42
- static flags = {
43
- registry: Flags.string({
44
- char: "r",
45
- summary: "full address of the registry",
46
- helpValue: "<address>",
47
- env: "PL_REGISTRY",
48
- required: true,
49
- }),
50
-
51
- manifest: Flags.file({
52
- char: "m",
53
- summary: "manifest file path",
54
- exists: true,
55
- default: `./block-pack/${ManifestFileName}`,
56
- }),
57
-
58
- "version-override": Flags.file({
59
- char: "v",
60
- summary: "override package version",
61
- }),
62
-
63
- refresh: Flags.boolean({
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
- this.log(`Manifest root = ${manifestRoot}`);
77
+ logger.info(`Manifest root = ${manifestRoot}`);
93
78
 
94
- if (flags["version-override"])
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, new OclifLoggerAdapter(this));
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
- this.log(`Adding package to ${StableChannel} channel...`);
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
  }