@kubb/cli 0.14.1 → 0.19.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.
- package/dist/index.js +34 -15
- package/dist/index.mjs +35 -16
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ var cosmiconfig = require('cosmiconfig');
|
|
|
6
6
|
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
7
7
|
var pc2 = require('picocolors');
|
|
8
8
|
var ora = require('ora');
|
|
9
|
+
var execa = require('execa');
|
|
10
|
+
var stringArgv = require('string-argv');
|
|
9
11
|
var core = require('@kubb/core');
|
|
10
12
|
|
|
11
13
|
// src/utils/getPlugins.ts
|
|
@@ -16,31 +18,33 @@ var isJSONPlugins = (plugins) => {
|
|
|
16
18
|
};
|
|
17
19
|
var getPlugins = (plugins) => {
|
|
18
20
|
if (isJSONPlugins(plugins)) {
|
|
19
|
-
|
|
21
|
+
const promises = plugins.map(async (plugin) => {
|
|
20
22
|
const [name, options = {}] = plugin;
|
|
21
23
|
const importedPlugin = await import(name);
|
|
22
24
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
23
25
|
});
|
|
26
|
+
return Promise.all(promises);
|
|
24
27
|
}
|
|
25
|
-
return plugins;
|
|
28
|
+
return Promise.resolve(plugins);
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
// src/utils/createConfig.ts
|
|
29
|
-
var createConfig = async (result) => {
|
|
30
|
-
|
|
32
|
+
var createConfig = async (result, options) => {
|
|
33
|
+
const config = result?.config;
|
|
31
34
|
if (result?.filepath.endsWith(".json")) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
let JSONConfig = config;
|
|
36
|
+
JSONConfig = {
|
|
37
|
+
...JSONConfig,
|
|
38
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
35
39
|
};
|
|
36
|
-
return
|
|
40
|
+
return Promise.resolve(JSONConfig);
|
|
37
41
|
}
|
|
38
42
|
if (typeof config === "function") {
|
|
39
|
-
const possiblePromise = config();
|
|
40
|
-
if (
|
|
43
|
+
const possiblePromise = config(options);
|
|
44
|
+
if (core.isPromise(possiblePromise)) {
|
|
41
45
|
return possiblePromise;
|
|
42
46
|
}
|
|
43
|
-
return possiblePromise;
|
|
47
|
+
return Promise.resolve(possiblePromise);
|
|
44
48
|
}
|
|
45
49
|
return config;
|
|
46
50
|
};
|
|
@@ -58,16 +62,31 @@ async function run({ result, options, spinner: spinner2 }) {
|
|
|
58
62
|
};
|
|
59
63
|
try {
|
|
60
64
|
spinner2.start("Building");
|
|
61
|
-
const config = await createConfig(result);
|
|
65
|
+
const config = await createConfig(result, options);
|
|
62
66
|
await core.build({
|
|
63
67
|
config: {
|
|
64
|
-
|
|
68
|
+
root: process.cwd(),
|
|
65
69
|
...config
|
|
66
70
|
},
|
|
67
71
|
mode: options.mode || "development",
|
|
68
72
|
logger
|
|
69
73
|
});
|
|
70
74
|
spinner2.succeed(pc2.blue("Kubb generation done"));
|
|
75
|
+
if (config.hooks?.done) {
|
|
76
|
+
spinner2.start("Running hooks");
|
|
77
|
+
let commands = [];
|
|
78
|
+
if (typeof config.hooks?.done === "string") {
|
|
79
|
+
commands = [config.hooks.done];
|
|
80
|
+
} else {
|
|
81
|
+
commands = config.hooks.done;
|
|
82
|
+
}
|
|
83
|
+
const promises = commands.map(async (command) => {
|
|
84
|
+
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
85
|
+
return execa.execa(cmd, _args);
|
|
86
|
+
});
|
|
87
|
+
await Promise.all(promises);
|
|
88
|
+
spinner2.succeed("Running hooks completed");
|
|
89
|
+
}
|
|
71
90
|
} catch (err) {
|
|
72
91
|
spinner2.fail("Something went wrong\n");
|
|
73
92
|
console.error(err);
|
|
@@ -76,7 +95,7 @@ async function run({ result, options, spinner: spinner2 }) {
|
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
// package.json
|
|
79
|
-
var version = "0.
|
|
98
|
+
var version = "0.19.0";
|
|
80
99
|
|
|
81
100
|
// src/index.ts
|
|
82
101
|
var moduleName = "kubb";
|
|
@@ -102,7 +121,7 @@ var explorer = cosmiconfig.cosmiconfig(moduleName, {
|
|
|
102
121
|
noExt: cosmiconfig.defaultLoaders[".js"]
|
|
103
122
|
}
|
|
104
123
|
});
|
|
105
|
-
var program = new commander.Command(moduleName).description("
|
|
124
|
+
var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
|
|
106
125
|
spinner.succeed(pc2.blue("Kubb generation started"));
|
|
107
126
|
spinner.start("Loading config");
|
|
108
127
|
const result = options.config ? await explorer.load(options.config) : await explorer.search();
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,9 @@ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
|
4
4
|
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
|
|
5
5
|
import pc2 from 'picocolors';
|
|
6
6
|
import ora from 'ora';
|
|
7
|
-
import {
|
|
7
|
+
import { execa } from 'execa';
|
|
8
|
+
import { parseArgsStringToArgv } from 'string-argv';
|
|
9
|
+
import { build, isPromise } from '@kubb/core';
|
|
8
10
|
|
|
9
11
|
// src/utils/getPlugins.ts
|
|
10
12
|
var isJSONPlugins = (plugins) => {
|
|
@@ -14,31 +16,33 @@ var isJSONPlugins = (plugins) => {
|
|
|
14
16
|
};
|
|
15
17
|
var getPlugins = (plugins) => {
|
|
16
18
|
if (isJSONPlugins(plugins)) {
|
|
17
|
-
|
|
19
|
+
const promises = plugins.map(async (plugin) => {
|
|
18
20
|
const [name, options = {}] = plugin;
|
|
19
21
|
const importedPlugin = await import(name);
|
|
20
22
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
21
23
|
});
|
|
24
|
+
return Promise.all(promises);
|
|
22
25
|
}
|
|
23
|
-
return plugins;
|
|
26
|
+
return Promise.resolve(plugins);
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
// src/utils/createConfig.ts
|
|
27
|
-
var createConfig = async (result) => {
|
|
28
|
-
|
|
30
|
+
var createConfig = async (result, options) => {
|
|
31
|
+
const config = result?.config;
|
|
29
32
|
if (result?.filepath.endsWith(".json")) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
let JSONConfig = config;
|
|
34
|
+
JSONConfig = {
|
|
35
|
+
...JSONConfig,
|
|
36
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
33
37
|
};
|
|
34
|
-
return
|
|
38
|
+
return Promise.resolve(JSONConfig);
|
|
35
39
|
}
|
|
36
40
|
if (typeof config === "function") {
|
|
37
|
-
const possiblePromise = config();
|
|
38
|
-
if (
|
|
41
|
+
const possiblePromise = config(options);
|
|
42
|
+
if (isPromise(possiblePromise)) {
|
|
39
43
|
return possiblePromise;
|
|
40
44
|
}
|
|
41
|
-
return possiblePromise;
|
|
45
|
+
return Promise.resolve(possiblePromise);
|
|
42
46
|
}
|
|
43
47
|
return config;
|
|
44
48
|
};
|
|
@@ -56,16 +60,31 @@ async function run({ result, options, spinner: spinner2 }) {
|
|
|
56
60
|
};
|
|
57
61
|
try {
|
|
58
62
|
spinner2.start("Building");
|
|
59
|
-
const config = await createConfig(result);
|
|
63
|
+
const config = await createConfig(result, options);
|
|
60
64
|
await build({
|
|
61
65
|
config: {
|
|
62
|
-
|
|
66
|
+
root: process.cwd(),
|
|
63
67
|
...config
|
|
64
68
|
},
|
|
65
69
|
mode: options.mode || "development",
|
|
66
70
|
logger
|
|
67
71
|
});
|
|
68
72
|
spinner2.succeed(pc2.blue("Kubb generation done"));
|
|
73
|
+
if (config.hooks?.done) {
|
|
74
|
+
spinner2.start("Running hooks");
|
|
75
|
+
let commands = [];
|
|
76
|
+
if (typeof config.hooks?.done === "string") {
|
|
77
|
+
commands = [config.hooks.done];
|
|
78
|
+
} else {
|
|
79
|
+
commands = config.hooks.done;
|
|
80
|
+
}
|
|
81
|
+
const promises = commands.map(async (command) => {
|
|
82
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)];
|
|
83
|
+
return execa(cmd, _args);
|
|
84
|
+
});
|
|
85
|
+
await Promise.all(promises);
|
|
86
|
+
spinner2.succeed("Running hooks completed");
|
|
87
|
+
}
|
|
69
88
|
} catch (err) {
|
|
70
89
|
spinner2.fail("Something went wrong\n");
|
|
71
90
|
console.error(err);
|
|
@@ -74,7 +93,7 @@ async function run({ result, options, spinner: spinner2 }) {
|
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
// package.json
|
|
77
|
-
var version = "0.
|
|
96
|
+
var version = "0.19.0";
|
|
78
97
|
|
|
79
98
|
// src/index.ts
|
|
80
99
|
var moduleName = "kubb";
|
|
@@ -100,7 +119,7 @@ var explorer = cosmiconfig(moduleName, {
|
|
|
100
119
|
noExt: defaultLoaders[".js"]
|
|
101
120
|
}
|
|
102
121
|
});
|
|
103
|
-
var program = new Command(moduleName).description("
|
|
122
|
+
var program = new Command(moduleName).description("Kubb").action(async (options) => {
|
|
104
123
|
spinner.succeed(pc2.blue("Kubb generation started"));
|
|
105
124
|
spinner.start("Loading config");
|
|
106
125
|
const result = options.config ? await explorer.load(options.config) : await explorer.search();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,17 +20,19 @@
|
|
|
20
20
|
"!/**/__tests__/**"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@kubb/core": "0.
|
|
23
|
+
"@kubb/core": "0.19.0",
|
|
24
24
|
"commander": "^9.4.1",
|
|
25
25
|
"cosmiconfig": "^8.0.0",
|
|
26
26
|
"cosmiconfig-typescript-loader": "^4.3.0",
|
|
27
|
+
"execa": "^6.1.0",
|
|
27
28
|
"ora": "^6.1.2",
|
|
28
|
-
"picocolors": "^1.0.0"
|
|
29
|
+
"picocolors": "^1.0.0",
|
|
30
|
+
"string-argv": "^0.3.1"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
33
|
+
"@types/node": "^18.11.18",
|
|
31
34
|
"tsup": "^6.5.0",
|
|
32
|
-
"typescript": "^4.9.4"
|
|
33
|
-
"@types/node": "^18.11.18"
|
|
35
|
+
"typescript": "^4.9.4"
|
|
34
36
|
},
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public",
|