@bemedev/codebase 0.1.2 → 0.2.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.
Files changed (108) hide show
  1. package/README.md +8 -8
  2. package/lib/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/lib/analyse.cjs +48 -62
  4. package/lib/analyse.cjs.map +1 -1
  5. package/lib/analyse.d.ts +21 -3
  6. package/lib/analyse.js +45 -60
  7. package/lib/analyse.js.map +1 -1
  8. package/lib/analyse.utils.cjs +154 -205
  9. package/lib/analyse.utils.cjs.map +1 -1
  10. package/lib/analyse.utils.d.ts +1 -2
  11. package/lib/analyse.utils.js +153 -203
  12. package/lib/analyse.utils.js.map +1 -1
  13. package/lib/cli/cli.cjs +28 -27
  14. package/lib/cli/cli.cjs.map +1 -1
  15. package/lib/cli/cli.d.ts +0 -1
  16. package/lib/cli/cli.js +25 -24
  17. package/lib/cli/cli.js.map +1 -1
  18. package/lib/cli/constants.cjs +6 -5
  19. package/lib/cli/constants.cjs.map +1 -1
  20. package/lib/cli/constants.d.ts +0 -1
  21. package/lib/cli/constants.js +5 -3
  22. package/lib/cli/constants.js.map +1 -1
  23. package/lib/cli/index.cjs +6 -6
  24. package/lib/cli/index.cjs.map +1 -1
  25. package/lib/cli/index.d.ts +0 -1
  26. package/lib/cli/index.js +7 -4
  27. package/lib/cli/index.js.map +1 -1
  28. package/lib/constants.cjs +26 -28
  29. package/lib/constants.cjs.map +1 -1
  30. package/lib/constants.d.ts +0 -1
  31. package/lib/constants.js +24 -26
  32. package/lib/constants.js.map +1 -1
  33. package/lib/exports.cjs +51 -72
  34. package/lib/exports.cjs.map +1 -1
  35. package/lib/exports.d.ts +1 -2
  36. package/lib/exports.js +49 -70
  37. package/lib/exports.js.map +1 -1
  38. package/lib/functions/add.cjs +71 -84
  39. package/lib/functions/add.cjs.map +1 -1
  40. package/lib/functions/add.d.ts +1 -2
  41. package/lib/functions/add.js +68 -82
  42. package/lib/functions/add.js.map +1 -1
  43. package/lib/functions/generate.cjs +53 -56
  44. package/lib/functions/generate.cjs.map +1 -1
  45. package/lib/functions/generate.d.ts +1 -2
  46. package/lib/functions/generate.js +51 -54
  47. package/lib/functions/generate.js.map +1 -1
  48. package/lib/functions/index.cjs +11 -16
  49. package/lib/functions/index.d.ts +0 -1
  50. package/lib/functions/index.js +5 -5
  51. package/lib/functions/init.cjs +68 -97
  52. package/lib/functions/init.cjs.map +1 -1
  53. package/lib/functions/init.d.ts +1 -2
  54. package/lib/functions/init.js +66 -95
  55. package/lib/functions/init.js.map +1 -1
  56. package/lib/functions/remove.cjs +85 -103
  57. package/lib/functions/remove.cjs.map +1 -1
  58. package/lib/functions/remove.d.ts +1 -2
  59. package/lib/functions/remove.js +82 -101
  60. package/lib/functions/remove.js.map +1 -1
  61. package/lib/helpers.cjs +32 -38
  62. package/lib/helpers.cjs.map +1 -1
  63. package/lib/helpers.d.ts +3 -4
  64. package/lib/helpers.js +30 -36
  65. package/lib/helpers.js.map +1 -1
  66. package/lib/imports.cjs +88 -118
  67. package/lib/imports.cjs.map +1 -1
  68. package/lib/imports.d.ts +2 -3
  69. package/lib/imports.js +86 -116
  70. package/lib/imports.js.map +1 -1
  71. package/lib/index.cjs +22 -24
  72. package/lib/index.d.ts +4 -4
  73. package/lib/index.js +8 -6
  74. package/lib/schemas.cjs +53 -63
  75. package/lib/schemas.cjs.map +1 -1
  76. package/lib/schemas.d.ts +5 -2
  77. package/lib/schemas.js +43 -35
  78. package/lib/schemas.js.map +1 -1
  79. package/lib/types.d.ts +0 -1
  80. package/lib/utils.cjs +9 -10
  81. package/lib/utils.cjs.map +1 -1
  82. package/lib/utils.d.ts +0 -1
  83. package/lib/utils.js +8 -8
  84. package/lib/utils.js.map +1 -1
  85. package/package.json +56 -44
  86. package/CHANGE_LOG.md +0 -143
  87. package/lib/analyse.d.ts.map +0 -1
  88. package/lib/analyse.utils.d.ts.map +0 -1
  89. package/lib/cli/cli.d.ts.map +0 -1
  90. package/lib/cli/constants.d.ts.map +0 -1
  91. package/lib/cli/index.d.ts.map +0 -1
  92. package/lib/constants.d.ts.map +0 -1
  93. package/lib/exports.d.ts.map +0 -1
  94. package/lib/functions/add.d.ts.map +0 -1
  95. package/lib/functions/generate.d.ts.map +0 -1
  96. package/lib/functions/index.cjs.map +0 -1
  97. package/lib/functions/index.d.ts.map +0 -1
  98. package/lib/functions/index.js.map +0 -1
  99. package/lib/functions/init.d.ts.map +0 -1
  100. package/lib/functions/remove.d.ts.map +0 -1
  101. package/lib/helpers.d.ts.map +0 -1
  102. package/lib/imports.d.ts.map +0 -1
  103. package/lib/index.cjs.map +0 -1
  104. package/lib/index.d.ts.map +0 -1
  105. package/lib/index.js.map +0 -1
  106. package/lib/schemas.d.ts.map +0 -1
  107. package/lib/types.d.ts.map +0 -1
  108. package/lib/utils.d.ts.map +0 -1
@@ -1 +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, 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 let relativePath = relative(process.cwd(), folderPath);\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 = relative(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,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAI;AACjE,QAAA,OAAO,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC;AAC3D,IAAA,CAAC,CAAC;IAEF,MAAM,KAAK,GAAa,EAAE;IAE1B,OAAO,CAAC,GAAG,CACT,CAAA,sCAAA,EAAyC,OAAO,CAAC,MAAM,CAAA,aAAA,CAAe,CACvE;IAED,KAAK,MAAM,GAAG,YAAY,CAAC,IAAI,OAAO,EAAE;QACtC,MAAM,IAAI,GAAG,iBAAiB,CAAC,YAAY,EAAE,UAAU,CAAC;AACxD,QAAA,IAAI,IAAI;AAAE,YAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IAC5B;AAEA,IAAA,OAAO,CAAC,GAAG,CAAC,CAAA,uCAAA,CAAyC,CAAC;AACtD,IAAA,OAAO,KAAK;AACd;AAEO,MAAM,IAAI,GAAG,CAClB,iBAAmC,EACnC,EAAE,IAAI,EAAE,IAAI,EAAe,KACzB;AACF,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACzB,MAAM,UAAU,GAAG,IA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d;AAEA,IAAA,OAAO,CAAC,GAAG,CAAC,CAAA,kDAAA,CAAoD,CAAC;AACjE,IAAA,OAAO,IAAI;AACb;;;;"}
1
+ {"version":3,"file":"init.js","names":[],"sources":["../../src/functions/init.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } 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(`❌ Erreur lors de la création du dossier .bemedev:`, error);\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(`❌ Erreur lors de la création de la structure de types:`);\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] = [`${relativePath}/*`];\n\n writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), \"utf8\");\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"],"mappings":";;;;;AAeA,MAAa,wBACX,YACA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AE,EAAE,OAAO;AACtE,UAAQ,IAAI,4CAA4C;UACjD,OAAO;AACd,UAAQ,MACN,qDACA,MACD;AACD,SAAO;;KAGT,SAAQ,KAAK,wDAAwD;CAKvE,MAAM,SAAS;EACb,SAAS;GACR,WAAW,OAAO;GAClB,WAAW,QAAQ;EACrB;AAED,KAAI;AACF,gBAAc,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"}
@@ -1,108 +1,90 @@
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
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = 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
+ let edit_json_file = require("edit-json-file");
8
+ edit_json_file = require_runtime.__toESM(edit_json_file);
9
+ //#region src/functions/remove.ts
9
10
  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;
11
+ const cwd = process.cwd();
12
+ return entries.map(([key, { imports, relativePath }]) => [
13
+ key,
14
+ relativePath,
15
+ imports
16
+ ]).map(([key, relativePath, imports]) => {
17
+ const specifiers = imports.map(({ moduleSpecifier }) => {
18
+ return require_helpers.transformModule({
19
+ cwd,
20
+ relativePath,
21
+ moduleSpecifier
22
+ });
23
+ }).map((_path) => [_path, `${_path}.index`]).flat().filter((s) => files.includes(s));
24
+ return [key, Array.from(new Set(specifiers))];
25
+ });
28
26
  };
29
27
  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 root = helpers.getFolderPath(file.get(constants.PATH_PROPERTY));
40
- const files = file.get(constants.FILES_PROPERTY);
41
- const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
42
- const entries = entries2.filter(([key]) => paths.some(p => key.startsWith(p)));
43
- // Vérifier les dépendances avant suppression
44
- const safesToRemove = [];
45
- const cannotsRemove = [];
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 cannotsRemove.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 (cannotsRemove.length > 0) {
62
- const len = cannotsRemove.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
- cannotsRemove.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(root, _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 {
91
- console.error(` - ❌ Erreur, ${key} :`);
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;
28
+ if (paths.length === 0) return console.warn("No files specified for removal.");
29
+ try {
30
+ let file = (0, edit_json_file.default)((0, path.join)(process.cwd(), require_constants.JSON_FILE_NAME));
31
+ if (!file) return;
32
+ const root = require_helpers.getFolderPath(file.get(require_constants.PATH_PROPERTY));
33
+ const files = file.get(require_constants.FILES_PROPERTY);
34
+ const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
35
+ const entries = entries2.filter(([key]) => paths.some((p) => key.startsWith(p)));
36
+ const safesToRemove = [];
37
+ const cannotsRemove = [];
38
+ entries.forEach(([key]) => {
39
+ const importedFroms = transformModules(entries2, ...files).filter(([, specifiers]) => specifiers.includes(key)).map(([k]) => k);
40
+ const check = importedFroms.length > 0;
41
+ console.log("modules", "=>", importedFroms);
42
+ console.log("key", "=>", key);
43
+ if (check) return cannotsRemove.push([key, importedFroms]);
44
+ return safesToRemove.push(key);
45
+ });
46
+ require_helpers.consoleStars();
47
+ console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);
48
+ if (cannotsRemove.length > 0) {
49
+ const len = cannotsRemove.length;
50
+ console.warn(`⚠️ ${len} ${len === 1 ? "fichier ne peut pas être supprimé (importé dans d'autres fichiers)" : "fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)"} :`);
51
+ cannotsRemove.forEach(([key, modules]) => {
52
+ console.warn(` - ⚠️ ${key} importé par :`);
53
+ modules.forEach((m) => console.warn(` -> 📌 ${m}`));
54
+ });
55
+ }
56
+ if (safesToRemove.length === 0) {
57
+ console.warn("❌ Aucun fichier ne peut être supprimé.");
58
+ return require_helpers.consoleStars();
59
+ }
60
+ const formatteds = safesToRemove.map((key) => {
61
+ return [key, (0, path.join)(root, `${key.replaceAll(".", "/")}.ts`)];
62
+ });
63
+ console.log(`🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`);
64
+ let success = 0;
65
+ const length = formatteds.length;
66
+ formatteds.forEach(([key, path$1]) => {
67
+ try {
68
+ (0, fs.unlinkSync)(path$1);
69
+ console.log(` - 🗑️ ${key}`);
70
+ file?.set(require_constants.FILES_PROPERTY, files.filter((key1) => key1 !== key));
71
+ success++;
72
+ } catch {
73
+ console.error(` - Erreur, ${key} :`);
74
+ }
75
+ });
76
+ file.save();
77
+ console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);
78
+ file = void 0;
79
+ } catch {
80
+ console.error(`❌ Erreur lors de la création des fichiers`);
81
+ require_helpers.consoleStars();
82
+ return false;
83
+ }
84
+ require_helpers.consoleStars();
85
+ return true;
105
86
  };
106
-
87
+ //#endregion
107
88
  exports.remove = remove;
108
- //# sourceMappingURL=remove.cjs.map
89
+
90
+ //# sourceMappingURL=remove.cjs.map
@@ -1 +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, getFolderPath, 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 root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as 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 // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\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 cannotsRemove.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 (cannotsRemove.length > 0) {\n const len = cannotsRemove.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 cannotsRemove.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(root, _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 {\n console.error(` - ❌ Erreur, ${key} :`);\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","getFolderPath","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,EA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AO,CAAC,GAAG,CAAC,WAAW,GAAG,CAAA,CAAE,CAAC;AAC7B,gBAAA,IAAI,EAAE,GAAG,CACPF,wBAAc,EACd,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CACnC;AACD,gBAAA,OAAO,EAAE;YACX;AAAE,YAAA,MAAM;AACN,gBAAA,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAA,EAAA,CAAI,CAAC;YACzC;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,QAAAC,oBAAY,EAAE;AACd,QAAA,OAAO,KAAK;IACd;AACA,IAAAA,oBAAY,EAAE;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
1
+ {"version":3,"file":"remove.cjs","names":["transformModule","JSON_FILE_NAME","getFolderPath","PATH_PROPERTY","FILES_PROPERTY","consoleStars","path"],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from \"edit-json-file\";\nimport { unlinkSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { FILES_PROPERTY, JSON_FILE_NAME, PATH_PROPERTY } from \"../constants\";\nimport { consoleStars, getFolderPath, 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 root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as 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 // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\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 cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);\n\n // Afficher les fichiers qui ne peuvent pas être supprimés\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.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 cannotsRemove.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(root, _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 {\n console.error(` - ❌ Erreur, ${key} :`);\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"],"mappings":";;;;;;;;;AAOA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,KAAK;AAsBzB,QArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;EAAQ,CAC/B,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;AAC5B,UAAOA,gBAAAA,gBAAgB;IACrB;IACA;IACA;IACD,CAAC;IACF,CACD,KAAK,UAAU,CAAC,OAAO,GAAG,MAAM,QAAQ,CAAC,CACzC,MAAM,CACN,QAAQ,MAAM,MAAM,SAAS,EAAE,CAAC;AAEnC,SAAO,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,WAAW,CAAC,CAAC;GAC7C;;AAKN,MAAa,UACX,mBACA,GAAG,UACA;AAEH,KADgB,MAAM,WAAW,EACpB,QAAO,QAAQ,KAAK,kCAAkC;AACnE,KAAI;EAGF,IAAI,QAAA,GAAA,eAAA,UAAA,GAAA,KAAA,MAFQ,QAAQ,KAAK,EACFC,kBAAAA,eAAe,CACO;AAE7C,MAAI,CAAC,K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ADR,GAAG,IAAI,WAAW,KAAK,IAAI,CAAC,KACR,CACZ;IACtB;AAEF,UAAQ,IACN,iCAAiC,cAAc,OAAO,eACvD;EAED,IAAI,UAAU;EACd,MAAM,SAAS,WAAW;AAE1B,aAAW,SAAS,CAAC,KAAKC,YAAU;AAClC,OAAI;AACF,KAAA,GAAA,GAAA,YAAWA,OAAK;AAChB,YAAQ,IAAI,WAAW,MAAM;AAC7B,UAAM,IACJF,kBAAAA,gBACA,MAAM,QAAQ,SAAS,SAAS,IAAI,CACrC;AACD;WACM;AACN,YAAQ,MAAM,iBAAiB,IAAI,IAAI;;IAEzC;AAEF,OAAK,MAAM;AACX,UAAQ,IAAI,4BAA4B,QAAQ,GAAG,OAAO,GAAG;AAC7D,SAAO,KAAA;SACD;AACN,UAAQ,MAAM,4CAA4C;AAC1D,kBAAA,cAAc;AACd,SAAO;;AAET,iBAAA,cAAc;AACd,QAAO"}
@@ -1,3 +1,2 @@
1
- import { CodebaseAnalysis } from '../schemas';
1
+ import { CodebaseAnalysis } from "../schemas";
2
2
  export declare const remove: (CODEBASE_ANALYSIS: CodebaseAnalysis, ...paths: string[]) => boolean | void;
3
- //# sourceMappingURL=remove.d.ts.map
@@ -1,106 +1,87 @@
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 { getFolderPath, consoleStars, transformModule } from '../helpers.js';
6
-
1
+ import { FILES_PROPERTY, JSON_FILE_NAME, PATH_PROPERTY } from "../constants.js";
2
+ import { consoleStars, getFolderPath, transformModule } from "../helpers.js";
3
+ import { join } from "path";
4
+ import { unlinkSync } from "fs";
5
+ import edit from "edit-json-file";
6
+ //#region src/functions/remove.ts
7
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;
8
+ const cwd = process.cwd();
9
+ return entries.map(([key, { imports, relativePath }]) => [
10
+ key,
11
+ relativePath,
12
+ imports
13
+ ]).map(([key, relativePath, imports]) => {
14
+ const specifiers = imports.map(({ moduleSpecifier }) => {
15
+ return transformModule({
16
+ cwd,
17
+ relativePath,
18
+ moduleSpecifier
19
+ });
20
+ }).map((_path) => [_path, `${_path}.index`]).flat().filter((s) => files.includes(s));
21
+ return [key, Array.from(new Set(specifiers))];
22
+ });
26
23
  };
27
24
  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 root = getFolderPath(file.get(PATH_PROPERTY));
38
- const files = file.get(FILES_PROPERTY);
39
- const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
40
- const entries = entries2.filter(([key]) => paths.some(p => key.startsWith(p)));
41
- // Vérifier les dépendances avant suppression
42
- const safesToRemove = [];
43
- const cannotsRemove = [];
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 cannotsRemove.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 (cannotsRemove.length > 0) {
60
- const len = cannotsRemove.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
- cannotsRemove.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(root, _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 {
89
- console.error(` - ❌ Erreur, ${key} :`);
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;
25
+ if (paths.length === 0) return console.warn("No files specified for removal.");
26
+ try {
27
+ let file = edit(join(process.cwd(), JSON_FILE_NAME));
28
+ if (!file) return;
29
+ const root = getFolderPath(file.get(PATH_PROPERTY));
30
+ const files = file.get(FILES_PROPERTY);
31
+ const entries2 = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => files.includes(key));
32
+ const entries = entries2.filter(([key]) => paths.some((p) => key.startsWith(p)));
33
+ const safesToRemove = [];
34
+ const cannotsRemove = [];
35
+ entries.forEach(([key]) => {
36
+ const importedFroms = transformModules(entries2, ...files).filter(([, specifiers]) => specifiers.includes(key)).map(([k]) => k);
37
+ const check = importedFroms.length > 0;
38
+ console.log("modules", "=>", importedFroms);
39
+ console.log("key", "=>", key);
40
+ if (check) return cannotsRemove.push([key, importedFroms]);
41
+ return safesToRemove.push(key);
42
+ });
43
+ consoleStars();
44
+ console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);
45
+ if (cannotsRemove.length > 0) {
46
+ const len = cannotsRemove.length;
47
+ console.warn(`⚠️ ${len} ${len === 1 ? "fichier ne peut pas être supprimé (importé dans d'autres fichiers)" : "fichiers ne peuvent pas être supprimés (importés dans d'autres fichiers)"} :`);
48
+ cannotsRemove.forEach(([key, modules]) => {
49
+ console.warn(` - ⚠️ ${key} importé par :`);
50
+ modules.forEach((m) => console.warn(` -> 📌 ${m}`));
51
+ });
52
+ }
53
+ if (safesToRemove.length === 0) {
54
+ console.warn("❌ Aucun fichier ne peut être supprimé.");
55
+ return consoleStars();
56
+ }
57
+ const formatteds = safesToRemove.map((key) => {
58
+ return [key, join(root, `${key.replaceAll(".", "/")}.ts`)];
59
+ });
60
+ console.log(`🗑️ Suppression des fichiers (${safesToRemove.length} fichiers)...`);
61
+ let success = 0;
62
+ const length = formatteds.length;
63
+ formatteds.forEach(([key, path]) => {
64
+ try {
65
+ unlinkSync(path);
66
+ console.log(` - 🗑️ ${key}`);
67
+ file?.set(FILES_PROPERTY, files.filter((key1) => key1 !== key));
68
+ success++;
69
+ } catch {
70
+ console.error(` - Erreur, ${key} :`);
71
+ }
72
+ });
73
+ file.save();
74
+ console.log(`🗑️ Fichiers supprimés! (${success}/${length})`);
75
+ file = void 0;
76
+ } catch {
77
+ console.error(`❌ Erreur lors de la création des fichiers`);
78
+ consoleStars();
79
+ return false;
80
+ }
81
+ consoleStars();
82
+ return true;
103
83
  };
104
-
84
+ //#endregion
105
85
  export { remove };
106
- //# sourceMappingURL=remove.js.map
86
+
87
+ //# sourceMappingURL=remove.js.map
@@ -1 +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, getFolderPath, 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 root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as 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 // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\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 cannotsRemove.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 (cannotsRemove.length > 0) {\n const len = cannotsRemove.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 cannotsRemove.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(root, _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 {\n console.error(` - ❌ Erreur, ${key} :`);\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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AACjC,YAAA,IAAI;gBACF,UAAU,CAAC,IAAI,CAAC;AAChB,gBAAA,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,CAAA,CAAE,CAAC;AAC7B,gBAAA,IAAI,EAAE,GAAG,CACP,cAAc,EACd,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG,CAAC,CACnC;AACD,gBAAA,OAAO,EAAE;YACX;AAAE,YAAA,MAAM;AACN,gBAAA,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAA,EAAA,CAAI,CAAC;YACzC;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;;;;"}
1
+ {"version":3,"file":"remove.js","names":[],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from \"edit-json-file\";\nimport { unlinkSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { FILES_PROPERTY, JSON_FILE_NAME, PATH_PROPERTY } from \"../constants\";\nimport { consoleStars, getFolderPath, 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 root = getFolderPath(file.get(PATH_PROPERTY) as string);\n const files = file.get(FILES_PROPERTY) as 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 // Vérifier les dépendances avant suppression\n const safesToRemove: string[] = [];\n const cannotsRemove: [string, string[]][] = [];\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 cannotsRemove.push([key, importedFroms]);\n return safesToRemove.push(key);\n });\n\n consoleStars();\n console.log(`🔧 Suppression des fichiers (${entries.length} fichiers)...`);\n\n // Afficher les fichiers qui ne peuvent pas être supprimés\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.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 cannotsRemove.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(root, _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 {\n console.error(` - ❌ Erreur, ${key} :`);\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"],"mappings":";;;;;;AAOA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,KAAK;AAsBzB,QArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;EAAQ,CAC/B,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;AAC5B,UAAO,gBAAgB;IACrB;IACA;IACA;IACD,CAAC;IACF,CACD,KAAK,UAAU,CAAC,OAAO,GAAG,MAAM,QAAQ,CAAC,CACzC,MAAM,CACN,QAAQ,MAAM,MAAM,SAAS,EAAE,CAAC;AAEnC,SAAO,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,WAAW,CAAC,CAAC;GAC7C;;AAKN,MAAa,UACX,mBACA,GAAG,UACA;AAEH,KADgB,MAAM,WAAW,EACpB,QAAO,QAAQ,KAAK,kCAAkC;AACnE,KAAI;EAGF,IAAI,OAA+B,KADtB,KADD,QAAQ,KAAK,EACF,eAAe,CACO;AAE7C,MAAI,CAAC,KAAM;EAEX,MAAM,OAAO,cAAc,KAAK,IAAI,cAAc,CAAW;EAC7D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