@kubb/cli 0.55.0 → 0.56.1

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/README.md CHANGED
@@ -4,13 +4,13 @@
4
4
  <h1>@kubb/cli</h1>
5
5
 
6
6
  <p>
7
- With Kubb you can create and use plugins that will generate code based on a specific input.
7
+ CLI package to generate the different clients when using the terminal.
8
8
  </p>
9
9
 
10
10
  <!-- Badges -->
11
11
  <p>
12
12
  <a href="https://www.npmjs.com/package/@kubb/cli">
13
- <img alt="Npm verssion" src="https://img.shields.io/npm/v/@kubb/cli?style=for-the-badge"/>
13
+ <img alt="Npm version" src="https://img.shields.io/npm/v/@kubb/cli?style=for-the-badge"/>
14
14
  </a>
15
15
  <a href="https://www.npmjs.com/package/@kubb/cli">
16
16
  <img alt="Npm downloads" src="https://img.shields.io/bundlephobia/min/@kubb/cli?style=for-the-badge"/>
package/dist/index.js CHANGED
@@ -1,23 +1,16 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import { createRequire } from 'module';
3
+ import { Command, Option } from 'commander';
4
+ import pc3 from 'picocolors';
5
+ import ora from 'ora';
6
+ import { execa } from 'execa';
7
+ import { parseArgsStringToArgv } from 'string-argv';
8
+ import { build, isPromise } from '@kubb/core';
9
+ import { ModuleImporter } from '@humanwhocodes/module-importer';
10
+ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
11
+ import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
3
12
 
4
- var module$1 = require('module');
5
- var commander = require('commander');
6
- var pc3 = require('picocolors');
7
- var ora = require('ora');
8
- var execa = require('execa');
9
- var stringArgv = require('string-argv');
10
- var core = require('@kubb/core');
11
- var moduleImporter = require('@humanwhocodes/module-importer');
12
- var cosmiconfig = require('cosmiconfig');
13
- var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
14
-
15
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
-
17
- var pc3__default = /*#__PURE__*/_interopDefault(pc3);
18
- var ora__default = /*#__PURE__*/_interopDefault(ora);
19
-
20
- module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
13
+ createRequire(import.meta.url);
21
14
  async function run({ config, options, spinner: spinner2 }) {
22
15
  const logger = {
23
16
  log(message, logLevel) {
@@ -40,15 +33,15 @@ async function run({ config, options, spinner: spinner2 }) {
40
33
  commands = config2.hooks.done;
41
34
  }
42
35
  const promises = commands.map(async (command) => {
43
- const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
44
- return execa.execa(cmd, _args);
36
+ const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
37
+ return execa(cmd, _args);
45
38
  });
46
39
  await Promise.all(promises);
47
40
  spinner2.succeed("\u{1FA82} Hooks runned");
48
41
  };
49
42
  try {
50
43
  spinner2.start("\u{1F680} Building");
51
- await core.build({
44
+ await build({
52
45
  config: {
53
46
  root: process.cwd(),
54
47
  ...config,
@@ -60,13 +53,16 @@ async function run({ config, options, spinner: spinner2 }) {
60
53
  mode: options.mode || "development",
61
54
  logger
62
55
  });
63
- spinner2.succeed(pc3__default.default.blue("\u{1F308} Generation complete"));
56
+ spinner2.succeed(pc3.blue("\u{1F308} Generation complete"));
64
57
  await onDone(config);
65
58
  } catch (err) {
66
- spinner2.fail(`Something went wrong
67
- ${err?.message}`);
68
59
  if (options.debug) {
69
- console.error(err);
60
+ spinner2.fail(`Something went wrong
61
+ `);
62
+ console.log(err?.cause || err);
63
+ } else {
64
+ spinner2.fail(`Something went wrong
65
+ ${err?.message}`);
70
66
  }
71
67
  }
72
68
  return true;
@@ -80,12 +76,12 @@ var startWatcher = async (cb, options) => {
80
76
  ignored
81
77
  });
82
78
  watcher.on("all", async (type, file) => {
83
- spinner2.succeed(pc3__default.default.yellow(pc3__default.default.bold(`Change detected: ${type} ${file}`)));
79
+ spinner2.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
84
80
  spinner2.spinner = "clock";
85
81
  try {
86
82
  await cb(options.path);
87
83
  } catch (e) {
88
- spinner2.warn(pc3__default.default.red(e));
84
+ spinner2.warn(pc3.red(e));
89
85
  }
90
86
  });
91
87
  };
@@ -95,7 +91,7 @@ var isJSONPlugins = (plugins) => {
95
91
  });
96
92
  };
97
93
  var importPlugin = async (name, options) => {
98
- const importer = new moduleImporter.ModuleImporter(process.cwd());
94
+ const importer = new ModuleImporter(process.cwd());
99
95
  const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
100
96
  return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
101
97
  };
@@ -116,7 +112,7 @@ var getConfig = async (result, options) => {
116
112
  let kubbUserConfig = Promise.resolve(config);
117
113
  if (typeof config === "function") {
118
114
  const possiblePromise = config(options);
119
- if (core.isPromise(possiblePromise)) {
115
+ if (isPromise(possiblePromise)) {
120
116
  kubbUserConfig = possiblePromise;
121
117
  }
122
118
  kubbUserConfig = Promise.resolve(possiblePromise);
@@ -129,7 +125,7 @@ var getConfig = async (result, options) => {
129
125
  return JSONConfig;
130
126
  };
131
127
  var getCosmiConfig = async (moduleName2, config) => {
132
- const explorer = cosmiconfig.cosmiconfig(moduleName2, {
128
+ const explorer = cosmiconfig(moduleName2, {
133
129
  cache: false,
134
130
  searchPlaces: [
135
131
  "package.json",
@@ -145,11 +141,11 @@ var getCosmiConfig = async (moduleName2, config) => {
145
141
  `${moduleName2}.config.ts`
146
142
  ],
147
143
  loaders: {
148
- ".ts": cosmiconfigTypescriptLoader.TypeScriptLoader({
144
+ ".ts": TypeScriptLoader({
149
145
  swc: true,
150
146
  typeCheck: false
151
147
  }),
152
- noExt: cosmiconfig.defaultLoaders[".js"]
148
+ noExt: defaultLoaders[".js"]
153
149
  }
154
150
  });
155
151
  const result = config ? await explorer.load(config) : await explorer.search();
@@ -160,16 +156,16 @@ var getCosmiConfig = async (moduleName2, config) => {
160
156
  };
161
157
 
162
158
  // package.json
163
- var version = "0.55.0";
159
+ var version = "0.56.1";
164
160
 
165
161
  // src/index.ts
166
162
  var moduleName = "kubb";
167
- var spinner = ora__default.default({
163
+ var spinner = ora({
168
164
  color: "blue",
169
- text: pc3__default.default.blue("\u{1F3CE}\uFE0F Kubb generation started"),
165
+ text: pc3.blue("\u{1F3CE}\uFE0F Kubb generation started"),
170
166
  spinner: "clock"
171
167
  }).start();
172
- var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
168
+ var program = new Command(moduleName).description("Kubb").action(async (options) => {
173
169
  try {
174
170
  spinner.start("\u{1F4BE} Loading config");
175
171
  const result = await getCosmiConfig(moduleName, options.config);
@@ -180,7 +176,7 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
180
176
  async (paths) => {
181
177
  await run({ config, spinner, options });
182
178
  spinner.spinner = "simpleDotsScrolling";
183
- spinner.start(pc3__default.default.yellow(pc3__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
179
+ spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
184
180
  },
185
181
  {
186
182
  spinner,
@@ -192,7 +188,7 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
192
188
  await run({ config, spinner, options });
193
189
  }
194
190
  } catch (e) {
195
- spinner.fail(pc3__default.default.red(e.message));
191
+ spinner.fail(pc3.red(e.message));
196
192
  }
197
- }).addOption(new commander.Option("-m, --mode <mode>", "Mode of Kubb, development or production").default("development")).addOption(new commander.Option("-c, --config <path>", "Path to @kubb config")).addOption(new commander.Option("-d, --debug", "Debug mode").default(false)).addOption(new commander.Option("-w, --watch", "Watch mode based on the input file"));
193
+ }).addOption(new Option("-m, --mode <mode>", "Mode of Kubb, development or production").default("development")).addOption(new Option("-c, --config <path>", "Path to @kubb config")).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file"));
198
194
  program.name(moduleName).description("Generate").version(version, "-v").parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/cli",
3
- "version": "0.55.0",
3
+ "version": "0.56.1",
4
4
  "description": "Generator cli",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,6 +17,10 @@
17
17
  "cli"
18
18
  ],
19
19
  "sideEffects": false,
20
+ "type": "module",
21
+ "main": "dist/index.mjs",
22
+ "module": "dist/index.mjs",
23
+ "types": "./dist/index.d.ts",
20
24
  "bin": {
21
25
  "kubb": "dist/index.mjs"
22
26
  },
@@ -28,10 +32,10 @@
28
32
  ],
29
33
  "dependencies": {
30
34
  "@humanwhocodes/module-importer": "^1.0.1",
31
- "@kubb/core": "0.55.0",
35
+ "@kubb/core": "0.56.1",
32
36
  "chokidar": "^3.5.3",
33
37
  "commander": "^10.0.0",
34
- "cosmiconfig": "^8.0.0",
38
+ "cosmiconfig": "^8.1.0",
35
39
  "cosmiconfig-typescript-loader": "^4.3.0",
36
40
  "execa": "^7.0.0",
37
41
  "ora": "^6.1.2",
@@ -40,8 +44,7 @@
40
44
  "ts-node": "^10.9.1"
41
45
  },
42
46
  "devDependencies": {
43
- "@kubb/swagger": "0.55.0",
44
- "@types/node": "^18.14.1",
47
+ "@types/node": "^18.14.2",
45
48
  "tsup": "^6.6.3",
46
49
  "typescript": "^4.9.5"
47
50
  },
@@ -49,15 +52,18 @@
49
52
  "access": "public",
50
53
  "registry": "https://registry.npmjs.org/"
51
54
  },
55
+ "engines": {
56
+ "node": "^12.17.0 || ^14.13 || >=16.0.0"
57
+ },
52
58
  "scripts": {
53
59
  "build": "tsup",
54
60
  "start": "tsup --watch",
55
61
  "release": "pnpm publish --no-git-check",
56
62
  "pre-commit": "echo 'pre-commit not configured'",
57
63
  "pre-push": "pnpm typecheck",
58
- "test": "jest --config ../../jest.config.js --passWithNoTests --runInBand --testPathPattern=packages/core/src",
59
- "test:local": "jest --config ../../jest.config.js --testPathPattern=packages/core/src --maxWorkers=50%",
60
- "test:watch": "jest --config ../../jest.config.js --testPathPattern=packages/core/src --maxWorkers=25% --watch",
64
+ "test": "jest --config ../../jest.config.ts --passWithNoTests --runInBand --testPathPattern=packages/cli/src",
65
+ "test:local": "jest --config ../../jest.config.ts --testPathPattern=packages/cli/src --maxWorkers=50%",
66
+ "test:watch": "jest --config ../../jest.config.ts --testPathPattern=packages/cli/src --maxWorkers=25% --watch",
61
67
  "upgrade": "ncu -u",
62
68
  "upgrade:local": "ncu --interactive --doctor",
63
69
  "typecheck": "tsc -p ./tsconfig.json --noEmit"
package/dist/index.mjs DELETED
@@ -1,191 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from 'module';
3
- import { Command, Option } from 'commander';
4
- import pc3 from 'picocolors';
5
- import ora from 'ora';
6
- import { execa } from 'execa';
7
- import { parseArgsStringToArgv } from 'string-argv';
8
- import { build, isPromise } from '@kubb/core';
9
- import { ModuleImporter } from '@humanwhocodes/module-importer';
10
- import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
11
- import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
12
-
13
- createRequire(import.meta.url);
14
- async function run({ config, options, spinner: spinner2 }) {
15
- const logger = {
16
- log(message, logLevel) {
17
- if (logLevel === "error") {
18
- spinner2.fail(message);
19
- }
20
- spinner2[logLevel](message);
21
- },
22
- spinner: spinner2
23
- };
24
- const onDone = async (config2) => {
25
- if (!config2.hooks?.done) {
26
- return;
27
- }
28
- spinner2.start("\u{1FA82} Running hooks");
29
- let commands = [];
30
- if (typeof config2.hooks?.done === "string") {
31
- commands = [config2.hooks.done];
32
- } else {
33
- commands = config2.hooks.done;
34
- }
35
- const promises = commands.map(async (command) => {
36
- const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
37
- return execa(cmd, _args);
38
- });
39
- await Promise.all(promises);
40
- spinner2.succeed("\u{1FA82} Hooks runned");
41
- };
42
- try {
43
- spinner2.start("\u{1F680} Building");
44
- await build({
45
- config: {
46
- root: process.cwd(),
47
- ...config,
48
- output: {
49
- write: true,
50
- ...config.output
51
- }
52
- },
53
- mode: options.mode || "development",
54
- logger
55
- });
56
- spinner2.succeed(pc3.blue("\u{1F308} Generation complete"));
57
- await onDone(config);
58
- } catch (err) {
59
- spinner2.fail(`Something went wrong
60
- ${err?.message}`);
61
- if (options.debug) {
62
- console.error(err);
63
- }
64
- }
65
- return true;
66
- }
67
- var startWatcher = async (cb, options) => {
68
- const { spinner: spinner2, path } = options;
69
- const { watch } = await import('chokidar');
70
- const ignored = ["**/{.git,node_modules}/**"];
71
- const watcher = watch(path, {
72
- ignorePermissionErrors: true,
73
- ignored
74
- });
75
- watcher.on("all", async (type, file) => {
76
- spinner2.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
77
- spinner2.spinner = "clock";
78
- try {
79
- await cb(options.path);
80
- } catch (e) {
81
- spinner2.warn(pc3.red(e));
82
- }
83
- });
84
- };
85
- var isJSONPlugins = (plugins) => {
86
- return !!plugins?.some((plugin) => {
87
- return typeof plugin?.[0] === "string";
88
- });
89
- };
90
- var importPlugin = async (name, options) => {
91
- const importer = new ModuleImporter(process.cwd());
92
- const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
93
- return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
94
- };
95
- var getPlugins = (plugins) => {
96
- if (isJSONPlugins(plugins)) {
97
- const promises = plugins.map(async (plugin) => {
98
- const [name, options = {}] = plugin;
99
- return importPlugin(name, options);
100
- });
101
- return Promise.all(promises);
102
- }
103
- return Promise.resolve(plugins);
104
- };
105
-
106
- // src/utils/getConfig.ts
107
- var getConfig = async (result, options) => {
108
- const config = result?.config;
109
- let kubbUserConfig = Promise.resolve(config);
110
- if (typeof config === "function") {
111
- const possiblePromise = config(options);
112
- if (isPromise(possiblePromise)) {
113
- kubbUserConfig = possiblePromise;
114
- }
115
- kubbUserConfig = Promise.resolve(possiblePromise);
116
- }
117
- let JSONConfig = await kubbUserConfig;
118
- JSONConfig = {
119
- ...JSONConfig,
120
- plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
121
- };
122
- return JSONConfig;
123
- };
124
- var getCosmiConfig = async (moduleName2, config) => {
125
- const explorer = cosmiconfig(moduleName2, {
126
- cache: false,
127
- searchPlaces: [
128
- "package.json",
129
- `.${moduleName2}rc`,
130
- `.${moduleName2}rc.json`,
131
- // commonjs
132
- `.${moduleName2}rc.js`,
133
- `.${moduleName2}rc.cjs`,
134
- `${moduleName2}.config.js`,
135
- `${moduleName2}.config.cjs`,
136
- // esm and typescript
137
- `.${moduleName2}rc.ts`,
138
- `${moduleName2}.config.ts`
139
- ],
140
- loaders: {
141
- ".ts": TypeScriptLoader({
142
- swc: true,
143
- typeCheck: false
144
- }),
145
- noExt: defaultLoaders[".js"]
146
- }
147
- });
148
- const result = config ? await explorer.load(config) : await explorer.search();
149
- if (result?.isEmpty || !result || !result.config) {
150
- throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
151
- }
152
- return result;
153
- };
154
-
155
- // package.json
156
- var version = "0.55.0";
157
-
158
- // src/index.ts
159
- var moduleName = "kubb";
160
- var spinner = ora({
161
- color: "blue",
162
- text: pc3.blue("\u{1F3CE}\uFE0F Kubb generation started"),
163
- spinner: "clock"
164
- }).start();
165
- var program = new Command(moduleName).description("Kubb").action(async (options) => {
166
- try {
167
- spinner.start("\u{1F4BE} Loading config");
168
- const result = await getCosmiConfig(moduleName, options.config);
169
- spinner.succeed("\u{1F4BE} Config loaded");
170
- if (options.watch) {
171
- const config = await getConfig(result, options);
172
- startWatcher(
173
- async (paths) => {
174
- await run({ config, spinner, options });
175
- spinner.spinner = "simpleDotsScrolling";
176
- spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
177
- },
178
- {
179
- spinner,
180
- path: [config.input.path]
181
- }
182
- );
183
- } else {
184
- const config = await getConfig(result, options);
185
- await run({ config, spinner, options });
186
- }
187
- } catch (e) {
188
- spinner.fail(pc3.red(e.message));
189
- }
190
- }).addOption(new Option("-m, --mode <mode>", "Mode of Kubb, development or production").default("development")).addOption(new Option("-c, --config <path>", "Path to @kubb config")).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file"));
191
- program.name(moduleName).description("Generate").version(version, "-v").parse();