@lastbrain/app 0.1.34 → 0.1.37
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 +23 -5
- package/dist/__tests__/module-registry.test.js +5 -16
- package/dist/scripts/init-app.d.ts.map +1 -1
- package/dist/scripts/init-app.js +2 -2
- package/dist/scripts/module-add.d.ts +0 -11
- package/dist/scripts/module-add.d.ts.map +1 -1
- package/dist/scripts/module-add.js +45 -22
- package/dist/scripts/module-build.d.ts.map +1 -1
- package/dist/scripts/module-build.js +90 -1
- package/dist/scripts/module-create.d.ts +23 -0
- package/dist/scripts/module-create.d.ts.map +1 -1
- package/dist/scripts/module-create.js +737 -52
- package/dist/scripts/module-delete.d.ts +6 -0
- package/dist/scripts/module-delete.d.ts.map +1 -0
- package/dist/scripts/module-delete.js +143 -0
- package/dist/scripts/module-list.d.ts.map +1 -1
- package/dist/scripts/module-list.js +2 -2
- package/dist/scripts/module-remove.d.ts.map +1 -1
- package/dist/scripts/module-remove.js +20 -4
- package/dist/styles.css +1 -1
- package/dist/templates/DefaultDoc.d.ts.map +1 -1
- package/dist/templates/DefaultDoc.js +170 -30
- package/dist/templates/DocPage.d.ts.map +1 -1
- package/dist/templates/DocPage.js +25 -8
- package/dist/templates/migrations/20201010100000_app_base.sql +23 -24
- package/package.json +4 -4
- package/src/__tests__/module-registry.test.ts +5 -17
- package/src/scripts/db-init.ts +2 -2
- package/src/scripts/init-app.ts +5 -2
- package/src/scripts/module-add.ts +55 -23
- package/src/scripts/module-build.ts +109 -1
- package/src/scripts/module-create.ts +885 -63
- package/src/scripts/module-delete.ts +202 -0
- package/src/scripts/module-list.ts +9 -2
- package/src/scripts/module-remove.ts +36 -4
- package/src/templates/DefaultDoc.tsx +1163 -753
- package/src/templates/DocPage.tsx +28 -11
- package/src/templates/migrations/20201010100000_app_base.sql +23 -24
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import inquirer from "inquirer";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import {
|
|
7
|
+
AVAILABLE_MODULES,
|
|
8
|
+
type ModuleMetadata,
|
|
9
|
+
} from "@lastbrain/core/config/modules";
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Supprime un module du monorepo (physiquement)
|
|
16
|
+
* Cette commande est réservée aux développeurs du framework
|
|
17
|
+
*/
|
|
18
|
+
export async function deleteModule() {
|
|
19
|
+
const rootDir = path.resolve(__dirname, "../../../..");
|
|
20
|
+
|
|
21
|
+
console.log(
|
|
22
|
+
chalk.blue("\n🗑️ Suppression d'un module du monorepo LastBrain\n"),
|
|
23
|
+
);
|
|
24
|
+
console.log(
|
|
25
|
+
chalk.yellow(
|
|
26
|
+
"⚠️ ATTENTION: Cette opération supprime physiquement le module du monorepo!",
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
console.log(
|
|
30
|
+
chalk.gray("Cette commande est réservée aux développeurs du framework.\n"),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Lister les modules disponibles
|
|
34
|
+
if (AVAILABLE_MODULES.length === 0) {
|
|
35
|
+
console.log(chalk.red("❌ Aucun module disponible dans le registre"));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const answers = await inquirer.prompt([
|
|
40
|
+
{
|
|
41
|
+
type: "list",
|
|
42
|
+
name: "moduleName",
|
|
43
|
+
message: "Quel module voulez-vous supprimer du monorepo ?",
|
|
44
|
+
choices: AVAILABLE_MODULES.map((m) => ({
|
|
45
|
+
name: `${m.emoji} ${m.name} - ${m.description}`,
|
|
46
|
+
value: m.name,
|
|
47
|
+
})),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "confirm",
|
|
51
|
+
name: "confirm",
|
|
52
|
+
message: (answers: any) =>
|
|
53
|
+
`Êtes-vous sûr de vouloir supprimer le module "${answers.moduleName}" ? Cette action est irréversible.`,
|
|
54
|
+
default: false,
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
if (!answers.confirm) {
|
|
59
|
+
console.log(chalk.gray("\n❌ Opération annulée"));
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const moduleName = answers.moduleName;
|
|
64
|
+
const moduleMeta = AVAILABLE_MODULES.find((m) => m.name === moduleName);
|
|
65
|
+
|
|
66
|
+
if (!moduleMeta) {
|
|
67
|
+
console.log(chalk.red(`❌ Module ${moduleName} non trouvé`));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log(
|
|
72
|
+
chalk.blue(`\n🗑️ Suppression du module ${moduleMeta.package}...\n`),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// 1. Supprimer le répertoire du module
|
|
76
|
+
const moduleDir = path.join(
|
|
77
|
+
rootDir,
|
|
78
|
+
"packages",
|
|
79
|
+
moduleMeta.package.replace("@lastbrain/", ""),
|
|
80
|
+
);
|
|
81
|
+
if (fs.existsSync(moduleDir)) {
|
|
82
|
+
console.log(chalk.yellow(`📁 Suppression du répertoire: ${moduleDir}`));
|
|
83
|
+
await fs.remove(moduleDir);
|
|
84
|
+
console.log(chalk.green(" ✓ Répertoire supprimé"));
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.yellow(` ⚠️ Répertoire non trouvé: ${moduleDir}`));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 2. Supprimer du registre central
|
|
90
|
+
console.log(chalk.yellow("\n📝 Mise à jour du registre central..."));
|
|
91
|
+
const moduleRegistryPath = path.join(
|
|
92
|
+
rootDir,
|
|
93
|
+
"packages",
|
|
94
|
+
"core",
|
|
95
|
+
"src",
|
|
96
|
+
"config",
|
|
97
|
+
"modules.ts",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (fs.existsSync(moduleRegistryPath)) {
|
|
101
|
+
try {
|
|
102
|
+
let content = await fs.readFile(moduleRegistryPath, "utf-8");
|
|
103
|
+
|
|
104
|
+
// Vérifier si le module est dans le registre
|
|
105
|
+
if (!content.includes(`name: "${moduleName}"`)) {
|
|
106
|
+
console.log(
|
|
107
|
+
chalk.yellow(` ⚠️ Module ${moduleName} n'est pas dans le registre`),
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
// Parser et reconstruire le tableau proprement
|
|
111
|
+
const arrayMatch = content.match(
|
|
112
|
+
/export const AVAILABLE_MODULES: ModuleMetadata\[\] = \[([\s\S]*?)\];/,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (arrayMatch) {
|
|
116
|
+
const arrayContent = arrayMatch[1];
|
|
117
|
+
const modules: string[] = [];
|
|
118
|
+
let currentModule = "";
|
|
119
|
+
let braceDepth = 0;
|
|
120
|
+
|
|
121
|
+
// Parser chaque module
|
|
122
|
+
for (const line of arrayContent.split("\n")) {
|
|
123
|
+
if (line.trim().startsWith("{")) {
|
|
124
|
+
braceDepth++;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
currentModule += line + "\n";
|
|
128
|
+
|
|
129
|
+
if (line.includes("},")) {
|
|
130
|
+
braceDepth--;
|
|
131
|
+
if (braceDepth === 0) {
|
|
132
|
+
// Module complet trouvé
|
|
133
|
+
if (!currentModule.includes(`name: "${moduleName}"`)) {
|
|
134
|
+
modules.push(currentModule.trim());
|
|
135
|
+
}
|
|
136
|
+
currentModule = "";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Reconstruire le tableau
|
|
142
|
+
const newArrayContent =
|
|
143
|
+
modules.length > 0 ? "\n " + modules.join("\n ") + "\n" : "\n";
|
|
144
|
+
|
|
145
|
+
content = content.replace(
|
|
146
|
+
/export const AVAILABLE_MODULES: ModuleMetadata\[\] = \[([\s\S]*?)\];/,
|
|
147
|
+
`export const AVAILABLE_MODULES: ModuleMetadata[] = [${newArrayContent}];`,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await fs.writeFile(moduleRegistryPath, content, "utf-8");
|
|
151
|
+
console.log(
|
|
152
|
+
chalk.green(` ✓ Module ${moduleName} supprimé du registre`),
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
console.log(chalk.yellow(" ⚠️ Format du registre non reconnu"));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.log(
|
|
160
|
+
chalk.red(` ❌ Erreur lors de la mise à jour du registre: ${error}`),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 3. Supprimer des scripts de publication
|
|
166
|
+
console.log(chalk.yellow("\n📝 Mise à jour du package.json racine..."));
|
|
167
|
+
const rootPackageJson = path.join(rootDir, "package.json");
|
|
168
|
+
if (fs.existsSync(rootPackageJson)) {
|
|
169
|
+
try {
|
|
170
|
+
const pkg = await fs.readJson(rootPackageJson);
|
|
171
|
+
const publishScript = `publish:${moduleName}`;
|
|
172
|
+
|
|
173
|
+
if (pkg.scripts && pkg.scripts[publishScript]) {
|
|
174
|
+
delete pkg.scripts[publishScript];
|
|
175
|
+
await fs.writeJson(rootPackageJson, pkg, { spaces: 2 });
|
|
176
|
+
console.log(chalk.green(` ✓ Script de publication supprimé`));
|
|
177
|
+
} else {
|
|
178
|
+
console.log(chalk.gray(` ℹ️ Aucun script de publication trouvé`));
|
|
179
|
+
}
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.log(
|
|
182
|
+
chalk.yellow(` ⚠️ Erreur lors de la mise à jour: ${error}`),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
console.log(chalk.green(`\n✅ Module ${moduleName} supprimé avec succès!\n`));
|
|
188
|
+
console.log(chalk.yellow("Prochaines étapes:"));
|
|
189
|
+
console.log(chalk.gray(" 1. cd packages/core && pnpm build"));
|
|
190
|
+
console.log(
|
|
191
|
+
chalk.gray(" 2. Vérifier les projets qui utilisaient ce module"),
|
|
192
|
+
);
|
|
193
|
+
console.log(chalk.gray(" 3. Commiter les changements\n"));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Point d'entrée CLI
|
|
197
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
198
|
+
deleteModule().catch((error) => {
|
|
199
|
+
console.error(chalk.red("\n❌ Erreur:"), error);
|
|
200
|
+
process.exit(1);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import chalk from "chalk";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AVAILABLE_MODULES,
|
|
6
|
+
type ModuleMetadata,
|
|
7
|
+
} from "@lastbrain/core/config/modules";
|
|
5
8
|
|
|
6
9
|
export async function listModules(targetDir: string) {
|
|
7
10
|
console.log(chalk.blue("\n📦 Modules disponibles:\n"));
|
|
@@ -22,7 +25,11 @@ export async function listModules(targetDir: string) {
|
|
|
22
25
|
? chalk.green("✓ installé")
|
|
23
26
|
: chalk.gray(" disponible");
|
|
24
27
|
|
|
25
|
-
console.log(
|
|
28
|
+
console.log(
|
|
29
|
+
chalk.bold(
|
|
30
|
+
`${module.emoji} ${module.name.charAt(0).toUpperCase() + module.name.slice(1)}`,
|
|
31
|
+
),
|
|
32
|
+
);
|
|
26
33
|
console.log(chalk.gray(` Nom: ${module.name}`));
|
|
27
34
|
console.log(chalk.gray(` Package: ${module.package}`));
|
|
28
35
|
console.log(chalk.gray(` Description: ${module.description}`));
|
|
@@ -3,7 +3,33 @@ import path from "path";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
5
|
import inquirer from "inquirer";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
AVAILABLE_MODULES,
|
|
8
|
+
type ModuleMetadata,
|
|
9
|
+
} from "@lastbrain/core/config/modules";
|
|
10
|
+
|
|
11
|
+
interface ModuleDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
package: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
description: string;
|
|
16
|
+
hasMigrations: boolean;
|
|
17
|
+
migrationsPath?: string;
|
|
18
|
+
migrationsDownPath?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Convert core module metadata to local module definition
|
|
22
|
+
function toModuleDefinition(meta: ModuleMetadata): ModuleDefinition {
|
|
23
|
+
return {
|
|
24
|
+
name: meta.name,
|
|
25
|
+
package: meta.package,
|
|
26
|
+
displayName: `${meta.emoji} ${meta.name.charAt(0).toUpperCase() + meta.name.slice(1)}`,
|
|
27
|
+
description: meta.description,
|
|
28
|
+
hasMigrations: true,
|
|
29
|
+
migrationsPath: "supabase/migrations",
|
|
30
|
+
migrationsDownPath: "supabase/migrations-down",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
7
33
|
|
|
8
34
|
async function removeGeneratedFiles(
|
|
9
35
|
moduleName: string,
|
|
@@ -68,17 +94,19 @@ async function removeGeneratedFiles(
|
|
|
68
94
|
export async function removeModule(moduleName: string, targetDir: string) {
|
|
69
95
|
console.log(chalk.blue(`\n🗑️ Suppression du module: ${moduleName}\n`));
|
|
70
96
|
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
97
|
+
const moduleMeta = AVAILABLE_MODULES.find((m) => m.name === moduleName);
|
|
98
|
+
if (!moduleMeta) {
|
|
73
99
|
console.error(
|
|
74
100
|
chalk.red(`❌ Module "${moduleName}" non trouvé. Modules disponibles:`),
|
|
75
101
|
);
|
|
76
102
|
AVAILABLE_MODULES.forEach((m) => {
|
|
77
|
-
console.log(chalk.gray(` - ${m.name}: ${m.description}`));
|
|
103
|
+
console.log(chalk.gray(` - ${m.emoji} ${m.name}: ${m.description}`));
|
|
78
104
|
});
|
|
79
105
|
process.exit(1);
|
|
80
106
|
}
|
|
81
107
|
|
|
108
|
+
const module = toModuleDefinition(moduleMeta);
|
|
109
|
+
|
|
82
110
|
// 1. Vérifier qu'on est dans un projet LastBrain
|
|
83
111
|
const pkgPath = path.join(targetDir, "package.json");
|
|
84
112
|
if (!fs.existsSync(pkgPath)) {
|
|
@@ -398,6 +426,10 @@ export async function removeModule(moduleName: string, targetDir: string) {
|
|
|
398
426
|
}
|
|
399
427
|
}
|
|
400
428
|
|
|
429
|
+
// 5.5. Note: On ne supprime PAS le module du registre central
|
|
430
|
+
// car cette commande est pour les utilisateurs finaux qui n'ont pas accès à core/config/modules.ts
|
|
431
|
+
// Pour supprimer un module du monorepo, utiliser: pnpm delete-module
|
|
432
|
+
|
|
401
433
|
// 6. Nettoyer les dépendances
|
|
402
434
|
console.log(chalk.yellow("\n🧹 Nettoyage des dépendances..."));
|
|
403
435
|
try {
|