@kubb/cli 1.0.0-alpha.7 → 1.0.0-beta.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.cjs +209 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -0
- package/package.json +10 -10
- package/src/index.ts +63 -0
- package/src/run.ts +88 -0
- package/src/types.ts +7 -0
- package/src/utils/getConfig.ts +28 -0
- package/src/utils/getCosmiConfig.ts +39 -0
- package/src/utils/getPlugins.ts +29 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/watcher.ts +30 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
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)));
|
|
21
|
+
async function run({ config, options, spinner: spinner2 }) {
|
|
22
|
+
const logger = {
|
|
23
|
+
log(message, logLevel) {
|
|
24
|
+
if (logLevel === "error") {
|
|
25
|
+
spinner2.fail(message);
|
|
26
|
+
}
|
|
27
|
+
switch (logLevel) {
|
|
28
|
+
case "error":
|
|
29
|
+
spinner2.fail(message);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
spinner2.info(message);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
spinner: spinner2
|
|
37
|
+
};
|
|
38
|
+
const onDone = async (config2) => {
|
|
39
|
+
if (!config2.hooks?.done) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
spinner2.start("\u{1FA82} Running hooks");
|
|
43
|
+
let commands = [];
|
|
44
|
+
if (typeof config2.hooks?.done === "string") {
|
|
45
|
+
commands = [config2.hooks.done];
|
|
46
|
+
} else {
|
|
47
|
+
commands = config2.hooks.done;
|
|
48
|
+
}
|
|
49
|
+
const promises = commands.map(async (command) => {
|
|
50
|
+
const [cmd, ..._args] = [...stringArgv.parseArgsStringToArgv(command)];
|
|
51
|
+
return execa.execa(cmd, _args);
|
|
52
|
+
});
|
|
53
|
+
await Promise.all(promises);
|
|
54
|
+
spinner2.succeed("\u{1FA82} Hooks runned");
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
spinner2.start("\u{1F680} Building");
|
|
58
|
+
await core.build({
|
|
59
|
+
config: {
|
|
60
|
+
root: process.cwd(),
|
|
61
|
+
...config,
|
|
62
|
+
output: {
|
|
63
|
+
write: true,
|
|
64
|
+
...config.output
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
logger
|
|
68
|
+
});
|
|
69
|
+
spinner2.succeed(pc3__default.default.blue("\u{1F308} Generation complete"));
|
|
70
|
+
await onDone(config);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (options.debug) {
|
|
73
|
+
spinner2.fail(`Something went wrong
|
|
74
|
+
`);
|
|
75
|
+
console.log(err?.cause || err);
|
|
76
|
+
} else {
|
|
77
|
+
spinner2.fail(`Something went wrong
|
|
78
|
+
${err?.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
async function startWatcher(cb, options) {
|
|
84
|
+
const { spinner: spinner2, path } = options;
|
|
85
|
+
const { watch } = await import('chokidar');
|
|
86
|
+
const ignored = ["**/{.git,node_modules}/**"];
|
|
87
|
+
const watcher = watch(path, {
|
|
88
|
+
ignorePermissionErrors: true,
|
|
89
|
+
ignored
|
|
90
|
+
});
|
|
91
|
+
watcher.on("all", async (type, file) => {
|
|
92
|
+
spinner2.succeed(pc3__default.default.yellow(pc3__default.default.bold(`Change detected: ${type} ${file}`)));
|
|
93
|
+
spinner2.spinner = "clock";
|
|
94
|
+
try {
|
|
95
|
+
await cb(options.path);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
spinner2.warn(pc3__default.default.red("Watcher failed"));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function isJSONPlugins(plugins) {
|
|
102
|
+
return !!plugins?.some((plugin) => {
|
|
103
|
+
return typeof plugin?.[0] === "string";
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function importPlugin(name, options) {
|
|
107
|
+
const importer = new moduleImporter.ModuleImporter(process.cwd());
|
|
108
|
+
const importedPlugin = process.env.NODE_ENV === "test" ? await import(name) : await importer.import(name);
|
|
109
|
+
return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options);
|
|
110
|
+
}
|
|
111
|
+
function getPlugins(plugins) {
|
|
112
|
+
if (isJSONPlugins(plugins)) {
|
|
113
|
+
const promises = plugins.map(async (plugin) => {
|
|
114
|
+
const [name, options = {}] = plugin;
|
|
115
|
+
return importPlugin(name, options);
|
|
116
|
+
});
|
|
117
|
+
return Promise.all(promises);
|
|
118
|
+
}
|
|
119
|
+
return Promise.resolve(plugins);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/utils/getConfig.ts
|
|
123
|
+
async function getConfig(result, options) {
|
|
124
|
+
const config = result?.config;
|
|
125
|
+
let kubbUserConfig = Promise.resolve(config);
|
|
126
|
+
if (typeof config === "function") {
|
|
127
|
+
const possiblePromise = config(options);
|
|
128
|
+
if (core.isPromise(possiblePromise)) {
|
|
129
|
+
kubbUserConfig = possiblePromise;
|
|
130
|
+
}
|
|
131
|
+
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
132
|
+
}
|
|
133
|
+
let JSONConfig = await kubbUserConfig;
|
|
134
|
+
JSONConfig = {
|
|
135
|
+
...JSONConfig,
|
|
136
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
|
|
137
|
+
};
|
|
138
|
+
return JSONConfig;
|
|
139
|
+
}
|
|
140
|
+
async function getCosmiConfig(moduleName2, config) {
|
|
141
|
+
const explorer = cosmiconfig.cosmiconfig(moduleName2, {
|
|
142
|
+
cache: false,
|
|
143
|
+
searchPlaces: [
|
|
144
|
+
"package.json",
|
|
145
|
+
`.${moduleName2}rc`,
|
|
146
|
+
`.${moduleName2}rc.json`,
|
|
147
|
+
// commonjs
|
|
148
|
+
`.${moduleName2}rc.js`,
|
|
149
|
+
`.${moduleName2}rc.cjs`,
|
|
150
|
+
`${moduleName2}.config.js`,
|
|
151
|
+
`${moduleName2}.config.cjs`,
|
|
152
|
+
// esm and typescript
|
|
153
|
+
`.${moduleName2}rc.ts`,
|
|
154
|
+
`${moduleName2}.config.ts`
|
|
155
|
+
],
|
|
156
|
+
loaders: {
|
|
157
|
+
".ts": cosmiconfigTypescriptLoader.TypeScriptLoader({
|
|
158
|
+
swc: true,
|
|
159
|
+
typeCheck: false
|
|
160
|
+
}),
|
|
161
|
+
noExt: cosmiconfig.defaultLoaders[".js"]
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const result = config ? await explorer.load(config) : await explorer.search();
|
|
165
|
+
if (result?.isEmpty || !result || !result.config) {
|
|
166
|
+
throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// package.json
|
|
172
|
+
var version = "1.0.0-beta.1";
|
|
173
|
+
|
|
174
|
+
// src/index.ts
|
|
175
|
+
var moduleName = "kubb";
|
|
176
|
+
var spinner = ora__default.default({
|
|
177
|
+
color: "blue",
|
|
178
|
+
text: pc3__default.default.blue("\u{1F3CE}\uFE0F Kubb generation started"),
|
|
179
|
+
spinner: "clock"
|
|
180
|
+
}).start();
|
|
181
|
+
var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
|
|
182
|
+
try {
|
|
183
|
+
spinner.start("\u{1F4BE} Loading config");
|
|
184
|
+
const result = await getCosmiConfig(moduleName, options.config);
|
|
185
|
+
spinner.succeed("\u{1F4BE} Config loaded");
|
|
186
|
+
if (options.watch) {
|
|
187
|
+
const config = await getConfig(result, options);
|
|
188
|
+
startWatcher(
|
|
189
|
+
async (paths) => {
|
|
190
|
+
await run({ config, spinner, options });
|
|
191
|
+
spinner.spinner = "simpleDotsScrolling";
|
|
192
|
+
spinner.start(pc3__default.default.yellow(pc3__default.default.bold(`Watching for changes in ${paths.join(" and ")}`)));
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
spinner,
|
|
196
|
+
path: [config.input.path]
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
} else {
|
|
200
|
+
const config = await getConfig(result, options);
|
|
201
|
+
await run({ config, spinner, options });
|
|
202
|
+
}
|
|
203
|
+
} catch (e) {
|
|
204
|
+
spinner.fail(pc3__default.default.red(e.message));
|
|
205
|
+
}
|
|
206
|
+
}).addOption(new commander.Option("-c, --config <path>", "Path to the 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"));
|
|
207
|
+
program.name(moduleName).description("Generate").version(version, "-v").parse();
|
|
208
|
+
//# sourceMappingURL=out.js.map
|
|
209
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/run.ts","../src/utils/watcher.ts","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/getCosmiConfig.ts","../package.json"],"names":["pc","spinner","config","moduleName"],"mappings":";;;;AAGA,SAAS,SAAS,cAAc;AAChC,OAAOA,SAAQ;AACf,OAAO,SAAS;;;ACJhB,OAAO,QAAQ;AACf,SAAS,aAAa;AACtB,SAAS,6BAA6B;AAEtC,SAAS,aAAa;AAWtB,eAAsB,IAAI,EAAE,QAAQ,SAAS,SAAAC,SAAQ,GAAa;AAChE,QAAM,SAAiB;AAAA,IACrB,IAAI,SAAS,UAAU;AACrB,UAAI,aAAa,SAAS;AACxB,QAAAA,SAAQ,KAAK,OAAO;AAAA,MACtB;AAEA,cAAQ,UAAU;AAAA,QAChB,KAAK;AACH,UAAAA,SAAQ,KAAK,OAAO;AACpB;AAAA,QAEF;AACE,UAAAA,SAAQ,KAAK,OAAO;AACpB;AAAA,MACJ;AAAA,IACF;AAAA,IACA,SAAAA;AAAA,EACF;AAEA,QAAM,SAAS,OAAOC,YAA2B;AAC/C,QAAI,CAACA,QAAO,OAAO,MAAM;AACvB;AAAA,IACF;AACA,IAAAD,SAAQ,MAAM,yBAAkB;AAEhC,QAAI,WAAqB,CAAC;AAC1B,QAAI,OAAOC,QAAO,OAAO,SAAS,UAAU;AAC1C,iBAAW,CAACA,QAAO,MAAM,IAAI;AAAA,IAC/B,OAAO;AACL,iBAAWA,QAAO,MAAM;AAAA,IAC1B;AAEA,UAAM,WAAW,SAAS,IAAI,OAAO,YAAY;AAC/C,YAAM,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,GAAG,sBAAsB,OAAO,CAAC;AAC1D,aAAO,MAAM,KAAK,KAAK;AAAA,IACzB,CAAC;AAED,UAAM,QAAQ,IAAI,QAAQ;AAE1B,IAAAD,SAAQ,QAAQ,wBAAiB;AAAA,EACnC;AAEA,MAAI;AACF,IAAAA,SAAQ,MAAM,o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YAAM,IAAI,EAAE,QAAQ,SAAS,QAAQ,CAAC;AAAA,IACxC;AAAA,EACF,SAAS,GAAP;AACA,YAAQ,KAAKA,IAAG,IAAK,EAAY,OAAO,CAAC;AAAA,EAC3C;AACF,CAAC,EACA,UAAU,IAAI,OAAO,uBAAuB,yBAAyB,CAAC,EACtE,UAAU,IAAI,OAAO,eAAe,YAAY,EAAE,QAAQ,KAAK,CAAC,EAChE,UAAU,IAAI,OAAO,eAAe,oCAAoC,CAAC;AAE5E,QAAQ,KAAK,UAAU,EAAE,YAAY,UAAU,EAAE,QAAQ,SAAS,IAAI,EAAE,MAAM","sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-console */\n\nimport { Command, Option } from 'commander'\nimport pc from 'picocolors'\nimport ora from 'ora'\n\nimport type { CLIOptions } from '@kubb/core'\n\nimport { run } from './run'\nimport { startWatcher } from './utils/watcher'\nimport { getConfig, getCosmiConfig } from './utils'\n\nimport { version } from '../package.json'\n\nconst moduleName = 'kubb'\n\nconst spinner = ora({\n color: 'blue',\n text: pc.blue('🏎️ Kubb generation started'),\n spinner: 'clock',\n}).start()\n\nconst program = new Command(moduleName)\n .description('Kubb')\n .action(async (options: CLIOptions) => {\n try {\n // CONFIG\n\n spinner.start('💾 Loading config')\n const result = await getCosmiConfig(moduleName, options.config)\n spinner.succeed('💾 Config loaded')\n\n // END CONFIG\n\n if (options.watch) {\n const config = await getConfig(result, options)\n\n startWatcher(\n async (paths) => {\n await run({ config, spinner, options })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n },\n {\n spinner,\n path: [config.input.path],\n }\n )\n } else {\n const config = await getConfig(result, options)\n\n await run({ config, spinner, options })\n }\n } catch (e) {\n spinner.fail(pc.red((e as Error).message))\n }\n })\n .addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))\n .addOption(new Option('-d, --debug', 'Debug mode').default(false))\n .addOption(new Option('-w, --watch', 'Watch mode based on the input file'))\n\nprogram.name(moduleName).description('Generate').version(version, '-v').parse()\n","/* eslint-disable no-console */\nimport pc from 'picocolors'\nimport { execa } from 'execa'\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { build } from '@kubb/core'\nimport type { Logger, CLIOptions, KubbUserConfig } from '@kubb/core'\n\nimport type { Ora } from 'ora'\n\ntype RunProps = {\n config: KubbUserConfig\n spinner: Ora\n options: CLIOptions\n}\n\nexport async function run({ config, options, spinner }: RunProps) {\n const logger: Logger = {\n log(message, logLevel) {\n if (logLevel === 'error') {\n spinner.fail(message)\n }\n\n switch (logLevel) {\n case 'error':\n spinner.fail(message)\n break\n\n default:\n spinner.info(message)\n break\n }\n },\n spinner,\n }\n\n const onDone = async (config: KubbUserConfig) => {\n if (!config.hooks?.done) {\n return\n }\n spinner.start('🪂 Running hooks')\n\n let commands: string[] = []\n if (typeof config.hooks?.done === 'string') {\n commands = [config.hooks.done]\n } else {\n commands = config.hooks.done\n }\n\n const promises = commands.map(async (command) => {\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n return execa(cmd, _args)\n })\n\n await Promise.all(promises)\n\n spinner.succeed('🪂 Hooks runned')\n }\n\n try {\n spinner.start('🚀 Building')\n\n await build({\n config: {\n root: process.cwd(),\n ...config,\n output: {\n write: true,\n ...config.output,\n },\n },\n logger,\n })\n\n spinner.succeed(pc.blue('🌈 Generation complete'))\n\n await onDone(config)\n } catch (err) {\n if (options.debug) {\n spinner.fail(`Something went wrong\\n`)\n console.log((err as Error)?.cause || err)\n } else {\n spinner.fail(`Something went wrong\\n${(err as Error)?.message}`)\n }\n }\n\n return true\n}\n","import pc from 'picocolors'\n\nimport type { Ora } from 'ora'\n\ntype Options = {\n path: string[]\n spinner: Ora\n}\nexport async function startWatcher(cb: (path: string[]) => Promise<void>, options: Options) {\n const { spinner, path } = options\n const { watch } = await import('chokidar')\n\n const ignored = ['**/{.git,node_modules}/**']\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', async (type, file) => {\n spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n // revert back\n spinner.spinner = 'clock'\n\n try {\n await cb(options.path)\n } catch (e) {\n spinner.warn(pc.red('Watcher failed'))\n }\n })\n}\n","import type { KubbUserConfig, CLIOptions } from '@kubb/core'\nimport { isPromise } from '@kubb/core'\n\nimport { getPlugins } from './getPlugins'\n\nimport type { CosmiconfigResult } from '../types'\n\nexport async function getConfig(result: CosmiconfigResult, options: CLIOptions) {\n const config = result?.config\n let kubbUserConfig: Promise<KubbUserConfig> = Promise.resolve(config) as Promise<KubbUserConfig>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(options)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig\n}\n","import { ModuleImporter } from '@humanwhocodes/module-importer'\n// see https://github.com/eslint/eslint/blob/740b20826fadc5322ea5547c1ba41793944e571d/lib/cli.js\n\nimport type { KubbUserConfig, KubbJSONPlugin } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbJSONPlugin[] {\n return !!(plugins as KubbJSONPlugin[])?.some((plugin) => {\n return typeof plugin?.[0] === 'string'\n })\n}\n\nasync function importPlugin(name: string, options: Record<string, unknown>) {\n const importer = new ModuleImporter(process.cwd())\n\n const importedPlugin = process.env.NODE_ENV === 'test' ? await import(name) : await importer.import(name)\n\n return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options)\n}\n\nexport function getPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): Promise<KubbUserConfig['plugins']> {\n if (isJSONPlugins(plugins)) {\n const promises = plugins.map(async (plugin) => {\n const [name, options = {}] = plugin\n return importPlugin(name, options)\n })\n return Promise.all(promises)\n }\n return Promise.resolve(plugins)\n}\n","/* eslint-disable consistent-return */\nimport { cosmiconfig, defaultLoaders } from 'cosmiconfig'\nimport { TypeScriptLoader } from 'cosmiconfig-typescript-loader'\n\nimport type { CosmiconfigResult } from '../types'\n\nexport async function getCosmiConfig(moduleName: string, config?: string) {\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n // commonjs\n `.${moduleName}rc.js`,\n `.${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`,\n // esm and typescript\n `.${moduleName}rc.ts`,\n `${moduleName}.config.ts`,\n ],\n loaders: {\n '.ts': TypeScriptLoader({\n swc: true,\n typeCheck: false,\n }),\n noExt: defaultLoaders['.js'],\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"1.0.0-beta.1\",\n \"description\": \"Generator cli\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git://github.com/kubb-project/kubb.git\",\n \"directory\": \"packages/cli\"\n },\n \"license\": \"MIT\",\n \"author\": \"Stijn Van Hulle <stijn@stijnvanhulle.be\",\n \"keywords\": [\n \"typescript\",\n \"plugins\",\n \"kubb\",\n \"codegen\",\n \"cli\"\n ],\n \"sideEffects\": false,\n \"type\": \"module\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"kubb\": \"dist/index.js\"\n },\n \"preferGlobal\": true,\n \"files\": [\n \"dist\",\n \"src\",\n \"!/**/**.test.**\",\n \"!/**/__tests__/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"start\": \"tsup --watch\",\n \"release\": \"pnpm publish --no-git-check\",\n \"prepack\": \"pnpm build\",\n \"pre-commit\": \"echo 'pre-commit not configured'\",\n \"pre-push\": \"pnpm typecheck\",\n \"test\": \"vitest --passWithNoTests\",\n \"upgrade\": \"ncu -u\",\n \"upgrade:local\": \"ncu --interactive --doctor\",\n \"typecheck\": \"tsc -p ./tsconfig.json --noEmit\"\n },\n \"dependencies\": {\n \"@humanwhocodes/module-importer\": \"^1.0.1\",\n \"@kubb/core\": \"workspace:*\",\n \"chokidar\": \"^3.5.3\",\n \"commander\": \"^10.0.0\",\n \"cosmiconfig\": \"^8.1.3\",\n \"cosmiconfig-typescript-loader\": \"^4.3.0\",\n \"execa\": \"^7.1.1\",\n \"ora\": \"^6.3.0\",\n \"picocolors\": \"^1.0.0\",\n \"string-argv\": \"^0.3.1\",\n \"ts-node\": \"^10.9.1\",\n \"@swc/core\": \"^1.3.42\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@types/node\": \"^18.15.9\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.0.2\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n },\n \"engines\": {\n \"node\": \"^12.17.0 || ^14.13 || >=16.0.0\"\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,14 @@ async function run({ config, options, spinner: spinner2 }) {
|
|
|
17
17
|
if (logLevel === "error") {
|
|
18
18
|
spinner2.fail(message);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
switch (logLevel) {
|
|
21
|
+
case "error":
|
|
22
|
+
spinner2.fail(message);
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
spinner2.info(message);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
21
28
|
},
|
|
22
29
|
spinner: spinner2
|
|
23
30
|
};
|
|
@@ -80,7 +87,7 @@ async function startWatcher(cb, options) {
|
|
|
80
87
|
try {
|
|
81
88
|
await cb(options.path);
|
|
82
89
|
} catch (e) {
|
|
83
|
-
spinner2.warn(pc3.red(
|
|
90
|
+
spinner2.warn(pc3.red("Watcher failed"));
|
|
84
91
|
}
|
|
85
92
|
});
|
|
86
93
|
}
|
|
@@ -155,7 +162,7 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
// package.json
|
|
158
|
-
var version = "1.0.0-
|
|
165
|
+
var version = "1.0.0-beta.1";
|
|
159
166
|
|
|
160
167
|
// src/index.ts
|
|
161
168
|
var moduleName = "kubb";
|
|
@@ -191,3 +198,5 @@ var program = new Command(moduleName).description("Kubb").action(async (options)
|
|
|
191
198
|
}
|
|
192
199
|
}).addOption(new Option("-c, --config <path>", "Path to the Kubb config")).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file"));
|
|
193
200
|
program.name(moduleName).description("Generate").version(version, "-v").parse();
|
|
201
|
+
//# sourceMappingURL=out.js.map
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/run.ts","../src/utils/watcher.ts","../src/utils/getConfig.ts","../src/utils/getPlugins.ts","../src/utils/getCosmiConfig.ts","../package.json"],"names":["pc","spinner","config","moduleName"],"mappings":";;;;AAGA,SAAS,SAAS,cAAc;AAChC,OAAOA,SAAQ;AACf,OAAO,SAAS;;;ACJhB,OAAO,QAAQ;AACf,SAAS,aAAa;AACtB,SAAS,6BAA6B;AAEtC,SAAS,aAAa;AAWtB,eAAsB,IAAI,EAAE,QAAQ,SAAS,SAAAC,SAAQ,GAAa;AAChE,QAAM,SAAiB;AAAA,IACrB,IAAI,SAAS,UAAU;AACrB,UAAI,aAAa,SAAS;AACxB,QAAAA,SAAQ,KAAK,OAAO;AAAA,MACtB;AAEA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B,IAAM,UAAU,IAAI;AAAA,EAClB,OAAO;AAAA,EACP,MAAMH,IAAG,KAAK,yCAA6B;AAAA,EAC3C,SAAS;AACX,CAAC,EAAE,MAAM;AAET,IAAM,UAAU,IAAI,QAAQ,UAAU,EACnC,YAAY,MAAM,EAClB,OAAO,OAAO,YAAwB;AACrC,MAAI;AAGF,YAAQ,MAAM,0BAAmB;AACjC,UAAM,SAAS,MAAM,eAAe,YAAY,QAAQ,MAAM;AAC9D,YAAQ,QAAQ,yBAAkB;AAIlC,QAAI,QAAQ,OAAO;AACjB,YAAM,SAAS,MAAM,UAAU,QAAQ,OAAO;AAE9C;AAAA,QACE,OAAO,UAAU;AACf,gBAAM,IAAI,EAAE,QAAQ,SAAS,QAAQ,CAAC;AACtC,kBAAQ,UAAU;AAClB,kBAAQ,MAAMA,IAAG,OAAOA,IAAG,KAAK,2BAA2B,MAAM,KAAK,OAAO,GAAG,CAAC,CAAC;AAAA,QACpF;AAAA,QACA;AAAA,UACE;AAAA,UACA,MAAM,CAAC,OAAO,MAAM,IAAI;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM,SAAS,MAAM,UAAU,QAAQ,OAAO;AAE9C,YAAM,IAAI,EAAE,QAAQ,SAAS,QAAQ,CAAC;AAAA,IACxC;AAAA,EACF,SAAS,GAAP;AACA,YAAQ,KAAKA,IAAG,IAAK,EAAY,OAAO,CAAC;AAAA,EAC3C;AACF,CAAC,EACA,UAAU,IAAI,OAAO,uBAAuB,yBAAyB,CAAC,EACtE,UAAU,IAAI,OAAO,eAAe,YAAY,EAAE,QAAQ,KAAK,CAAC,EAChE,UAAU,IAAI,OAAO,eAAe,oCAAoC,CAAC;AAE5E,QAAQ,KAAK,UAAU,EAAE,YAAY,UAAU,EAAE,QAAQ,SAAS,IAAI,EAAE,MAAM","sourcesContent":["#!/usr/bin/env node\n/* eslint-disable no-console */\n\nimport { Command, Option } from 'commander'\nimport pc from 'picocolors'\nimport ora from 'ora'\n\nimport type { CLIOptions } from '@kubb/core'\n\nimport { run } from './run'\nimport { startWatcher } from './utils/watcher'\nimport { getConfig, getCosmiConfig } from './utils'\n\nimport { version } from '../package.json'\n\nconst moduleName = 'kubb'\n\nconst spinner = ora({\n color: 'blue',\n text: pc.blue('🏎️ Kubb generation started'),\n spinner: 'clock',\n}).start()\n\nconst program = new Command(moduleName)\n .description('Kubb')\n .action(async (options: CLIOptions) => {\n try {\n // CONFIG\n\n spinner.start('💾 Loading config')\n const result = await getCosmiConfig(moduleName, options.config)\n spinner.succeed('💾 Config loaded')\n\n // END CONFIG\n\n if (options.watch) {\n const config = await getConfig(result, options)\n\n startWatcher(\n async (paths) => {\n await run({ config, spinner, options })\n spinner.spinner = 'simpleDotsScrolling'\n spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n },\n {\n spinner,\n path: [config.input.path],\n }\n )\n } else {\n const config = await getConfig(result, options)\n\n await run({ config, spinner, options })\n }\n } catch (e) {\n spinner.fail(pc.red((e as Error).message))\n }\n })\n .addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))\n .addOption(new Option('-d, --debug', 'Debug mode').default(false))\n .addOption(new Option('-w, --watch', 'Watch mode based on the input file'))\n\nprogram.name(moduleName).description('Generate').version(version, '-v').parse()\n","/* eslint-disable no-console */\nimport pc from 'picocolors'\nimport { execa } from 'execa'\nimport { parseArgsStringToArgv } from 'string-argv'\n\nimport { build } from '@kubb/core'\nimport type { Logger, CLIOptions, KubbUserConfig } from '@kubb/core'\n\nimport type { Ora } from 'ora'\n\ntype RunProps = {\n config: KubbUserConfig\n spinner: Ora\n options: CLIOptions\n}\n\nexport async function run({ config, options, spinner }: RunProps) {\n const logger: Logger = {\n log(message, logLevel) {\n if (logLevel === 'error') {\n spinner.fail(message)\n }\n\n switch (logLevel) {\n case 'error':\n spinner.fail(message)\n break\n\n default:\n spinner.info(message)\n break\n }\n },\n spinner,\n }\n\n const onDone = async (config: KubbUserConfig) => {\n if (!config.hooks?.done) {\n return\n }\n spinner.start('🪂 Running hooks')\n\n let commands: string[] = []\n if (typeof config.hooks?.done === 'string') {\n commands = [config.hooks.done]\n } else {\n commands = config.hooks.done\n }\n\n const promises = commands.map(async (command) => {\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n return execa(cmd, _args)\n })\n\n await Promise.all(promises)\n\n spinner.succeed('🪂 Hooks runned')\n }\n\n try {\n spinner.start('🚀 Building')\n\n await build({\n config: {\n root: process.cwd(),\n ...config,\n output: {\n write: true,\n ...config.output,\n },\n },\n logger,\n })\n\n spinner.succeed(pc.blue('🌈 Generation complete'))\n\n await onDone(config)\n } catch (err) {\n if (options.debug) {\n spinner.fail(`Something went wrong\\n`)\n console.log((err as Error)?.cause || err)\n } else {\n spinner.fail(`Something went wrong\\n${(err as Error)?.message}`)\n }\n }\n\n return true\n}\n","import pc from 'picocolors'\n\nimport type { Ora } from 'ora'\n\ntype Options = {\n path: string[]\n spinner: Ora\n}\nexport async function startWatcher(cb: (path: string[]) => Promise<void>, options: Options) {\n const { spinner, path } = options\n const { watch } = await import('chokidar')\n\n const ignored = ['**/{.git,node_modules}/**']\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', async (type, file) => {\n spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n // revert back\n spinner.spinner = 'clock'\n\n try {\n await cb(options.path)\n } catch (e) {\n spinner.warn(pc.red('Watcher failed'))\n }\n })\n}\n","import type { KubbUserConfig, CLIOptions } from '@kubb/core'\nimport { isPromise } from '@kubb/core'\n\nimport { getPlugins } from './getPlugins'\n\nimport type { CosmiconfigResult } from '../types'\n\nexport async function getConfig(result: CosmiconfigResult, options: CLIOptions) {\n const config = result?.config\n let kubbUserConfig: Promise<KubbUserConfig> = Promise.resolve(config) as Promise<KubbUserConfig>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(options)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig\n}\n","import { ModuleImporter } from '@humanwhocodes/module-importer'\n// see https://github.com/eslint/eslint/blob/740b20826fadc5322ea5547c1ba41793944e571d/lib/cli.js\n\nimport type { KubbUserConfig, KubbJSONPlugin } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbJSONPlugin[] {\n return !!(plugins as KubbJSONPlugin[])?.some((plugin) => {\n return typeof plugin?.[0] === 'string'\n })\n}\n\nasync function importPlugin(name: string, options: Record<string, unknown>) {\n const importer = new ModuleImporter(process.cwd())\n\n const importedPlugin = process.env.NODE_ENV === 'test' ? await import(name) : await importer.import(name)\n\n return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options)\n}\n\nexport function getPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): Promise<KubbUserConfig['plugins']> {\n if (isJSONPlugins(plugins)) {\n const promises = plugins.map(async (plugin) => {\n const [name, options = {}] = plugin\n return importPlugin(name, options)\n })\n return Promise.all(promises)\n }\n return Promise.resolve(plugins)\n}\n","/* eslint-disable consistent-return */\nimport { cosmiconfig, defaultLoaders } from 'cosmiconfig'\nimport { TypeScriptLoader } from 'cosmiconfig-typescript-loader'\n\nimport type { CosmiconfigResult } from '../types'\n\nexport async function getCosmiConfig(moduleName: string, config?: string) {\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n // commonjs\n `.${moduleName}rc.js`,\n `.${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`,\n // esm and typescript\n `.${moduleName}rc.ts`,\n `${moduleName}.config.ts`,\n ],\n loaders: {\n '.ts': TypeScriptLoader({\n swc: true,\n typeCheck: false,\n }),\n noExt: defaultLoaders['.js'],\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","{\n \"name\": \"@kubb/cli\",\n \"version\": \"1.0.0-beta.1\",\n \"description\": \"Generator cli\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git://github.com/kubb-project/kubb.git\",\n \"directory\": \"packages/cli\"\n },\n \"license\": \"MIT\",\n \"author\": \"Stijn Van Hulle <stijn@stijnvanhulle.be\",\n \"keywords\": [\n \"typescript\",\n \"plugins\",\n \"kubb\",\n \"codegen\",\n \"cli\"\n ],\n \"sideEffects\": false,\n \"type\": \"module\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"kubb\": \"dist/index.js\"\n },\n \"preferGlobal\": true,\n \"files\": [\n \"dist\",\n \"src\",\n \"!/**/**.test.**\",\n \"!/**/__tests__/**\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"start\": \"tsup --watch\",\n \"release\": \"pnpm publish --no-git-check\",\n \"prepack\": \"pnpm build\",\n \"pre-commit\": \"echo 'pre-commit not configured'\",\n \"pre-push\": \"pnpm typecheck\",\n \"test\": \"vitest --passWithNoTests\",\n \"upgrade\": \"ncu -u\",\n \"upgrade:local\": \"ncu --interactive --doctor\",\n \"typecheck\": \"tsc -p ./tsconfig.json --noEmit\"\n },\n \"dependencies\": {\n \"@humanwhocodes/module-importer\": \"^1.0.1\",\n \"@kubb/core\": \"workspace:*\",\n \"chokidar\": \"^3.5.3\",\n \"commander\": \"^10.0.0\",\n \"cosmiconfig\": \"^8.1.3\",\n \"cosmiconfig-typescript-loader\": \"^4.3.0\",\n \"execa\": \"^7.1.1\",\n \"ora\": \"^6.3.0\",\n \"picocolors\": \"^1.0.0\",\n \"string-argv\": \"^0.3.1\",\n \"ts-node\": \"^10.9.1\",\n \"@swc/core\": \"^1.3.42\"\n },\n \"devDependencies\": {\n \"@kubb/swagger\": \"workspace:*\",\n \"@types/node\": \"^18.15.9\",\n \"tsup\": \"^6.7.0\",\n \"typescript\": \"^5.0.2\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n },\n \"engines\": {\n \"node\": \"^12.17.0 || ^14.13 || >=16.0.0\"\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,26 +27,28 @@
|
|
|
27
27
|
"preferGlobal": true,
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
|
30
|
+
"src",
|
|
30
31
|
"!/**/**.test.**",
|
|
31
32
|
"!/**/__tests__/**"
|
|
32
33
|
],
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@humanwhocodes/module-importer": "^1.0.1",
|
|
35
|
-
"@kubb/core": "1.0.0-
|
|
36
|
+
"@kubb/core": "1.0.0-beta.1",
|
|
36
37
|
"chokidar": "^3.5.3",
|
|
37
38
|
"commander": "^10.0.0",
|
|
38
|
-
"cosmiconfig": "^8.1.
|
|
39
|
+
"cosmiconfig": "^8.1.3",
|
|
39
40
|
"cosmiconfig-typescript-loader": "^4.3.0",
|
|
40
41
|
"execa": "^7.1.1",
|
|
41
|
-
"ora": "^6.
|
|
42
|
+
"ora": "^6.3.0",
|
|
42
43
|
"picocolors": "^1.0.0",
|
|
43
44
|
"string-argv": "^0.3.1",
|
|
44
45
|
"ts-node": "^10.9.1",
|
|
45
|
-
"@swc/core": "^1.3.
|
|
46
|
+
"@swc/core": "^1.3.42"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
49
|
+
"@kubb/swagger": "1.0.0-beta.1",
|
|
50
|
+
"@types/node": "^18.15.9",
|
|
51
|
+
"tsup": "^6.7.0",
|
|
50
52
|
"typescript": "^5.0.2"
|
|
51
53
|
},
|
|
52
54
|
"publishConfig": {
|
|
@@ -62,9 +64,7 @@
|
|
|
62
64
|
"release": "pnpm publish --no-git-check",
|
|
63
65
|
"pre-commit": "echo 'pre-commit not configured'",
|
|
64
66
|
"pre-push": "pnpm typecheck",
|
|
65
|
-
"test": "
|
|
66
|
-
"test:local": "jest --config ../../jest.config.ts --testPathPattern=packages/cli/src --maxWorkers=50%",
|
|
67
|
-
"test:watch": "jest --config ../../jest.config.ts --testPathPattern=packages/cli/src --maxWorkers=25% --watch",
|
|
67
|
+
"test": "vitest --passWithNoTests",
|
|
68
68
|
"upgrade": "ncu -u",
|
|
69
69
|
"upgrade:local": "ncu --interactive --doctor",
|
|
70
70
|
"typecheck": "tsc -p ./tsconfig.json --noEmit"
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
import { Command, Option } from 'commander'
|
|
5
|
+
import pc from 'picocolors'
|
|
6
|
+
import ora from 'ora'
|
|
7
|
+
|
|
8
|
+
import type { CLIOptions } from '@kubb/core'
|
|
9
|
+
|
|
10
|
+
import { run } from './run'
|
|
11
|
+
import { startWatcher } from './utils/watcher'
|
|
12
|
+
import { getConfig, getCosmiConfig } from './utils'
|
|
13
|
+
|
|
14
|
+
import { version } from '../package.json'
|
|
15
|
+
|
|
16
|
+
const moduleName = 'kubb'
|
|
17
|
+
|
|
18
|
+
const spinner = ora({
|
|
19
|
+
color: 'blue',
|
|
20
|
+
text: pc.blue('🏎️ Kubb generation started'),
|
|
21
|
+
spinner: 'clock',
|
|
22
|
+
}).start()
|
|
23
|
+
|
|
24
|
+
const program = new Command(moduleName)
|
|
25
|
+
.description('Kubb')
|
|
26
|
+
.action(async (options: CLIOptions) => {
|
|
27
|
+
try {
|
|
28
|
+
// CONFIG
|
|
29
|
+
|
|
30
|
+
spinner.start('💾 Loading config')
|
|
31
|
+
const result = await getCosmiConfig(moduleName, options.config)
|
|
32
|
+
spinner.succeed('💾 Config loaded')
|
|
33
|
+
|
|
34
|
+
// END CONFIG
|
|
35
|
+
|
|
36
|
+
if (options.watch) {
|
|
37
|
+
const config = await getConfig(result, options)
|
|
38
|
+
|
|
39
|
+
startWatcher(
|
|
40
|
+
async (paths) => {
|
|
41
|
+
await run({ config, spinner, options })
|
|
42
|
+
spinner.spinner = 'simpleDotsScrolling'
|
|
43
|
+
spinner.start(pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
spinner,
|
|
47
|
+
path: [config.input.path],
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
} else {
|
|
51
|
+
const config = await getConfig(result, options)
|
|
52
|
+
|
|
53
|
+
await run({ config, spinner, options })
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
spinner.fail(pc.red((e as Error).message))
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))
|
|
60
|
+
.addOption(new Option('-d, --debug', 'Debug mode').default(false))
|
|
61
|
+
.addOption(new Option('-w, --watch', 'Watch mode based on the input file'))
|
|
62
|
+
|
|
63
|
+
program.name(moduleName).description('Generate').version(version, '-v').parse()
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import pc from 'picocolors'
|
|
3
|
+
import { execa } from 'execa'
|
|
4
|
+
import { parseArgsStringToArgv } from 'string-argv'
|
|
5
|
+
|
|
6
|
+
import { build } from '@kubb/core'
|
|
7
|
+
import type { Logger, CLIOptions, KubbUserConfig } from '@kubb/core'
|
|
8
|
+
|
|
9
|
+
import type { Ora } from 'ora'
|
|
10
|
+
|
|
11
|
+
type RunProps = {
|
|
12
|
+
config: KubbUserConfig
|
|
13
|
+
spinner: Ora
|
|
14
|
+
options: CLIOptions
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function run({ config, options, spinner }: RunProps) {
|
|
18
|
+
const logger: Logger = {
|
|
19
|
+
log(message, logLevel) {
|
|
20
|
+
if (logLevel === 'error') {
|
|
21
|
+
spinner.fail(message)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
switch (logLevel) {
|
|
25
|
+
case 'error':
|
|
26
|
+
spinner.fail(message)
|
|
27
|
+
break
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
spinner.info(message)
|
|
31
|
+
break
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
spinner,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const onDone = async (config: KubbUserConfig) => {
|
|
38
|
+
if (!config.hooks?.done) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
spinner.start('🪂 Running hooks')
|
|
42
|
+
|
|
43
|
+
let commands: string[] = []
|
|
44
|
+
if (typeof config.hooks?.done === 'string') {
|
|
45
|
+
commands = [config.hooks.done]
|
|
46
|
+
} else {
|
|
47
|
+
commands = config.hooks.done
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const promises = commands.map(async (command) => {
|
|
51
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
52
|
+
return execa(cmd, _args)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await Promise.all(promises)
|
|
56
|
+
|
|
57
|
+
spinner.succeed('🪂 Hooks runned')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
spinner.start('🚀 Building')
|
|
62
|
+
|
|
63
|
+
await build({
|
|
64
|
+
config: {
|
|
65
|
+
root: process.cwd(),
|
|
66
|
+
...config,
|
|
67
|
+
output: {
|
|
68
|
+
write: true,
|
|
69
|
+
...config.output,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
logger,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
spinner.succeed(pc.blue('🌈 Generation complete'))
|
|
76
|
+
|
|
77
|
+
await onDone(config)
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (options.debug) {
|
|
80
|
+
spinner.fail(`Something went wrong\n`)
|
|
81
|
+
console.log((err as Error)?.cause || err)
|
|
82
|
+
} else {
|
|
83
|
+
spinner.fail(`Something went wrong\n${(err as Error)?.message}`)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return true
|
|
88
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { KubbUserConfig, CLIOptions } from '@kubb/core'
|
|
2
|
+
import { isPromise } from '@kubb/core'
|
|
3
|
+
|
|
4
|
+
import { getPlugins } from './getPlugins'
|
|
5
|
+
|
|
6
|
+
import type { CosmiconfigResult } from '../types'
|
|
7
|
+
|
|
8
|
+
export async function getConfig(result: CosmiconfigResult, options: CLIOptions) {
|
|
9
|
+
const config = result?.config
|
|
10
|
+
let kubbUserConfig: Promise<KubbUserConfig> = Promise.resolve(config) as Promise<KubbUserConfig>
|
|
11
|
+
|
|
12
|
+
// for ts or js files
|
|
13
|
+
if (typeof config === 'function') {
|
|
14
|
+
const possiblePromise = config(options)
|
|
15
|
+
if (isPromise(possiblePromise)) {
|
|
16
|
+
kubbUserConfig = possiblePromise
|
|
17
|
+
}
|
|
18
|
+
kubbUserConfig = Promise.resolve(possiblePromise)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let JSONConfig = await kubbUserConfig
|
|
22
|
+
JSONConfig = {
|
|
23
|
+
...JSONConfig,
|
|
24
|
+
plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return JSONConfig
|
|
28
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable consistent-return */
|
|
2
|
+
import { cosmiconfig, defaultLoaders } from 'cosmiconfig'
|
|
3
|
+
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader'
|
|
4
|
+
|
|
5
|
+
import type { CosmiconfigResult } from '../types'
|
|
6
|
+
|
|
7
|
+
export async function getCosmiConfig(moduleName: string, config?: string) {
|
|
8
|
+
const explorer = cosmiconfig(moduleName, {
|
|
9
|
+
cache: false,
|
|
10
|
+
searchPlaces: [
|
|
11
|
+
'package.json',
|
|
12
|
+
`.${moduleName}rc`,
|
|
13
|
+
`.${moduleName}rc.json`,
|
|
14
|
+
// commonjs
|
|
15
|
+
`.${moduleName}rc.js`,
|
|
16
|
+
`.${moduleName}rc.cjs`,
|
|
17
|
+
`${moduleName}.config.js`,
|
|
18
|
+
`${moduleName}.config.cjs`,
|
|
19
|
+
// esm and typescript
|
|
20
|
+
`.${moduleName}rc.ts`,
|
|
21
|
+
`${moduleName}.config.ts`,
|
|
22
|
+
],
|
|
23
|
+
loaders: {
|
|
24
|
+
'.ts': TypeScriptLoader({
|
|
25
|
+
swc: true,
|
|
26
|
+
typeCheck: false,
|
|
27
|
+
}),
|
|
28
|
+
noExt: defaultLoaders['.js'],
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const result = config ? await explorer.load(config) : await explorer.search()
|
|
33
|
+
|
|
34
|
+
if (result?.isEmpty || !result || !result.config) {
|
|
35
|
+
throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return result as CosmiconfigResult
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ModuleImporter } from '@humanwhocodes/module-importer'
|
|
2
|
+
// see https://github.com/eslint/eslint/blob/740b20826fadc5322ea5547c1ba41793944e571d/lib/cli.js
|
|
3
|
+
|
|
4
|
+
import type { KubbUserConfig, KubbJSONPlugin } from '@kubb/core'
|
|
5
|
+
|
|
6
|
+
function isJSONPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): plugins is KubbJSONPlugin[] {
|
|
7
|
+
return !!(plugins as KubbJSONPlugin[])?.some((plugin) => {
|
|
8
|
+
return typeof plugin?.[0] === 'string'
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function importPlugin(name: string, options: Record<string, unknown>) {
|
|
13
|
+
const importer = new ModuleImporter(process.cwd())
|
|
14
|
+
|
|
15
|
+
const importedPlugin = process.env.NODE_ENV === 'test' ? await import(name) : await importer.import(name)
|
|
16
|
+
|
|
17
|
+
return importedPlugin?.default?.default ? importedPlugin.default.default(options) : importedPlugin.default(options)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getPlugins(plugins: KubbUserConfig['plugins'] | KubbJSONPlugin[]): Promise<KubbUserConfig['plugins']> {
|
|
21
|
+
if (isJSONPlugins(plugins)) {
|
|
22
|
+
const promises = plugins.map(async (plugin) => {
|
|
23
|
+
const [name, options = {}] = plugin
|
|
24
|
+
return importPlugin(name, options)
|
|
25
|
+
})
|
|
26
|
+
return Promise.all(promises)
|
|
27
|
+
}
|
|
28
|
+
return Promise.resolve(plugins)
|
|
29
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pc from 'picocolors'
|
|
2
|
+
|
|
3
|
+
import type { Ora } from 'ora'
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
path: string[]
|
|
7
|
+
spinner: Ora
|
|
8
|
+
}
|
|
9
|
+
export async function startWatcher(cb: (path: string[]) => Promise<void>, options: Options) {
|
|
10
|
+
const { spinner, path } = options
|
|
11
|
+
const { watch } = await import('chokidar')
|
|
12
|
+
|
|
13
|
+
const ignored = ['**/{.git,node_modules}/**']
|
|
14
|
+
|
|
15
|
+
const watcher = watch(path, {
|
|
16
|
+
ignorePermissionErrors: true,
|
|
17
|
+
ignored,
|
|
18
|
+
})
|
|
19
|
+
watcher.on('all', async (type, file) => {
|
|
20
|
+
spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
|
|
21
|
+
// revert back
|
|
22
|
+
spinner.spinner = 'clock'
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
await cb(options.path)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
spinner.warn(pc.red('Watcher failed'))
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|