@kubb/cli 1.1.3 → 1.1.5
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 +61 -4
- package/dist/index.js +63 -6
- package/package.json +4 -5
- package/src/index.ts +9 -2
- package/src/init.ts +91 -0
package/dist/index.cjs
CHANGED
|
@@ -309,19 +309,76 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
309
309
|
}
|
|
310
310
|
return result;
|
|
311
311
|
}
|
|
312
|
+
var presets = {
|
|
313
|
+
simple: {
|
|
314
|
+
"kubb.config": `
|
|
315
|
+
import { defineConfig } from '@kubb/core'
|
|
316
|
+
import createSwagger from '@kubb/swagger'
|
|
317
|
+
import createSwaggerTS from '@kubb/swagger-ts'
|
|
318
|
+
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
319
|
+
|
|
320
|
+
export default defineConfig({
|
|
321
|
+
root: '.',
|
|
322
|
+
input: {
|
|
323
|
+
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
324
|
+
},
|
|
325
|
+
output: {
|
|
326
|
+
path: './src/gen',
|
|
327
|
+
clean: true,
|
|
328
|
+
},
|
|
329
|
+
hooks: {
|
|
330
|
+
done: 'echo "\u{1F389} done"',
|
|
331
|
+
},
|
|
332
|
+
logLevel: 'info',
|
|
333
|
+
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
334
|
+
})
|
|
335
|
+
`,
|
|
336
|
+
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
340
|
+
try {
|
|
341
|
+
const presetMeta = presets[preset];
|
|
342
|
+
const path = pathParser__default.default.resolve(process.cwd(), "./kubb.config.js");
|
|
343
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
344
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc__default.default.dim(path)}`);
|
|
345
|
+
await core.write(presetMeta["kubb.config"], path);
|
|
346
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc__default.default.dim(path)}`);
|
|
347
|
+
const data = await Promise.all([
|
|
348
|
+
execa.$`npm init es6 -y`,
|
|
349
|
+
...presetMeta.packages.map(async (pack) => {
|
|
350
|
+
spinner2.start(`\u{1F4C0} Installing ${pc__default.default.dim(pack)}`);
|
|
351
|
+
const { stdout } = await execa.$({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
352
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc__default.default.dim(pack)}`);
|
|
353
|
+
return stdout;
|
|
354
|
+
})
|
|
355
|
+
]);
|
|
356
|
+
if (logLevel === "info") {
|
|
357
|
+
data.forEach((text) => console.log(text));
|
|
358
|
+
}
|
|
359
|
+
} catch (error) {
|
|
360
|
+
spinner2.fail(pc__default.default.red(`Something went wrong
|
|
361
|
+
|
|
362
|
+
${error?.message}`));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
312
365
|
|
|
313
366
|
// package.json
|
|
314
|
-
var version = "1.1.
|
|
367
|
+
var version = "1.1.5";
|
|
315
368
|
|
|
316
369
|
// src/index.ts
|
|
317
370
|
var moduleName = "kubb";
|
|
318
371
|
var spinner = ora__default.default({
|
|
319
|
-
color: "blue",
|
|
320
|
-
text: pc__default.default.blue("\u{1F3CE}\uFE0F Kubb generation started"),
|
|
321
372
|
spinner: "clock"
|
|
322
373
|
}).start();
|
|
323
374
|
var program = new commander.Command(moduleName).description("Kubb").action(async (options) => {
|
|
324
375
|
try {
|
|
376
|
+
if (options.init) {
|
|
377
|
+
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
378
|
+
await init({ spinner, logLevel: options.logLevel });
|
|
379
|
+
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
325
382
|
spinner.start("\u{1F4BE} Loading config");
|
|
326
383
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
327
384
|
spinner.succeed(`\u{1F4BE} Config loaded(${pc__default.default.dim(pathParser__default.default.relative(process.cwd(), result.filepath))})`);
|
|
@@ -345,5 +402,5 @@ var program = new commander.Command(moduleName).description("Kubb").action(async
|
|
|
345
402
|
} catch (e) {
|
|
346
403
|
process.exit(1);
|
|
347
404
|
}
|
|
348
|
-
}).addOption(new commander.Option("-c, --config <path>", "Path to the Kubb config")).addOption(new commander.Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new commander.Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new commander.Option("-d, --debug", "Debug mode").default(false)).addOption(new commander.Option("-w, --watch", "Watch mode based on the input file"));
|
|
405
|
+
}).addOption(new commander.Option("-c, --config <path>", "Path to the Kubb config")).addOption(new commander.Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new commander.Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new commander.Option("--init", "Init Kubb")).addOption(new commander.Option("-d, --debug", "Debug mode").default(false)).addOption(new commander.Option("-w, --watch", "Watch mode based on the input file"));
|
|
349
406
|
program.name(moduleName).description("Generate").version(version, "-v").parse();
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import pathParser from 'node:path';
|
|
|
4
4
|
import { Command, Option } from 'commander';
|
|
5
5
|
import pc from 'picocolors';
|
|
6
6
|
import ora from 'ora';
|
|
7
|
-
import { execa } from 'execa';
|
|
7
|
+
import { $, execa } from 'execa';
|
|
8
8
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
9
9
|
import PrettyError from 'pretty-error';
|
|
10
|
-
import { build, PluginError, ParallelPluginError, isPromise } from '@kubb/core';
|
|
10
|
+
import { build, PluginError, ParallelPluginError, isPromise, write } from '@kubb/core';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
12
|
import mod from 'node:module';
|
|
13
13
|
import { cosmiconfig } from 'cosmiconfig';
|
|
@@ -298,19 +298,76 @@ async function getCosmiConfig(moduleName2, config) {
|
|
|
298
298
|
}
|
|
299
299
|
return result;
|
|
300
300
|
}
|
|
301
|
+
var presets = {
|
|
302
|
+
simple: {
|
|
303
|
+
"kubb.config": `
|
|
304
|
+
import { defineConfig } from '@kubb/core'
|
|
305
|
+
import createSwagger from '@kubb/swagger'
|
|
306
|
+
import createSwaggerTS from '@kubb/swagger-ts'
|
|
307
|
+
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
308
|
+
|
|
309
|
+
export default defineConfig({
|
|
310
|
+
root: '.',
|
|
311
|
+
input: {
|
|
312
|
+
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
313
|
+
},
|
|
314
|
+
output: {
|
|
315
|
+
path: './src/gen',
|
|
316
|
+
clean: true,
|
|
317
|
+
},
|
|
318
|
+
hooks: {
|
|
319
|
+
done: 'echo "\u{1F389} done"',
|
|
320
|
+
},
|
|
321
|
+
logLevel: 'info',
|
|
322
|
+
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
323
|
+
})
|
|
324
|
+
`,
|
|
325
|
+
packages: ["@kubb/core", "@kubb/cli", "@kubb/swagger", "@kubb/swagger-ts", "@kubb/swagger-tanstack-query"]
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
async function init({ spinner: spinner2, preset = "simple", logLevel = "silent", packageManager = "pnpm" }) {
|
|
329
|
+
try {
|
|
330
|
+
const presetMeta = presets[preset];
|
|
331
|
+
const path = pathParser.resolve(process.cwd(), "./kubb.config.js");
|
|
332
|
+
const installCommand = packageManager === "npm" ? "install" : "add";
|
|
333
|
+
spinner2.start(`\u{1F4C0} Writing \`kubb.config.js\` ${pc.dim(path)}`);
|
|
334
|
+
await write(presetMeta["kubb.config"], path);
|
|
335
|
+
spinner2.succeed(`\u{1F4C0} Wrote \`kubb.config.js\` ${pc.dim(path)}`);
|
|
336
|
+
const data = await Promise.all([
|
|
337
|
+
$`npm init es6 -y`,
|
|
338
|
+
...presetMeta.packages.map(async (pack) => {
|
|
339
|
+
spinner2.start(`\u{1F4C0} Installing ${pc.dim(pack)}`);
|
|
340
|
+
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`;
|
|
341
|
+
spinner2.succeed(`\u{1F4C0} Installed ${pc.dim(pack)}`);
|
|
342
|
+
return stdout;
|
|
343
|
+
})
|
|
344
|
+
]);
|
|
345
|
+
if (logLevel === "info") {
|
|
346
|
+
data.forEach((text) => console.log(text));
|
|
347
|
+
}
|
|
348
|
+
} catch (error) {
|
|
349
|
+
spinner2.fail(pc.red(`Something went wrong
|
|
350
|
+
|
|
351
|
+
${error?.message}`));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
301
354
|
|
|
302
355
|
// package.json
|
|
303
|
-
var version = "1.1.
|
|
356
|
+
var version = "1.1.5";
|
|
304
357
|
|
|
305
358
|
// src/index.ts
|
|
306
359
|
var moduleName = "kubb";
|
|
307
360
|
var spinner = ora({
|
|
308
|
-
color: "blue",
|
|
309
|
-
text: pc.blue("\u{1F3CE}\uFE0F Kubb generation started"),
|
|
310
361
|
spinner: "clock"
|
|
311
362
|
}).start();
|
|
312
363
|
var program = new Command(moduleName).description("Kubb").action(async (options) => {
|
|
313
364
|
try {
|
|
365
|
+
if (options.init) {
|
|
366
|
+
spinner.start("\u{1F4E6} Initializing Kubb");
|
|
367
|
+
await init({ spinner, logLevel: options.logLevel });
|
|
368
|
+
spinner.succeed(`\u{1F4E6} initialized Kubb`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
314
371
|
spinner.start("\u{1F4BE} Loading config");
|
|
315
372
|
const result = await getCosmiConfig(moduleName, options.config);
|
|
316
373
|
spinner.succeed(`\u{1F4BE} Config loaded(${pc.dim(pathParser.relative(process.cwd(), result.filepath))})`);
|
|
@@ -334,5 +391,5 @@ var program = new Command(moduleName).description("Kubb").action(async (options)
|
|
|
334
391
|
} catch (e) {
|
|
335
392
|
process.exit(1);
|
|
336
393
|
}
|
|
337
|
-
}).addOption(new Option("-c, --config <path>", "Path to the Kubb config")).addOption(new Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file"));
|
|
394
|
+
}).addOption(new Option("-c, --config <path>", "Path to the Kubb config")).addOption(new Option("-i, --input <path>", "Path of the input file(overrides the one in `kubb.config.js`)")).addOption(new Option("-l, --logLevel <type>", "Type of the logging(overrides the one in `kubb.config.js`)").choices(["error", "info", "silent"])).addOption(new Option("--init", "Init Kubb")).addOption(new Option("-d, --debug", "Debug mode").default(false)).addOption(new Option("-w, --watch", "Watch mode based on the input file"));
|
|
338
395
|
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": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"yaml": "^2.3.1",
|
|
44
44
|
"@swc/core": "^1.3.62",
|
|
45
45
|
"pretty-error": "^4.0.0",
|
|
46
|
-
"@kubb/core": "1.1.
|
|
46
|
+
"@kubb/core": "1.1.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^20.2.5",
|
|
50
50
|
"tsup": "^6.7.0",
|
|
51
51
|
"typescript": "^5.1.3",
|
|
52
|
-
"@kubb/swagger": "1.1.
|
|
52
|
+
"@kubb/swagger": "1.1.5"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public",
|
|
@@ -66,8 +66,7 @@
|
|
|
66
66
|
"pre-commit": "echo 'pre-commit not configured'",
|
|
67
67
|
"pre-push": "pnpm typecheck",
|
|
68
68
|
"test": "vitest --passWithNoTests",
|
|
69
|
-
"upgrade": "
|
|
70
|
-
"upgrade:local": "ncu --interactive --doctor",
|
|
69
|
+
"upgrade": "pnpm update",
|
|
71
70
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
72
71
|
}
|
|
73
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,14 +10,13 @@ import type { CLIOptions } from '@kubb/core'
|
|
|
10
10
|
|
|
11
11
|
import { run } from './run.ts'
|
|
12
12
|
import { startWatcher, getConfig, getCosmiConfig } from './utils/index.ts'
|
|
13
|
+
import { init } from './init.ts'
|
|
13
14
|
|
|
14
15
|
import { version } from '../package.json'
|
|
15
16
|
|
|
16
17
|
const moduleName = 'kubb'
|
|
17
18
|
|
|
18
19
|
const spinner = ora({
|
|
19
|
-
color: 'blue',
|
|
20
|
-
text: pc.blue('🏎️ Kubb generation started'),
|
|
21
20
|
spinner: 'clock',
|
|
22
21
|
}).start()
|
|
23
22
|
|
|
@@ -25,6 +24,13 @@ const program = new Command(moduleName)
|
|
|
25
24
|
.description('Kubb')
|
|
26
25
|
.action(async (options: CLIOptions) => {
|
|
27
26
|
try {
|
|
27
|
+
if (options.init) {
|
|
28
|
+
spinner.start('📦 Initializing Kubb')
|
|
29
|
+
await init({ spinner, logLevel: options.logLevel })
|
|
30
|
+
spinner.succeed(`📦 initialized Kubb`)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
// CONFIG
|
|
29
35
|
spinner.start('💾 Loading config')
|
|
30
36
|
const result = await getCosmiConfig(moduleName, options.config)
|
|
@@ -58,6 +64,7 @@ const program = new Command(moduleName)
|
|
|
58
64
|
.addOption(new Option('-c, --config <path>', 'Path to the Kubb config'))
|
|
59
65
|
.addOption(new Option('-i, --input <path>', 'Path of the input file(overrides the one in `kubb.config.js`)'))
|
|
60
66
|
.addOption(new Option('-l, --logLevel <type>', 'Type of the logging(overrides the one in `kubb.config.js`)').choices(['error', 'info', 'silent']))
|
|
67
|
+
.addOption(new Option('--init', 'Init Kubb'))
|
|
61
68
|
.addOption(new Option('-d, --debug', 'Debug mode').default(false))
|
|
62
69
|
.addOption(new Option('-w, --watch', 'Watch mode based on the input file'))
|
|
63
70
|
|
package/src/init.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import pathParser from 'node:path'
|
|
2
|
+
|
|
3
|
+
import pc from 'picocolors'
|
|
4
|
+
import { $ } from 'execa'
|
|
5
|
+
|
|
6
|
+
import type { LogLevel } from '@kubb/core'
|
|
7
|
+
import { write } from '@kubb/core'
|
|
8
|
+
|
|
9
|
+
import type { Ora } from 'ora'
|
|
10
|
+
|
|
11
|
+
export type Preset = 'simple'
|
|
12
|
+
|
|
13
|
+
export type PackageManager = 'pnpm' | 'npm' | 'yarn'
|
|
14
|
+
|
|
15
|
+
export type PresetMeta = {
|
|
16
|
+
'kubb.config': string
|
|
17
|
+
packages: string[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type RunProps = {
|
|
21
|
+
spinner: Ora
|
|
22
|
+
/**
|
|
23
|
+
* @default `'silent'`
|
|
24
|
+
*/
|
|
25
|
+
logLevel?: LogLevel
|
|
26
|
+
/**
|
|
27
|
+
* @default `'simple'`
|
|
28
|
+
*/
|
|
29
|
+
preset?: Preset
|
|
30
|
+
/**
|
|
31
|
+
* @default `'pnpm'`
|
|
32
|
+
*/
|
|
33
|
+
packageManager?: PackageManager
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const presets: Record<Preset, PresetMeta> = {
|
|
37
|
+
simple: {
|
|
38
|
+
'kubb.config': `
|
|
39
|
+
import { defineConfig } from '@kubb/core'
|
|
40
|
+
import createSwagger from '@kubb/swagger'
|
|
41
|
+
import createSwaggerTS from '@kubb/swagger-ts'
|
|
42
|
+
import createSwaggerTanstackQuery from '@kubb/swagger-tanstack-query'
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
root: '.',
|
|
46
|
+
input: {
|
|
47
|
+
path: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
48
|
+
},
|
|
49
|
+
output: {
|
|
50
|
+
path: './src/gen',
|
|
51
|
+
clean: true,
|
|
52
|
+
},
|
|
53
|
+
hooks: {
|
|
54
|
+
done: 'echo "🎉 done"',
|
|
55
|
+
},
|
|
56
|
+
logLevel: 'info',
|
|
57
|
+
plugins: [createSwagger({}), createSwaggerTS({ output: 'models', enumType: 'enum' }), createSwaggerTanstackQuery({ output: './hooks' })],
|
|
58
|
+
})
|
|
59
|
+
`,
|
|
60
|
+
packages: ['@kubb/core', '@kubb/cli', '@kubb/swagger', '@kubb/swagger-ts', '@kubb/swagger-tanstack-query'],
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function init({ spinner, preset = 'simple', logLevel = 'silent', packageManager = 'pnpm' }: RunProps): Promise<void> {
|
|
65
|
+
try {
|
|
66
|
+
const presetMeta = presets[preset]
|
|
67
|
+
const path = pathParser.resolve(process.cwd(), './kubb.config.js')
|
|
68
|
+
const installCommand = packageManager === 'npm' ? 'install' : 'add'
|
|
69
|
+
|
|
70
|
+
spinner.start(`📀 Writing \`kubb.config.js\` ${pc.dim(path)}`)
|
|
71
|
+
await write(presetMeta['kubb.config'], path)
|
|
72
|
+
spinner.succeed(`📀 Wrote \`kubb.config.js\` ${pc.dim(path)}`)
|
|
73
|
+
|
|
74
|
+
const data = await Promise.all([
|
|
75
|
+
$`npm init es6 -y`,
|
|
76
|
+
...presetMeta.packages.map(async (pack) => {
|
|
77
|
+
spinner.start(`📀 Installing ${pc.dim(pack)}`)
|
|
78
|
+
const { stdout } = await $({ preferLocal: false })`${packageManager} ${installCommand} ${pack}`
|
|
79
|
+
spinner.succeed(`📀 Installed ${pc.dim(pack)}`)
|
|
80
|
+
|
|
81
|
+
return stdout
|
|
82
|
+
}),
|
|
83
|
+
])
|
|
84
|
+
|
|
85
|
+
if (logLevel === 'info') {
|
|
86
|
+
data.forEach((text) => console.log(text))
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
spinner.fail(pc.red(`Something went wrong\n\n${(error as Error)?.message}`))
|
|
90
|
+
}
|
|
91
|
+
}
|