kalo-cli 0.2.27 → 0.3.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/README.md +80 -46
- package/bin/kalo.ts +3 -2
- package/package.json +2 -1
- package/plopfile.ts +182 -25
- package/dist/docs/app.js +0 -42644
- package/dist/docs/index.html +0 -32
- package/generators/constants.ts +0 -52
- package/generators/generator/django-app/index.ts +0 -72
- package/generators/generator/django-app/templates/admin.py.hbs +0 -6
- package/generators/generator/django-app/templates/apps.py.hbs +0 -9
- package/generators/generator/django-app/templates/init.py.hbs +0 -0
- package/generators/generator/django-app/templates/models_init.py.hbs +0 -2
- package/generators/generator/django-app/templates/urls.py.hbs +0 -8
- package/generators/generator/django-app/templates/views.py.hbs +0 -5
- package/generators/generator/django-channel/index.ts +0 -80
- package/generators/generator/django-channel/templates/consumer.py.hbs +0 -47
- package/generators/generator/django-channel/templates/routing.py.hbs +0 -8
- package/generators/generator/django-form/index.ts +0 -64
- package/generators/generator/django-form/templates/form.py.hbs +0 -15
- package/generators/generator/django-form/templates/forms_file.py.hbs +0 -6
- package/generators/generator/django-form/templates/model_form.py.hbs +0 -19
- package/generators/generator/django-view/index.ts +0 -96
- package/generators/generator/django-view/templates/view_cbv.py.hbs +0 -14
- package/generators/generator/django-view/templates/view_fbv.py.hbs +0 -10
- package/generators/generator/django-view/templates/view_template.html.hbs +0 -8
- package/generators/generator/main/index.ts +0 -70
- package/generators/generator/wagtail-admin/index.ts +0 -124
- package/generators/generator/wagtail-admin/templates/admin_view.html.hbs +0 -21
- package/generators/generator/wagtail-admin/templates/admin_view.py.hbs +0 -15
- package/generators/generator/wagtail-admin/templates/component.html.hbs +0 -6
- package/generators/generator/wagtail-admin/templates/component.py.hbs +0 -11
- package/generators/generator/wagtail-admin/templates/wagtail_hooks.py.hbs +0 -18
- package/generators/generator/wagtail-block/index.ts +0 -53
- package/generators/generator/wagtail-block/templates/block_class.py.hbs +0 -16
- package/generators/generator/wagtail-block/templates/block_template.html.hbs +0 -5
- package/generators/generator/wagtail-page/actions/model.ts +0 -20
- package/generators/generator/wagtail-page/actions/orderable.ts +0 -23
- package/generators/generator/wagtail-page/actions/page.ts +0 -42
- package/generators/generator/wagtail-page/actions/snippet.ts +0 -20
- package/generators/generator/wagtail-page/index.ts +0 -63
- package/generators/generator/wagtail-page/templates/django_model.py.hbs +0 -21
- package/generators/generator/wagtail-page/templates/orderable_model.py.hbs +0 -27
- package/generators/generator/wagtail-page/templates/page_pair_model.py.hbs +0 -69
- package/generators/generator/wagtail-page/templates/page_template.html.hbs +0 -14
- package/generators/generator/wagtail-page/templates/snippet_model.py.hbs +0 -29
- package/generators/ia/ai-enhancer/index.ts +0 -319
- package/generators/ia/docs/index.ts +0 -36
- package/generators/ia/docs/keywords.json +0 -1158
- package/generators/ia/help/index.ts +0 -85
- package/generators/main/index.ts +0 -422
- package/generators/utils/ai/common.ts +0 -141
- package/generators/utils/ai/index.ts +0 -2
- package/generators/utils/analysis.ts +0 -88
- package/generators/utils/code-manipulation.ts +0 -229
- package/generators/utils/config.ts +0 -43
- package/generators/utils/filesystem.ts +0 -131
- package/generators/utils/index.ts +0 -35
- package/generators/utils/plop-actions.ts +0 -104
- package/generators/utils/search.ts +0 -24
- package/tsconfig.json +0 -29
package/README.md
CHANGED
|
@@ -1,68 +1,102 @@
|
|
|
1
|
-
# Kalo -
|
|
1
|
+
# Kalo CLI - Django/Wagtail Generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is a command-line interface tool for generating Django and Wagtail components using Plop.js.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Generate Django models, views, forms, APIs, and more
|
|
8
|
+
- Generate Wagtail pages, snippets, blocks, and other components
|
|
9
|
+
- Smart file appending to avoid duplicate classes
|
|
10
|
+
- Configuration loading from `kalo.config.json`
|
|
11
|
+
- Project root detection
|
|
12
|
+
- Searchable prompts for selecting existing apps
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
# Installation de Bun (Mac, Linux, WSL)
|
|
11
|
-
curl -fsSL https://bun.sh/install | bash
|
|
14
|
+
## Utilities
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
powershell -c "irm bun.sh/install.ps1 | iex"
|
|
15
|
-
```
|
|
16
|
+
The project includes several utility modules:
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
### Analysis Utilities (`src/utils/analysis.ts`)
|
|
19
|
+
- Functions to analyze Python files and extract class definitions
|
|
20
|
+
- Used to prevent duplicate class generation
|
|
18
21
|
|
|
19
|
-
###
|
|
22
|
+
### Code Manipulation Utilities (`src/utils/code-manipulation.ts`)
|
|
23
|
+
- Functions to inject markers in code for AI-assisted generation
|
|
24
|
+
- Apply generated code with imports, replacements, and code injection
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
bun add -g kalo-cli
|
|
25
|
-
```
|
|
26
|
+
### Configuration Utilities (`src/utils/config.ts`)
|
|
27
|
+
- Load configuration from `kalo.config.json` or `kalo.config.js`
|
|
28
|
+
- Support for AI providers, temperature settings, and verbosity levels
|
|
26
29
|
|
|
30
|
+
### File System Utilities (`src/utils/filesystem.ts`)
|
|
31
|
+
- Find project root directory
|
|
32
|
+
- Resolve application paths
|
|
33
|
+
- Get list of existing Django applications
|
|
34
|
+
- Get files and directories within an application
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
### Naming Conventions (`src/utils/naming-conventions.ts`)
|
|
37
|
+
- Validation functions for model names, app names, and page names
|
|
38
|
+
- Field validation utilities
|
|
29
39
|
|
|
30
|
-
###
|
|
40
|
+
### Plop Actions (`src/utils/plop-actions.ts`)
|
|
41
|
+
- `createAppendActions`: Creates pairs of actions to ensure files exist and append content
|
|
42
|
+
- Prevents duplicate class generation by checking existing classes
|
|
31
43
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
### Search Utilities (`src/utils/search.ts`)
|
|
45
|
+
- Fuzzy searching for autocomplete prompts
|
|
46
|
+
- Filter choices based on user input
|
|
35
47
|
|
|
36
|
-
###
|
|
48
|
+
### String Formatting (`src/utils/index.ts`)
|
|
49
|
+
- Format strings to slugs, snake_case, or PascalCase
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
## Usage
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
```bash
|
|
54
|
+
bun run plop # List all available generators
|
|
55
|
+
bun run plop model # Generate a new Django model
|
|
56
|
+
bun run plop view # Generate a new Django view
|
|
57
|
+
bun run plop wagtail-page # Generate a new Wagtail page
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Generators
|
|
61
|
+
|
|
62
|
+
The project includes generators for:
|
|
63
|
+
|
|
64
|
+
- Django apps
|
|
65
|
+
- Django models
|
|
66
|
+
- Django views
|
|
67
|
+
- Django forms
|
|
68
|
+
- Django APIs
|
|
69
|
+
- Django QuerySets
|
|
70
|
+
- Wagtail pages
|
|
71
|
+
- Wagtail snippets
|
|
72
|
+
- Wagtail blocks
|
|
73
|
+
- Wagtail streamfields
|
|
74
|
+
- Wagtail forms
|
|
75
|
+
- Wagtail tags
|
|
76
|
+
- Wagtail groups
|
|
77
|
+
- Wagtail hooks
|
|
78
|
+
- Wagtail locales
|
|
79
|
+
- Wagtail admin
|
|
80
|
+
- Wagtail commands
|
|
81
|
+
- Wagtail templates
|
|
82
|
+
- Wagtail API v2
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
Create a `kalo.config.json` file in your project root:
|
|
41
87
|
|
|
42
88
|
```json
|
|
43
89
|
{
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
90
|
+
"aiProvider": "openai",
|
|
91
|
+
"temperature": 0.7,
|
|
92
|
+
"verbosity": "standard",
|
|
93
|
+
"appDir": "src"
|
|
48
94
|
}
|
|
49
95
|
```
|
|
50
96
|
|
|
51
|
-
|
|
52
|
-
- `appDir` : Le dossier où se trouvent vos applications Django (par défaut: `app`).
|
|
53
|
-
- `aiProvider` : Le fournisseur d'IA par défaut (`Qwen`, `Ollama`, `Mistral`, `OpenAI`).
|
|
54
|
-
- `temperature` : La créativité de l'IA (entre 0 et 1).
|
|
55
|
-
- `verbosity` : Le niveau de détail des commentaires générés (`minimal`, `standard`, `verbose`).
|
|
56
|
-
|
|
57
|
-
### Si installé dans un projet
|
|
58
|
-
|
|
59
|
-
Utilisez `bun run` ou `bunx` :
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
bun run kalo
|
|
63
|
-
# ou
|
|
64
|
-
bunx kalo
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Si vous utilisez `npx`, assurez-vous que l'environnement peut exécuter le script (nécessite un environnement compatible avec le shebang `#!/usr/bin/env bun`, généralement Mac/Linux/WSL). Sur Windows standard, préférez `bunx`.
|
|
97
|
+
## Integration Notes
|
|
68
98
|
|
|
99
|
+
- The `createAppendActions` utility is now used in ALL generators (model, view, api, form, queryset, wagtail-admin, wagtail-api-v2, wagtail-block, wagtail-command, wagtail-form, wagtail-hook, wagtail-page, wagtail-snippet, wagtail-streamfield, wagtail-tag, wagtail-template) to append to existing files instead of overwriting them
|
|
100
|
+
- The `plopfile.ts` now loads configuration and sets up project root detection
|
|
101
|
+
- Multiple generators now use searchable prompts for app selection (api, form, queryset, wagtail-admin, wagtail-api-v2, wagtail-block, wagtail-command, wagtail-form, wagtail-hook, wagtail-snippet, wagtail-streamfield, wagtail-tag, wagtail-template)
|
|
102
|
+
- File system utilities are used throughout for path resolution and app detection
|
package/bin/kalo.ts
CHANGED
|
@@ -4,8 +4,9 @@ import fs from "node:fs";
|
|
|
4
4
|
import minimist from "minimist";
|
|
5
5
|
import { Plop, run } from "plop";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { findProjectRoot } from "../src/utils/filesystem";
|
|
8
|
+
import { loadConfig } from "../src/utils/config";
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
const args = process.argv.slice(2);
|
|
11
12
|
const argv = minimist(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kalo-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Générateur de code structuré et uniforme pour Django et Wagtail",
|
|
5
5
|
"bin": {
|
|
6
6
|
"kalo": "./bin/kalo.ts"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"kalo": "bun bin/kalo.ts",
|
|
11
|
+
"dev": "plop --plopfile plopfile.ts",
|
|
11
12
|
"doc": "serve dist/docs -p 3333",
|
|
12
13
|
"doc:dev": "bun run --port 3333 docs-site/index.html",
|
|
13
14
|
"build": "bun scripts/build-docs.ts"
|
package/plopfile.ts
CHANGED
|
@@ -1,26 +1,183 @@
|
|
|
1
1
|
import { NodePlopAPI } from 'plop';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
import { findProjectRoot } from './src/utils/filesystem';
|
|
3
|
+
import { loadConfig } from './src/utils/config';
|
|
4
|
+
|
|
5
|
+
// Import all generators
|
|
6
|
+
import appGenerator from './src/gen/app/index';
|
|
7
|
+
import modelGenerator from './src/gen/model/index';
|
|
8
|
+
import viewGenerator from './src/gen/view/index';
|
|
9
|
+
import formGenerator from './src/gen/form/index';
|
|
10
|
+
import apiGenerator from './src/gen/api/index';
|
|
11
|
+
import querysetGenerator from './src/gen/queryset/index';
|
|
12
|
+
import wagtailPageGenerator from './src/gen/wagtail-page/index';
|
|
13
|
+
import wagtailSnippetGenerator from './src/gen/wagtail-snippet/index';
|
|
14
|
+
import wagtailBlockGenerator from './src/gen/wagtail-block/index';
|
|
15
|
+
import wagtailStreamfieldGenerator from './src/gen/wagtail-streamfield/index';
|
|
16
|
+
import wagtailFormGenerator from './src/gen/wagtail-form/index';
|
|
17
|
+
import wagtailTagGenerator from './src/gen/wagtail-tag/index';
|
|
18
|
+
import wagtailGroupGenerator from './src/gen/wagtail-group/index';
|
|
19
|
+
import wagtailHookGenerator from './src/gen/wagtail-hook/index';
|
|
20
|
+
import wagtailLocaleGenerator from './src/gen/wagtail-locale/index';
|
|
21
|
+
import wagtailAdminGenerator from './src/gen/wagtail-admin/index';
|
|
22
|
+
import wagtailCommandGenerator from './src/gen/wagtail-command/index';
|
|
23
|
+
import wagtailTemplateGenerator from './src/gen/wagtail-template/index';
|
|
24
|
+
import wagtailApiV2Generator from './src/gen/wagtail-api-v2/index';
|
|
25
|
+
|
|
26
|
+
export default async function (plop: NodePlopAPI) {
|
|
27
|
+
// Load configuration
|
|
28
|
+
const config = await loadConfig();
|
|
29
|
+
|
|
30
|
+
// Register custom helpers
|
|
31
|
+
plop.setHelper('toPascalCase', function(str: string) {
|
|
32
|
+
if (!str) return str;
|
|
33
|
+
return str.replace(/(\w)(\w*)/g, (g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase()).replace(/\W/g, '');
|
|
34
|
+
});
|
|
35
|
+
// Snake case helper to enforce snake_case filenames
|
|
36
|
+
plop.setHelper('toSnakeCase', function(str: string) {
|
|
37
|
+
if (!str) return str;
|
|
38
|
+
return String(str)
|
|
39
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
40
|
+
.replace(/[\s\-]+/g, '_')
|
|
41
|
+
.toLowerCase();
|
|
42
|
+
});
|
|
43
|
+
// Title case for human-facing labels
|
|
44
|
+
plop.setHelper('titleCase', function(str: string) {
|
|
45
|
+
if (!str) return str;
|
|
46
|
+
return String(str)
|
|
47
|
+
.replace(/[_\-]+/g, ' ')
|
|
48
|
+
.replace(/\s+/g, ' ')
|
|
49
|
+
.trim()
|
|
50
|
+
.split(' ')
|
|
51
|
+
.map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
52
|
+
.join(' ');
|
|
53
|
+
});
|
|
54
|
+
// Map generic type to Django Model Field
|
|
55
|
+
plop.setHelper('djangoModelField', function(type: string) {
|
|
56
|
+
if (!type) return 'CharField';
|
|
57
|
+
const t = String(type).toLowerCase();
|
|
58
|
+
const map: Record<string, string> = {
|
|
59
|
+
char: 'CharField',
|
|
60
|
+
text: 'TextField',
|
|
61
|
+
integer: 'IntegerField',
|
|
62
|
+
small_integer: 'SmallIntegerField',
|
|
63
|
+
positive_integer: 'PositiveIntegerField',
|
|
64
|
+
float: 'FloatField',
|
|
65
|
+
decimal: 'DecimalField',
|
|
66
|
+
boolean: 'BooleanField',
|
|
67
|
+
date: 'DateField',
|
|
68
|
+
datetime: 'DateTimeField',
|
|
69
|
+
email: 'EmailField',
|
|
70
|
+
url: 'URLField',
|
|
71
|
+
file: 'FileField',
|
|
72
|
+
image: 'ImageField',
|
|
73
|
+
uuid: 'UUIDField',
|
|
74
|
+
json: 'JSONField',
|
|
75
|
+
ip_address: 'GenericIPAddressField',
|
|
76
|
+
foreign_key: 'ForeignKey',
|
|
77
|
+
many_to_many: 'ManyToManyField',
|
|
78
|
+
one_to_one: 'OneToOneField',
|
|
79
|
+
};
|
|
80
|
+
return map[t] || (type.endsWith('Field') ? type : 'CharField');
|
|
81
|
+
});
|
|
82
|
+
// Map generic type to Django Form Field
|
|
83
|
+
plop.setHelper('djangoFormField', function(type: string) {
|
|
84
|
+
if (!type) return 'CharField';
|
|
85
|
+
const t = String(type).toLowerCase();
|
|
86
|
+
const map: Record<string, string> = {
|
|
87
|
+
char: 'CharField',
|
|
88
|
+
text: 'CharField',
|
|
89
|
+
integer: 'IntegerField',
|
|
90
|
+
float: 'FloatField',
|
|
91
|
+
decimal: 'DecimalField',
|
|
92
|
+
boolean: 'BooleanField',
|
|
93
|
+
date: 'DateField',
|
|
94
|
+
datetime: 'DateTimeField',
|
|
95
|
+
email: 'EmailField',
|
|
96
|
+
url: 'URLField',
|
|
97
|
+
file: 'FileField',
|
|
98
|
+
image: 'ImageField',
|
|
99
|
+
uuid: 'UUIDField',
|
|
100
|
+
json: 'JSONField',
|
|
101
|
+
};
|
|
102
|
+
return map[t] || (type.endsWith('Field') ? type : 'CharField');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
plop.setHelper('trim', (str) => {
|
|
106
|
+
return str ? String(str).trim() : '';
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
plop.setHelper('eq', (a, b) => {
|
|
110
|
+
return a == b;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
plop.setHelper('split', (str, separator) => {
|
|
114
|
+
return str ? String(str).split(separator) : [];
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
plop.setHelper('replace', (str, find, replace) => {
|
|
118
|
+
return str ? String(str).split(find).join(replace) : '';
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
plop.setHelper('includes', (arr, value) => {
|
|
122
|
+
if (Array.isArray(arr)) return arr.includes(value);
|
|
123
|
+
if (typeof arr === 'string') return arr.includes(value);
|
|
124
|
+
return false;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Set the project root as a global helper
|
|
128
|
+
plop.setHelper('projectRoot', function() {
|
|
129
|
+
return findProjectRoot();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Set configuration as a global helper
|
|
133
|
+
plop.setHelper('getConfig', function(key: string) {
|
|
134
|
+
return config[key] || null;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Register the autocomplete prompt
|
|
138
|
+
try {
|
|
139
|
+
const autoCompletePrompt = await import('inquirer-autocomplete-prompt');
|
|
140
|
+
plop.setPrompt('autocomplete', autoCompletePrompt.default);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.warn('inquirer-autocomplete-prompt not found. Install it to enable autocomplete prompts.');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Register all generators
|
|
146
|
+
appGenerator(plop);
|
|
147
|
+
modelGenerator(plop);
|
|
148
|
+
viewGenerator(plop);
|
|
149
|
+
formGenerator(plop);
|
|
150
|
+
apiGenerator(plop);
|
|
151
|
+
querysetGenerator(plop);
|
|
152
|
+
wagtailPageGenerator(plop);
|
|
153
|
+
wagtailSnippetGenerator(plop);
|
|
154
|
+
wagtailBlockGenerator(plop);
|
|
155
|
+
wagtailStreamfieldGenerator(plop);
|
|
156
|
+
wagtailFormGenerator(plop);
|
|
157
|
+
wagtailTagGenerator(plop);
|
|
158
|
+
wagtailGroupGenerator(plop);
|
|
159
|
+
wagtailHookGenerator(plop);
|
|
160
|
+
wagtailLocaleGenerator(plop);
|
|
161
|
+
wagtailAdminGenerator(plop);
|
|
162
|
+
wagtailCommandGenerator(plop);
|
|
163
|
+
wagtailTemplateGenerator(plop);
|
|
164
|
+
wagtailApiV2Generator(plop);
|
|
165
|
+
|
|
166
|
+
plop.setGenerator('component', {
|
|
167
|
+
description: 'Create a new component',
|
|
168
|
+
prompts: [
|
|
169
|
+
{
|
|
170
|
+
type: 'input',
|
|
171
|
+
name: 'name',
|
|
172
|
+
message: 'Component name:'
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
actions: [
|
|
176
|
+
{
|
|
177
|
+
type: 'add',
|
|
178
|
+
path: 'src/components/{{name}}.tsx',
|
|
179
|
+
template: 'export const {{name}} = () => <div>{{name}}</div>;'
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
};
|