@kubb/cli 0.8.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Stijn Van Hulle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Demo
package/dist/index.js ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ moduleName: () => moduleName
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+ var import_commander = require("commander");
33
+ var import_cosmiconfig = require("cosmiconfig");
34
+ var import_cosmiconfig_typescript_loader = require("cosmiconfig-typescript-loader");
35
+ var import_picocolors2 = __toESM(require("picocolors"));
36
+
37
+ // src/run.ts
38
+ var import_picocolors = __toESM(require("picocolors"));
39
+ var import_ora = __toESM(require("ora"));
40
+ var import_core = require("@kubb/core");
41
+
42
+ // src/utils/getPlugins.ts
43
+ var isJSONPlugins = (plugins) => {
44
+ return !!plugins?.some((plugin) => {
45
+ return typeof plugin?.[0] === "string";
46
+ });
47
+ };
48
+ var getPlugins = (plugins) => {
49
+ if (isJSONPlugins(plugins)) {
50
+ return plugins.map((plugin) => {
51
+ const [name, options = {}] = plugin;
52
+ const importedPlugin = require(name);
53
+ return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
54
+ });
55
+ }
56
+ return plugins;
57
+ };
58
+
59
+ // src/utils/createConfig.ts
60
+ var createConfig = async (result) => {
61
+ let config = result?.config;
62
+ if (result?.filepath.endsWith(".json")) {
63
+ config = {
64
+ ...result.config,
65
+ plugins: getPlugins(result.config.plugins)
66
+ };
67
+ }
68
+ if (typeof result?.config === "function") {
69
+ const possiblePromise = result?.config();
70
+ if (typeof possiblePromise?.then === "function") {
71
+ config = await possiblePromise;
72
+ } else {
73
+ config = possiblePromise;
74
+ }
75
+ }
76
+ return config;
77
+ };
78
+
79
+ // src/run.ts
80
+ var date = new Date();
81
+ async function run(result) {
82
+ const spinner = (0, import_ora.default)({
83
+ color: "blue",
84
+ text: import_picocolors.default.blue("Generating files"),
85
+ spinner: date.getMonth() >= 10 && date.getMonth() < 12 ? "christmas" : "timeTravel",
86
+ stream: process.stdout
87
+ }).start();
88
+ const buildContext = {
89
+ logger: {
90
+ log(message, logLevel) {
91
+ if (logLevel === "error") {
92
+ spinner.fail(message);
93
+ }
94
+ spinner[logLevel](message);
95
+ },
96
+ spinner
97
+ }
98
+ };
99
+ try {
100
+ const config = await createConfig(result);
101
+ await import_core.build.call(buildContext, config, { mode: "development" });
102
+ spinner.succeed(import_picocolors.default.blue("Generated files"));
103
+ } catch (err) {
104
+ spinner.fail("Something went wrong\n");
105
+ console.error(err);
106
+ }
107
+ return true;
108
+ }
109
+
110
+ // src/index.ts
111
+ var moduleName = "regenerator";
112
+ var explorer = (0, import_cosmiconfig.cosmiconfig)(moduleName, {
113
+ searchPlaces: [
114
+ "package.json",
115
+ `.${moduleName}rc`,
116
+ `.${moduleName}rc.json`,
117
+ `.${moduleName}rc.yaml`,
118
+ `.${moduleName}rc.yml`,
119
+ `.${moduleName}rc.js`,
120
+ `.${moduleName}rc.cjs`,
121
+ `${moduleName}.config.js`,
122
+ `${moduleName}.config.cjs`,
123
+ `.${moduleName}rc.ts`,
124
+ `${moduleName}.config.ts`
125
+ ],
126
+ loaders: {
127
+ ".ts": (0, import_cosmiconfig_typescript_loader.TypeScriptLoader)()
128
+ }
129
+ });
130
+ var program = new import_commander.Command("model").description("Generate models").action(async (options) => {
131
+ const result = options.config ? await explorer.load(options.config) : await explorer.search();
132
+ if (result?.isEmpty || !result || !result.config) {
133
+ console.log(import_picocolors2.default.red("Config not defined, create a regenerator.config.js or pass through your config with the option --config"));
134
+ return;
135
+ }
136
+ if (options.debug) {
137
+ console.log(`Reading config from ${result?.filepath}`);
138
+ if (typeof result?.config === "function") {
139
+ console.log(`Config data
140
+ ${result?.config}`);
141
+ } else {
142
+ console.log(`Config data
143
+ ${JSON.stringify(result?.config, void 0, 2)}`);
144
+ }
145
+ }
146
+ if (options.debug) {
147
+ console.log("\n");
148
+ console.log(import_picocolors2.default.blue("Build started with:\n"));
149
+ console.log(import_picocolors2.default.white(JSON.stringify(result.config, void 0, 2)));
150
+ console.log("\n");
151
+ }
152
+ await run(result);
153
+ }).addOption(new import_commander.Option("-c, --config <path>", "Path to @kubb config")).addOption(new import_commander.Option("-d, --debug", "Debug mode").default(false));
154
+ program.name(moduleName).description("Generate").version("0.0.1");
155
+ program.parse();
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ moduleName
159
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env node
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined")
6
+ return require.apply(this, arguments);
7
+ throw new Error('Dynamic require of "' + x + '" is not supported');
8
+ });
9
+
10
+ // src/index.ts
11
+ import { Command, Option } from "commander";
12
+ import { cosmiconfig } from "cosmiconfig";
13
+ import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
14
+ import pc2 from "picocolors";
15
+
16
+ // src/run.ts
17
+ import pc from "picocolors";
18
+ import ora from "ora";
19
+ import { build } from "@kubb/core";
20
+
21
+ // src/utils/getPlugins.ts
22
+ var isJSONPlugins = (plugins) => {
23
+ return !!plugins?.some((plugin) => {
24
+ return typeof plugin?.[0] === "string";
25
+ });
26
+ };
27
+ var getPlugins = (plugins) => {
28
+ if (isJSONPlugins(plugins)) {
29
+ return plugins.map((plugin) => {
30
+ const [name, options = {}] = plugin;
31
+ const importedPlugin = __require(name);
32
+ return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options);
33
+ });
34
+ }
35
+ return plugins;
36
+ };
37
+
38
+ // src/utils/createConfig.ts
39
+ var createConfig = async (result) => {
40
+ let config = result?.config;
41
+ if (result?.filepath.endsWith(".json")) {
42
+ config = {
43
+ ...result.config,
44
+ plugins: getPlugins(result.config.plugins)
45
+ };
46
+ }
47
+ if (typeof result?.config === "function") {
48
+ const possiblePromise = result?.config();
49
+ if (typeof possiblePromise?.then === "function") {
50
+ config = await possiblePromise;
51
+ } else {
52
+ config = possiblePromise;
53
+ }
54
+ }
55
+ return config;
56
+ };
57
+
58
+ // src/run.ts
59
+ var date = new Date();
60
+ async function run(result) {
61
+ const spinner = ora({
62
+ color: "blue",
63
+ text: pc.blue("Generating files"),
64
+ spinner: date.getMonth() >= 10 && date.getMonth() < 12 ? "christmas" : "timeTravel",
65
+ stream: process.stdout
66
+ }).start();
67
+ const buildContext = {
68
+ logger: {
69
+ log(message, logLevel) {
70
+ if (logLevel === "error") {
71
+ spinner.fail(message);
72
+ }
73
+ spinner[logLevel](message);
74
+ },
75
+ spinner
76
+ }
77
+ };
78
+ try {
79
+ const config = await createConfig(result);
80
+ await build.call(buildContext, config, { mode: "development" });
81
+ spinner.succeed(pc.blue("Generated files"));
82
+ } catch (err) {
83
+ spinner.fail("Something went wrong\n");
84
+ console.error(err);
85
+ }
86
+ return true;
87
+ }
88
+
89
+ // src/index.ts
90
+ var moduleName = "regenerator";
91
+ var explorer = cosmiconfig(moduleName, {
92
+ searchPlaces: [
93
+ "package.json",
94
+ `.${moduleName}rc`,
95
+ `.${moduleName}rc.json`,
96
+ `.${moduleName}rc.yaml`,
97
+ `.${moduleName}rc.yml`,
98
+ `.${moduleName}rc.js`,
99
+ `.${moduleName}rc.cjs`,
100
+ `${moduleName}.config.js`,
101
+ `${moduleName}.config.cjs`,
102
+ `.${moduleName}rc.ts`,
103
+ `${moduleName}.config.ts`
104
+ ],
105
+ loaders: {
106
+ ".ts": TypeScriptLoader()
107
+ }
108
+ });
109
+ var program = new Command("model").description("Generate models").action(async (options) => {
110
+ const result = options.config ? await explorer.load(options.config) : await explorer.search();
111
+ if (result?.isEmpty || !result || !result.config) {
112
+ console.log(pc2.red("Config not defined, create a regenerator.config.js or pass through your config with the option --config"));
113
+ return;
114
+ }
115
+ if (options.debug) {
116
+ console.log(`Reading config from ${result?.filepath}`);
117
+ if (typeof result?.config === "function") {
118
+ console.log(`Config data
119
+ ${result?.config}`);
120
+ } else {
121
+ console.log(`Config data
122
+ ${JSON.stringify(result?.config, void 0, 2)}`);
123
+ }
124
+ }
125
+ if (options.debug) {
126
+ console.log("\n");
127
+ console.log(pc2.blue("Build started with:\n"));
128
+ console.log(pc2.white(JSON.stringify(result.config, void 0, 2)));
129
+ console.log("\n");
130
+ }
131
+ await run(result);
132
+ }).addOption(new Option("-c, --config <path>", "Path to @kubb config")).addOption(new Option("-d, --debug", "Debug mode").default(false));
133
+ program.name(moduleName).description("Generate").version("0.0.1");
134
+ program.parse();
135
+ export {
136
+ moduleName
137
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@kubb/cli",
3
+ "version": "0.8.0",
4
+ "description": "Generator cli",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git://github.com/stijnvanhulle/kubb.git",
8
+ "directory": "packages/cli"
9
+ },
10
+ "license": "MIT",
11
+ "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
12
+ "sideEffects": false,
13
+ "bin": {
14
+ "regenerator": "dist/index.mjs"
15
+ },
16
+ "preferGlobal": true,
17
+ "files": [
18
+ "dist",
19
+ "!/**/**.test.**",
20
+ "!/**/__tests__/**"
21
+ ],
22
+ "dependencies": {
23
+ "@kubb/core": "0.8.0",
24
+ "commander": "^9.4.1",
25
+ "cosmiconfig": "^7.1.0",
26
+ "cosmiconfig-typescript-loader": "^4.2.0",
27
+ "ora": "^5.4.1",
28
+ "picocolors": "^1.0.0",
29
+ "ts-node": "^10.9.1"
30
+ },
31
+ "devDependencies": {
32
+ "@kubb/swagger": "0.8.0",
33
+ "@kubb/swagger-typescript": "0.8.0",
34
+ "tsup": "^6.5.0",
35
+ "typescript": "^4.9.3",
36
+ "@types/node": "^18.11.9"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "start": "tsup --watch",
45
+ "release": "pnpm publish --no-git-check",
46
+ "pre-commit": "echo 'pre-commit not configured'",
47
+ "pre-push": "pnpm typecheck",
48
+ "test": "jest --config ../../jest.config.js --passWithNoTests --runInBand --testPathPattern=packages/core/src",
49
+ "test:local": "jest --config ../../jest.config.js --testPathPattern=packages/core/src --maxWorkers=50%",
50
+ "test:watch": "jest --config ../../jest.config.js --testPathPattern=packages/core/src --maxWorkers=25% --watch",
51
+ "upgrade": "ncu -u",
52
+ "upgrade:local": "ncu --interactive --doctor",
53
+ "typecheck": "tsc -p ./tsconfig.json --noEmit"
54
+ }
55
+ }