@bemedev/codebase 0.1.3 → 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 +8 -8
- package/lib/_virtual/_rolldown/runtime.cjs +23 -0
- package/lib/analyse.cjs +48 -62
- package/lib/analyse.cjs.map +1 -1
- package/lib/analyse.d.ts +21 -3
- package/lib/analyse.js +45 -60
- package/lib/analyse.js.map +1 -1
- package/lib/analyse.utils.cjs +154 -205
- package/lib/analyse.utils.cjs.map +1 -1
- package/lib/analyse.utils.d.ts +1 -2
- package/lib/analyse.utils.js +153 -203
- package/lib/analyse.utils.js.map +1 -1
- package/lib/cli/cli.cjs +28 -27
- package/lib/cli/cli.cjs.map +1 -1
- package/lib/cli/cli.d.ts +0 -1
- package/lib/cli/cli.js +25 -24
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/constants.cjs +6 -5
- package/lib/cli/constants.cjs.map +1 -1
- package/lib/cli/constants.d.ts +0 -1
- package/lib/cli/constants.js +5 -3
- package/lib/cli/constants.js.map +1 -1
- package/lib/cli/index.cjs +6 -6
- package/lib/cli/index.cjs.map +1 -1
- package/lib/cli/index.d.ts +0 -1
- package/lib/cli/index.js +7 -4
- package/lib/cli/index.js.map +1 -1
- package/lib/constants.cjs +26 -28
- package/lib/constants.cjs.map +1 -1
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +24 -26
- package/lib/constants.js.map +1 -1
- package/lib/exports.cjs +51 -72
- package/lib/exports.cjs.map +1 -1
- package/lib/exports.d.ts +1 -2
- package/lib/exports.js +49 -70
- package/lib/exports.js.map +1 -1
- package/lib/functions/add.cjs +71 -84
- package/lib/functions/add.cjs.map +1 -1
- package/lib/functions/add.d.ts +1 -2
- package/lib/functions/add.js +68 -82
- package/lib/functions/add.js.map +1 -1
- package/lib/functions/generate.cjs +53 -56
- package/lib/functions/generate.cjs.map +1 -1
- package/lib/functions/generate.d.ts +1 -2
- package/lib/functions/generate.js +51 -54
- package/lib/functions/generate.js.map +1 -1
- package/lib/functions/index.cjs +11 -16
- package/lib/functions/index.d.ts +0 -1
- package/lib/functions/index.js +5 -5
- package/lib/functions/init.cjs +68 -97
- package/lib/functions/init.cjs.map +1 -1
- package/lib/functions/init.d.ts +0 -1
- package/lib/functions/init.js +66 -95
- package/lib/functions/init.js.map +1 -1
- package/lib/functions/remove.cjs +85 -103
- package/lib/functions/remove.cjs.map +1 -1
- package/lib/functions/remove.d.ts +1 -2
- package/lib/functions/remove.js +82 -101
- package/lib/functions/remove.js.map +1 -1
- package/lib/helpers.cjs +32 -38
- package/lib/helpers.cjs.map +1 -1
- package/lib/helpers.d.ts +3 -4
- package/lib/helpers.js +30 -36
- package/lib/helpers.js.map +1 -1
- package/lib/imports.cjs +88 -124
- package/lib/imports.cjs.map +1 -1
- package/lib/imports.d.ts +2 -3
- package/lib/imports.js +86 -122
- package/lib/imports.js.map +1 -1
- package/lib/index.cjs +22 -24
- package/lib/index.d.ts +4 -4
- package/lib/index.js +8 -6
- package/lib/schemas.cjs +53 -64
- package/lib/schemas.cjs.map +1 -1
- package/lib/schemas.d.ts +1 -2
- package/lib/schemas.js +43 -36
- package/lib/schemas.js.map +1 -1
- package/lib/types.d.ts +0 -1
- package/lib/utils.cjs +9 -10
- package/lib/utils.cjs.map +1 -1
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js +8 -8
- package/lib/utils.js.map +1 -1
- package/package.json +56 -44
- package/CHANGE_LOG.md +0 -161
- package/lib/analyse.d.ts.map +0 -1
- package/lib/analyse.utils.d.ts.map +0 -1
- package/lib/cli/cli.d.ts.map +0 -1
- package/lib/cli/constants.d.ts.map +0 -1
- package/lib/cli/index.d.ts.map +0 -1
- package/lib/constants.d.ts.map +0 -1
- package/lib/exports.d.ts.map +0 -1
- package/lib/functions/add.d.ts.map +0 -1
- package/lib/functions/generate.d.ts.map +0 -1
- package/lib/functions/index.cjs.map +0 -1
- package/lib/functions/index.d.ts.map +0 -1
- package/lib/functions/index.js.map +0 -1
- package/lib/functions/init.d.ts.map +0 -1
- package/lib/functions/remove.d.ts.map +0 -1
- package/lib/helpers.d.ts.map +0 -1
- package/lib/imports.d.ts.map +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/schemas.d.ts.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/utils.d.ts.map +0 -1
|
@@ -1,59 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { CODEBASE_FILE, SRC_DIR } from "../constants.js";
|
|
2
|
+
import { analyze } from "../analyse.js";
|
|
3
|
+
import { relative } from "path";
|
|
4
|
+
import { writeFileSync } from "fs";
|
|
5
|
+
//#region src/functions/generate.ts
|
|
6
6
|
const transformJSON = (data) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
CODEBASE_ANALYSIS,
|
|
31
|
-
};
|
|
7
|
+
let imports = 0;
|
|
8
|
+
let exports = 0;
|
|
9
|
+
let files = 0;
|
|
10
|
+
const entries = Object.entries(data).map(([key, { imports: _imports, relativePath, text, exports: _exports }]) => {
|
|
11
|
+
imports += _imports.length;
|
|
12
|
+
exports += _exports?.length ?? 0;
|
|
13
|
+
files++;
|
|
14
|
+
return [key, {
|
|
15
|
+
imports: _imports,
|
|
16
|
+
relativePath,
|
|
17
|
+
text,
|
|
18
|
+
exports: _exports?.filter(({ moduleSpecifier }) => moduleSpecifier !== void 0)
|
|
19
|
+
}];
|
|
20
|
+
});
|
|
21
|
+
const CODEBASE_ANALYSIS = Object.fromEntries(entries);
|
|
22
|
+
return {
|
|
23
|
+
STATS: {
|
|
24
|
+
files,
|
|
25
|
+
imports,
|
|
26
|
+
exports
|
|
27
|
+
},
|
|
28
|
+
CODEBASE_ANALYSIS
|
|
29
|
+
};
|
|
32
30
|
};
|
|
33
31
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const generate = ({ output = CODEBASE_FILE, excludes, src = SRC_DIR
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
32
|
+
* Fonction principale d'exécution
|
|
33
|
+
*/
|
|
34
|
+
const generate = ({ output = CODEBASE_FILE, excludes, src = SRC_DIR } = {}) => {
|
|
35
|
+
const _output = output.endsWith("codebase.json") ? output : `${output}.codebase.json`;
|
|
36
|
+
try {
|
|
37
|
+
const transformed = transformJSON(analyze({
|
|
38
|
+
src,
|
|
39
|
+
excludes
|
|
40
|
+
}));
|
|
41
|
+
writeFileSync(_output, JSON.stringify(transformed, null, 2));
|
|
42
|
+
console.log(`📁 Analyse sauvegardée dans: ${relative(process.cwd(), _output)}`);
|
|
43
|
+
console.log(`📊 Statistiques:`);
|
|
44
|
+
console.log(` - Fichiers analysés: ${transformed.STATS.files}`);
|
|
45
|
+
console.log(` - Total imports: ${transformed.STATS.imports}`);
|
|
46
|
+
console.log(` - Total exports: ${transformed.STATS.exports}`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error("❌ Erreur lors de l'analyse du codebase:", error);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
56
52
|
};
|
|
57
|
-
|
|
53
|
+
//#endregion
|
|
58
54
|
export { generate, transformJSON };
|
|
59
|
-
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sources":["../../src/functions/generate.ts"],"sourcesContent":["import { writeFileSync } from
|
|
1
|
+
{"version":3,"file":"generate.js","names":[],"sources":["../../src/functions/generate.ts"],"sourcesContent":["import { writeFileSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport { CODEBASE_FILE, SRC_DIR } from \"../constants\";\nimport { analyze } from \"../analyse\";\nimport { CodebaseAnalysis } from \"../schemas\";\n\nexport const transformJSON = (data: CodebaseAnalysis) => {\n let imports = 0;\n let exports = 0;\n let files = 0;\n\n const entries = Object.entries(data).map(\n ([key, { imports: _imports, relativePath, text, exports: _exports }]) => {\n imports += _imports.length;\n exports += _exports?.length ?? 0;\n files++;\n\n const value: any = {\n imports: _imports,\n relativePath,\n text,\n exports: _exports?.filter(\n ({ moduleSpecifier }) => moduleSpecifier !== undefined,\n ),\n };\n\n return [key, value] as const;\n },\n );\n\n const CODEBASE_ANALYSIS = Object.fromEntries(entries);\n\n const STATS = {\n files,\n imports,\n exports,\n };\n\n return {\n STATS,\n CODEBASE_ANALYSIS,\n };\n};\n\nexport type GenerateOptions = {\n output?: string;\n excludes?: string[] | string;\n src?: string;\n};\n\n/**\n * Fonction principale d'exécution\n */\nexport const generate = ({\n output = CODEBASE_FILE,\n excludes,\n src = SRC_DIR,\n}: GenerateOptions = {}) => {\n const _output = output.endsWith(\"codebase.json\")\n ? output\n : `${output}.codebase.json`;\n\n try {\n const analysis = analyze({ src, excludes });\n const transformed = transformJSON(analysis);\n\n const json = JSON.stringify(transformed, null, 2);\n writeFileSync(_output, json);\n\n console.log(\n `📁 Analyse sauvegardée dans: ${relative(process.cwd(), _output)}`,\n );\n console.log(`📊 Statistiques:`);\n console.log(` - Fichiers analysés: ${transformed.STATS.files}`);\n console.log(` - Total imports: ${transformed.STATS.imports}`);\n console.log(` - Total exports: ${transformed.STATS.exports}`);\n } catch (error) {\n console.error(\"❌ Erreur lors de l'analyse du codebase:\", error);\n process.exit(1);\n }\n\n return true;\n};\n"],"mappings":";;;;;AAMA,MAAa,iBAAiB,SAA2B;CACvD,IAAI,UAAU;CACd,IAAI,UAAU;CACd,IAAI,QAAQ;CAEZ,MAAM,UAAU,OAAO,QAAQ,KAAK,CAAC,KAClC,CAAC,KAAK,EAAE,SAAS,UAAU,cAAc,MAAM,SAAS,gBAAgB;AACvE,aAAW,SAAS;AACpB,aAAW,UAAU,UAAU;AAC/B;AAWA,SAAO,CAAC,KATW;GACjB,SAAS;GACT;GACA;GACA,SAAS,UAAU,QAChB,EAAE,sBAAsB,oBAAoB,KAAA,EAC9C;GACF,CAEkB;GAEtB;CAED,MAAM,oBAAoB,OAAO,YAAY,QAAQ;AAQrD,QAAO;EACL,OAPY;GACZ;GACA;GACA;GACD;EAIC;EACD;;;;;AAYH,MAAa,YAAY,EACvB,SAAS,eACT,UACA,MAAM,YACa,EAAE,KAAK;CAC1B,MAAM,UAAU,OAAO,SAAS,gBAAgB,GAC5C,SACA,GAAG,OAAO;AAEd,KAAI;EAEF,MAAM,cAAc,cADH,QAAQ;GAAE;GAAK;GAAU,CAAC,CACA;AAG3C,gBAAc,SADD,KAAK,UAAU,aAAa,MAAM,EAAE,CACrB;AAE5B,UAAQ,IACN,gCAAgC,SAAS,QAAQ,KAAK,EAAE,QAAQ,GACjE;AACD,UAAQ,IAAI,mBAAmB;AAC/B,UAAQ,IAAI,2BAA2B,YAAY,MAAM,QAAQ;AACjE,UAAQ,IAAI,uBAAuB,YAAY,MAAM,UAAU;AAC/D,UAAQ,IAAI,uBAAuB,YAAY,MAAM,UAAU;UACxD,OAAO;AACd,UAAQ,MAAM,2CAA2C,MAAM;AAC/D,UAAQ,KAAK,EAAE;;AAGjB,QAAO"}
|
package/lib/functions/index.cjs
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.transformJSON = functions_generate.transformJSON;
|
|
13
|
-
exports.createTypesStructure = functions_init.createTypesStructure;
|
|
14
|
-
exports.init = functions_init.init;
|
|
15
|
-
exports.remove = functions_remove.remove;
|
|
16
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_functions_add = require("./add.cjs");
|
|
3
|
+
const require_functions_generate = require("./generate.cjs");
|
|
4
|
+
const require_functions_init = require("./init.cjs");
|
|
5
|
+
const require_functions_remove = require("./remove.cjs");
|
|
6
|
+
exports.add = require_functions_add.add;
|
|
7
|
+
exports.createTypesStructure = require_functions_init.createTypesStructure;
|
|
8
|
+
exports.generate = require_functions_generate.generate;
|
|
9
|
+
exports.init = require_functions_init.init;
|
|
10
|
+
exports.remove = require_functions_remove.remove;
|
|
11
|
+
exports.transformJSON = require_functions_generate.transformJSON;
|
package/lib/functions/index.d.ts
CHANGED
package/lib/functions/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { add } from "./add.js";
|
|
2
|
+
import { generate, transformJSON } from "./generate.js";
|
|
3
|
+
import { createTypesStructure, init } from "./init.js";
|
|
4
|
+
import { remove } from "./remove.js";
|
|
5
|
+
export { add, createTypesStructure, generate, init, remove, transformJSON };
|
package/lib/functions/init.cjs
CHANGED
|
@@ -1,103 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_constants = require("../constants.cjs");
|
|
4
|
+
const require_helpers = require("../helpers.cjs");
|
|
5
|
+
let path = require("path");
|
|
6
|
+
let fs = require("fs");
|
|
7
|
+
//#region src/functions/init.ts
|
|
8
8
|
const createTypesStructure = (folderPath, CODEBASE_ANALYSIS) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return PATHS;
|
|
9
|
+
const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {
|
|
10
|
+
return key.endsWith("types") || key.endsWith("constants");
|
|
11
|
+
});
|
|
12
|
+
const PATHS = [];
|
|
13
|
+
console.log(`🔧 Création de la structure de types (${entries.length} fichiers)...`);
|
|
14
|
+
for (const [, fileAnalysis] of entries) {
|
|
15
|
+
const file = require_helpers.writeFileAnalysis(fileAnalysis, folderPath);
|
|
16
|
+
if (file) PATHS.push(file);
|
|
17
|
+
}
|
|
18
|
+
console.log(`✅ Structure de types créée avec succès!`);
|
|
19
|
+
return PATHS;
|
|
21
20
|
};
|
|
22
21
|
const init = (CODEBASE_ANALYSIS, { root, json }) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
tsconfig.compilerOptions.paths[constants.PATH_KEY] = [`${relativePath}/*`];
|
|
72
|
-
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), 'utf8');
|
|
73
|
-
console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error(`❌ Erreur lors de la mise à jour du tsconfig.json:`, error);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
console.warn(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);
|
|
82
|
-
}
|
|
83
|
-
// 3. Créer le fichier .bemedev.json à la racine
|
|
84
|
-
const config = {
|
|
85
|
-
version: '1.0.0',
|
|
86
|
-
[constants.PROPERTIES.PATH]: root,
|
|
87
|
-
[constants.PROPERTIES.FILES]: files,
|
|
88
|
-
};
|
|
89
|
-
try {
|
|
90
|
-
fs.writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
91
|
-
console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
console.error(`❌ Erreur lors de la création du fichier .bemedev.json:`, error);
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
console.log(`🎉 Initialisation de bemedev terminée avec succès!`);
|
|
98
|
-
return true;
|
|
22
|
+
const cwd = process.cwd();
|
|
23
|
+
const configFile = (0, path.join)(cwd, json);
|
|
24
|
+
if ((0, fs.existsSync)(configFile)) return true;
|
|
25
|
+
const folderPath = require_helpers.getFolderPath(root);
|
|
26
|
+
try {
|
|
27
|
+
(0, fs.mkdirSync)(folderPath, { recursive: true });
|
|
28
|
+
console.log(`✅ Dossier .bemedev créé dans: ${root}`);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(`❌ Erreur lors de la création du dossier .bemedev:`, error);
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
let files = [];
|
|
34
|
+
try {
|
|
35
|
+
files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);
|
|
36
|
+
} catch {
|
|
37
|
+
console.error(`❌ Erreur lors de la création de la structure de types:`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const tsconfigPath = (0, path.join)(cwd, "tsconfig.json");
|
|
41
|
+
if ((0, fs.existsSync)(tsconfigPath)) try {
|
|
42
|
+
const tsconfigContent = (0, fs.readFileSync)(tsconfigPath, "utf8");
|
|
43
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
44
|
+
if (!tsconfig.compilerOptions) tsconfig.compilerOptions = {};
|
|
45
|
+
if (!tsconfig.compilerOptions.paths) tsconfig.compilerOptions.paths = {};
|
|
46
|
+
const relativePath = (0, path.relative)(process.cwd(), folderPath);
|
|
47
|
+
tsconfig.compilerOptions.paths[require_constants.PATH_KEY] = [`./${relativePath}/*`];
|
|
48
|
+
(0, fs.writeFileSync)(tsconfigPath, JSON.stringify(tsconfig, null, 2), "utf8");
|
|
49
|
+
console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`❌ Erreur lors de la mise à jour du tsconfig.json:`, error);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
else console.warn(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);
|
|
55
|
+
const config = {
|
|
56
|
+
version: "1.0.0",
|
|
57
|
+
[require_constants.PROPERTIES.PATH]: root,
|
|
58
|
+
[require_constants.PROPERTIES.FILES]: files
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
(0, fs.writeFileSync)(configFile, JSON.stringify(config, null, 2), "utf8");
|
|
62
|
+
console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(`❌ Erreur lors de la création du fichier .bemedev.json:`, error);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
console.log(`🎉 Initialisation de bemedev terminée avec succès!`);
|
|
68
|
+
return true;
|
|
99
69
|
};
|
|
100
|
-
|
|
70
|
+
//#endregion
|
|
101
71
|
exports.createTypesStructure = createTypesStructure;
|
|
102
72
|
exports.init = init;
|
|
103
|
-
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=init.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.cjs","sources":["../../src/functions/init.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { PATH_KEY, PROPERTIES } from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Emplacement personnalisé pour le dossier .bemedev\n * Par défaut: 'src/.bemedev' si src existe, sinon '.bemedev' à la racine\n */\n root: string;\n json: string;\n}\n\nexport const createTypesStructure = (\n folderPath: string,\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {\n return key.endsWith('types') || key.endsWith('constants');\n });\n\n const PATHS: string[] = [];\n\n console.log(\n `🔧 Création de la structure de types (${entries.length} fichiers)...`,\n );\n\n for (const [, fileAnalysis] of entries) {\n const file = writeFileAnalysis(fileAnalysis, folderPath);\n if (file) PATHS.push(file);\n }\n\n console.log(`✅ Structure de types créée avec succès!`);\n return PATHS;\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n { root, json }: InitOptions,\n) => {\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Créer le dossier\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Dossier .bemedev créé dans: ${root}`);\n } catch (error) {\n console.error(\n `❌ Erreur lors de la création du dossier .bemedev:`,\n error,\n );\n return false;\n }\n\n let files: string[] = [];\n // 1.5. Créer la structure des fichiers types\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(\n `❌ Erreur lors de la création de la structure de types:`,\n );\n return false;\n }\n\n // 2. Mettre à jour le tsconfig.json\n const tsconfigPath = join(cwd, 'tsconfig.json');\n\n if (existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n // Initialiser compilerOptions et paths si ils n'existent pas\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Ajouter le path #bemedev/*\n
|
|
1
|
+
{"version":3,"file":"init.cjs","names":["writeFileAnalysis","getFolderPath","PATH_KEY","PROPERTIES"],"sources":["../../src/functions/init.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs';\nimport { join, relative } from 'node:path';\nimport { PATH_KEY, PROPERTIES } from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Emplacement personnalisé pour le dossier .bemedev\n * Par défaut: 'src/.bemedev' si src existe, sinon '.bemedev' à la racine\n */\n root: string;\n json: string;\n}\n\nexport const createTypesStructure = (\n folderPath: string,\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {\n return key.endsWith('types') || key.endsWith('constants');\n });\n\n const PATHS: string[] = [];\n\n console.log(\n `🔧 Création de la structure de types (${entries.length} fichiers)...`,\n );\n\n for (const [, fileAnalysis] of entries) {\n const file = writeFileAnalysis(fileAnalysis, folderPath);\n if (file) PATHS.push(file);\n }\n\n console.log(`✅ Structure de types créée avec succès!`);\n return PATHS;\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n { root, json }: InitOptions,\n) => {\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Créer le dossier\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Dossier .bemedev créé dans: ${root}`);\n } catch (error) {\n console.error(\n `❌ Erreur lors de la création du dossier .bemedev:`,\n error,\n );\n return false;\n }\n\n // eslint-disable-next-line no-useless-assignment\n let files: string[] = [];\n // 1.5. Créer la structure des fichiers types\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(\n `❌ Erreur lors de la création de la structure de types:`,\n );\n return false;\n }\n\n // 2. Mettre à jour le tsconfig.json\n const tsconfigPath = join(cwd, 'tsconfig.json');\n\n if (existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n // Initialiser compilerOptions et paths si ils n'existent pas\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Ajouter le path #bemedev/*\n const relativePath = relative(process.cwd(), folderPath);\n\n {\n // Remove baseUrl since typescript 6.0 will no longer use it\n // const baseUrl = tsconfig.compilerOptions.baseUrl;\n // if (typeof baseUrl === 'string') {\n // // Si baseUrl est défini, calculer le chemin relatif par rapport à baseUrl\n // relativePath = relative(baseUrl, relativePath);\n // } else {\n // // Si baseUrl n'est pas défini, utiliser le chemin absolu\n // tsconfig.compilerOptions.baseUrl = '.';\n // }\n }\n\n tsconfig.compilerOptions.paths[PATH_KEY] = [\n `./${relativePath}/*`,\n ];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);\n } catch (error) {\n console.error(\n `❌ Erreur lors de la mise à jour du tsconfig.json:`,\n error,\n );\n return false;\n }\n } else {\n console.warn(\n `⚠️ Fichier tsconfig.json introuvable, path non ajouté`,\n );\n }\n\n // 3. Créer le fichier .bemedev.json à la racine\n\n const config = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');\n console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);\n } catch (error) {\n console.error(\n `❌ Erreur lors de la création du fichier .bemedev.json:`,\n error,\n );\n return false;\n }\n\n console.log(`🎉 Initialisation de bemedev terminée avec succès!`);\n return true;\n};\n"],"mappings":";;;;;;;AAoBA,MAAa,wBACX,YACA,sBACG;CACH,MAAM,UAAU,OAAO,QAAQ,kBAAkB,CAAC,QAAQ,CAAC,SAAS;AAClE,SAAO,IAAI,SAAS,QAAQ,IAAI,IAAI,SAAS,YAAY;GACzD;CAEF,MAAM,QAAkB,EAAE;AAE1B,SAAQ,IACN,yCAAyC,QAAQ,OAAO,eACzD;AAED,MAAK,MAAM,GAAG,iBAAiB,SAAS;EACtC,MAAM,OAAOA,gBAAAA,kBAAkB,cAAc,WAAW;AACxD,MAAI,KAAM,OAAM,KAAK,KAAK;;AAG5B,SAAQ,IAAI,0CAA0C;AACtD,QAAO;;AAGT,MAAa,QACX,mBACA,EAAE,MAAM,WACL;CACH,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,cAAA,GAAA,KAAA,MAAkB,KAAK,KAAK;AAGlC,MAAA,GAAA,GAAA,YAFgC,WAAW,CAEzB,QAAO;CACzB,MAAM,aAAaC,gBAAAA,cAAc,KAAK;AAGtC,KAAI;AACF,GAAA,GAAA,GAAA,WAAU,YAAY,EAAE,WAAW,MAAM,CAAC;AAC1C,UAAQ,IAAI,iCAAiC,OAAO;UAC7C,OAAO;AACd,UAAQ,MACN,qDACA,MACD;AACD,SAAO;;CAIT,IAAI,QAAkB,EAAE;AAExB,KAAI;AACF,UAAQ,qBAAqB,YAAY,kBAAkB;SACrD;AACN,UAAQ,MACN,yDACD;AACD,SAAO;;CAIT,MAAM,gBAAA,GAAA,KAAA,MAAoB,KAAK,gBAAgB;AAE/C,MAAA,GAAA,GAAA,YAAe,aAAa,CAC1B,KAAI;EACF,MAAM,mBAAA,GAAA,GAAA,cAA+B,cAAc,OAAO;EAC1D,MAAM,WAAW,KAAK,MAAM,gBAAgB;AAG5C,MAAI,CAAC,SAAS,gBACZ,UAAS,kBAAkB,EAAE;AAG/B,MAAI,CAAC,SAAS,gBAAgB,MAC5B,UAAS,gBAAgB,QAAQ,EAAE;EAIrC,MAAM,gBAAA,GAAA,KAAA,UAAwB,QAAQ,KAAK,EAAE,WAAW;AAcxD,WAAS,gBAAgB,MAAMC,kBAAAA,YAAY,CACzC,KAAK,aAAa,IACnB;AAED,GAAA,GAAA,GAAA,eACE,cACA,KAAK,UAAU,UAAU,MAAM,EAAE,EACjC,OACD;AACD,UAAQ,IAAI,4CAA4C;UACjD,OAAO;AACd,UAAQ,MACN,qDACA,MACD;AACD,SAAO;;KAGT,SAAQ,KACN,wDACD;CAKH,MAAM,SAAS;EACb,SAAS;GACRC,kBAAAA,WAAW,OAAO;GAClBA,kBAAAA,WAAW,QAAQ;EACrB;AAED,KAAI;AACF,GAAA,GAAA,GAAA,eAAc,YAAY,KAAK,UAAU,QAAQ,MAAM,EAAE,EAAE,OAAO;AAClE,UAAQ,IAAI,qDAAqD;UAC1D,OAAO;AACd,UAAQ,MACN,0DACA,MACD;AACD,SAAO;;AAGT,SAAQ,IAAI,qDAAqD;AACjE,QAAO"}
|
package/lib/functions/init.d.ts
CHANGED
|
@@ -9,4 +9,3 @@ export interface InitOptions {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const createTypesStructure: (folderPath: string, CODEBASE_ANALYSIS: CodebaseAnalysis) => string[];
|
|
11
11
|
export declare const init: (CODEBASE_ANALYSIS: CodebaseAnalysis, { root, json }: InitOptions) => boolean;
|
|
12
|
-
//# sourceMappingURL=init.d.ts.map
|
package/lib/functions/init.js
CHANGED
|
@@ -1,100 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { PATH_KEY, PROPERTIES } from "../constants.js";
|
|
2
|
+
import { getFolderPath, writeFileAnalysis } from "../helpers.js";
|
|
3
|
+
import { join, relative } from "path";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
+
//#region src/functions/init.ts
|
|
6
6
|
const createTypesStructure = (folderPath, CODEBASE_ANALYSIS) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return PATHS;
|
|
7
|
+
const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {
|
|
8
|
+
return key.endsWith("types") || key.endsWith("constants");
|
|
9
|
+
});
|
|
10
|
+
const PATHS = [];
|
|
11
|
+
console.log(`🔧 Création de la structure de types (${entries.length} fichiers)...`);
|
|
12
|
+
for (const [, fileAnalysis] of entries) {
|
|
13
|
+
const file = writeFileAnalysis(fileAnalysis, folderPath);
|
|
14
|
+
if (file) PATHS.push(file);
|
|
15
|
+
}
|
|
16
|
+
console.log(`✅ Structure de types créée avec succès!`);
|
|
17
|
+
return PATHS;
|
|
19
18
|
};
|
|
20
19
|
const init = (CODEBASE_ANALYSIS, { root, json }) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
tsconfig.compilerOptions.paths[PATH_KEY] = [`${relativePath}/*`];
|
|
70
|
-
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), 'utf8');
|
|
71
|
-
console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error(`❌ Erreur lors de la mise à jour du tsconfig.json:`, error);
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
console.warn(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);
|
|
80
|
-
}
|
|
81
|
-
// 3. Créer le fichier .bemedev.json à la racine
|
|
82
|
-
const config = {
|
|
83
|
-
version: '1.0.0',
|
|
84
|
-
[PROPERTIES.PATH]: root,
|
|
85
|
-
[PROPERTIES.FILES]: files,
|
|
86
|
-
};
|
|
87
|
-
try {
|
|
88
|
-
writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
89
|
-
console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
console.error(`❌ Erreur lors de la création du fichier .bemedev.json:`, error);
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
console.log(`🎉 Initialisation de bemedev terminée avec succès!`);
|
|
96
|
-
return true;
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
const configFile = join(cwd, json);
|
|
22
|
+
if (existsSync(configFile)) return true;
|
|
23
|
+
const folderPath = getFolderPath(root);
|
|
24
|
+
try {
|
|
25
|
+
mkdirSync(folderPath, { recursive: true });
|
|
26
|
+
console.log(`✅ Dossier .bemedev créé dans: ${root}`);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(`❌ Erreur lors de la création du dossier .bemedev:`, error);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
let files = [];
|
|
32
|
+
try {
|
|
33
|
+
files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);
|
|
34
|
+
} catch {
|
|
35
|
+
console.error(`❌ Erreur lors de la création de la structure de types:`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const tsconfigPath = join(cwd, "tsconfig.json");
|
|
39
|
+
if (existsSync(tsconfigPath)) try {
|
|
40
|
+
const tsconfigContent = readFileSync(tsconfigPath, "utf8");
|
|
41
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
42
|
+
if (!tsconfig.compilerOptions) tsconfig.compilerOptions = {};
|
|
43
|
+
if (!tsconfig.compilerOptions.paths) tsconfig.compilerOptions.paths = {};
|
|
44
|
+
const relativePath = relative(process.cwd(), folderPath);
|
|
45
|
+
tsconfig.compilerOptions.paths[PATH_KEY] = [`./${relativePath}/*`];
|
|
46
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), "utf8");
|
|
47
|
+
console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`❌ Erreur lors de la mise à jour du tsconfig.json:`, error);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
else console.warn(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);
|
|
53
|
+
const config = {
|
|
54
|
+
version: "1.0.0",
|
|
55
|
+
[PROPERTIES.PATH]: root,
|
|
56
|
+
[PROPERTIES.FILES]: files
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
writeFileSync(configFile, JSON.stringify(config, null, 2), "utf8");
|
|
60
|
+
console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`❌ Erreur lors de la création du fichier .bemedev.json:`, error);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
console.log(`🎉 Initialisation de bemedev terminée avec succès!`);
|
|
66
|
+
return true;
|
|
97
67
|
};
|
|
98
|
-
|
|
68
|
+
//#endregion
|
|
99
69
|
export { createTypesStructure, init };
|
|
100
|
-
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=init.js.map
|