@ciwergrp/nuxid 1.0.2-release
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/README.md +119 -0
- package/bin/kiban.mjs +41 -0
- package/console/request.mjs +337 -0
- package/dist/module.d.mts +188 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +439 -0
- package/dist/runtime/form.d.ts +21 -0
- package/dist/runtime/form.js +161 -0
- package/dist/runtime/helper/array/collapse.d.ts +1 -0
- package/dist/runtime/helper/array/collapse.js +9 -0
- package/dist/runtime/helper/array/crossJoin.d.ts +1 -0
- package/dist/runtime/helper/array/crossJoin.js +17 -0
- package/dist/runtime/helper/array/every.d.ts +1 -0
- package/dist/runtime/helper/array/every.js +3 -0
- package/dist/runtime/helper/array/first.d.ts +1 -0
- package/dist/runtime/helper/array/first.js +11 -0
- package/dist/runtime/helper/array/flatten.d.ts +1 -0
- package/dist/runtime/helper/array/flatten.js +14 -0
- package/dist/runtime/helper/array/index.d.ts +46 -0
- package/dist/runtime/helper/array/index.js +69 -0
- package/dist/runtime/helper/array/join.d.ts +1 -0
- package/dist/runtime/helper/array/join.js +11 -0
- package/dist/runtime/helper/array/last.d.ts +1 -0
- package/dist/runtime/helper/array/last.js +11 -0
- package/dist/runtime/helper/array/map.d.ts +1 -0
- package/dist/runtime/helper/array/map.js +3 -0
- package/dist/runtime/helper/array/mapSpread.d.ts +1 -0
- package/dist/runtime/helper/array/mapSpread.js +3 -0
- package/dist/runtime/helper/array/partition.d.ts +1 -0
- package/dist/runtime/helper/array/partition.js +12 -0
- package/dist/runtime/helper/array/random.d.ts +1 -0
- package/dist/runtime/helper/array/random.js +19 -0
- package/dist/runtime/helper/array/reject.d.ts +1 -0
- package/dist/runtime/helper/array/reject.js +3 -0
- package/dist/runtime/helper/array/shuffle.d.ts +1 -0
- package/dist/runtime/helper/array/shuffle.js +8 -0
- package/dist/runtime/helper/array/sole.d.ts +1 -0
- package/dist/runtime/helper/array/sole.js +7 -0
- package/dist/runtime/helper/array/some.d.ts +1 -0
- package/dist/runtime/helper/array/some.js +3 -0
- package/dist/runtime/helper/array/sort.d.ts +1 -0
- package/dist/runtime/helper/array/sort.js +4 -0
- package/dist/runtime/helper/array/sortDesc.d.ts +1 -0
- package/dist/runtime/helper/array/sortDesc.js +9 -0
- package/dist/runtime/helper/array/take.d.ts +1 -0
- package/dist/runtime/helper/array/take.js +9 -0
- package/dist/runtime/helper/array/where.d.ts +1 -0
- package/dist/runtime/helper/array/where.js +3 -0
- package/dist/runtime/helper/array/whereNotNull.d.ts +1 -0
- package/dist/runtime/helper/array/whereNotNull.js +3 -0
- package/dist/runtime/helper/array/wrap.d.ts +1 -0
- package/dist/runtime/helper/array/wrap.js +6 -0
- package/dist/runtime/helper/index.d.ts +4 -0
- package/dist/runtime/helper/index.js +4 -0
- package/dist/runtime/helper/number/clamp.d.ts +1 -0
- package/dist/runtime/helper/number/clamp.js +3 -0
- package/dist/runtime/helper/number/currency.d.ts +1 -0
- package/dist/runtime/helper/number/currency.js +14 -0
- package/dist/runtime/helper/number/fileSize.d.ts +1 -0
- package/dist/runtime/helper/number/fileSize.js +12 -0
- package/dist/runtime/helper/number/format.d.ts +1 -0
- package/dist/runtime/helper/number/format.js +12 -0
- package/dist/runtime/helper/number/humanize.d.ts +5 -0
- package/dist/runtime/helper/number/humanize.js +39 -0
- package/dist/runtime/helper/number/index.d.ts +37 -0
- package/dist/runtime/helper/number/index.js +60 -0
- package/dist/runtime/helper/number/intl.d.ts +5 -0
- package/dist/runtime/helper/number/intl.js +32 -0
- package/dist/runtime/helper/number/ordinal.d.ts +1 -0
- package/dist/runtime/helper/number/ordinal.js +26 -0
- package/dist/runtime/helper/number/pairs.d.ts +1 -0
- package/dist/runtime/helper/number/pairs.js +11 -0
- package/dist/runtime/helper/number/parse.d.ts +4 -0
- package/dist/runtime/helper/number/parse.js +19 -0
- package/dist/runtime/helper/number/percentage.d.ts +1 -0
- package/dist/runtime/helper/number/percentage.js +14 -0
- package/dist/runtime/helper/number/spell.d.ts +2 -0
- package/dist/runtime/helper/number/spell.js +145 -0
- package/dist/runtime/helper/number/state.d.ts +1 -0
- package/dist/runtime/helper/number/state.js +8 -0
- package/dist/runtime/helper/number/trim.d.ts +1 -0
- package/dist/runtime/helper/number/trim.js +3 -0
- package/dist/runtime/helper/object/add.d.ts +2 -0
- package/dist/runtime/helper/object/add.js +8 -0
- package/dist/runtime/helper/object/dot.d.ts +1 -0
- package/dist/runtime/helper/object/dot.js +19 -0
- package/dist/runtime/helper/object/except.d.ts +2 -0
- package/dist/runtime/helper/object/except.js +10 -0
- package/dist/runtime/helper/object/forget.d.ts +2 -0
- package/dist/runtime/helper/object/forget.js +24 -0
- package/dist/runtime/helper/object/get.d.ts +2 -0
- package/dist/runtime/helper/object/get.js +15 -0
- package/dist/runtime/helper/object/has.d.ts +2 -0
- package/dist/runtime/helper/object/has.js +5 -0
- package/dist/runtime/helper/object/index.d.ts +22 -0
- package/dist/runtime/helper/object/index.js +33 -0
- package/dist/runtime/helper/object/only.d.ts +2 -0
- package/dist/runtime/helper/object/only.js +12 -0
- package/dist/runtime/helper/object/set.d.ts +2 -0
- package/dist/runtime/helper/object/set.js +23 -0
- package/dist/runtime/helper/object/undot.d.ts +1 -0
- package/dist/runtime/helper/object/undot.js +8 -0
- package/dist/runtime/helper/object/utils.d.ts +3 -0
- package/dist/runtime/helper/object/utils.js +10 -0
- package/dist/runtime/helper/state.d.ts +6 -0
- package/dist/runtime/helper/state.js +50 -0
- package/dist/runtime/helper/string/basic.d.ts +7 -0
- package/dist/runtime/helper/string/basic.js +42 -0
- package/dist/runtime/helper/string/bounds.d.ts +6 -0
- package/dist/runtime/helper/string/bounds.js +42 -0
- package/dist/runtime/helper/string/case.d.ts +9 -0
- package/dist/runtime/helper/string/case.js +50 -0
- package/dist/runtime/helper/string/index.d.ts +57 -0
- package/dist/runtime/helper/string/index.js +100 -0
- package/dist/runtime/helper/string/locale.d.ts +1 -0
- package/dist/runtime/helper/string/locale.js +1 -0
- package/dist/runtime/helper/string/match.d.ts +4 -0
- package/dist/runtime/helper/string/match.js +15 -0
- package/dist/runtime/helper/string/pad.d.ts +3 -0
- package/dist/runtime/helper/string/pad.js +12 -0
- package/dist/runtime/helper/string/plural.d.ts +3 -0
- package/dist/runtime/helper/string/plural.js +16 -0
- package/dist/runtime/helper/string/replace.d.ts +4 -0
- package/dist/runtime/helper/string/replace.js +25 -0
- package/dist/runtime/helper/string/slug.d.ts +1 -0
- package/dist/runtime/helper/string/slug.js +8 -0
- package/dist/runtime/helper/string/transliterate.d.ts +2 -0
- package/dist/runtime/helper/string/transliterate.js +8 -0
- package/dist/runtime/helper/string/words.d.ts +2 -0
- package/dist/runtime/helper/string/words.js +13 -0
- package/dist/runtime/lodash.d.ts +1 -0
- package/dist/runtime/lodash.js +1 -0
- package/dist/runtime/pinia/composables.d.ts +2 -0
- package/dist/runtime/pinia/composables.js +3 -0
- package/dist/runtime/pinia/payload-plugin.d.ts +5 -0
- package/dist/runtime/pinia/payload-plugin.js +15 -0
- package/dist/runtime/pinia/plugin.d.ts +6 -0
- package/dist/runtime/pinia/plugin.js +22 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +4 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/validator.d.ts +13 -0
- package/dist/runtime/validator.js +445 -0
- package/dist/types.d.mts +11 -0
- package/package.json +90 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Kiban – Nuxt Essentials
|
|
2
|
+
|
|
3
|
+
Kiban bundles a handful of productivity helpers for Nuxt projects: icon defaults, lodash auto-imports, Element Plus validation helpers, and a flexible form composable. Enable the pieces you need and keep the rest off.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
Install and register the module:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add kiban
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// nuxt.config.ts
|
|
15
|
+
export default defineNuxtConfig({
|
|
16
|
+
modules: ['kiban'],
|
|
17
|
+
kiban: {
|
|
18
|
+
// lodash, validator, icon, and form are enabled by default
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Icon defaults** (`@nuxt/icon` dependency): component name `KIcon`, size `1.25em`, base class `align-middle inline-block text-current`, mode `svg`. Override via `kiban.icon`, or disable with `kiban.icon = false`.
|
|
26
|
+
- **Lodash auto-imports**: imports from `lodash-es` with prefix `ki` (e.g. `kiDebounce`), skips prefix for names starting with `is`. Configure with:
|
|
27
|
+
- `enabled` (default `true`)
|
|
28
|
+
- `prefix` (`false | string`, default `'ki'`)
|
|
29
|
+
- `prefixSkip` (`string | string[] | false`, default `'is'`)
|
|
30
|
+
- `upperAfterPrefix` (`boolean`, default `true`)
|
|
31
|
+
- `exclude` (`string[]`)
|
|
32
|
+
- `alias` (`Array<[from, to]>`)
|
|
33
|
+
- **Validator helpers**: Element Plus friendly `createValidationRules` plus `ValidationRule` and `ValidationOptions` types. Auto-imported when enabled.
|
|
34
|
+
- **Form composable**: `useForm` wraps `$fetch`, handles `processing`, `errors`, `response`, and builds `FormData` automatically (or always when `alwaysFormData: true`). Auto-imported when enabled.
|
|
35
|
+
|
|
36
|
+
## Usage snippets
|
|
37
|
+
|
|
38
|
+
**Lodash example**
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const result = kiDebounce(() => console.log('hello'), 200)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Validator example**
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const rules = createValidationRules(
|
|
48
|
+
{
|
|
49
|
+
email: ['required', 'email'],
|
|
50
|
+
password: ['required', 'min:8'],
|
|
51
|
+
},
|
|
52
|
+
formState,
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Form example**
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const form = useForm({ name: '', avatar: null }, { alwaysFormData: false })
|
|
60
|
+
|
|
61
|
+
await form.post('/api/profile')
|
|
62
|
+
|
|
63
|
+
if (form.errors) {
|
|
64
|
+
console.error(form.errors)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration reference
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
export default defineNuxtConfig({
|
|
72
|
+
modules: ['kiban'],
|
|
73
|
+
kiban: {
|
|
74
|
+
icon: {
|
|
75
|
+
enabled: true,
|
|
76
|
+
componentName: 'KIcon',
|
|
77
|
+
size: '1.25em',
|
|
78
|
+
class: 'align-middle inline-block text-current',
|
|
79
|
+
mode: 'svg',
|
|
80
|
+
provider: undefined,
|
|
81
|
+
collections: undefined,
|
|
82
|
+
aliases: undefined,
|
|
83
|
+
fallbacks: undefined,
|
|
84
|
+
extend: undefined,
|
|
85
|
+
},
|
|
86
|
+
lodash: {
|
|
87
|
+
enabled: true,
|
|
88
|
+
prefix: 'ki',
|
|
89
|
+
prefixSkip: 'is',
|
|
90
|
+
upperAfterPrefix: true,
|
|
91
|
+
exclude: [],
|
|
92
|
+
alias: [],
|
|
93
|
+
},
|
|
94
|
+
validator: {
|
|
95
|
+
enabled: true,
|
|
96
|
+
},
|
|
97
|
+
form: {
|
|
98
|
+
enabled: true,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Disable any feature by setting it to `false` (e.g. `kiban: { lodash: false }`).
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm install
|
|
110
|
+
pnpm run dev:prepare # generate stubs for module + playground
|
|
111
|
+
pnpm run dev # playground with local module
|
|
112
|
+
pnpm run dev:build # production-like build of playground
|
|
113
|
+
pnpm run lint
|
|
114
|
+
pnpm run test
|
|
115
|
+
pnpm run test:types
|
|
116
|
+
pnpm run prepack # build distributable into dist/
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Playground lives in `playground/`. Module entry is at `src/module.ts`; runtime code under `src/runtime`; features under `src/features`.
|
package/bin/kiban.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
|
|
11
|
+
function printHelp() {
|
|
12
|
+
console.log('\nkiban - helper wrapper for console scripts\n');
|
|
13
|
+
console.log('Usage: pnpm kiban <command> [options]\n');
|
|
14
|
+
console.log('Commands:');
|
|
15
|
+
console.log(' make:request <name> Interactive generator for request validation files');
|
|
16
|
+
console.log('\nUse `pnpm kiban <command> --help` for more information.\n');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (args.length === 0) {
|
|
20
|
+
printHelp();
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const [command, ...rest] = args;
|
|
25
|
+
|
|
26
|
+
if (command === 'make:request') {
|
|
27
|
+
const scriptPath = path.join(__dirname, '../console/request.mjs');
|
|
28
|
+
const child = spawn(process.execPath, [scriptPath, ...rest], {
|
|
29
|
+
stdio: 'inherit',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
child.on('exit', code => process.exit(code ?? 0));
|
|
33
|
+
}
|
|
34
|
+
else if (command === '--help' || command === '-h') {
|
|
35
|
+
printHelp();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error(`Unknown command: ${command}`);
|
|
39
|
+
printHelp();
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { cwd } from 'node:process';
|
|
5
|
+
import { checkbox, confirm, input } from '@inquirer/prompts';
|
|
6
|
+
|
|
7
|
+
const colors = {
|
|
8
|
+
reset: '\x1B[0m',
|
|
9
|
+
cyan: '\x1B[36m',
|
|
10
|
+
yellow: '\x1B[33m',
|
|
11
|
+
green: '\x1B[32m',
|
|
12
|
+
red: '\x1B[31m',
|
|
13
|
+
dim: '\x1B[2m',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const availableRules = [
|
|
17
|
+
'required',
|
|
18
|
+
'string',
|
|
19
|
+
'nullable',
|
|
20
|
+
'email',
|
|
21
|
+
'alpha',
|
|
22
|
+
'alpha_num',
|
|
23
|
+
'alpha_dash',
|
|
24
|
+
'numeric',
|
|
25
|
+
'integer',
|
|
26
|
+
'date',
|
|
27
|
+
'min',
|
|
28
|
+
'max',
|
|
29
|
+
'same',
|
|
30
|
+
'different',
|
|
31
|
+
'gt',
|
|
32
|
+
'gte',
|
|
33
|
+
'lt',
|
|
34
|
+
'lte',
|
|
35
|
+
'starts_with',
|
|
36
|
+
'ends_with',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const parameterizedRules = new Set([
|
|
40
|
+
'min',
|
|
41
|
+
'max',
|
|
42
|
+
'same',
|
|
43
|
+
'different',
|
|
44
|
+
'gt',
|
|
45
|
+
'gte',
|
|
46
|
+
'lt',
|
|
47
|
+
'lte',
|
|
48
|
+
'starts_with',
|
|
49
|
+
'ends_with',
|
|
50
|
+
'regex',
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
function toCamelCase(str) {
|
|
54
|
+
return str.replace(/[-_\s]+(.)?/g, (_match, c) => (c ? c.toUpperCase() : '')).replace(/^\w/, c => c.toLowerCase());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getTemplate(name, definitions) {
|
|
58
|
+
const definitionsString = Object.entries(definitions)
|
|
59
|
+
.map(([field, rules]) => ` ${field}: [${rules.map(r => `'${r}'`).join(', ')}],`)
|
|
60
|
+
.join('\n');
|
|
61
|
+
|
|
62
|
+
return `import type { ValidationRule, ValidationOptions } from 'kiban' // Adjust this import path if needed
|
|
63
|
+
import { createValidationRules } from 'kiban' // Adjust this import path if needed
|
|
64
|
+
// import { useI18n } from 'vue-i18n' // Uncomment if you use i18n
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Validation rules for the ${name} request.
|
|
68
|
+
*
|
|
69
|
+
* @param form - The reactive form object.
|
|
70
|
+
* @returns A fully compatible Element Plus FormRules object.
|
|
71
|
+
*/
|
|
72
|
+
export function ${name}Request(form: Record<string, any>) {
|
|
73
|
+
// const { t } = useI18n() // Uncomment if you use i18n
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The validation rules for the request.
|
|
77
|
+
*/
|
|
78
|
+
const definitions: Record<string, ValidationRule[] | { rules: ValidationRule[], sometimes: (data: Record<string, any>) => boolean }> = {
|
|
79
|
+
${definitionsString}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The validation options.
|
|
85
|
+
*/
|
|
86
|
+
const options: ValidationOptions = {
|
|
87
|
+
/**
|
|
88
|
+
* Custom friendly names for fields in error messages.
|
|
89
|
+
*
|
|
90
|
+
* email: t('attributes.email'),
|
|
91
|
+
* password: t('attributes.password'),
|
|
92
|
+
*/
|
|
93
|
+
attributes: {
|
|
94
|
+
//
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Custom messages for specific validation rules.
|
|
99
|
+
*
|
|
100
|
+
* 'email.required': 'You must provide an email address.'
|
|
101
|
+
* 'password.min': 'Your password is too short.'
|
|
102
|
+
*/
|
|
103
|
+
messages: {
|
|
104
|
+
//
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A hook to transform data before validation.
|
|
109
|
+
*
|
|
110
|
+
* data.email = data.email.trim().toLowerCase()
|
|
111
|
+
* return data
|
|
112
|
+
*/
|
|
113
|
+
prepareForValidation: (data) => {
|
|
114
|
+
return data
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* An authorization check before validation runs.
|
|
119
|
+
*
|
|
120
|
+
* () => user.can('update-profile')
|
|
121
|
+
*/
|
|
122
|
+
authorize: () => {
|
|
123
|
+
return true
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return createValidationRules(definitions, form, options)
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function displayHeader(title) {
|
|
133
|
+
const width = title.length + 4;
|
|
134
|
+
const border = '─'.repeat(width);
|
|
135
|
+
console.log(`┌${border}┐`);
|
|
136
|
+
console.log(`│ ${colors.cyan}${title}${colors.reset} │`);
|
|
137
|
+
console.log(`└${border}┘\n`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function loadPrefixFromProjectConfig() {
|
|
141
|
+
const candidates = [
|
|
142
|
+
'kiban.mjs',
|
|
143
|
+
'kiban.cjs',
|
|
144
|
+
'kiban.js',
|
|
145
|
+
'kiban.ts',
|
|
146
|
+
'kiban.json',
|
|
147
|
+
'kiban.config.json',
|
|
148
|
+
'artisan.mjs',
|
|
149
|
+
'artisan.cjs',
|
|
150
|
+
'artisan.js',
|
|
151
|
+
'artisan.ts',
|
|
152
|
+
'artisan.json',
|
|
153
|
+
'artisan.config.json',
|
|
154
|
+
'package.json',
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
for (const file of candidates) {
|
|
158
|
+
const p = path.join(cwd(), file);
|
|
159
|
+
if (!fs.existsSync(p)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
if (file.endsWith('.json')) {
|
|
165
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
166
|
+
const obj = JSON.parse(raw);
|
|
167
|
+
if (file === 'package.json') {
|
|
168
|
+
if (obj?.kiban && typeof obj.kiban.prefix === 'string') {
|
|
169
|
+
return obj.kiban.prefix;
|
|
170
|
+
}
|
|
171
|
+
if (obj?.artisan && typeof obj.artisan.prefix === 'string') {
|
|
172
|
+
return obj.artisan.prefix;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (typeof obj?.prefix === 'string') {
|
|
176
|
+
return obj.prefix;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (file.endsWith('.js') || file.endsWith('.mjs') || file.endsWith('.cjs') || file.endsWith('.ts')) {
|
|
181
|
+
const raw = fs.readFileSync(p, 'utf8');
|
|
182
|
+
const m = raw.match(/prefix\s*:\s*['"`]([^'"`]+)['"`]/);
|
|
183
|
+
if (m && m[1] !== undefined) {
|
|
184
|
+
return m[1];
|
|
185
|
+
}
|
|
186
|
+
const mEmpty = raw.match(/prefix\s*:\s*['"`]['"`]/);
|
|
187
|
+
if (mEmpty) {
|
|
188
|
+
return '';
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
console.error(`${colors.red}Failed to read config ${file}: ${err.message}${colors.reset}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function runLinter(filePath) {
|
|
201
|
+
console.log(`\n${colors.dim}Running linter...${colors.reset}`);
|
|
202
|
+
const command = `npx eslint --fix "${filePath}"`;
|
|
203
|
+
|
|
204
|
+
exec(command, (error, _stdout, stderr) => {
|
|
205
|
+
if (error) {
|
|
206
|
+
console.error(`\n${colors.red}Error running linter on ${filePath}: ${error.message}${colors.reset}`);
|
|
207
|
+
if (stderr) {
|
|
208
|
+
console.error(stderr);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
console.log(`${colors.green}✅ Linter finished successfully for: ${colors.dim}${filePath}${colors.reset}`);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function run() {
|
|
218
|
+
const globalArgs = process.argv.slice(2);
|
|
219
|
+
if (globalArgs.includes('--help') || globalArgs.includes('-h')) {
|
|
220
|
+
console.log('\nUsage: pnpm kiban make:request [options]\n');
|
|
221
|
+
console.log('Options:');
|
|
222
|
+
console.log(' -p, --prefix <dir> Override the target prefix (default: project\'s config or \'app\')');
|
|
223
|
+
console.log(' -h, --help Show this help message\n');
|
|
224
|
+
console.log('Examples:');
|
|
225
|
+
console.log(' pnpm kiban make:request login --prefix=src\n');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
console.clear();
|
|
230
|
+
displayHeader('Create New Request File');
|
|
231
|
+
|
|
232
|
+
const name = await input({
|
|
233
|
+
message: 'What is the name of the request?',
|
|
234
|
+
validate: value => (value ? true : 'Name is required.'),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const fieldsAnswer = await input({
|
|
238
|
+
message: 'List the fields to add (comma-separated):',
|
|
239
|
+
});
|
|
240
|
+
const fields = fieldsAnswer.split(',').map(f => f.trim()).filter(Boolean);
|
|
241
|
+
|
|
242
|
+
if (fields.length === 0) {
|
|
243
|
+
console.log(`\n${colors.dim}No fields provided. Exiting.${colors.reset}`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const finalDefinitions = {};
|
|
248
|
+
for (const field of fields) {
|
|
249
|
+
const selectedRules = await checkbox({
|
|
250
|
+
message: `Select validation rules for "${field}":`,
|
|
251
|
+
choices: availableRules.map(rule => ({ name: rule, value: rule })),
|
|
252
|
+
theme: {
|
|
253
|
+
icon: {
|
|
254
|
+
checked: `${colors.green}☑${colors.reset}`,
|
|
255
|
+
unchecked: '☐',
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const processedRules = [];
|
|
261
|
+
for (const rule of selectedRules) {
|
|
262
|
+
if (parameterizedRules.has(rule)) {
|
|
263
|
+
const param = await input({ message: `Enter parameter for "${rule}":` });
|
|
264
|
+
processedRules.push(`${rule}:${param}`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
processedRules.push(rule);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
finalDefinitions[field] = processedRules;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const camelCaseName = toCamelCase(name);
|
|
274
|
+
const fileName = `${camelCaseName}Request.ts`;
|
|
275
|
+
|
|
276
|
+
const argv = process.argv.slice(2);
|
|
277
|
+
let cliPrefix;
|
|
278
|
+
for (let i = 0; i < argv.length; i++) {
|
|
279
|
+
const a = argv[i];
|
|
280
|
+
if (a.startsWith('--prefix=')) {
|
|
281
|
+
cliPrefix = a.split('=')[1];
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
if (a === '--prefix' && argv[i + 1] !== undefined) {
|
|
285
|
+
cliPrefix = argv[i + 1];
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
if (a.startsWith('-p=')) {
|
|
289
|
+
cliPrefix = a.split('=')[1];
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
if (a === '-p' && argv[i + 1] !== undefined) {
|
|
293
|
+
cliPrefix = argv[i + 1];
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const configuredPrefix = loadPrefixFromProjectConfig();
|
|
299
|
+
const prefix = cliPrefix !== undefined ? cliPrefix : (typeof configuredPrefix === 'string' ? configuredPrefix : 'app');
|
|
300
|
+
|
|
301
|
+
const baseDir = prefix === '' ? cwd() : path.join(cwd(), prefix);
|
|
302
|
+
const targetDir = path.join(baseDir, 'requests');
|
|
303
|
+
const targetPath = path.join(targetDir, fileName);
|
|
304
|
+
|
|
305
|
+
const shownPrefix = prefix === '' ? '(project root)' : prefix;
|
|
306
|
+
console.log(`${colors.dim}Using prefix: ${colors.cyan}${shownPrefix}${colors.reset} -> ${colors.dim}${path.relative(cwd(), targetDir) || '.'}${colors.reset}`);
|
|
307
|
+
|
|
308
|
+
const writeFileAndLint = () => {
|
|
309
|
+
const fileContent = getTemplate(camelCaseName, finalDefinitions).trim();
|
|
310
|
+
fs.writeFileSync(targetPath, fileContent, 'utf8');
|
|
311
|
+
console.log(`\n${colors.green}✅ Success! Created/updated request file at: ${colors.dim}${path.relative(cwd(), targetPath)}${colors.reset}`);
|
|
312
|
+
runLinter(targetPath);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
if (!fs.existsSync(targetDir)) {
|
|
316
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (fs.existsSync(targetPath)) {
|
|
320
|
+
const overwrite = await confirm({
|
|
321
|
+
message: 'File already exists. Overwrite?',
|
|
322
|
+
default: false,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (overwrite) {
|
|
326
|
+
writeFileAndLint();
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
console.log(`\n${colors.dim}Operation cancelled.${colors.reset}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
writeFileAndLint();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
run();
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
export * from '../dist/runtime/form.js';
|
|
3
|
+
export { default as useForm } from '../dist/runtime/form.js';
|
|
4
|
+
export * from '../dist/runtime/validator.js';
|
|
5
|
+
export * from '../dist/runtime/helper/index.js';
|
|
6
|
+
|
|
7
|
+
interface LodashOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Enable lodash auto-imports
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Prefix applied to each import (set `false` to disable)
|
|
15
|
+
* @default 'use'
|
|
16
|
+
*/
|
|
17
|
+
prefix: false | string;
|
|
18
|
+
/**
|
|
19
|
+
* Skip prefix for names starting with these strings (set `false` to disable)
|
|
20
|
+
* @default 'is'
|
|
21
|
+
*/
|
|
22
|
+
prefixSkip: string | string[] | false;
|
|
23
|
+
/**
|
|
24
|
+
* Uppercase first letter after the prefix
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
upperAfterPrefix: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Extra lodash functions to exclude
|
|
30
|
+
*/
|
|
31
|
+
exclude: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Function aliases as [from, to]
|
|
34
|
+
*/
|
|
35
|
+
alias: Array<[string, string]>;
|
|
36
|
+
}
|
|
37
|
+
type LodashFeatureInput = boolean | Partial<LodashOptions> | undefined;
|
|
38
|
+
|
|
39
|
+
interface ValidatorOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Enable validator helpers and auto-imports
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
}
|
|
46
|
+
type ValidatorFeatureInput = boolean | Partial<ValidatorOptions> | undefined;
|
|
47
|
+
|
|
48
|
+
interface IconOptionConfig {
|
|
49
|
+
/**
|
|
50
|
+
* Default component name
|
|
51
|
+
* @default 'KIcon'
|
|
52
|
+
*/
|
|
53
|
+
componentName: string;
|
|
54
|
+
/**
|
|
55
|
+
* Default icon size
|
|
56
|
+
* @default '1.25em'
|
|
57
|
+
*/
|
|
58
|
+
size: string;
|
|
59
|
+
/**
|
|
60
|
+
* Default class applied to the icon component
|
|
61
|
+
*/
|
|
62
|
+
class?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Render mode for @nuxt/icon
|
|
65
|
+
* @default 'svg'
|
|
66
|
+
*/
|
|
67
|
+
mode?: 'svg' | 'css';
|
|
68
|
+
/**
|
|
69
|
+
* Custom Iconify provider URL
|
|
70
|
+
*/
|
|
71
|
+
provider?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Custom icon collections
|
|
74
|
+
*/
|
|
75
|
+
collections?: Record<string, any>;
|
|
76
|
+
/**
|
|
77
|
+
* Aliases for icon names
|
|
78
|
+
*/
|
|
79
|
+
aliases?: Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* Fallback icons to try
|
|
82
|
+
*/
|
|
83
|
+
fallbacks?: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Extra options passed directly to @nuxt/icon
|
|
86
|
+
*/
|
|
87
|
+
extend?: Record<string, any>;
|
|
88
|
+
}
|
|
89
|
+
interface IconOptions {
|
|
90
|
+
/**
|
|
91
|
+
* Enable the icon feature
|
|
92
|
+
* @default true
|
|
93
|
+
*/
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Options passed through to @nuxt/icon
|
|
97
|
+
*/
|
|
98
|
+
config?: IconOptionConfig;
|
|
99
|
+
}
|
|
100
|
+
type IconFeatureInput = boolean | Partial<IconOptions> | undefined;
|
|
101
|
+
|
|
102
|
+
interface FormOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Enable form composable auto-import
|
|
105
|
+
* @default true
|
|
106
|
+
*/
|
|
107
|
+
enabled: boolean;
|
|
108
|
+
}
|
|
109
|
+
type FormFeatureInput = boolean | Partial<FormOptions> | undefined;
|
|
110
|
+
|
|
111
|
+
interface ElementPlusOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Enable Element Plus Nuxt module
|
|
114
|
+
* @default true
|
|
115
|
+
*/
|
|
116
|
+
enabled: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Options passed through to @element-plus/nuxt
|
|
119
|
+
*/
|
|
120
|
+
config: Record<string, any>;
|
|
121
|
+
}
|
|
122
|
+
type ElementPlusFeatureInput = boolean | Partial<ElementPlusOptions> | Record<string, any> | undefined;
|
|
123
|
+
|
|
124
|
+
interface HelperOptions {
|
|
125
|
+
/**
|
|
126
|
+
* @default true
|
|
127
|
+
*/
|
|
128
|
+
enabled: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Helper configuration
|
|
131
|
+
*/
|
|
132
|
+
config?: {
|
|
133
|
+
/**
|
|
134
|
+
* Choose either fluent factory (`number().abbreviate()`) or prefixed functions (`numberAbbreviate()`, etc.)
|
|
135
|
+
* @default 'factory'
|
|
136
|
+
*/
|
|
137
|
+
style?: 'factory' | 'prefix';
|
|
138
|
+
/**
|
|
139
|
+
* Locale lookup source
|
|
140
|
+
* @default 'cookie'
|
|
141
|
+
*/
|
|
142
|
+
localeSource?: 'cookie' | 'localStorage' | 'query';
|
|
143
|
+
/**
|
|
144
|
+
* Key name for locale lookup
|
|
145
|
+
* @default 'lang'
|
|
146
|
+
*/
|
|
147
|
+
localeKey?: string;
|
|
148
|
+
/**
|
|
149
|
+
* Fallback locale when none is found
|
|
150
|
+
* @default 'en'
|
|
151
|
+
*/
|
|
152
|
+
localeFallback?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Default currency code
|
|
155
|
+
* @default 'USD'
|
|
156
|
+
*/
|
|
157
|
+
defaultCurrency?: string;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
type HelperFeatureInput = boolean | Partial<HelperOptions> | undefined;
|
|
161
|
+
|
|
162
|
+
interface PiniaOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Enable Pinia integration
|
|
165
|
+
* @default true
|
|
166
|
+
*/
|
|
167
|
+
enabled: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Directories to auto-import stores from (relative to `srcDir`)
|
|
170
|
+
* @default ['stores']
|
|
171
|
+
*/
|
|
172
|
+
storesDirs: string[];
|
|
173
|
+
}
|
|
174
|
+
type PiniaFeatureInput = boolean | Partial<PiniaOptions> | undefined;
|
|
175
|
+
|
|
176
|
+
interface ModuleOptions {
|
|
177
|
+
lodash?: LodashFeatureInput;
|
|
178
|
+
validator?: ValidatorFeatureInput;
|
|
179
|
+
icon?: IconFeatureInput;
|
|
180
|
+
form?: FormFeatureInput;
|
|
181
|
+
elementPlus?: ElementPlusFeatureInput;
|
|
182
|
+
helper?: HelperFeatureInput;
|
|
183
|
+
pinia?: PiniaFeatureInput;
|
|
184
|
+
}
|
|
185
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
186
|
+
|
|
187
|
+
export { _default as default };
|
|
188
|
+
export type { ModuleOptions };
|