@bemedev/codebase 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/lib/analyse.cjs +68 -0
- package/lib/analyse.cjs.map +1 -0
- package/lib/analyse.d.ts +10 -0
- package/lib/analyse.d.ts.map +1 -0
- package/lib/analyse.js +66 -0
- package/lib/analyse.js.map +1 -0
- package/lib/analyse.utils.cjs +240 -0
- package/lib/analyse.utils.cjs.map +1 -0
- package/lib/analyse.utils.d.ts +30 -0
- package/lib/analyse.utils.d.ts.map +1 -0
- package/lib/analyse.utils.js +232 -0
- package/lib/analyse.utils.js.map +1 -0
- package/lib/cli/cli.cjs +27 -0
- package/lib/cli/cli.cjs.map +1 -0
- package/lib/cli/cli.d.ts +12 -0
- package/lib/cli/cli.d.ts.map +1 -0
- package/lib/cli/cli.js +25 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/constants.cjs +6 -0
- package/lib/cli/constants.cjs.map +1 -0
- package/lib/cli/constants.d.ts +2 -0
- package/lib/cli/constants.d.ts.map +1 -0
- package/lib/cli/constants.js +4 -0
- package/lib/cli/constants.js.map +1 -0
- package/lib/cli/index.cjs +8 -0
- package/lib/cli/index.cjs.map +1 -0
- package/lib/cli/index.d.ts +3 -0
- package/lib/cli/index.d.ts.map +1 -0
- package/lib/cli/index.js +6 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/constants.cjs +40 -0
- package/lib/constants.cjs.map +1 -0
- package/lib/constants.d.ts +17 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +31 -0
- package/lib/constants.js.map +1 -0
- package/lib/exports.cjs +75 -0
- package/lib/exports.cjs.map +1 -0
- package/lib/exports.d.ts +4 -0
- package/lib/exports.d.ts.map +1 -0
- package/lib/exports.js +73 -0
- package/lib/exports.js.map +1 -0
- package/lib/functions/add.cjs +85 -0
- package/lib/functions/add.cjs.map +1 -0
- package/lib/functions/add.d.ts +3 -0
- package/lib/functions/add.d.ts.map +1 -0
- package/lib/functions/add.js +83 -0
- package/lib/functions/add.js.map +1 -0
- package/lib/functions/generate.cjs +61 -0
- package/lib/functions/generate.cjs.map +1 -0
- package/lib/functions/generate.d.ts +25 -0
- package/lib/functions/generate.d.ts.map +1 -0
- package/lib/functions/generate.js +58 -0
- package/lib/functions/generate.js.map +1 -0
- package/lib/functions/index.cjs +16 -0
- package/lib/functions/index.cjs.map +1 -0
- package/lib/functions/index.d.ts +5 -0
- package/lib/functions/index.d.ts.map +1 -0
- package/lib/functions/index.js +5 -0
- package/lib/functions/index.js.map +1 -0
- package/lib/functions/init.cjs +104 -0
- package/lib/functions/init.cjs.map +1 -0
- package/lib/functions/init.d.ts +12 -0
- package/lib/functions/init.d.ts.map +1 -0
- package/lib/functions/init.js +101 -0
- package/lib/functions/init.js.map +1 -0
- package/lib/functions/remove.cjs +108 -0
- package/lib/functions/remove.cjs.map +1 -0
- package/lib/functions/remove.d.ts +3 -0
- package/lib/functions/remove.d.ts.map +1 -0
- package/lib/functions/remove.js +106 -0
- package/lib/functions/remove.js.map +1 -0
- package/lib/helpers.cjs +47 -0
- package/lib/helpers.cjs.map +1 -0
- package/lib/helpers.d.ts +11 -0
- package/lib/helpers.d.ts.map +1 -0
- package/lib/helpers.js +42 -0
- package/lib/helpers.js.map +1 -0
- package/lib/imports.cjs +128 -0
- package/lib/imports.cjs.map +1 -0
- package/lib/imports.d.ts +8 -0
- package/lib/imports.d.ts.map +1 -0
- package/lib/imports.js +125 -0
- package/lib/imports.js.map +1 -0
- package/lib/index.cjs +16 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/schemas.cjs +80 -0
- package/lib/schemas.cjs.map +1 -0
- package/lib/schemas.d.ts +90 -0
- package/lib/schemas.d.ts.map +1 -0
- package/lib/schemas.js +53 -0
- package/lib/schemas.js.map +1 -0
- package/lib/types.d.ts +43 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils.cjs +14 -0
- package/lib/utils.cjs.map +1 -0
- package/lib/utils.d.ts +6 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +12 -0
- package/lib/utils.js.map +1 -0
- package/package.json +125 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/functions/init.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,mBAAmB,gBAAgB,aAmBpC,CAAC;AAEF,eAAO,MAAM,IAAI,GACf,mBAAmB,gBAAgB,EACnC,gBAAgB,WAAW,YAuG5B,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { PATH_KEY, PROPERTIES } from '../constants.js';
|
|
4
|
+
import { writeFileAnalysis } from '../helpers.js';
|
|
5
|
+
|
|
6
|
+
const createTypesStructure = (folderPath, CODEBASE_ANALYSIS) => {
|
|
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)
|
|
15
|
+
PATHS.push(file);
|
|
16
|
+
}
|
|
17
|
+
console.log(`✅ Structure de types créée avec succès!`);
|
|
18
|
+
return PATHS;
|
|
19
|
+
};
|
|
20
|
+
const init = (CODEBASE_ANALYSIS, { root, json }) => {
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
const configFile = join(cwd, json);
|
|
23
|
+
const configExists = existsSync(configFile);
|
|
24
|
+
if (configExists)
|
|
25
|
+
return true;
|
|
26
|
+
const srcExists = existsSync(join(cwd, 'src'));
|
|
27
|
+
const folderPath = srcExists ? join(cwd, 'src', root) : join(cwd, root);
|
|
28
|
+
// 1. Créer le dossier
|
|
29
|
+
try {
|
|
30
|
+
mkdirSync(folderPath, { recursive: true });
|
|
31
|
+
console.log(`✅ Dossier .bemedev créé dans: ${root}`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(`❌ Erreur lors de la création du dossier .bemedev:`, error);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
let files = [];
|
|
38
|
+
// 1.5. Créer la structure des fichiers types
|
|
39
|
+
try {
|
|
40
|
+
files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
console.error(`❌ Erreur lors de la création de la structure de types:`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// 2. Mettre à jour le tsconfig.json
|
|
47
|
+
const tsconfigPath = join(cwd, 'tsconfig.json');
|
|
48
|
+
if (existsSync(tsconfigPath)) {
|
|
49
|
+
try {
|
|
50
|
+
const tsconfigContent = readFileSync(tsconfigPath, 'utf8');
|
|
51
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
52
|
+
// Initialiser compilerOptions et paths si ils n'existent pas
|
|
53
|
+
if (!tsconfig.compilerOptions) {
|
|
54
|
+
tsconfig.compilerOptions = {};
|
|
55
|
+
}
|
|
56
|
+
if (!tsconfig.compilerOptions.paths) {
|
|
57
|
+
tsconfig.compilerOptions.paths = {};
|
|
58
|
+
}
|
|
59
|
+
// Ajouter le path #bemedev/*
|
|
60
|
+
let relativePath = root;
|
|
61
|
+
const baseUrl = tsconfig.compilerOptions.baseUrl;
|
|
62
|
+
if (typeof baseUrl === 'string') {
|
|
63
|
+
// Si baseUrl est défini, calculer le chemin relatif par rapport à baseUrl
|
|
64
|
+
relativePath = join(baseUrl, relativePath);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Si baseUrl n'est pas défini, utiliser le chemin absolu
|
|
68
|
+
tsconfig.compilerOptions.baseUrl = '.';
|
|
69
|
+
}
|
|
70
|
+
tsconfig.compilerOptions.paths[PATH_KEY] = [`${relativePath}/*`];
|
|
71
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), 'utf8');
|
|
72
|
+
console.log(`✅ Path #bemedev/* ajouté au tsconfig.json`);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error(`❌ Erreur lors de la mise à jour du tsconfig.json:`, error);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.warn(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);
|
|
81
|
+
}
|
|
82
|
+
// 3. Créer le fichier .bemedev.json à la racine
|
|
83
|
+
const config = {
|
|
84
|
+
version: '1.0.0',
|
|
85
|
+
[PROPERTIES.PATH]: root,
|
|
86
|
+
[PROPERTIES.FILES]: files,
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
90
|
+
console.log(`✅ Fichier .bemedev.json créé à la racine du projet`);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`❌ Erreur lors de la création du fichier .bemedev.json:`, error);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
console.log(`🎉 Initialisation de bemedev terminée avec succès!`);
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export { createTypesStructure, init };
|
|
101
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sources":["../../src/functions/init.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs';\nimport { join } from 'node:path';\nimport { PATH_KEY, PROPERTIES } from '../constants';\nimport { 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 srcExists = existsSync(join(cwd, 'src'));\n const folderPath = srcExists ? join(cwd, 'src', root) : join(cwd, 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 let relativePath = root;\n const baseUrl = tsconfig.compilerOptions.baseUrl;\n\n if (typeof baseUrl === 'string') {\n // Si baseUrl est défini, calculer le chemin relatif par rapport à baseUrl\n\n relativePath = join(baseUrl, relativePath);\n } else {\n // Si baseUrl n'est pas défini, utiliser le chemin absolu\n tsconfig.compilerOptions.baseUrl = '.';\n }\n\n tsconfig.compilerOptions.paths[PATH_KEY] = [`${relativePath}/*`];\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(`⚠️ Fichier tsconfig.json introuvable, path non ajouté`);\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"],"names":[],"mappings":";;;;;MAoBa,oBAAoB,GAAG,CAClC,UAAkB,EAClB,iBAAmC,KACjC;AACF,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB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I,CAAC;AAEhE,YAAA,aAAa,CACX,YAAY,EACZ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EACjC,MAAM,CACP;AACD,YAAA,OAAO,CAAC,GAAG,CAAC,CAAA,yCAAA,CAA2C,CAAC;QAC1D;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CACX,mDAAmD,EACnD,KAAK,CACN;AACD,YAAA,OAAO,KAAK;QACd;IACF;SAAO;AACL,QAAA,OAAO,CAAC,IAAI,CAAC,CAAA,qDAAA,CAAuD,CAAC;IACvE;;AAIA,IAAA,MAAM,MAAM,GAAG;AACb,QAAA,OAAO,EAAE,OAAO;AAChB,QAAA,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI;AACvB,QAAA,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK;KAC1B;AAED,IAAA,IAAI;AACF,QAAA,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC;AAClE,QAAA,OAAO,CAAC,GAAG,CAAC,CAAA,kDAAA,CAAoD,CAAC;IACnE;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CACX,wDAAwD,EACxD,KAAK,CACN;AACD,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,OAAO,CAAC,GAAG,CAAC,CAAA,kDAAA,CAAoD,CAAC;AACjE,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var edit = require('edit-json-file');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var constants = require('../constants.cjs');
|
|
7
|
+
var helpers = require('../helpers.cjs');
|
|
8
|
+
|
|
9
|
+
const transformModules = (entries, ...files) => {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const out = entries
|
|
12
|
+
.map(([key, { imports, relativePath }]) => [key, relativePath, imports])
|
|
13
|
+
.map(([key, relativePath, imports]) => {
|
|
14
|
+
const specifiers = imports
|
|
15
|
+
.map(({ moduleSpecifier }) => {
|
|
16
|
+
return helpers.transformModule({
|
|
17
|
+
cwd,
|
|
18
|
+
relativePath,
|
|
19
|
+
moduleSpecifier,
|
|
20
|
+
});
|
|
21
|
+
})
|
|
22
|
+
.map(_path => [_path, `${_path}.index`]) // Ajouter les variantes .index
|
|
23
|
+
.flat()
|
|
24
|
+
.filter(s => files.includes(s));
|
|
25
|
+
return [key, Array.from(new Set(specifiers))];
|
|
26
|
+
});
|
|
27
|
+
return out;
|
|
28
|
+
};
|
|
29
|
+
const remove = (CODEBASE_ANALYSIS, ...paths) => {
|
|
30
|
+
const isEmpty = paths.length === 0;
|
|
31
|
+
if (isEmpty)
|
|
32
|
+
return console.warn('No files specified for removal.');
|
|
33
|
+
try {
|
|
34
|
+
const cwd = process.cwd();
|
|
35
|
+
const json = path.join(cwd, constants.JSON_FILE_NAME);
|
|
36
|
+
let file = edit(json);
|
|
37
|
+
if (!file)
|
|
38
|
+
return;
|
|
39
|
+
const bemedevPath = file.get(constants.PATH_PROPERTY);
|
|
40
|
+
const files = file.get(constants.FILES_PROPERTY);
|
|
41
|
+
// Vérifier les dépendances avant suppression
|
|
42
|
+
const safesToRemove = [];
|
|
43
|
+
const cannotRemoves2 = [];
|
|
44
|
+
const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
|
|
45
|
+
const entries = entries2.filter(([key]) => paths.some(p => key.startsWith(p)));
|
|
46
|
+
entries.forEach(([key]) => {
|
|
47
|
+
const modules = transformModules(entries2, ...files);
|
|
48
|
+
const importedFroms = modules
|
|
49
|
+
.filter(([, specifiers]) => specifiers.includes(key))
|
|
50
|
+
.map(([k]) => k);
|
|
51
|
+
const check = importedFroms.length > 0;
|
|
52
|
+
console.log('modules', '=>', importedFroms);
|
|
53
|
+
console.log('key', '=>', key);
|
|
54
|
+
if (check)
|
|
55
|
+
return cannotRemoves2.push([key, importedFroms]);
|
|
56
|
+
return safesToRemove.push(key);
|
|
57
|
+
});
|
|
58
|
+
helpers.consoleStars();
|
|
59
|
+
console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);
|
|
60
|
+
// Afficher les fichiers qui ne peuvent pas être supprimés
|
|
61
|
+
if (cannotRemoves2.length > 0) {
|
|
62
|
+
const len = cannotRemoves2.length;
|
|
63
|
+
const one = "fichier ne peut pas être supprimé (importé dans d'autres fichiers)";
|
|
64
|
+
const many = "fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)";
|
|
65
|
+
console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);
|
|
66
|
+
cannotRemoves2.forEach(([key, modules]) => {
|
|
67
|
+
console.warn(` - ⚠️ ${key} importé par :`);
|
|
68
|
+
modules.forEach(m => console.warn(` -> 📌 ${m}`));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (safesToRemove.length === 0) {
|
|
72
|
+
console.warn('❌ Aucun fichier ne peut être supprimé.');
|
|
73
|
+
return helpers.consoleStars();
|
|
74
|
+
}
|
|
75
|
+
const formatteds = safesToRemove.map(key => {
|
|
76
|
+
const _path = `${key.replaceAll('.', '/')}.ts`;
|
|
77
|
+
const absolute = path.join(cwd, bemedevPath, _path);
|
|
78
|
+
return [key, absolute];
|
|
79
|
+
});
|
|
80
|
+
console.log(`🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`);
|
|
81
|
+
let success = 0;
|
|
82
|
+
const length = formatteds.length;
|
|
83
|
+
formatteds.forEach(([key, path]) => {
|
|
84
|
+
try {
|
|
85
|
+
fs.unlinkSync(path);
|
|
86
|
+
console.log(` - 🗑️ ${key}`);
|
|
87
|
+
file?.set(constants.FILES_PROPERTY, files.filter(key1 => key1 !== key));
|
|
88
|
+
success++;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error(` - ❌ Erreur, ${key} :`, error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
file.save();
|
|
95
|
+
console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);
|
|
96
|
+
file = undefined;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
console.error(`❌ Erreur lors de la création des fichiers`);
|
|
100
|
+
helpers.consoleStars();
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
helpers.consoleStars();
|
|
104
|
+
return true;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.remove = remove;
|
|
108
|
+
//# sourceMappingURL=remove.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.cjs","sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport {\n FILES_PROPERTY,\n JSON_FILE_NAME,\n PATH_PROPERTY,\n} from '../constants';\nimport { consoleStars, transformModule } from '../helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Ajouter les variantes .index\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, JSON_FILE_NAME);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const bemedevPath = file.get(PATH_PROPERTY) as string;\n const files = file.get(FILES_PROPERTY) as string[];\n\n // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotRemoves2: [string, string[]][] = [];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotRemoves2.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(\n `🔧 Suppression des fichiers (${entries.length} fichiers)...`,\n );\n\n // Afficher les fichiers qui ne peuvent pas être supprimés\n if (cannotRemoves2.length > 0) {\n const len = cannotRemoves2.length;\n const one =\n \"fichier ne peut pas être supprimé (importé dans d'autres fichiers)\";\n const many =\n \"fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)\";\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotRemoves2.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} importé par :`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ Aucun fichier ne peut être supprimé.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = `${key.replaceAll('.', '/')}.ts`;\n const absolute = join(cwd, bemedevPath, _path);\n return [key, absolute] as const;\n });\n\n console.log(\n `🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`,\n );\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch (error) {\n console.error(` - ❌ Erreur, ${key} :`, error);\n }\n });\n\n file.save();\n console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Erreur lors de la création des fichiers`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"names":["transformModule","join","JSON_FILE_NAME","PATH_PROPERTY","FILES_PROPERTY","consoleStars","unlinkSync"],"mappings":";;;;;;;;AAWA,MAAM,gBAAgB,GAAG,CACvB,OAAiC,EACjC,GAAG,KAAe,KAChB;AACF,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACzB,MAAM,GAAG,GAAG;SACT,GAAG,CACF,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,KAC/B,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAU;SAExC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,KAAI;QACpC,MAAM,UAAU,GAAG;AAChB,aAAA,GAAG,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;AAC3B,YAAA,OAAOA,uBAAe,CAAC;gBACrB,GAAG;gBACH,YAAY;gBACZ,eAAe;AAChB,aAAA,CAAC;AACJ,QAAA,CAAC;AACA,aAAA,GAAG,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,CAAA,EAAG,KAAK,CAAA,MAAA,CAAQ,CAAC,CAAC;AACvC,aAAA,IAAI;AACJ,aAAA,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAEjC,QAAA,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAU;AACxD,IAAA,CAAC,CAAC;AAEJ,IAAA,OAAO,GAAG;AACZ,CAAC;AAEM,MAAM,MAAM,GAAG,CACpB,iBAAmC,EACnC,GAAG,KAAe,KAChB;AACF,IAAA,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;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../src/functions/remove.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,YAAY,CAAC;AA+B5D,eAAO,MAAM,MAAM,GACjB,mBAAmB,gBAAgB,EACnC,GAAG,OAAO,MAAM,EAAE,mBAuGnB,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import edit from 'edit-json-file';
|
|
2
|
+
import { unlinkSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { JSON_FILE_NAME, PATH_PROPERTY, FILES_PROPERTY } from '../constants.js';
|
|
5
|
+
import { consoleStars, transformModule } from '../helpers.js';
|
|
6
|
+
|
|
7
|
+
const transformModules = (entries, ...files) => {
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
const out = entries
|
|
10
|
+
.map(([key, { imports, relativePath }]) => [key, relativePath, imports])
|
|
11
|
+
.map(([key, relativePath, imports]) => {
|
|
12
|
+
const specifiers = imports
|
|
13
|
+
.map(({ moduleSpecifier }) => {
|
|
14
|
+
return transformModule({
|
|
15
|
+
cwd,
|
|
16
|
+
relativePath,
|
|
17
|
+
moduleSpecifier,
|
|
18
|
+
});
|
|
19
|
+
})
|
|
20
|
+
.map(_path => [_path, `${_path}.index`]) // Ajouter les variantes .index
|
|
21
|
+
.flat()
|
|
22
|
+
.filter(s => files.includes(s));
|
|
23
|
+
return [key, Array.from(new Set(specifiers))];
|
|
24
|
+
});
|
|
25
|
+
return out;
|
|
26
|
+
};
|
|
27
|
+
const remove = (CODEBASE_ANALYSIS, ...paths) => {
|
|
28
|
+
const isEmpty = paths.length === 0;
|
|
29
|
+
if (isEmpty)
|
|
30
|
+
return console.warn('No files specified for removal.');
|
|
31
|
+
try {
|
|
32
|
+
const cwd = process.cwd();
|
|
33
|
+
const json = join(cwd, JSON_FILE_NAME);
|
|
34
|
+
let file = edit(json);
|
|
35
|
+
if (!file)
|
|
36
|
+
return;
|
|
37
|
+
const bemedevPath = file.get(PATH_PROPERTY);
|
|
38
|
+
const files = file.get(FILES_PROPERTY);
|
|
39
|
+
// Vérifier les dépendances avant suppression
|
|
40
|
+
const safesToRemove = [];
|
|
41
|
+
const cannotRemoves2 = [];
|
|
42
|
+
const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
|
|
43
|
+
const entries = entries2.filter(([key]) => paths.some(p => key.startsWith(p)));
|
|
44
|
+
entries.forEach(([key]) => {
|
|
45
|
+
const modules = transformModules(entries2, ...files);
|
|
46
|
+
const importedFroms = modules
|
|
47
|
+
.filter(([, specifiers]) => specifiers.includes(key))
|
|
48
|
+
.map(([k]) => k);
|
|
49
|
+
const check = importedFroms.length > 0;
|
|
50
|
+
console.log('modules', '=>', importedFroms);
|
|
51
|
+
console.log('key', '=>', key);
|
|
52
|
+
if (check)
|
|
53
|
+
return cannotRemoves2.push([key, importedFroms]);
|
|
54
|
+
return safesToRemove.push(key);
|
|
55
|
+
});
|
|
56
|
+
consoleStars();
|
|
57
|
+
console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);
|
|
58
|
+
// Afficher les fichiers qui ne peuvent pas être supprimés
|
|
59
|
+
if (cannotRemoves2.length > 0) {
|
|
60
|
+
const len = cannotRemoves2.length;
|
|
61
|
+
const one = "fichier ne peut pas être supprimé (importé dans d'autres fichiers)";
|
|
62
|
+
const many = "fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)";
|
|
63
|
+
console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);
|
|
64
|
+
cannotRemoves2.forEach(([key, modules]) => {
|
|
65
|
+
console.warn(` - ⚠️ ${key} importé par :`);
|
|
66
|
+
modules.forEach(m => console.warn(` -> 📌 ${m}`));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (safesToRemove.length === 0) {
|
|
70
|
+
console.warn('❌ Aucun fichier ne peut être supprimé.');
|
|
71
|
+
return consoleStars();
|
|
72
|
+
}
|
|
73
|
+
const formatteds = safesToRemove.map(key => {
|
|
74
|
+
const _path = `${key.replaceAll('.', '/')}.ts`;
|
|
75
|
+
const absolute = join(cwd, bemedevPath, _path);
|
|
76
|
+
return [key, absolute];
|
|
77
|
+
});
|
|
78
|
+
console.log(`🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`);
|
|
79
|
+
let success = 0;
|
|
80
|
+
const length = formatteds.length;
|
|
81
|
+
formatteds.forEach(([key, path]) => {
|
|
82
|
+
try {
|
|
83
|
+
unlinkSync(path);
|
|
84
|
+
console.log(` - 🗑️ ${key}`);
|
|
85
|
+
file?.set(FILES_PROPERTY, files.filter(key1 => key1 !== key));
|
|
86
|
+
success++;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(` - ❌ Erreur, ${key} :`, error);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
file.save();
|
|
93
|
+
console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);
|
|
94
|
+
file = undefined;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
console.error(`❌ Erreur lors de la création des fichiers`);
|
|
98
|
+
consoleStars();
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
consoleStars();
|
|
102
|
+
return true;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { remove };
|
|
106
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport {\n FILES_PROPERTY,\n JSON_FILE_NAME,\n PATH_PROPERTY,\n} from '../constants';\nimport { consoleStars, transformModule } from '../helpers';\nimport { CodebaseAnalysis, FileAnalysis } from '../schemas';\n\nconst transformModules = (\n entries: [string, FileAnalysis][],\n ...files: string[]\n) => {\n const cwd = process.cwd();\n const out = entries\n .map(\n ([key, { imports, relativePath }]) =>\n [key, relativePath, imports] as const,\n )\n .map(([key, relativePath, imports]) => {\n const specifiers = imports\n .map(({ moduleSpecifier }) => {\n return transformModule({\n cwd,\n relativePath,\n moduleSpecifier,\n });\n })\n .map(_path => [_path, `${_path}.index`]) // Ajouter les variantes .index\n .flat()\n .filter(s => files.includes(s));\n\n return [key, Array.from(new Set(specifiers))] as const;\n });\n\n return out;\n};\n\nexport const remove = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for removal.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, JSON_FILE_NAME);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const bemedevPath = file.get(PATH_PROPERTY) as string;\n const files = file.get(FILES_PROPERTY) as string[];\n\n // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotRemoves2: [string, string[]][] = [];\n\n const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) =>\n files.includes(key),\n );\n\n const entries = entries2.filter(([key]) =>\n paths.some(p => key.startsWith(p)),\n );\n\n entries.forEach(([key]) => {\n const modules = transformModules(entries2, ...files);\n const importedFroms = modules\n .filter(([, specifiers]) => specifiers.includes(key))\n .map(([k]) => k);\n\n const check = importedFroms.length > 0;\n\n console.log('modules', '=>', importedFroms);\n console.log('key', '=>', key);\n\n if (check) return cannotRemoves2.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(\n `🔧 Suppression des fichiers (${entries.length} fichiers)...`,\n );\n\n // Afficher les fichiers qui ne peuvent pas être supprimés\n if (cannotRemoves2.length > 0) {\n const len = cannotRemoves2.length;\n const one =\n \"fichier ne peut pas être supprimé (importé dans d'autres fichiers)\";\n const many =\n \"fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)\";\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotRemoves2.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} importé par :`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ Aucun fichier ne peut être supprimé.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = `${key.replaceAll('.', '/')}.ts`;\n const absolute = join(cwd, bemedevPath, _path);\n return [key, absolute] as const;\n });\n\n console.log(\n `🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`,\n );\n\n let success = 0;\n const length = formatteds.length;\n\n formatteds.forEach(([key, path]) => {\n try {\n unlinkSync(path);\n console.log(` - 🗑️ ${key}`);\n file?.set(\n FILES_PROPERTY,\n files.filter(key1 => key1 !== key),\n );\n success++;\n } catch (error) {\n console.error(` - ❌ Erreur, ${key} :`, error);\n }\n });\n\n file.save();\n console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Erreur lors de la création des fichiers`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"names":[],"mappings":";;;;;;AAWA,MAAM,gBAAgB,GAAG,CACvB,OAAiC,EACjC,GAAG,KAAe,KAChB;AACF,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACzB,MAAM,GAAG,GAAG;SACT,GAAG,CACF,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,KAC/B,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAU;SAExC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,KAAI;QACpC,MAAM,UAAU,GAAG;AAChB,aAAA,GAAG,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;AAC3B,YAAA,OAAO,eAAe,CAAC;gBACrB,GAAG;gBACH,YAAY;gBACZ,eAAe;AAChB,aAAA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E;gBACd,OAAO,CAAC,KAAK,CAAC,CAAA,cAAA,EAAiB,GAAG,CAAA,EAAA,CAAI,EAAE,KAAK,CAAC;YAChD;AACF,QAAA,CAAC,CAAC;QAEF,IAAI,CAAC,IAAI,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,CAAA,yBAAA,EAA4B,OAAO,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,CAAG,CAAC;QAC7D,IAAI,GAAG,SAAS;IAClB;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,CAAC,KAAK,CAAC,CAAA,yCAAA,CAA2C,CAAC;AAC1D,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,KAAK;IACd;AACA,IAAA,YAAY,EAAE;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
|
package/lib/helpers.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var constants = require('./constants.cjs');
|
|
6
|
+
|
|
7
|
+
const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier, }) => {
|
|
8
|
+
const out = path.relative(cwd, path.resolve(path.dirname(relativePath), moduleSpecifier)).replaceAll('/', '.');
|
|
9
|
+
return out;
|
|
10
|
+
};
|
|
11
|
+
const writeFileAnalysis = (fileAnalysis, folderPath) => {
|
|
12
|
+
const relativePath = fileAnalysis.relativePath;
|
|
13
|
+
// Créer le chemin de destination dans .bemedev en maintenant la structure
|
|
14
|
+
const destPath = path.join(folderPath, relativePath);
|
|
15
|
+
const destDir = path.dirname(destPath);
|
|
16
|
+
try {
|
|
17
|
+
// Créer le dossier de destination si nécessaire
|
|
18
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
19
|
+
let fileContent = fileAnalysis.text;
|
|
20
|
+
constants.REPLACERS.init
|
|
21
|
+
// .filter(() => false)
|
|
22
|
+
.forEach(([search, replace]) => {
|
|
23
|
+
fileContent = fileContent.replaceAll(search, replace);
|
|
24
|
+
});
|
|
25
|
+
// Écrire le contenu du fichier types
|
|
26
|
+
fs.writeFileSync(destPath, fileContent, 'utf8');
|
|
27
|
+
console.log(` ✅ ${relativePath}`);
|
|
28
|
+
return relativePath.slice(0, -3).replaceAll('/', '.');
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return console.error(` ❌ Erreur pour ${relativePath}:`, error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const consoleStars = () => {
|
|
35
|
+
console.log();
|
|
36
|
+
console.log('*'.repeat(30));
|
|
37
|
+
console.log();
|
|
38
|
+
};
|
|
39
|
+
const toArray = (value) => {
|
|
40
|
+
return Array.isArray(value) ? value : !value ? [] : [value];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.consoleStars = consoleStars;
|
|
44
|
+
exports.toArray = toArray;
|
|
45
|
+
exports.transformModule = transformModule;
|
|
46
|
+
exports.writeFileAnalysis = writeFileAnalysis;
|
|
47
|
+
//# sourceMappingURL=helpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sources":["../src/helpers.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { REPLACERS } from './constants';\nimport { FileAnalysis } from './schemas';\n\nexport type TransformModuleArgs = {\n cwd?: string;\n relativePath: string;\n moduleSpecifier: string;\n};\n\nexport const transformModule = ({\n cwd = process.cwd(),\n relativePath,\n moduleSpecifier,\n}: TransformModuleArgs) => {\n const out = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n ).replaceAll('/', '.');\n\n return out;\n};\n\nexport const writeFileAnalysis = (\n fileAnalysis: FileAnalysis,\n folderPath: string,\n) => {\n const relativePath = fileAnalysis.relativePath;\n\n // Créer le chemin de destination dans .bemedev en maintenant la structure\n const destPath = join(folderPath, relativePath);\n const destDir = dirname(destPath);\n\n try {\n // Créer le dossier de destination si nécessaire\n mkdirSync(destDir, { recursive: true });\n\n let fileContent = fileAnalysis.text;\n REPLACERS.init\n // .filter(() => false)\n .forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Écrire le contenu du fichier types\n writeFileSync(destPath, fileContent, 'utf8');\n\n console.log(` ✅ ${relativePath}`);\n return relativePath.slice(0, -3).replaceAll('/', '.');\n } catch (error) {\n return console.error(` ❌ Erreur pour ${relativePath}:`, error);\n }\n};\n\nexport const consoleStars = () => {\n console.log();\n console.log('*'.repeat(30));\n console.log();\n};\n\nexport const toArray = <T>(value?: T | T[]): T[] => {\n return Array.isArray(value) ? value : !value ? [] : [value];\n};\n"],"names":["relative","resolve","dirname","join","mkdirSync","REPLACERS","writeFileSync"],"mappings":";;;;;;AAWO,MAAM,eAAe,GAAG,CAAC,EAC9B,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,YAAY,EACZ,eAAe,GACK,KAAI;IACxB,MAAM,GAAG,GAAGA,aAAQ,CAClB,GAAG,EACHC,YAAO,CAACC,YAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAChD,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;AAEtB,IAAA,OAAO,GAAG;AACZ;MAEa,iBAAiB,GAAG,CAC/B,YAA0B,EAC1B,UAAkB,KAChB;AACF,IAAA,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY;;IAG9C,MAAM,QAAQ,GAAGC,SAAI,CAAC,UAAU,EAAE,YAAY,CAAC;AAC/C,IAAA,MAAM,OAAO,GAAGD,YAAO,CAAC,QAAQ,CAAC;AAEjC,IAAA,IAAI;;QAEFE,YAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAEvC,QAAA,IAAI,WAAW,GAAG,YAAY,CAAC,IAAI;AACnC,QAAAC,mBAAS,CAAC;;aAEP,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAI;YAC7B,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;AACvD,QAAA,CAAC,CAAC;;AAGJ,QAAAC,gBAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC;AAE5C,QAAA,OAAO,CAAC,GAAG,CAAC,OAAO,YAAY,CAAA,CAAE,CAAC;AAClC,QAAA,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;IACvD;IAAE,OAAO,KAAK,EAAE;QACd,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA,gBAAA,EAAmB,YAAY,CAAA,CAAA,CAAG,EAAE,KAAK,CAAC;IACjE;AACF;AAEO,MAAM,YAAY,GAAG,MAAK;IAC/B,OAAO,CAAC,GAAG,EAAE;IACb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,EAAE;AACf;AAEO,MAAM,OAAO,GAAG,CAAI,KAAe,KAAS;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC;AAC7D;;;;;;;"}
|
package/lib/helpers.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileAnalysis } from './schemas';
|
|
2
|
+
export type TransformModuleArgs = {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
relativePath: string;
|
|
5
|
+
moduleSpecifier: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const transformModule: ({ cwd, relativePath, moduleSpecifier, }: TransformModuleArgs) => string;
|
|
8
|
+
export declare const writeFileAnalysis: (fileAnalysis: FileAnalysis, folderPath: string) => string | void;
|
|
9
|
+
export declare const consoleStars: () => void;
|
|
10
|
+
export declare const toArray: <T>(value?: T | T[]) => T[];
|
|
11
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,yCAI7B,mBAAmB,WAOrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,cAAc,YAAY,EAC1B,YAAY,MAAM,kBA2BnB,CAAC;AAEF,eAAO,MAAM,YAAY,YAIxB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAG,CAAC,EAE7C,CAAC"}
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
2
|
+
import { relative, resolve, dirname, join } from 'path';
|
|
3
|
+
import { REPLACERS } from './constants.js';
|
|
4
|
+
|
|
5
|
+
const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier, }) => {
|
|
6
|
+
const out = relative(cwd, resolve(dirname(relativePath), moduleSpecifier)).replaceAll('/', '.');
|
|
7
|
+
return out;
|
|
8
|
+
};
|
|
9
|
+
const writeFileAnalysis = (fileAnalysis, folderPath) => {
|
|
10
|
+
const relativePath = fileAnalysis.relativePath;
|
|
11
|
+
// Créer le chemin de destination dans .bemedev en maintenant la structure
|
|
12
|
+
const destPath = join(folderPath, relativePath);
|
|
13
|
+
const destDir = dirname(destPath);
|
|
14
|
+
try {
|
|
15
|
+
// Créer le dossier de destination si nécessaire
|
|
16
|
+
mkdirSync(destDir, { recursive: true });
|
|
17
|
+
let fileContent = fileAnalysis.text;
|
|
18
|
+
REPLACERS.init
|
|
19
|
+
// .filter(() => false)
|
|
20
|
+
.forEach(([search, replace]) => {
|
|
21
|
+
fileContent = fileContent.replaceAll(search, replace);
|
|
22
|
+
});
|
|
23
|
+
// Écrire le contenu du fichier types
|
|
24
|
+
writeFileSync(destPath, fileContent, 'utf8');
|
|
25
|
+
console.log(` ✅ ${relativePath}`);
|
|
26
|
+
return relativePath.slice(0, -3).replaceAll('/', '.');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return console.error(` ❌ Erreur pour ${relativePath}:`, error);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const consoleStars = () => {
|
|
33
|
+
console.log();
|
|
34
|
+
console.log('*'.repeat(30));
|
|
35
|
+
console.log();
|
|
36
|
+
};
|
|
37
|
+
const toArray = (value) => {
|
|
38
|
+
return Array.isArray(value) ? value : !value ? [] : [value];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { consoleStars, toArray, transformModule, writeFileAnalysis };
|
|
42
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { REPLACERS } from './constants';\nimport { FileAnalysis } from './schemas';\n\nexport type TransformModuleArgs = {\n cwd?: string;\n relativePath: string;\n moduleSpecifier: string;\n};\n\nexport const transformModule = ({\n cwd = process.cwd(),\n relativePath,\n moduleSpecifier,\n}: TransformModuleArgs) => {\n const out = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n ).replaceAll('/', '.');\n\n return out;\n};\n\nexport const writeFileAnalysis = (\n fileAnalysis: FileAnalysis,\n folderPath: string,\n) => {\n const relativePath = fileAnalysis.relativePath;\n\n // Créer le chemin de destination dans .bemedev en maintenant la structure\n const destPath = join(folderPath, relativePath);\n const destDir = dirname(destPath);\n\n try {\n // Créer le dossier de destination si nécessaire\n mkdirSync(destDir, { recursive: true });\n\n let fileContent = fileAnalysis.text;\n REPLACERS.init\n // .filter(() => false)\n .forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Écrire le contenu du fichier types\n writeFileSync(destPath, fileContent, 'utf8');\n\n console.log(` ✅ ${relativePath}`);\n return relativePath.slice(0, -3).replaceAll('/', '.');\n } catch (error) {\n return console.error(` ❌ Erreur pour ${relativePath}:`, error);\n }\n};\n\nexport const consoleStars = () => {\n console.log();\n console.log('*'.repeat(30));\n console.log();\n};\n\nexport const toArray = <T>(value?: T | T[]): T[] => {\n return Array.isArray(value) ? value : !value ? [] : [value];\n};\n"],"names":[],"mappings":";;;;AAWO,MAAM,eAAe,GAAG,CAAC,EAC9B,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,YAAY,EACZ,eAAe,GACK,KAAI;IACxB,MAAM,GAAG,GAAG,QAAQ,CAClB,GAAG,EACH,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAChD,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;AAEtB,IAAA,OAAO,GAAG;AACZ;MAEa,iBAAiB,GAAG,CAC/B,YAA0B,EAC1B,UAAkB,KAChB;AACF,IAAA,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY;;IAG9C,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC;AAC/C,IAAA,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;AAEjC,IAAA,IAAI;;QAEF,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAEvC,QAAA,IAAI,WAAW,GAAG,YAAY,CAAC,IAAI;AACnC,QAAA,SAAS,CAAC;;aAEP,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAI;YAC7B,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;AACvD,QAAA,CAAC,CAAC;;AAGJ,QAAA,aAAa,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC;AAE5C,QAAA,OAAO,CAAC,GAAG,CAAC,OAAO,YAAY,CAAA,CAAE,CAAC;AAClC,QAAA,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;IACvD;IAAE,OAAO,KAAK,EAAE;QACd,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA,gBAAA,EAAmB,YAAY,CAAA,CAAA,CAAG,EAAE,KAAK,CAAC;IACjE;AACF;AAEO,MAAM,YAAY,GAAG,MAAK;IAC/B,OAAO,CAAC,GAAG,EAAE;IACb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,CAAC,GAAG,EAAE;AACf;AAEO,MAAM,OAAO,GAAG,CAAI,KAAe,KAAS;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC;AAC7D;;;;"}
|
package/lib/imports.cjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var tsMorph = require('ts-morph');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Résout le moduleSpecifier en utilisant les paths du tsconfig si il commence par "#"
|
|
8
|
+
*/
|
|
9
|
+
const resolveModuleSpecifier = (sourceFile, moduleSpecifier) => {
|
|
10
|
+
const paths = sourceFile.getProject().getCompilerOptions().paths;
|
|
11
|
+
if (!paths)
|
|
12
|
+
return moduleSpecifier;
|
|
13
|
+
const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;
|
|
14
|
+
const paths2 = Object.entries(paths);
|
|
15
|
+
// Chercher la correspondance dans les paths
|
|
16
|
+
for (const [pattern, mappings] of paths2) {
|
|
17
|
+
// Remplacer * par une regex pour matcher
|
|
18
|
+
const regexPattern = pattern.replace(/\*/g, '(.*)');
|
|
19
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
20
|
+
const match = moduleSpecifier.match(regex);
|
|
21
|
+
if (match) {
|
|
22
|
+
// Prendre le premier mapping disponible
|
|
23
|
+
const first = mappings[0];
|
|
24
|
+
// Résoudre le chemin absolu
|
|
25
|
+
let relativedPath = baseUrl ? path.join(baseUrl, first) : first;
|
|
26
|
+
if (match[1]) {
|
|
27
|
+
relativedPath = relativedPath.replace('*', match[1]);
|
|
28
|
+
}
|
|
29
|
+
// Calculer le chemin relatif depuis le fichier source actuel
|
|
30
|
+
const sourceFileDir = path.relative(process.cwd(), sourceFile.getDirectoryPath());
|
|
31
|
+
const relativePath = path.relative(sourceFileDir, relativedPath);
|
|
32
|
+
// S'assurer que le chemin relatif commence par ./ ou ../
|
|
33
|
+
return relativePath.startsWith('.')
|
|
34
|
+
? relativePath
|
|
35
|
+
: `./${relativePath}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return moduleSpecifier;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Analyse les imports d'un fichier
|
|
42
|
+
*/
|
|
43
|
+
const analyzeImports = (sourceFile) => {
|
|
44
|
+
const imports = [];
|
|
45
|
+
// Import declarations (import ... from '...')
|
|
46
|
+
sourceFile.getImportDeclarations().forEach(importDecl => {
|
|
47
|
+
const rawModuleSpecifier = importDecl.getModuleSpecifierValue();
|
|
48
|
+
const moduleSpecifier = resolveModuleSpecifier(sourceFile, rawModuleSpecifier);
|
|
49
|
+
// Import default
|
|
50
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
51
|
+
if (defaultImport) {
|
|
52
|
+
imports.push({
|
|
53
|
+
moduleSpecifier,
|
|
54
|
+
kind: 'default',
|
|
55
|
+
default: defaultImport.getText(),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Import namespace (* as name)
|
|
59
|
+
const namespaceImport = importDecl.getNamespaceImport();
|
|
60
|
+
if (namespaceImport) {
|
|
61
|
+
imports.push({
|
|
62
|
+
moduleSpecifier,
|
|
63
|
+
kind: 'namespace',
|
|
64
|
+
default: namespaceImport.getText(),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Named imports ({ name1, name2 })
|
|
68
|
+
const namedImports = importDecl.getNamedImports();
|
|
69
|
+
if (namedImports.length > 0) {
|
|
70
|
+
imports.push({
|
|
71
|
+
moduleSpecifier,
|
|
72
|
+
kind: 'named',
|
|
73
|
+
namedImports: namedImports.map(ni => ni.getName()),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Side-effect import (import '...')
|
|
77
|
+
if (!defaultImport && !namespaceImport && namedImports.length === 0) {
|
|
78
|
+
imports.push({
|
|
79
|
+
moduleSpecifier,
|
|
80
|
+
kind: 'side-effect',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Dynamic imports (import('...'))
|
|
85
|
+
sourceFile
|
|
86
|
+
.getDescendantsOfKind(tsMorph.SyntaxKind.CallExpression)
|
|
87
|
+
.forEach(callExpr => {
|
|
88
|
+
if (callExpr.getExpression().getKind() === tsMorph.SyntaxKind.ImportKeyword) {
|
|
89
|
+
const arg = callExpr.getArguments()[0];
|
|
90
|
+
if (arg && arg.getKind() === tsMorph.SyntaxKind.StringLiteral) {
|
|
91
|
+
const rawModuleSpecifier = arg.getText().replace(/['"]/g, '');
|
|
92
|
+
const moduleSpecifier = resolveModuleSpecifier(sourceFile, rawModuleSpecifier);
|
|
93
|
+
imports.push({
|
|
94
|
+
moduleSpecifier,
|
|
95
|
+
kind: 'side-effect',
|
|
96
|
+
isDynamic: true,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return imports;
|
|
102
|
+
};
|
|
103
|
+
const buildImportStrings = (imports) => {
|
|
104
|
+
return imports.map(imp => {
|
|
105
|
+
switch (imp.kind) {
|
|
106
|
+
case 'named': {
|
|
107
|
+
const namedImports = imp.namedImports?.join(', ') || '';
|
|
108
|
+
return `import { ${namedImports} } from '${imp.moduleSpecifier}';`;
|
|
109
|
+
}
|
|
110
|
+
case 'namespace':
|
|
111
|
+
return `import * as ${imp.default} from '${imp.moduleSpecifier}';`;
|
|
112
|
+
case 'side-effect': {
|
|
113
|
+
if (imp.isDynamic) {
|
|
114
|
+
return `// Dynamic import: import('${imp.moduleSpecifier}')`;
|
|
115
|
+
}
|
|
116
|
+
return `import '${imp.moduleSpecifier}';`;
|
|
117
|
+
}
|
|
118
|
+
case 'default':
|
|
119
|
+
return `import ${imp.default} from '${imp.moduleSpecifier}';`;
|
|
120
|
+
default:
|
|
121
|
+
return '';
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
exports.analyzeImports = analyzeImports;
|
|
127
|
+
exports.buildImportStrings = buildImportStrings;
|
|
128
|
+
//# sourceMappingURL=imports.cjs.map
|