@saltify/milky-generator 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/cli.mjs +46 -9
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -29461,7 +29461,7 @@ var import_cjs = (/* @__PURE__ */ __commonJSMin(((exports) => {
29461
29461
  }
29462
29462
  });
29463
29463
  })))();
29464
- var version = "0.2.1";
29464
+ var version = "0.3.0";
29465
29465
  var description = "Milky codegen CLI";
29466
29466
  //#endregion
29467
29467
  //#region src/cli.ts
@@ -29499,11 +29499,24 @@ const generators = [
29499
29499
  generate: generateTypeScriptZodSpec
29500
29500
  }
29501
29501
  ];
29502
- async function resolveProtocolOfVersion(version) {
29503
- if (version === "latest") return await fetch("https://cdn.jsdelivr.net/npm/@saltify/milky-protocol/dist/protocol.json").then((res) => res.json());
29504
- else if (version === "local") return ir;
29502
+ const cdns = [
29503
+ {
29504
+ name: "unpkg",
29505
+ generateUrl: (packageName, version) => `https://unpkg.com/${packageName}@${version}/dist/protocol.json`
29506
+ },
29507
+ {
29508
+ name: "esmsh",
29509
+ generateUrl: (packageName, version) => `https://esm.sh/${packageName}@${version}/dist/protocol.json`
29510
+ },
29511
+ {
29512
+ name: "jsdelivr",
29513
+ generateUrl: (packageName, version) => `https://cdn.jsdelivr.net/npm/${packageName}@${version}/dist/protocol.json`
29514
+ }
29515
+ ];
29516
+ async function resolveProtocolOfVersion(version, cdn) {
29517
+ if (version === "local") return ir;
29505
29518
  else {
29506
- const response = await fetch(`https://cdn.jsdelivr.net/npm/@saltify/milky-protocol@${version}/dist/protocol.json`);
29519
+ const response = await fetch(cdn.generateUrl("@saltify/milky-protocol", version));
29507
29520
  if (!response.ok) throw new Error(`Failed to fetch protocol of version ${version}: ${response.status} ${response.statusText}`);
29508
29521
  return await response.json();
29509
29522
  }
@@ -29521,22 +29534,29 @@ function serializeOutput(output) {
29521
29534
  description: "Generate a spec from Milky IR.",
29522
29535
  args: {
29523
29536
  generator: (0, import_cjs.positional)({
29537
+ displayName: "generator",
29524
29538
  type: import_cjs.string,
29525
- description: "The canonical name of the generator to run. Use \"list\" to see all available generators."
29539
+ description: "Name of the generator to run. Use \"list\" for all available generators."
29526
29540
  }),
29527
29541
  output: (0, import_cjs.option)({
29528
29542
  type: import_cjs.string,
29529
29543
  long: "output",
29530
29544
  short: "o",
29531
- description: "The output file path. If not specified, the generated spec will be printed to stdout.",
29545
+ description: "The output file path. The generator writes to stdout if not provided.",
29532
29546
  defaultValue: () => ""
29533
29547
  }),
29534
29548
  version: (0, import_cjs.option)({
29535
29549
  type: import_cjs.string,
29536
29550
  long: "version",
29537
29551
  short: "v",
29538
- description: "The version of the Milky IR to use. If not specified, the latest version (the version published with `latest` tag on npm) will be used.",
29552
+ description: "The version of the Milky IR to use. Latest stable version if not specified.",
29539
29553
  defaultValue: () => "latest"
29554
+ }),
29555
+ cdn: (0, import_cjs.option)({
29556
+ type: import_cjs.string,
29557
+ long: "cdn",
29558
+ description: `The CDN to fetch the protocol definition from. "${cdns[0].name}" if not specified.`,
29559
+ defaultValue: () => cdns[0].name
29540
29560
  })
29541
29561
  },
29542
29562
  handler: async (args) => {
@@ -29546,7 +29566,13 @@ function serializeOutput(output) {
29546
29566
  console.error("Use \"milkygen list\" to see all available generators.");
29547
29567
  process.exit(1);
29548
29568
  }
29549
- const protocol = await resolveProtocolOfVersion(args.version);
29569
+ const cdnSpec = cdns.find((c) => c.name === args.cdn);
29570
+ if (!cdnSpec) {
29571
+ console.error(`Unknown CDN: ${args.cdn}`);
29572
+ console.error(`Use "milkygen list-cdns" to see all supported CDNs.`);
29573
+ process.exit(1);
29574
+ }
29575
+ const protocol = await resolveProtocolOfVersion(args.version, cdnSpec);
29550
29576
  const content = serializeOutput(await spec.generate(protocol));
29551
29577
  if (args.output.length === 0) {
29552
29578
  process.stdout.write(content);
@@ -29572,6 +29598,17 @@ function serializeOutput(output) {
29572
29598
  });
29573
29599
  }
29574
29600
  }),
29601
+ "list-cdns": (0, import_cjs.command)({
29602
+ name: "list-cdns",
29603
+ description: "List all supported CDNs to fetch protocol definitions from.",
29604
+ args: {},
29605
+ handler: () => {
29606
+ console.log("Supported CDNs:");
29607
+ cdns.forEach((cdn) => {
29608
+ console.log(` - ${cdn.name}`);
29609
+ });
29610
+ }
29611
+ }),
29575
29612
  version: (0, import_cjs.command)({
29576
29613
  name: "version",
29577
29614
  description: "Print the version of milkygen.",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saltify/milky-generator",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "description": "Milky codegen CLI",
6
6
  "bin": {
7
7
  "milkygen": "dist/cli.mjs"