@kubb/cli 0.56.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/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,7 +53,7 @@ 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
59
  if (options.debug) {
@@ -83,12 +76,12 @@ var startWatcher = async (cb, options) => {
83
76
  ignored
84
77
  });
85
78
  watcher.on("all", async (type, file) => {
86
- 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}`)));
87
80
  spinner2.spinner = "clock";
88
81
  try {
89
82
  await cb(options.path);
90
83
  } catch (e) {
91
- spinner2.warn(pc3__default.default.red(e));
84
+ spinner2.warn(pc3.red(e));
92
85
  }
93
86
  });
94
87
  };
@@ -98,7 +91,7 @@ var isJSONPlugins = (plugins) => {
98
91
  });
99
92
  };
100
93
  var importPlugin = async (name, options) => {
101
- const importer = new moduleImporter.ModuleImporter(process.cwd());
94
+ const importer = new ModuleImporter(process.cwd());
102
95
  const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
103
96
  return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
104
97
  };
@@ -119,7 +112,7 @@ var getConfig = async (result, options) => {
119
112
  let kubbUserConfig = Promise.resolve(config);
120
113
  if (typeof config === "function") {
121
114
  const possiblePromise = config(options);
122
- if (core.isPromise(possiblePromise)) {
115
+ if (isPromise(possiblePromise)) {
123
116
  kubbUserConfig = possiblePromise;
124
117
  }
125
118
  kubbUserConfig = Promise.resolve(possiblePromise);
@@ -132,7 +125,7 @@ var getConfig = async (result, options) => {
132
125
  return JSONConfig;
133
126
  };
134
127
  var getCosmiConfig = async (moduleName2, config) => {
135
- const explorer = cosmiconfig.cosmiconfig(moduleName2, {
128
+ const explorer = cosmiconfig(moduleName2, {
136
129
  cache: false,
137
130
  searchPlaces: [
138
131
  "package.json",
@@ -148,11 +141,11 @@ var getCosmiConfig = async (moduleName2, config) => {
148
141
  `${moduleName2}.config.ts`
149
142
  ],
150
143
  loaders: {
151
- ".ts": cosmiconfigTypescriptLoader.TypeScriptLoader({
144
+ ".ts": TypeScriptLoader({
152
145
  swc: true,
153
146
  typeCheck: false
154
147
  }),
155
- noExt: cosmiconfig.defaultLoaders[".js"]
148
+ noExt: defaultLoaders[".js"]
156
149
  }
157
150
  });
158
151
  const result = config ? await explorer.load(config) : await explorer.search();
@@ -163,16 +156,16 @@ var getCosmiConfig = async (moduleName2, config) => {
163
156
  };
164
157
 
165
158
  // package.json
166
- var version = "0.56.0";
159
+ var version = "0.56.1";
167
160
 
168
161
  // src/index.ts
169
162
  var moduleName = "kubb";
170
- var spinner = ora__default.default({
163
+ var spinner = ora({
171
164
  color: "blue",
172
- text: pc3__default.default.blue("\u{1F3CE}\uFE0F Kubb generation started"),
165
+ text: pc3.blue("\u{1F3CE}\uFE0F Kubb generation started"),
173
166
  spinner: "clock"
174
167
  }).start();
175
- var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
168
+ var program = new Command(moduleName).description("Kubb").action(async (options) => {
176
169
  try {
177
170
  spinner.start("\u{1F4BE} Loading config");
178
171
  const result = await getCosmiConfig(moduleName, options.config);
@@ -183,7 +176,7 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
183
176
  async (paths) => {
184
177
  await run({ config, spinner, options });
185
178
  spinner.spinner = "simpleDotsScrolling";
186
- 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 ")}`)));
187
180
  },
188
181
  {
189
182
  spinner,
@@ -195,7 +188,7 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
195
188
  await run({ config, spinner, options });
196
189
  }
197
190
  } catch (e) {
198
- spinner.fail(pc3__default.default.red(e.message));
191
+ spinner.fail(pc3.red(e.message));
199
192
  }
200
- }).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"));
201
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.56.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.56.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.56.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,194 +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
- if (options.debug) {
60
- spinner2.fail(`Something went wrong
61
- `);
62
- console.log(err?.cause || err);
63
- } else {
64
- spinner2.fail(`Something went wrong
65
- ${err?.message}`);
66
- }
67
- }
68
- return true;
69
- }
70
- var startWatcher = async (cb, options) => {
71
- const { spinner: spinner2, path } = options;
72
- const { watch } = await import('chokidar');
73
- const ignored = ["**/{.git,node_modules}/**"];
74
- const watcher = watch(path, {
75
- ignorePermissionErrors: true,
76
- ignored
77
- });
78
- watcher.on("all", async (type, file) => {
79
- spinner2.succeed(pc3.yellow(pc3.bold(`Change detected: ${type} ${file}`)));
80
- spinner2.spinner = "clock";
81
- try {
82
- await cb(options.path);
83
- } catch (e) {
84
- spinner2.warn(pc3.red(e));
85
- }
86
- });
87
- };
88
- var isJSONPlugins = (plugins) => {
89
- return !!plugins?.some((plugin) => {
90
- return typeof plugin?.[0] === "string";
91
- });
92
- };
93
- var importPlugin = async (name, options) => {
94
- const importer = new ModuleImporter(process.cwd());
95
- const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
96
- return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
97
- };
98
- var getPlugins = (plugins) => {
99
- if (isJSONPlugins(plugins)) {
100
- const promises = plugins.map(async (plugin) => {
101
- const [name, options = {}] = plugin;
102
- return importPlugin(name, options);
103
- });
104
- return Promise.all(promises);
105
- }
106
- return Promise.resolve(plugins);
107
- };
108
-
109
- // src/utils/getConfig.ts
110
- var getConfig = async (result, options) => {
111
- const config = result?.config;
112
- let kubbUserConfig = Promise.resolve(config);
113
- if (typeof config === "function") {
114
- const possiblePromise = config(options);
115
- if (isPromise(possiblePromise)) {
116
- kubbUserConfig = possiblePromise;
117
- }
118
- kubbUserConfig = Promise.resolve(possiblePromise);
119
- }
120
- let JSONConfig = await kubbUserConfig;
121
- JSONConfig = {
122
- ...JSONConfig,
123
- plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
124
- };
125
- return JSONConfig;
126
- };
127
- var getCosmiConfig = async (moduleName2, config) => {
128
- const explorer = cosmiconfig(moduleName2, {
129
- cache: false,
130
- searchPlaces: [
131
- "package.json",
132
- `.${moduleName2}rc`,
133
- `.${moduleName2}rc.json`,
134
- // commonjs
135
- `.${moduleName2}rc.js`,
136
- `.${moduleName2}rc.cjs`,
137
- `${moduleName2}.config.js`,
138
- `${moduleName2}.config.cjs`,
139
- // esm and typescript
140
- `.${moduleName2}rc.ts`,
141
- `${moduleName2}.config.ts`
142
- ],
143
- loaders: {
144
- ".ts": TypeScriptLoader({
145
- swc: true,
146
- typeCheck: false
147
- }),
148
- noExt: defaultLoaders[".js"]
149
- }
150
- });
151
- const result = config ? await explorer.load(config) : await explorer.search();
152
- if (result?.isEmpty || !result || !result.config) {
153
- throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
154
- }
155
- return result;
156
- };
157
-
158
- // package.json
159
- var version = "0.56.0";
160
-
161
- // src/index.ts
162
- var moduleName = "kubb";
163
- var spinner = ora({
164
- color: "blue",
165
- text: pc3.blue("\u{1F3CE}\uFE0F Kubb generation started"),
166
- spinner: "clock"
167
- }).start();
168
- var program = new Command(moduleName).description("Kubb").action(async (options) => {
169
- try {
170
- spinner.start("\u{1F4BE} Loading config");
171
- const result = await getCosmiConfig(moduleName, options.config);
172
- spinner.succeed("\u{1F4BE} Config loaded");
173
- if (options.watch) {
174
- const config = await getConfig(result, options);
175
- startWatcher(
176
- async (paths) => {
177
- await run({ config, spinner, options });
178
- spinner.spinner = "simpleDotsScrolling";
179
- spinner.start(pc3.yellow(pc3.bold(`Watching for changes in ${paths.join(" and ")}`)));
180
- },
181
- {
182
- spinner,
183
- path: [config.input.path]
184
- }
185
- );
186
- } else {
187
- const config = await getConfig(result, options);
188
- await run({ config, spinner, options });
189
- }
190
- } catch (e) {
191
- spinner.fail(pc3.red(e.message));
192
- }
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"));
194
- program.name(moduleName).description("Generate").version(version, "-v").parse();