@kaapi/cli 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 demingongo
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,3 @@
1
+ # @kaapi/cli
2
+
3
+ CLI for kaapi.
@@ -0,0 +1,8 @@
1
+ import { CmdAction } from '../definitions';
2
+ declare const _default: CmdAction<{
3
+ type?: "plugin" | "auth-design";
4
+ generator?: string;
5
+ help?: boolean;
6
+ [key: string]: unknown;
7
+ }>;
8
+ export default _default;
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const prompts = tslib_1.__importStar(require("@clack/prompts"));
5
+ const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
6
+ const definitions_1 = require("../definitions");
7
+ const plugin_1 = require("./generators/plugin");
8
+ const utils_1 = require("../utils");
9
+ const FILE_TYPES = {
10
+ 'auth-design': 'Auth Design',
11
+ plugin: 'Plugin'
12
+ };
13
+ function createHelpMessage(action, fileGenerators, fileGenerator, generatorOptions) {
14
+ const defaultDescription = 'Interactive CLI to generate files.';
15
+ let optionsString = '';
16
+ if (generatorOptions && Object.keys(generatorOptions).length) {
17
+ const longestOptionLength = (Object.keys(generatorOptions).map(k => k.length).sort((a, b) => b - a)[0] || 1);
18
+ for (const p in generatorOptions) {
19
+ optionsString += ` --${p.padEnd(longestOptionLength, ' ')} ${generatorOptions[p]}
20
+ `;
21
+ }
22
+ }
23
+ let defaultHelp = `\
24
+
25
+ Usage: kaapi ${action} [OPTION]...
26
+
27
+ ${defaultDescription}
28
+
29
+ Options:
30
+ --generator NAME use a generator
31
+ --type TYPE type of generator
32
+
33
+ Available types:
34
+ auth-design
35
+ plugin
36
+ `;
37
+ if (fileGenerator) {
38
+ defaultHelp = `\
39
+
40
+ Usage: kaapi ${action} --generator ${fileGenerator.name} [OPTION]...
41
+
42
+ ${fileGenerator.description || defaultDescription}
43
+
44
+ Options:
45
+ ${optionsString}
46
+ `;
47
+ }
48
+ else {
49
+ defaultHelp += `
50
+ Available generators:
51
+ `;
52
+ for (const g of fileGenerators) {
53
+ defaultHelp += ` ${g.name}
54
+ `;
55
+ }
56
+ }
57
+ return defaultHelp;
58
+ }
59
+ function cleanupOptionsDefinition(defOptions) {
60
+ const options = {};
61
+ if (defOptions) {
62
+ for (const k in defOptions) {
63
+ if (!['_', 'generator', 'help', 'type'].includes(k))
64
+ options[k] = defOptions[k];
65
+ }
66
+ }
67
+ return options;
68
+ }
69
+ function doContinue(cwd) {
70
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
71
+ prompts.log.info('action: generate');
72
+ if (!(yield (0, utils_1.isKaapiProjectRoot)(cwd))) {
73
+ const isOk = yield prompts.select({
74
+ message: 'Current working directory is not the root of a kaapi project, continue?',
75
+ options: [{
76
+ label: 'yes',
77
+ value: 'y',
78
+ },
79
+ {
80
+ label: 'No',
81
+ value: 'n',
82
+ }],
83
+ initialValue: 'n'
84
+ });
85
+ if (prompts.isCancel(isOk) || isOk == 'n')
86
+ return false;
87
+ }
88
+ return true;
89
+ });
90
+ }
91
+ exports.default = (function generate(argv_1, _a) {
92
+ return tslib_1.__awaiter(this, arguments, void 0, function* (argv, { cancel, config, error, cwd, action }) {
93
+ var _b, _d, _e;
94
+ let generators = [
95
+ plugin_1.pluginGenerator
96
+ ];
97
+ generators = generators.concat(((_b = config.generators) === null || _b === void 0 ? void 0 : _b.map(g => g)) || []);
98
+ let filterType = typeof argv.type === 'string' ? argv.type : undefined;
99
+ let fileGeneratorName = typeof argv.generator === 'string' ? argv.generator : '';
100
+ let fileGenerator;
101
+ const { _: _c, generator: _g, type: _t, help: _h } = argv, initOptions = tslib_1.__rest(argv, ["_", "generator", "type", "help"]);
102
+ if (!generators.length) {
103
+ return error(2, `No generator was found ${filterType ? `(type: ${filterType})` : ''}`);
104
+ }
105
+ if (!fileGeneratorName && argv.help) {
106
+ console.log(createHelpMessage(action, generators));
107
+ return;
108
+ }
109
+ if (!fileGeneratorName) {
110
+ if (!(yield doContinue(cwd)))
111
+ return cancel();
112
+ if (filterType) {
113
+ if (Object.keys(FILE_TYPES).includes(filterType)) {
114
+ generators = generators.filter(g => g.type == filterType) || [];
115
+ }
116
+ else {
117
+ return error(1, `Unknown type "${filterType}"`);
118
+ }
119
+ }
120
+ else {
121
+ const availables = {
122
+ 'auth-design': false,
123
+ plugin: false
124
+ };
125
+ let nbGeneratorTypes = 0;
126
+ let lastGeneratorType = undefined;
127
+ generators.forEach(g => {
128
+ if (availables[g.type] === false) {
129
+ availables[g.type] = true;
130
+ nbGeneratorTypes++;
131
+ lastGeneratorType = g.type;
132
+ }
133
+ });
134
+ if (!nbGeneratorTypes)
135
+ error(2, 'No generator type was found');
136
+ if (nbGeneratorTypes === 1 && lastGeneratorType) {
137
+ filterType = lastGeneratorType;
138
+ }
139
+ else {
140
+ const filterTypeChoice = yield prompts.select({
141
+ message: 'Select a type:',
142
+ options: Object.keys(availables).filter(v => availables[v]).map((value) => {
143
+ return {
144
+ label: FILE_TYPES[value],
145
+ value: value,
146
+ };
147
+ }),
148
+ });
149
+ if (prompts.isCancel(filterTypeChoice))
150
+ return cancel();
151
+ filterType = filterTypeChoice;
152
+ }
153
+ generators = generators.filter(g => g.type == filterType) || [];
154
+ }
155
+ if (!generators.length) {
156
+ return error(2, `No generator was found ${filterType ? `(type: ${filterType})` : ''}`);
157
+ }
158
+ const fileGeneratorChoice = yield prompts.select({
159
+ message: 'Select a generator:',
160
+ options: generators.map((g) => {
161
+ return {
162
+ label: g.name,
163
+ value: g,
164
+ };
165
+ }),
166
+ });
167
+ if (prompts.isCancel(fileGeneratorChoice))
168
+ return cancel();
169
+ fileGenerator = fileGeneratorChoice;
170
+ fileGeneratorName = fileGenerator.name;
171
+ }
172
+ else {
173
+ fileGenerator = generators.filter(g => g.name == fileGeneratorName)[0];
174
+ if (fileGenerator && argv.help) {
175
+ console.log(createHelpMessage(action, generators, fileGenerator, cleanupOptionsDefinition(fileGenerator.options)));
176
+ return;
177
+ }
178
+ if (!(yield doContinue(cwd)))
179
+ return cancel();
180
+ }
181
+ if (!fileGenerator) {
182
+ return error(2, `No generator was found ${fileGeneratorName ? `(name: ${fileGeneratorName})` : ''}`);
183
+ }
184
+ const defOptions = cleanupOptionsDefinition(fileGenerator.options || {});
185
+ const gOptions = {};
186
+ for (const k in defOptions) {
187
+ if (typeof initOptions[k] != 'undefined')
188
+ gOptions[k] = initOptions[k];
189
+ }
190
+ fileGenerator.init(gOptions);
191
+ const questions = ((_d = fileGenerator.getQuestions) === null || _d === void 0 ? void 0 : _d.call(fileGenerator)) || [];
192
+ for (const q of questions) {
193
+ if (q.type === definitions_1.QuestionType.text) {
194
+ const r = yield prompts.text(q.options);
195
+ if (prompts.isCancel(r))
196
+ return cancel();
197
+ q.setValue(r);
198
+ }
199
+ else if (q.type === definitions_1.QuestionType.select) {
200
+ const r = yield prompts.select(q.options);
201
+ if (prompts.isCancel(r))
202
+ return cancel();
203
+ q.setValue(r);
204
+ }
205
+ else if (q.type === definitions_1.QuestionType.multiselect) {
206
+ const r = yield prompts.multiselect(q.options);
207
+ if (prompts.isCancel(r))
208
+ return cancel();
209
+ q.setValue(r);
210
+ }
211
+ }
212
+ if (!fileGenerator.isValid()) {
213
+ return error(2, `Invalid options (generator: ${fileGeneratorName})`);
214
+ }
215
+ const content = fileGenerator.getFileContent();
216
+ if (!content) {
217
+ return error(2, `No content (generator: ${fileGeneratorName})`);
218
+ }
219
+ let filename = (_e = fileGenerator.getFilename) === null || _e === void 0 ? void 0 : _e.call(fileGenerator);
220
+ if (filename) {
221
+ if (!(0, utils_1.isValidFilename)(filename)) {
222
+ prompts.log.error(`Invalid filename: ${filename}`);
223
+ filename = (0, utils_1.kebabCase)(filterType) + '.ts';
224
+ }
225
+ }
226
+ else {
227
+ filename = (0, utils_1.kebabCase)(filterType) + '.ts';
228
+ }
229
+ const r = yield prompts.text({
230
+ message: 'The name of the file?',
231
+ defaultValue: `${filename}`,
232
+ placeholder: `${filename}`
233
+ });
234
+ if (prompts.isCancel(r))
235
+ return cancel();
236
+ if ((0, utils_1.isValidFilename)(r)) {
237
+ filename = r;
238
+ }
239
+ else {
240
+ return error(2, `Invalid filename: ${r}`);
241
+ }
242
+ const target = `plugins/${filename}`;
243
+ try {
244
+ yield promises_1.default.access(target);
245
+ const isOk = yield prompts.select({
246
+ message: `File ${target} already exists, overwrite?`,
247
+ options: [{
248
+ label: 'yes',
249
+ value: 'y',
250
+ },
251
+ {
252
+ label: 'No',
253
+ value: 'n',
254
+ }],
255
+ initialValue: 'n'
256
+ });
257
+ if (prompts.isCancel(isOk) || isOk == 'n')
258
+ return cancel();
259
+ }
260
+ catch (_err) {
261
+ //
262
+ }
263
+ const spinner = prompts.spinner({ indicator: 'dots' });
264
+ spinner.start(`Creating ${target}`);
265
+ try {
266
+ yield promises_1.default.mkdir('plugins', { recursive: true });
267
+ }
268
+ catch (_err) {
269
+ //
270
+ }
271
+ yield promises_1.default.writeFile(`${target}`, content);
272
+ spinner.stop(`Created plugins/${filename}`);
273
+ });
274
+ });
275
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/cmd/generate.ts"],"names":[],"mappings":";;;AAAA,gEAA0C;AAC1C,wEAAiC;AACjC,gDAA2F;AAC3F,gDAAsD;AACtD,oCAA0E;AAE1E,MAAM,UAAU,GAAsC;IAClD,aAAa,EAAE,aAAa;IAC5B,MAAM,EAAE,QAAQ;CACnB,CAAA;AAED,SAAS,iBAAiB,CAAC,MAAc,EAAE,cAA+B,EAAE,aAA6B,EAAE,gBAAyC;IAEhJ,MAAM,kBAAkB,GAAG,oCAAoC,CAAA;IAE/D,IAAI,aAAa,GAAG,EAAE,CAAA;IAEtB,IAAI,gBAAgB,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3D,MAAM,mBAAmB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAE5G,KAAK,MAAM,CAAC,IAAI,gBAAgB,EAAE,CAAC;YAC/B,aAAa,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE,GAAG,CAAC,aAAa,gBAAgB,CAAC,CAAC,CAAC;CACvG,CAAA;QACO,CAAC;IACL,CAAC;IAED,IAAI,WAAW,GAAG;;iBAEL,MAAM;;IAEnB,kBAAkB;;;;;;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AAC,IAAI,IAAI,IAAI,GAAG;gBAAE,OAAO,MAAM,EAAE,CAAA;QAC9D,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;YACZ,EAAE;QACN,CAAC;QACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAA;QACtD,OAAO,CAAC,KAAK,CAAC,YAAY,MAAM,EAAE,CAAC,CAAA;QACnC,IAAI,CAAC;YACD,MAAM,kBAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAClD,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;YACZ,EAAE;QACN,CAAC;QACD,MAAM,kBAAE,CAAC,SAAS,CAAC,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAA;IAE/C,CAAC;CAAA,CAA+G,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { FileGenerator } from '../../definitions';
2
+ export type PluginFileGenerator = FileGenerator & {
3
+ pluginName: string;
4
+ };
5
+ export declare const pluginGenerator: PluginFileGenerator;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginGenerator = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const definitions_1 = require("../../definitions");
6
+ exports.pluginGenerator = {
7
+ name: 'kaapi-plugin',
8
+ type: 'plugin',
9
+ description: 'Creates a simple plugin for kaapi.',
10
+ options: {
11
+ 'plugin-name': 'The name of the plugin'
12
+ },
13
+ pluginName: '',
14
+ init: function (options) {
15
+ if (typeof options['plugin-name'] == 'string') {
16
+ this.pluginName = (0, utils_1.camelCase)(options['plugin-name']);
17
+ }
18
+ },
19
+ getFileContent: function () {
20
+ return `
21
+ import { KaapiPlugin, KaapiTools } from '@kaapi/kaapi'
22
+
23
+ export const ${this.pluginName}: KaapiPlugin = {
24
+ integrate: function (_t: KaapiTools): void | Promise<void> {
25
+ // write your code here
26
+ }
27
+ }
28
+ `;
29
+ },
30
+ isValid() {
31
+ return !!this.pluginName;
32
+ },
33
+ getQuestions() {
34
+ const r = [];
35
+ if (!this.pluginName) {
36
+ r.push({
37
+ type: definitions_1.QuestionType.text,
38
+ options: {
39
+ message: 'The name of the plugin?',
40
+ defaultValue: 'customPlugin',
41
+ placeholder: 'customPlugin'
42
+ },
43
+ setValue: (pluginName) => {
44
+ this.pluginName = (0, utils_1.camelCase)(pluginName);
45
+ }
46
+ });
47
+ }
48
+ return r;
49
+ },
50
+ getFilename() {
51
+ return (0, utils_1.kebabCase)(`${this.pluginName}`) + '.ts';
52
+ }
53
+ };
54
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/cmd/generators/plugin.ts"],"names":[],"mappings":";;;AAAA,uCAAmD;AACnD,mDAA0E;AAM7D,QAAA,eAAe,GAAwB;IAChD,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,oCAAoC;IACjD,OAAO,EAAE;QACL,aAAa,EAAE,wBAAwB;KAC1C;IAED,UAAU,EAAE,EAAE;IAEd,IAAI,EAAE,UAAU,OAAgC;QAC5C,IAAI,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC5C,IAAI,CAAC,UAAU,GAAG,IAAA,iBAAS,EAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;QACvD,CAAC;IACL,CAAC;IACD,cAAc,EAAE;QACZ,OAAO;;;eAGA,IAAI,CAAC,UAAU;;;;;CAK7B,CAAA;IACG,CAAC;IACD,OAAO;QACH,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAA;IAC5B,CAAC;IACD,YAAY;QACR,MAAM,CAAC,GAAe,EAAE,CAAA;QAExB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnB,CAAC,CAAC,IAAI,CAAC;gBACH,IAAI,EAAE,0BAAY,CAAC,IAAI;gBACvB,OAAO,EAAE;oBACL,OAAO,EAAE,yBAAyB;oBAClC,YAAY,EAAE,cAAc;oBAC5B,WAAW,EAAE,cAAc;iBAC9B;gBACD,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE;oBACrB,IAAI,CAAC,UAAU,GAAG,IAAA,iBAAS,EAAC,UAAU,CAAC,CAAA;gBAC3C,CAAC;aACJ,CAAC,CAAA;QACN,CAAC;QAED,OAAO,CAAC,CAAA;IACZ,CAAC;IACD,WAAW;QACP,OAAO,IAAA,iBAAS,EAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,KAAK,CAAA;IAClD,CAAC;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { CmdAction } from '../definitions';
2
+ export declare const ALIASES: Record<string, string>;
3
+ export declare const CMDS: Record<string, CmdAction>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CMDS = exports.ALIASES = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const generate_1 = tslib_1.__importDefault(require("./generate"));
6
+ exports.ALIASES = {
7
+ g: 'generate'
8
+ };
9
+ exports.CMDS = {
10
+ generate: generate_1.default
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmd/index.ts"],"names":[],"mappings":";;;;AACA,kEAAuC;AAE1B,QAAA,OAAO,GAA2B;IAC3C,CAAC,EAAE,UAAU;CAChB,CAAA;AAEY,QAAA,IAAI,GAA8B;IAC3C,QAAQ,EAAE,kBAAc;CAC3B,CAAA"}
@@ -0,0 +1,45 @@
1
+ import { MultiSelectOptions, SelectOptions, TextOptions } from '@clack/prompts';
2
+ import { Argv } from 'mri';
3
+ export declare enum QuestionType {
4
+ text = "text",
5
+ select = "select",
6
+ multiselect = "multiselect"
7
+ }
8
+ export type Question<Value extends Readonly<string | boolean | number> = Readonly<string | boolean | number>> = {
9
+ type: QuestionType.select | 'select';
10
+ options: SelectOptions<Value>;
11
+ setValue(value: Value): void;
12
+ } | {
13
+ type: QuestionType.multiselect | 'multiselect';
14
+ options: MultiSelectOptions<Value>;
15
+ setValue(value: Value[]): void;
16
+ } | {
17
+ type: QuestionType.text | 'text';
18
+ options: TextOptions;
19
+ setValue(value: string): void;
20
+ };
21
+ export type FileGeneratorType = 'plugin' | 'auth-design';
22
+ export interface FileGenerator {
23
+ readonly name: string;
24
+ readonly type: FileGeneratorType;
25
+ readonly description?: string;
26
+ readonly options?: Record<string, string>;
27
+ init(options: Record<string, any>): void;
28
+ isValid(): boolean;
29
+ getFileContent(): string;
30
+ getQuestions?(): Question[];
31
+ getFilename?(): string;
32
+ }
33
+ export interface Config {
34
+ generators?: FileGenerator[];
35
+ }
36
+ export interface CmdContext {
37
+ action: string;
38
+ config: Config;
39
+ cwd: string;
40
+ cancel: () => void;
41
+ error: (code: number, message: string) => void;
42
+ }
43
+ export interface CmdAction<T = Record<string, any>> {
44
+ (argv: Argv<T>, opts: CmdContext): void | Promise<void>;
45
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionType = void 0;
4
+ var QuestionType;
5
+ (function (QuestionType) {
6
+ QuestionType["text"] = "text";
7
+ QuestionType["select"] = "select";
8
+ QuestionType["multiselect"] = "multiselect";
9
+ })(QuestionType || (exports.QuestionType = QuestionType = {}));
10
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":";;;AAGA,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,6BAAa,CAAA;IACb,iCAAiB,CAAA;IACjB,2CAA2B,CAAA;AAC/B,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ //1. questions
3
+ // - name of the class (to kebab case for the name of the strategy) => input text
4
+ // - type of auth (apiKey, bearer, basic, ...) => select
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //2. create file (filepath)
7
+ //# sourceMappingURL=authDesign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authDesign.js","sourceRoot":"","sources":["../../../src/generators/auth-design/authDesign.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,iFAAiF;AACjF,wDAAwD;;AAExD,2BAA2B"}
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const tslib_1 = require("tslib");
5
+ const prompts = tslib_1.__importStar(require("@clack/prompts"));
6
+ const load_config_1 = require("./load-config");
7
+ const package_json_1 = tslib_1.__importDefault(require("../package.json"));
8
+ const mri_1 = tslib_1.__importDefault(require("mri"));
9
+ const cmd_1 = require("./cmd");
10
+ const argv = (0, mri_1.default)(process.argv.slice(2), {
11
+ alias: { h: 'help' },
12
+ boolean: ['help']
13
+ });
14
+ const cwd = process.cwd();
15
+ const cancel = () => {
16
+ prompts.cancel('Operation cancelled');
17
+ process.exit(130);
18
+ };
19
+ const error = (code, message) => {
20
+ prompts.cancel(message);
21
+ process.exit(code);
22
+ };
23
+ (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
24
+ if (!argv.help)
25
+ prompts.intro(`${package_json_1.default.name} ${package_json_1.default.version}`);
26
+ const config = yield (0, load_config_1.loadKaapiConfig)(!!argv.help);
27
+ //console.log('Loaded kaapi config:', config);
28
+ const opts = {
29
+ config,
30
+ cwd,
31
+ cancel,
32
+ error,
33
+ action: ''
34
+ };
35
+ let cmd = argv._[0]
36
+ ? String(argv._[0])
37
+ : '';
38
+ if (!cmd) {
39
+ if (argv.help) {
40
+ // TODO: list actions
41
+ return;
42
+ }
43
+ const action = yield prompts.select({
44
+ message: 'What do you want to do?:',
45
+ options: Object.keys(cmd_1.CMDS).map((label) => {
46
+ return {
47
+ label,
48
+ value: cmd_1.CMDS[label],
49
+ };
50
+ }),
51
+ });
52
+ if (prompts.isCancel(action))
53
+ return cancel();
54
+ if (action) {
55
+ yield action(argv, opts);
56
+ }
57
+ }
58
+ else {
59
+ cmd = cmd_1.ALIASES[cmd] || cmd;
60
+ const action = cmd_1.CMDS[cmd];
61
+ if (action) {
62
+ opts.action = cmd;
63
+ yield action(argv, opts);
64
+ }
65
+ }
66
+ if (!argv.help)
67
+ prompts.outro('Operation ended');
68
+ }))();
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAEA,gEAA0C;AAC1C,+CAAgD;AAChD,2EAAmC;AACnC,sDAAsB;AAEtB,+BAGc;AAGd,MAAM,IAAI,GAAG,IAAA,aAAG,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACpC,KAAK,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE;IACpB,OAAO,EAAE,CAAC,MAAM,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAE1B,MAAM,MAAM,GAAG,GAAG,EAAE;IAChB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAA;IACrC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,EAAE;IAC5C,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,CAAC,GA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xB,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC,MAAM,GAAG,GAAG,CAAA;YACjB,MAAM,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC5B,CAAC;IACL,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,IAAI;QACV,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;AACxC,CAAC,CAAA,CAAC,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Config } from './definitions';
2
+ export declare function loadKaapiConfig(silent?: boolean): Promise<Config>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadKaapiConfig = loadKaapiConfig;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
+ const url_1 = require("url");
8
+ const prompts = tslib_1.__importStar(require("@clack/prompts"));
9
+ function loadKaapiConfig(silent) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ const configNames = ['kaapi.config.mjs', 'kaapi.config.js'];
12
+ let configPath;
13
+ for (const name of configNames) {
14
+ const fullPath = node_path_1.default.resolve(process.cwd(), name);
15
+ if (node_fs_1.default.existsSync(fullPath)) {
16
+ configPath = fullPath;
17
+ break;
18
+ }
19
+ }
20
+ if (!configPath) {
21
+ if (!silent)
22
+ prompts.log.warn('No kaapi config file found.');
23
+ return {};
24
+ }
25
+ // Support both CommonJS and ESM exports
26
+ const configModulePath = node_path_1.default.resolve(configPath);
27
+ const configModuleUrl = (0, url_1.pathToFileURL)(configModulePath).href;
28
+ const configModule = yield import(configModuleUrl);
29
+ const config = configModule.default || configModule;
30
+ if (!silent)
31
+ prompts.log.info(`Loaded kaapi config: ${configPath}`);
32
+ return config;
33
+ });
34
+ }
35
+ //# sourceMappingURL=load-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-config.js","sourceRoot":"","sources":["../src/load-config.ts"],"names":[],"mappings":";;AAMA,0CA0BC;;AAhCD,8DAAyB;AACzB,kEAA6B;AAC7B,6BAAoC;AACpC,gEAA0C;AAG1C,SAAsB,eAAe,CAAC,MAAgB;;QAClD,MAAM,WAAW,GAAG,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;QAC5D,IAAI,UAA8B,CAAC;QAEnC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;YACnD,IAAI,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1B,UAAU,GAAG,QAAQ,CAAC;gBACtB,MAAM;YACV,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,IAAG,CAAC,MAAM;gBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YAC5D,OAAO,EAAE,CAAA;QACb,CAAC;QAED,wCAAwC;QACxC,MAAM,gBAAgB,GAAG,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,eAAe,GAAG,IAAA,mBAAa,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;QAC7D,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC;QAEpD,IAAG,CAAC,MAAM;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,UAAU,EAAE,CAAC,CAAA;QAElE,OAAO,MAAM,CAAC;IAClB,CAAC;CAAA"}
@@ -0,0 +1,2 @@
1
+ import { Config } from './definitions';
2
+ export declare function loadKaapiConfig(): Promise<Config>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadKaapiConfig = loadKaapiConfig;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
7
+ const url_1 = require("url");
8
+ const prompts = tslib_1.__importStar(require("@clack/prompts"));
9
+ function loadKaapiConfig() {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ const configNames = ['kaapi.config.mjs', 'kaapi.config.js'];
12
+ let configPath;
13
+ for (const name of configNames) {
14
+ const fullPath = node_path_1.default.resolve(process.cwd(), name);
15
+ if (node_fs_1.default.existsSync(fullPath)) {
16
+ configPath = fullPath;
17
+ break;
18
+ }
19
+ }
20
+ if (!configPath) {
21
+ prompts.log.warn('No kaapi config file found.');
22
+ return {};
23
+ }
24
+ // Support both CommonJS and ESM exports
25
+ const configModulePath = node_path_1.default.resolve(configPath);
26
+ const configModuleUrl = (0, url_1.pathToFileURL)(configModulePath).href;
27
+ const configModule = yield import(configModuleUrl);
28
+ const config = configModule.default || configModule;
29
+ prompts.log.info(`Loaded kaapi config: ${configPath}`);
30
+ return config;
31
+ });
32
+ }
33
+ //# sourceMappingURL=loadConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../src/loadConfig.ts"],"names":[],"mappings":";;AAMA,0CA0BC;;AAhCD,8DAAyB;AACzB,kEAA6B;AAC7B,6BAAoC;AACpC,gEAA0C;AAG1C,SAAsB,eAAe;;QACjC,MAAM,WAAW,GAAG,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,CAAC;QAC5D,IAAI,UAA8B,CAAC;QAEnC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,mBAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;YACnD,IAAI,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1B,UAAU,GAAG,QAAQ,CAAC;gBACtB,MAAM;YACV,CAAC;QACL,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YAChD,OAAO,EAAE,CAAA;QACb,CAAC;QAED,wCAAwC;QACxC,MAAM,gBAAgB,GAAG,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,eAAe,GAAG,IAAA,mBAAa,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;QAC7D,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC;QAEpD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,UAAU,EAAE,CAAC,CAAA;QAEtD,OAAO,MAAM,CAAC;IAClB,CAAC;CAAA"}
@@ -0,0 +1,18 @@
1
+ export declare const camelCase: (string?: string) => string;
2
+ export declare const kebabCase: (string?: string) => string;
3
+ export declare const snakeCase: (string?: string) => string;
4
+ /**
5
+ * Allows only:
6
+ * - Letters (a-z, A-Z)
7
+ * - Numbers (0-9)
8
+ * - Dashes (-)
9
+ * - Underscores (_)
10
+ * - Dots (.)
11
+ *
12
+ * Enforces:
13
+ * - Minimum 4 characters
14
+ * - At least one dot (.)
15
+ * - At least one letter after the last dot
16
+ */
17
+ export declare function isValidFilename(input: string): boolean;
18
+ export declare function isKaapiProjectRoot(path: string): Promise<boolean>;
package/dist/utils.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.snakeCase = exports.kebabCase = exports.camelCase = void 0;
4
+ exports.isValidFilename = isValidFilename;
5
+ exports.isKaapiProjectRoot = isKaapiProjectRoot;
6
+ const tslib_1 = require("tslib");
7
+ const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
8
+ const kebabCase_1 = tslib_1.__importDefault(require("lodash/kebabCase"));
9
+ const snakeCase_1 = tslib_1.__importDefault(require("lodash/snakeCase"));
10
+ const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
11
+ const node_path_1 = tslib_1.__importDefault(require("node:path"));
12
+ exports.camelCase = camelCase_1.default;
13
+ exports.kebabCase = kebabCase_1.default;
14
+ exports.snakeCase = snakeCase_1.default;
15
+ /**
16
+ * Allows only:
17
+ * - Letters (a-z, A-Z)
18
+ * - Numbers (0-9)
19
+ * - Dashes (-)
20
+ * - Underscores (_)
21
+ * - Dots (.)
22
+ *
23
+ * Enforces:
24
+ * - Minimum 4 characters
25
+ * - At least one dot (.)
26
+ * - At least one letter after the last dot
27
+ */
28
+ function isValidFilename(input) {
29
+ const regex = /^(?=[a-zA-Z0-9._-]{4,}$)(?=.*\.)[a-zA-Z0-9_-]*\.[a-zA-Z]+$/;
30
+ return regex.test(input);
31
+ }
32
+ function isKaapiProjectRoot(path) {
33
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
34
+ var _a;
35
+ try {
36
+ const pkgPath = node_path_1.default.join(path, 'package.json');
37
+ //await fs.access(pkgPath);
38
+ const pkgContent = yield promises_1.default.readFile(pkgPath);
39
+ const pkg = JSON.parse(Buffer.from(pkgContent).toString('utf-8'));
40
+ if (typeof ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a['@kaapi/kaapi']) != 'string') {
41
+ return false;
42
+ }
43
+ return true;
44
+ }
45
+ catch (_b) {
46
+ return false;
47
+ }
48
+ });
49
+ }
50
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAuBA,0CAGC;AAED,gDAgBC;;AA5CD,yEAAyC;AACzC,yEAAyC;AACzC,yEAAyC;AACzC,wEAAiC;AACjC,kEAAgC;AAEnB,QAAA,SAAS,GAAG,mBAAU,CAAA;AACtB,QAAA,SAAS,GAAG,mBAAU,CAAA;AACtB,QAAA,SAAS,GAAG,mBAAU,CAAA;AAEnC;;;;;;;;;;;;GAYG;AACH,SAAgB,eAAe,CAAC,KAAa;IAC3C,MAAM,KAAK,GAAG,4DAA4D,CAAC;IAC3E,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAsB,kBAAkB,CAAC,IAAY;;;QACnD,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAA;YAEnD,2BAA2B;YAC3B,MAAM,UAAU,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;YAEjE,IAAG,OAAO,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,YAAY,0CAAG,cAAc,CAAC,CAAA,IAAI,QAAQ,EAAE,CAAC;gBACxD,OAAO,KAAK,CAAA;YAChB,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CAAA"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@kaapi/cli",
3
+ "version": "0.0.1",
4
+ "description": "CLI for kaapi",
5
+ "main": "dist/definitions.js",
6
+ "exports": {
7
+ "./definitions": {
8
+ "types": "./dist/definitions.d.ts",
9
+ "default": "./dist/definitions.js"
10
+ },
11
+ "./utils": {
12
+ "types": "./dist/utils.d.ts",
13
+ "default": "./dist/utils.js"
14
+ }
15
+ },
16
+ "bin": {
17
+ "kaapi": "dist/index.js"
18
+ },
19
+ "author": "demingongo",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/demingongo/kaapi.git",
23
+ "directory": "packages/cli"
24
+ },
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@clack/prompts": "^0.11.0",
28
+ "lodash": "^4.17.21",
29
+ "mri": "^1.2.0",
30
+ "tslib": "^2.8.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/lodash": "^4.17.20"
34
+ },
35
+ "scripts": {
36
+ "lint": "eslint .",
37
+ "build": "tsc",
38
+ "test": "ts-node src/index.ts",
39
+ "test:bin": "node dist/index.js"
40
+ }
41
+ }