@sdk-it/cli 0.14.2 → 0.14.4

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/dist/index.js CHANGED
@@ -30,7 +30,12 @@ async function loadRemote(location) {
30
30
  return parse(text);
31
31
  }
32
32
  default:
33
- throw new Error(`Unsupported file extension: ${extName}`);
33
+ try {
34
+ return response.json();
35
+ } catch {
36
+ const text = await response.text();
37
+ return parse(text);
38
+ }
34
39
  }
35
40
  }
36
41
  async function loadLocal(location) {
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/lib/cli.ts", "../src/lib/generate.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\nimport { Command, program } from 'commander';\n\nimport generate from './generate.ts';\n\nconst cli = program\n .description(`CLI tool to interact with SDK-IT.`)\n .addCommand(generate, { isDefault: true })\n .addCommand(\n new Command('_internal').action(() => {\n // do nothing\n }),\n { hidden: true },\n )\n .parse(process.argv);\n\nexport default cli;\n", "import { Command, Option } from 'commander';\nimport { execFile } from 'node:child_process';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { parse } from 'yaml';\n\nimport { generate } from '@sdk-it/typescript';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n framework?: string;\n}\n\nconst specOption = new Option(\n '-s, --spec <spec>',\n 'Path to OpenAPI specification file',\n);\n\nconst outputOption = new Option(\n '-o, --output <output>',\n 'Output directory for the generated SDK',\n);\n\nasync function loadRemote(location: string) {\n const extName = extname(location);\n const response = await fetch(location);\n switch (extName) {\n case '.json':\n return response.json();\n case '.yaml':\n case '.yml': {\n const text = await response.text();\n return parse(text);\n }\n default:\n throw new Error(`Unsupported file extension: ${extName}`);\n }\n}\n\nasync function loadLocal(location: string) {\n const extName = extname(location);\n switch (extName) {\n case '.json':\n return import(location);\n case '.yaml':\n case '.yml': {\n const text = await await readFile(location, 'utf-8');\n return parse(text);\n }\n default:\n throw new Error(`Unsupported file extension: ${extName}`);\n }\n}\n\nfunction loadSpec(location: string) {\n const [protocol] = location.split(':');\n if (protocol === 'http' || protocol === 'https') {\n return loadRemote(location);\n }\n return loadLocal(location);\n}\n\nexport default new Command('generate')\n .description(`Generate SDK out of a openapi spec file.`)\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option(\n '--useTsExtension [value]',\n 'Use .ts extension for generated files',\n (value) => (value === 'false' ? false : true),\n true,\n )\n .option('-l, --language <language>', 'Programming language for the SDK')\n .option(\n '-m, --mode <mode>',\n 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option(\n '-f, --framework <framework>',\n 'Framework that is integrating with the SDK',\n )\n .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'minimal',\n name: options.name,\n useTsExtension: options.useTsExtension,\n formatCode: ({ env, output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, { env: { ...env, SDK_IT_OUTPUT: output } });\n }\n },\n });\n });\n"],
5
- "mappings": ";;;AACA,SAAS,WAAAA,UAAS,eAAe;;;ACDjC,SAAS,SAAS,cAAc;AAChC,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AAkBzB,IAAM,aAAa,IAAI;AAAA,EACrB;AAAA,EACA;AACF;AAEA,IAAM,eAAe,IAAI;AAAA,EACvB;AAAA,EACA;AACF;AAEA,eAAe,WAAW,UAAkB;AA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,SAAS,QAAQ,IAAI;AACxC,QAAM,SAAS,MAAM;AAAA,IACnB,QAAQ,QAAQ;AAAA,IAChB,MAAM,QAAQ,QAAQ;AAAA,IACtB,MAAM,QAAQ;AAAA,IACd,gBAAgB,QAAQ;AAAA,IACxB,YAAY,CAAC,EAAE,KAAK,OAAO,MAAM;AAC/B,UAAI,QAAQ,WAAW;AACrB,cAAM,CAAC,SAAS,GAAG,IAAI,IAAI,QAAQ,UAAU,MAAM,GAAG;AACtD,iBAAS,SAAS,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,eAAe,OAAO,EAAE,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;;;ADvGH,IAAM,MAAM,QACT,YAAY,mCAAmC,EAC/C,WAAW,kBAAU,EAAE,WAAW,KAAK,CAAC,EACxC;AAAA,EACC,IAAIC,SAAQ,WAAW,EAAE,OAAO,MAAM;AAAA,EAEtC,CAAC;AAAA,EACD,EAAE,QAAQ,KAAK;AACjB,EACC,MAAM,QAAQ,IAAI;",
4
+ "sourcesContent": ["#!/usr/bin/env node\nimport { Command, program } from 'commander';\n\nimport generate from './generate.ts';\n\nconst cli = program\n .description(`CLI tool to interact with SDK-IT.`)\n .addCommand(generate, { isDefault: true })\n .addCommand(\n new Command('_internal').action(() => {\n // do nothing\n }),\n { hidden: true },\n )\n .parse(process.argv);\n\nexport default cli;\n", "import { Command, Option } from 'commander';\nimport { execFile } from 'node:child_process';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport { parse } from 'yaml';\n\nimport { generate } from '@sdk-it/typescript';\n\ninterface Options {\n spec: string;\n output: string;\n language: string;\n mode?: 'full' | 'minimal';\n name?: string;\n useTsExtension: boolean;\n /**\n * Command to run the formatter.\n * @example 'biome check $SDK_IT_OUTPUT --write'\n * @example 'prettier $SDK_IT_OUTPUT --write'\n */\n formatter?: string;\n framework?: string;\n}\n\nconst specOption = new Option(\n '-s, --spec <spec>',\n 'Path to OpenAPI specification file',\n);\n\nconst outputOption = new Option(\n '-o, --output <output>',\n 'Output directory for the generated SDK',\n);\n\nasync function loadRemote(location: string) {\n const extName = extname(location);\n const response = await fetch(location);\n switch (extName) {\n case '.json':\n return response.json();\n case '.yaml':\n case '.yml': {\n const text = await response.text();\n return parse(text);\n }\n default:\n try {\n // try to parse it as json first\n return response.json();\n } catch {\n // parse as yaml\n const text = await response.text();\n return parse(text);\n }\n }\n}\n\nasync function loadLocal(location: string) {\n const extName = extname(location);\n switch (extName) {\n case '.json':\n return import(location);\n case '.yaml':\n case '.yml': {\n const text = await await readFile(location, 'utf-8');\n return parse(text);\n }\n default:\n throw new Error(`Unsupported file extension: ${extName}`);\n }\n}\n\nfunction loadSpec(location: string) {\n const [protocol] = location.split(':');\n if (protocol === 'http' || protocol === 'https') {\n return loadRemote(location);\n }\n return loadLocal(location);\n}\n\nexport default new Command('generate')\n .description(`Generate SDK out of a openapi spec file.`)\n .addOption(specOption.makeOptionMandatory(true))\n .addOption(outputOption.makeOptionMandatory(true))\n .option(\n '--useTsExtension [value]',\n 'Use .ts extension for generated files',\n (value) => (value === 'false' ? false : true),\n true,\n )\n .option('-l, --language <language>', 'Programming language for the SDK')\n .option(\n '-m, --mode <mode>',\n 'full: generate a full project including package.json and tsconfig.json. useful for monorepo/workspaces minimal: generate only the client sdk',\n )\n .option('-n, --name <name>', 'Name of the generated client', 'Client')\n .option(\n '-f, --framework <framework>',\n 'Framework that is integrating with the SDK',\n )\n .option('--formatter <formatter>', 'Formatter to use for the generated code')\n .action(async (options: Options) => {\n const spec = await loadSpec(options.spec);\n await generate(spec, {\n output: options.output,\n mode: options.mode || 'minimal',\n name: options.name,\n useTsExtension: options.useTsExtension,\n formatCode: ({ env, output }) => {\n if (options.formatter) {\n const [command, ...args] = options.formatter.split(' ');\n execFile(command, args, { env: { ...env, SDK_IT_OUTPUT: output } });\n }\n },\n });\n });\n"],
5
+ "mappings": ";;;AACA,SAAS,WAAAA,UAAS,eAAe;;;ACDj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AC,EAC9C,UAAU,aAAa,oBAAoB,IAAI,CAAC,EAChD;AAAA,EACC;AAAA,EACA;AAAA,EACA,CAAC,UAAW,UAAU,UAAU,QAAQ;AAAA,EACxC;AACF,EACC,OAAO,6BAA6B,kCAAkC,EACtE;AAAA,EACC;AAAA,EACA;AACF,EACC,OAAO,qBAAqB,gCAAgC,QAAQ,EACpE;AAAA,EACC;AAAA,EACA;AACF,EACC,OAAO,2BAA2B,yCAAyC,EAC3E,OAAO,OAAO,YAAqB;AAClC,QAAM,OAAO,MAAM,SAAS,QAAQ,IAAI;AACxC,QAAM,SAAS,MAAM;AAAA,IACnB,QAAQ,QAAQ;AAAA,IAChB,MAAM,QAAQ,QAAQ;AAAA,IACtB,MAAM,QAAQ;AAAA,IACd,gBAAgB,QAAQ;AAAA,IACxB,YAAY,CAAC,EAAE,KAAK,OAAO,MAAM;AAC/B,UAAI,QAAQ,WAAW;AACrB,cAAM,CAAC,SAAS,GAAG,IAAI,IAAI,QAAQ,UAAU,MAAM,GAAG;AACtD,iBAAS,SAAS,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,eAAe,OAAO,EAAE,CAAC;AAAA,MACpE;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;;;AD9GH,IAAM,MAAM,QACT,YAAY,mCAAmC,EAC/C,WAAW,kBAAU,EAAE,WAAW,KAAK,CAAC,EACxC;AAAA,EACC,IAAIC,SAAQ,WAAW,EAAE,OAAO,MAAM;AAAA,EAEtC,CAAC;AAAA,EACD,EAAE,QAAQ,KAAK;AACjB,EACC,MAAM,QAAQ,IAAI;",
6
6
  "names": ["Command", "Command"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/lib/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;;AAyE5C,wBAmCK"}
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/lib/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;;AAgF5C,wBAmCK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdk-it/cli",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "commander": "^13.1.0",
23
- "@sdk-it/typescript": "0.14.2",
23
+ "@sdk-it/typescript": "0.14.4",
24
24
  "yaml": "^2.7.0"
25
25
  },
26
26
  "publishConfig": {