@kubb/cli 0.14.0 → 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 +63 -61
- package/dist/index.mjs +57 -39
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
18
|
-
mod
|
|
19
|
-
));
|
|
2
|
+
'use strict';
|
|
20
3
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
var import_ora = __toESM(require("ora"));
|
|
30
|
-
var import_core = require("@kubb/core");
|
|
4
|
+
var commander = require('commander');
|
|
5
|
+
var cosmiconfig = require('cosmiconfig');
|
|
6
|
+
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
7
|
+
var pc2 = require('picocolors');
|
|
8
|
+
var ora = require('ora');
|
|
9
|
+
var execa = require('execa');
|
|
10
|
+
var stringArgv = require('string-argv');
|
|
11
|
+
var core = require('@kubb/core');
|
|
31
12
|
|
|
32
13
|
// src/utils/getPlugins.ts
|
|
33
14
|
var isJSONPlugins = (plugins) => {
|
|
@@ -37,75 +18,93 @@ var isJSONPlugins = (plugins) => {
|
|
|
37
18
|
};
|
|
38
19
|
var getPlugins = (plugins) => {
|
|
39
20
|
if (isJSONPlugins(plugins)) {
|
|
40
|
-
|
|
21
|
+
const promises = plugins.map(async (plugin) => {
|
|
41
22
|
const [name, options = {}] = plugin;
|
|
42
23
|
const importedPlugin = await import(name);
|
|
43
24
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
44
25
|
});
|
|
26
|
+
return Promise.all(promises);
|
|
45
27
|
}
|
|
46
|
-
return plugins;
|
|
28
|
+
return Promise.resolve(plugins);
|
|
47
29
|
};
|
|
48
30
|
|
|
49
31
|
// src/utils/createConfig.ts
|
|
50
|
-
var createConfig = async (result) => {
|
|
51
|
-
|
|
32
|
+
var createConfig = async (result, options) => {
|
|
33
|
+
const config = result?.config;
|
|
52
34
|
if (result?.filepath.endsWith(".json")) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
let JSONConfig = config;
|
|
36
|
+
JSONConfig = {
|
|
37
|
+
...JSONConfig,
|
|
38
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
56
39
|
};
|
|
57
|
-
return
|
|
40
|
+
return Promise.resolve(JSONConfig);
|
|
58
41
|
}
|
|
59
42
|
if (typeof config === "function") {
|
|
60
|
-
const possiblePromise = config();
|
|
61
|
-
if (
|
|
43
|
+
const possiblePromise = config(options);
|
|
44
|
+
if (core.isPromise(possiblePromise)) {
|
|
62
45
|
return possiblePromise;
|
|
63
46
|
}
|
|
64
|
-
return possiblePromise;
|
|
47
|
+
return Promise.resolve(possiblePromise);
|
|
65
48
|
}
|
|
66
49
|
return config;
|
|
67
50
|
};
|
|
68
51
|
|
|
69
52
|
// src/run.ts
|
|
70
|
-
async function run(result, options) {
|
|
71
|
-
const spinner = (0, import_ora.default)({
|
|
72
|
-
color: "blue",
|
|
73
|
-
text: import_picocolors.default.blue("Kubb generation started"),
|
|
74
|
-
spinner: "timeTravel"
|
|
75
|
-
}).start();
|
|
53
|
+
async function run({ result, options, spinner: spinner2 }) {
|
|
76
54
|
const logger = {
|
|
77
55
|
log(message, logLevel) {
|
|
78
56
|
if (logLevel === "error") {
|
|
79
|
-
|
|
57
|
+
spinner2.fail(message);
|
|
80
58
|
}
|
|
81
|
-
|
|
59
|
+
spinner2[logLevel](message);
|
|
82
60
|
},
|
|
83
|
-
spinner
|
|
61
|
+
spinner: spinner2
|
|
84
62
|
};
|
|
85
63
|
try {
|
|
86
|
-
|
|
87
|
-
await (
|
|
64
|
+
spinner2.start("Building");
|
|
65
|
+
const config = await createConfig(result, options);
|
|
66
|
+
await core.build({
|
|
88
67
|
config: {
|
|
89
|
-
|
|
68
|
+
root: process.cwd(),
|
|
90
69
|
...config
|
|
91
70
|
},
|
|
92
71
|
mode: options.mode || "development",
|
|
93
72
|
logger
|
|
94
73
|
});
|
|
95
|
-
|
|
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
|
+
}
|
|
96
90
|
} catch (err) {
|
|
97
|
-
|
|
91
|
+
spinner2.fail("Something went wrong\n");
|
|
98
92
|
console.error(err);
|
|
99
93
|
}
|
|
100
94
|
return true;
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
// package.json
|
|
104
|
-
var version = "0.
|
|
98
|
+
var version = "0.19.0";
|
|
105
99
|
|
|
106
100
|
// src/index.ts
|
|
107
101
|
var moduleName = "kubb";
|
|
108
|
-
var
|
|
102
|
+
var spinner = ora({
|
|
103
|
+
color: "blue",
|
|
104
|
+
text: pc2.blue("Kubb generation started"),
|
|
105
|
+
spinner: "timeTravel"
|
|
106
|
+
}).start();
|
|
107
|
+
var explorer = cosmiconfig.cosmiconfig(moduleName, {
|
|
109
108
|
searchPlaces: [
|
|
110
109
|
"package.json",
|
|
111
110
|
`.${moduleName}rc`,
|
|
@@ -118,16 +117,19 @@ var explorer = (0, import_cosmiconfig.cosmiconfig)(moduleName, {
|
|
|
118
117
|
`${moduleName}.config.ts`
|
|
119
118
|
],
|
|
120
119
|
loaders: {
|
|
121
|
-
".ts":
|
|
122
|
-
noExt:
|
|
120
|
+
".ts": cosmiconfigTypescriptLoader.TypeScriptLoader(),
|
|
121
|
+
noExt: cosmiconfig.defaultLoaders[".js"]
|
|
123
122
|
}
|
|
124
123
|
});
|
|
125
|
-
var program = new
|
|
124
|
+
var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
|
|
125
|
+
spinner.succeed(pc2.blue("Kubb generation started"));
|
|
126
|
+
spinner.start("Loading config");
|
|
126
127
|
const result = options.config ? await explorer.load(options.config) : await explorer.search();
|
|
127
128
|
if (result?.isEmpty || !result || !result.config) {
|
|
128
|
-
|
|
129
|
+
spinner.fail(pc2.red("Config not defined, create a kubb.config.js or pass through your config with the option --config"));
|
|
129
130
|
return;
|
|
130
131
|
}
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
spinner.succeed("Config loaded");
|
|
133
|
+
await run({ result, spinner, options });
|
|
134
|
+
}).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));
|
|
133
135
|
program.name(moduleName).description("Generate").version(version, "-v").parse();
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import pc from "picocolors";
|
|
11
|
-
import ora from "ora";
|
|
12
|
-
import { build, defaultConfig } from "@kubb/core";
|
|
2
|
+
import { Command, Option } from 'commander';
|
|
3
|
+
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
4
|
+
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
|
|
5
|
+
import pc2 from 'picocolors';
|
|
6
|
+
import ora from 'ora';
|
|
7
|
+
import { execa } from 'execa';
|
|
8
|
+
import { parseArgsStringToArgv } from 'string-argv';
|
|
9
|
+
import { build, isPromise } from '@kubb/core';
|
|
13
10
|
|
|
14
11
|
// src/utils/getPlugins.ts
|
|
15
12
|
var isJSONPlugins = (plugins) => {
|
|
@@ -19,74 +16,92 @@ var isJSONPlugins = (plugins) => {
|
|
|
19
16
|
};
|
|
20
17
|
var getPlugins = (plugins) => {
|
|
21
18
|
if (isJSONPlugins(plugins)) {
|
|
22
|
-
|
|
19
|
+
const promises = plugins.map(async (plugin) => {
|
|
23
20
|
const [name, options = {}] = plugin;
|
|
24
21
|
const importedPlugin = await import(name);
|
|
25
22
|
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
|
|
26
23
|
});
|
|
24
|
+
return Promise.all(promises);
|
|
27
25
|
}
|
|
28
|
-
return plugins;
|
|
26
|
+
return Promise.resolve(plugins);
|
|
29
27
|
};
|
|
30
28
|
|
|
31
29
|
// src/utils/createConfig.ts
|
|
32
|
-
var createConfig = async (result) => {
|
|
33
|
-
|
|
30
|
+
var createConfig = async (result, options) => {
|
|
31
|
+
const config = result?.config;
|
|
34
32
|
if (result?.filepath.endsWith(".json")) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
let JSONConfig = config;
|
|
34
|
+
JSONConfig = {
|
|
35
|
+
...JSONConfig,
|
|
36
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
38
37
|
};
|
|
39
|
-
return
|
|
38
|
+
return Promise.resolve(JSONConfig);
|
|
40
39
|
}
|
|
41
40
|
if (typeof config === "function") {
|
|
42
|
-
const possiblePromise = config();
|
|
43
|
-
if (
|
|
41
|
+
const possiblePromise = config(options);
|
|
42
|
+
if (isPromise(possiblePromise)) {
|
|
44
43
|
return possiblePromise;
|
|
45
44
|
}
|
|
46
|
-
return possiblePromise;
|
|
45
|
+
return Promise.resolve(possiblePromise);
|
|
47
46
|
}
|
|
48
47
|
return config;
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
// src/run.ts
|
|
52
|
-
async function run(result, options) {
|
|
53
|
-
const spinner = ora({
|
|
54
|
-
color: "blue",
|
|
55
|
-
text: pc.blue("Kubb generation started"),
|
|
56
|
-
spinner: "timeTravel"
|
|
57
|
-
}).start();
|
|
51
|
+
async function run({ result, options, spinner: spinner2 }) {
|
|
58
52
|
const logger = {
|
|
59
53
|
log(message, logLevel) {
|
|
60
54
|
if (logLevel === "error") {
|
|
61
|
-
|
|
55
|
+
spinner2.fail(message);
|
|
62
56
|
}
|
|
63
|
-
|
|
57
|
+
spinner2[logLevel](message);
|
|
64
58
|
},
|
|
65
|
-
spinner
|
|
59
|
+
spinner: spinner2
|
|
66
60
|
};
|
|
67
61
|
try {
|
|
68
|
-
|
|
62
|
+
spinner2.start("Building");
|
|
63
|
+
const config = await createConfig(result, options);
|
|
69
64
|
await build({
|
|
70
65
|
config: {
|
|
71
|
-
|
|
66
|
+
root: process.cwd(),
|
|
72
67
|
...config
|
|
73
68
|
},
|
|
74
69
|
mode: options.mode || "development",
|
|
75
70
|
logger
|
|
76
71
|
});
|
|
77
|
-
|
|
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
|
+
}
|
|
78
88
|
} catch (err) {
|
|
79
|
-
|
|
89
|
+
spinner2.fail("Something went wrong\n");
|
|
80
90
|
console.error(err);
|
|
81
91
|
}
|
|
82
92
|
return true;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
// package.json
|
|
86
|
-
var version = "0.
|
|
96
|
+
var version = "0.19.0";
|
|
87
97
|
|
|
88
98
|
// src/index.ts
|
|
89
99
|
var moduleName = "kubb";
|
|
100
|
+
var spinner = ora({
|
|
101
|
+
color: "blue",
|
|
102
|
+
text: pc2.blue("Kubb generation started"),
|
|
103
|
+
spinner: "timeTravel"
|
|
104
|
+
}).start();
|
|
90
105
|
var explorer = cosmiconfig(moduleName, {
|
|
91
106
|
searchPlaces: [
|
|
92
107
|
"package.json",
|
|
@@ -104,12 +119,15 @@ var explorer = cosmiconfig(moduleName, {
|
|
|
104
119
|
noExt: defaultLoaders[".js"]
|
|
105
120
|
}
|
|
106
121
|
});
|
|
107
|
-
var program = new Command(moduleName).description("
|
|
122
|
+
var program = new Command(moduleName).description("Kubb").action(async (options) => {
|
|
123
|
+
spinner.succeed(pc2.blue("Kubb generation started"));
|
|
124
|
+
spinner.start("Loading config");
|
|
108
125
|
const result = options.config ? await explorer.load(options.config) : await explorer.search();
|
|
109
126
|
if (result?.isEmpty || !result || !result.config) {
|
|
110
|
-
|
|
127
|
+
spinner.fail(pc2.red("Config not defined, create a kubb.config.js or pass through your config with the option --config"));
|
|
111
128
|
return;
|
|
112
129
|
}
|
|
113
|
-
|
|
130
|
+
spinner.succeed("Config loaded");
|
|
131
|
+
await run({ result, spinner, options });
|
|
114
132
|
}).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));
|
|
115
133
|
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.
|
|
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",
|