@bemedev/codebase 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +0 -1
  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 -124
  67. package/lib/imports.cjs.map +1 -1
  68. package/lib/imports.d.ts +2 -3
  69. package/lib/imports.js +86 -122
  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 -64
  75. package/lib/schemas.cjs.map +1 -1
  76. package/lib/schemas.d.ts +1 -2
  77. package/lib/schemas.js +43 -36
  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 -161
  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
package/lib/helpers.cjs CHANGED
@@ -1,52 +1,46 @@
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;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./_virtual/_rolldown/runtime.cjs");
3
+ const require_constants = require("./constants.cjs");
4
+ let path = require("path");
5
+ let fs = require("fs");
6
+ //#region src/helpers.ts
7
+ const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier }) => {
8
+ return (0, path.relative)(cwd, (0, path.resolve)((0, path.dirname)(relativePath), moduleSpecifier)).replaceAll("/", ".");
10
9
  };
11
10
  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.forEach(([search, replace]) => {
21
- fileContent = fileContent.replaceAll(search, replace);
22
- });
23
- // Écrire le contenu du fichier types
24
- fs.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
- }
11
+ const relativePath = fileAnalysis.relativePath;
12
+ const destPath = (0, path.join)(folderPath, relativePath);
13
+ const destDir = (0, path.dirname)(destPath);
14
+ try {
15
+ (0, fs.mkdirSync)(destDir, { recursive: true });
16
+ let fileContent = fileAnalysis.text;
17
+ require_constants.REPLACERS.init.forEach(([search, replace]) => {
18
+ fileContent = fileContent.replaceAll(search, replace);
19
+ });
20
+ (0, fs.writeFileSync)(destPath, fileContent, "utf8");
21
+ console.log(` ✅ ${relativePath}`);
22
+ return relativePath.slice(0, -3).replaceAll("/", ".");
23
+ } catch (error) {
24
+ return console.error(` Erreur pour ${relativePath}:`, error);
25
+ }
31
26
  };
32
27
  const consoleStars = () => {
33
- console.log();
34
- console.log('*'.repeat(30));
35
- console.log();
28
+ console.log();
29
+ console.log("*".repeat(30));
30
+ console.log();
36
31
  };
37
32
  const toArray = (value) => {
38
- return Array.isArray(value) ? value : !value ? [] : [value];
33
+ return Array.isArray(value) ? value : !value ? [] : [value];
39
34
  };
40
35
  const getFolderPath = (root) => {
41
- const cwd = process.cwd();
42
- const srcExists = fs.existsSync(path.join(cwd, 'src'));
43
- const folderPath = srcExists ? path.join(cwd, 'src', root) : path.join(cwd, root);
44
- return folderPath;
36
+ const cwd = process.cwd();
37
+ return (0, fs.existsSync)((0, path.join)(cwd, "src")) ? (0, path.join)(cwd, "src", root) : (0, path.join)(cwd, root);
45
38
  };
46
-
39
+ //#endregion
47
40
  exports.consoleStars = consoleStars;
48
41
  exports.getFolderPath = getFolderPath;
49
42
  exports.toArray = toArray;
50
43
  exports.transformModule = transformModule;
51
44
  exports.writeFileAnalysis = writeFileAnalysis;
52
- //# sourceMappingURL=helpers.cjs.map
45
+
46
+ //# sourceMappingURL=helpers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, 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.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\nexport const getFolderPath = (root: string) => {\n const cwd = process.cwd();\n const srcExists = existsSync(join(cwd, 'src'));\n const folderPath = srcExists ? join(cwd, 'src', root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AAC,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;AAEO,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AAC5C,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACzB,MAAM,SAAS,GAAGC,aAAU,CAACJ,SAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,SAAS,GAAGA,SAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAGA,SAAI,CAAC,GAAG,EAAE,IAAI,CAAC;AAEvE,IAAA,OAAO,UAAU;AACnB;;;;;;;;"}
1
+ {"version":3,"file":"helpers.cjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, 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.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\nexport const getFolderPath = (root: string) => {\n const cwd = process.cwd();\n const srcExists = existsSync(join(cwd, \"src\"));\n const folderPath = srcExists ? join(cwd, \"src\", root) : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,KAAK,EACnB,cACA,sBACyB;AAMzB,SAAA,GAAA,KAAA,UAJE,MAAA,GAAA,KAAA,UAAA,GAAA,KAAA,SACgB,aAAa,EAAE,gBAAgB,CAChD,CAAC,WAAW,KAAK,IAAI;;AAKxB,MAAa,qBACX,cACA,eACG;CACH,MAAM,eAAe,aAAa;CAGlC,MAAM,YAAA,GAAA,KAAA,MAAgB,YAAY,aAAa;CAC/C,MAAM,WAAA,GAAA,KAAA,SAAkB,SAAS;AAEjC,KAAI;AAEF,GAAA,GAAA,GAAA,WAAU,SAAS,EAAE,WAAW,MAAM,CAAC;EAEvC,IAAI,cAAc,aAAa;AAC/B,oBAAA,UAAU,KAAK,SAAS,CAAC,QAAQ,aAAa;AAC5C,iBAAc,YAAY,WAAW,QAAQ,QAAQ;IACrD;AAGF,GAAA,GAAA,GAAA,eAAc,UAAU,aAAa,OAAO;AAE5C,UAAQ,IAAI,OAAO,eAAe;AAClC,SAAO,aAAa,MAAM,GAAG,GAAG,CAAC,WAAW,KAAK,IAAI;UAC9C,OAAO;AACd,SAAO,QAAQ,MAAM,mBAAmB,aAAa,IAAI,MAAM;;;AAInE,MAAa,qBAAqB;AAChC,SAAQ,KAAK;AACb,SAAQ,IAAI,IAAI,OAAO,GAAG,CAAC;AAC3B,SAAQ,KAAK;;AAGf,MAAa,WAAc,UAAyB;AAClD,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM;;AAG7D,MAAa,iBAAiB,SAAiB;CAC7C,MAAM,MAAM,QAAQ,KAAK;AAIzB,SAAA,GAAA,GAAA,aAAA,GAAA,KAAA,MAHkC,KAAK,MAAM,CAAC,IAAA,GAAA,KAAA,MACV,KAAK,OAAO,KAAK,IAAA,GAAA,KAAA,MAAQ,KAAK,KAAK"}
package/lib/helpers.d.ts CHANGED
@@ -1,12 +1,11 @@
1
- import { FileAnalysis } from './schemas';
1
+ import { FileAnalysis } from "./schemas";
2
2
  export type TransformModuleArgs = {
3
3
  cwd?: string;
4
4
  relativePath: string;
5
5
  moduleSpecifier: string;
6
6
  };
7
- export declare const transformModule: ({ cwd, relativePath, moduleSpecifier, }: TransformModuleArgs) => string;
8
- export declare const writeFileAnalysis: (fileAnalysis: FileAnalysis, folderPath: string) => string | void;
7
+ export declare const transformModule: ({ cwd, relativePath, moduleSpecifier, }: TransformModuleArgs) => any;
8
+ export declare const writeFileAnalysis: (fileAnalysis: FileAnalysis, folderPath: string) => any;
9
9
  export declare const consoleStars: () => void;
10
10
  export declare const toArray: <T>(value?: T | T[]) => T[];
11
11
  export declare const getFolderPath: (root: string) => string;
12
- //# sourceMappingURL=helpers.d.ts.map
package/lib/helpers.js CHANGED
@@ -1,46 +1,40 @@
1
- import { mkdirSync, writeFileSync, existsSync } 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;
1
+ import { REPLACERS } from "./constants.js";
2
+ import { dirname, join, relative, resolve } from "path";
3
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
4
+ //#region src/helpers.ts
5
+ const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier }) => {
6
+ return relative(cwd, resolve(dirname(relativePath), moduleSpecifier)).replaceAll("/", ".");
8
7
  };
9
8
  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.forEach(([search, replace]) => {
19
- fileContent = fileContent.replaceAll(search, replace);
20
- });
21
- // Écrire le contenu du fichier types
22
- writeFileSync(destPath, fileContent, 'utf8');
23
- console.log(` ${relativePath}`);
24
- return relativePath.slice(0, -3).replaceAll('/', '.');
25
- }
26
- catch (error) {
27
- return console.error(` ❌ Erreur pour ${relativePath}:`, error);
28
- }
9
+ const relativePath = fileAnalysis.relativePath;
10
+ const destPath = join(folderPath, relativePath);
11
+ const destDir = dirname(destPath);
12
+ try {
13
+ mkdirSync(destDir, { recursive: true });
14
+ let fileContent = fileAnalysis.text;
15
+ REPLACERS.init.forEach(([search, replace]) => {
16
+ fileContent = fileContent.replaceAll(search, replace);
17
+ });
18
+ writeFileSync(destPath, fileContent, "utf8");
19
+ console.log(` ✅ ${relativePath}`);
20
+ return relativePath.slice(0, -3).replaceAll("/", ".");
21
+ } catch (error) {
22
+ return console.error(` Erreur pour ${relativePath}:`, error);
23
+ }
29
24
  };
30
25
  const consoleStars = () => {
31
- console.log();
32
- console.log('*'.repeat(30));
33
- console.log();
26
+ console.log();
27
+ console.log("*".repeat(30));
28
+ console.log();
34
29
  };
35
30
  const toArray = (value) => {
36
- return Array.isArray(value) ? value : !value ? [] : [value];
31
+ return Array.isArray(value) ? value : !value ? [] : [value];
37
32
  };
38
33
  const getFolderPath = (root) => {
39
- const cwd = process.cwd();
40
- const srcExists = existsSync(join(cwd, 'src'));
41
- const folderPath = srcExists ? join(cwd, 'src', root) : join(cwd, root);
42
- return folderPath;
34
+ const cwd = process.cwd();
35
+ return existsSync(join(cwd, "src")) ? join(cwd, "src", root) : join(cwd, root);
43
36
  };
44
-
37
+ //#endregion
45
38
  export { consoleStars, getFolderPath, toArray, transformModule, writeFileAnalysis };
46
- //# sourceMappingURL=helpers.js.map
39
+
40
+ //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, 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.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\nexport const getFolderPath = (root: string) => {\n const cwd = process.cwd();\n const srcExists = existsSync(join(cwd, 'src'));\n const folderPath = srcExists ? join(cwd, 'src', root) : join(cwd, root);\n\n return folderPath;\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,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,KAAI;YAC3C,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;AACvD,QAAA,CAAC,CAAC;;AAGF,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;AAEO,MAAM,aAAa,GAAG,CAAC,IAAY,KAAI;AAC5C,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACzB,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;AAEvE,IAAA,OAAO,UAAU;AACnB;;;;"}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, 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.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\nexport const getFolderPath = (root: string) => {\n const cwd = process.cwd();\n const srcExists = existsSync(join(cwd, \"src\"));\n const folderPath = srcExists ? join(cwd, \"src\", root) : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,KAAK,EACnB,cACA,sBACyB;AAMzB,QALY,SACV,KACA,QAAQ,QAAQ,aAAa,EAAE,gBAAgB,CAChD,CAAC,WAAW,KAAK,IAAI;;AAKxB,MAAa,qBACX,cACA,eACG;CACH,MAAM,eAAe,aAAa;CAGlC,MAAM,WAAW,KAAK,YAAY,aAAa;CAC/C,MAAM,UAAU,QAAQ,SAAS;AAEjC,KAAI;AAEF,YAAU,SAAS,EAAE,WAAW,MAAM,CAAC;EAEvC,IAAI,cAAc,aAAa;AAC/B,YAAU,KAAK,SAAS,CAAC,QAAQ,aAAa;AAC5C,iBAAc,YAAY,WAAW,QAAQ,QAAQ;IACrD;AAGF,gBAAc,UAAU,aAAa,OAAO;AAE5C,UAAQ,IAAI,OAAO,eAAe;AAClC,SAAO,aAAa,MAAM,GAAG,GAAG,CAAC,WAAW,KAAK,IAAI;UAC9C,OAAO;AACd,SAAO,QAAQ,MAAM,mBAAmB,aAAa,IAAI,MAAM;;;AAInE,MAAa,qBAAqB;AAChC,SAAQ,KAAK;AACb,SAAQ,IAAI,IAAI,OAAO,GAAG,CAAC;AAC3B,SAAQ,KAAK;;AAGf,MAAa,WAAc,UAAyB;AAClD,QAAO,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM;;AAG7D,MAAa,iBAAiB,SAAiB;CAC7C,MAAM,MAAM,QAAQ,KAAK;AAIzB,QAHkB,WAAW,KAAK,KAAK,MAAM,CAAC,GACf,KAAK,KAAK,OAAO,KAAK,GAAG,KAAK,KAAK,KAAK"}
package/lib/imports.cjs CHANGED
@@ -1,134 +1,98 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var tsMorph = require('ts-morph');
5
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./_virtual/_rolldown/runtime.cjs");
3
+ let path = require("path");
4
+ let ts_morph = require("ts-morph");
5
+ //#region src/imports.ts
6
6
  /**
7
- * Résout le moduleSpecifier en utilisant les paths du tsconfig si il commence par "#"
8
- */
7
+ * Résout le moduleSpecifier en utilisant les paths du tsconfig si il commence par "#"
8
+ */
9
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;
10
+ const paths = sourceFile.getProject().getCompilerOptions().paths;
11
+ if (!paths) return moduleSpecifier;
12
+ const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;
13
+ const paths2 = Object.entries(paths);
14
+ for (const [pattern, mappings] of paths2) {
15
+ const regexPattern = pattern.replace(/\*/g, "(.*)");
16
+ const regex = new RegExp(`^${regexPattern}$`);
17
+ const match = moduleSpecifier.match(regex);
18
+ if (match) {
19
+ const first = mappings[0];
20
+ let relativedPath = baseUrl ? (0, path.join)(baseUrl, first) : first;
21
+ if (match[1]) relativedPath = relativedPath.replace("*", match[1]);
22
+ const relativePath = (0, path.relative)((0, path.relative)(process.cwd(), sourceFile.getDirectoryPath()), relativedPath);
23
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
24
+ }
25
+ }
26
+ return moduleSpecifier;
39
27
  };
40
28
  /**
41
- * Analyse les imports d'un fichier
42
- */
29
+ * Analyse les imports d'un fichier
30
+ */
43
31
  const analyzeImports = (sourceFile) => {
44
- const imports = [];
45
- // Import declarations (import ... from '...')
46
- sourceFile.getImportDeclarations().forEach(importDecl => {
47
- // Determine if this is a type-only import
48
- const isTypeOnly = importDecl.isTypeOnly();
49
- const rawModuleSpecifier = importDecl.getModuleSpecifierValue();
50
- const moduleSpecifier = resolveModuleSpecifier(sourceFile, rawModuleSpecifier);
51
- // Import default
52
- const defaultImport = importDecl.getDefaultImport();
53
- if (defaultImport) {
54
- imports.push({
55
- moduleSpecifier,
56
- kind: 'default',
57
- default: defaultImport.getText(),
58
- isTypeOnly,
59
- });
60
- }
61
- // Import namespace (* as name)
62
- const namespaceImport = importDecl.getNamespaceImport();
63
- if (namespaceImport) {
64
- imports.push({
65
- moduleSpecifier,
66
- kind: 'namespace',
67
- default: namespaceImport.getText(),
68
- isTypeOnly,
69
- });
70
- }
71
- // Named imports ({ name1, name2 })
72
- const namedImports = importDecl.getNamedImports();
73
- if (namedImports.length > 0) {
74
- imports.push({
75
- moduleSpecifier,
76
- kind: 'named',
77
- namedImports: namedImports.map(ni => ni.getName()),
78
- isTypeOnly,
79
- });
80
- }
81
- // Side-effect import (import '...')
82
- if (!defaultImport && !namespaceImport && namedImports.length === 0) {
83
- imports.push({
84
- moduleSpecifier,
85
- kind: 'side-effect',
86
- isTypeOnly,
87
- });
88
- }
89
- });
90
- // Dynamic imports (import('...'))
91
- sourceFile
92
- .getDescendantsOfKind(tsMorph.SyntaxKind.CallExpression)
93
- .forEach(callExpr => {
94
- if (callExpr.getExpression().getKind() === tsMorph.SyntaxKind.ImportKeyword) {
95
- const arg = callExpr.getArguments()[0];
96
- if (arg && arg.getKind() === tsMorph.SyntaxKind.StringLiteral) {
97
- const rawModuleSpecifier = arg.getText().replace(/['"]/g, '');
98
- const moduleSpecifier = resolveModuleSpecifier(sourceFile, rawModuleSpecifier);
99
- imports.push({
100
- moduleSpecifier,
101
- kind: 'side-effect',
102
- isDynamic: true,
103
- });
104
- }
105
- }
106
- });
107
- return imports;
32
+ const imports = [];
33
+ sourceFile.getImportDeclarations().forEach((importDecl) => {
34
+ const isTypeOnly = importDecl.isTypeOnly();
35
+ const moduleSpecifier = resolveModuleSpecifier(sourceFile, importDecl.getModuleSpecifierValue());
36
+ const defaultImport = importDecl.getDefaultImport();
37
+ if (defaultImport) imports.push({
38
+ moduleSpecifier,
39
+ kind: "default",
40
+ default: defaultImport.getText(),
41
+ isTypeOnly
42
+ });
43
+ const namespaceImport = importDecl.getNamespaceImport();
44
+ if (namespaceImport) imports.push({
45
+ moduleSpecifier,
46
+ kind: "namespace",
47
+ default: namespaceImport.getText(),
48
+ isTypeOnly
49
+ });
50
+ const namedImports = importDecl.getNamedImports();
51
+ if (namedImports.length > 0) imports.push({
52
+ moduleSpecifier,
53
+ kind: "named",
54
+ namedImports: namedImports.map((ni) => ni.getName()),
55
+ isTypeOnly
56
+ });
57
+ if (!defaultImport && !namespaceImport && namedImports.length === 0) imports.push({
58
+ moduleSpecifier,
59
+ kind: "side-effect",
60
+ isTypeOnly
61
+ });
62
+ });
63
+ sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).forEach((callExpr) => {
64
+ if (callExpr.getExpression().getKind() === ts_morph.SyntaxKind.ImportKeyword) {
65
+ const arg = callExpr.getArguments()[0];
66
+ if (arg && arg.getKind() === ts_morph.SyntaxKind.StringLiteral) {
67
+ const moduleSpecifier = resolveModuleSpecifier(sourceFile, arg.getText().replace(/['"]/g, ""));
68
+ imports.push({
69
+ moduleSpecifier,
70
+ kind: "side-effect",
71
+ isDynamic: true
72
+ });
73
+ }
74
+ }
75
+ });
76
+ return imports;
108
77
  };
109
78
  const buildImportStrings = (imports) => {
110
- return imports.map(imp => {
111
- switch (imp.kind) {
112
- case 'named': {
113
- const namedImports = imp.namedImports?.join(', ') || '';
114
- return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;
115
- }
116
- case 'namespace':
117
- return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;
118
- case 'side-effect': {
119
- if (imp.isDynamic) {
120
- return `// Dynamic import: import('${imp.moduleSpecifier}')`;
121
- }
122
- return `import '${imp.moduleSpecifier}';`;
123
- }
124
- case 'default':
125
- return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;
126
- default:
127
- return '';
128
- }
129
- });
79
+ return imports.map((imp) => {
80
+ switch (imp.kind) {
81
+ case "named": {
82
+ const namedImports = imp.namedImports?.join(", ") || "";
83
+ return `import ${imp.isTypeOnly ? "type " : ""}{ ${namedImports} } from '${imp.moduleSpecifier}';`;
84
+ }
85
+ case "namespace": return `import ${imp.isTypeOnly ? "type " : ""}* as ${imp.default} from '${imp.moduleSpecifier}';`;
86
+ case "side-effect":
87
+ if (imp.isDynamic) return `// Dynamic import: import('${imp.moduleSpecifier}')`;
88
+ return `import '${imp.moduleSpecifier}';`;
89
+ case "default": return `import ${imp.isTypeOnly ? "type " : ""}${imp.default} from '${imp.moduleSpecifier}';`;
90
+ default: return "";
91
+ }
92
+ });
130
93
  };
131
-
94
+ //#endregion
132
95
  exports.analyzeImports = analyzeImports;
133
96
  exports.buildImportStrings = buildImportStrings;
134
- //# sourceMappingURL=imports.cjs.map
97
+
98
+ //# sourceMappingURL=imports.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"imports.cjs","sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ImportInfo } from './schemas';\n\n/**\n * Résout le moduleSpecifier en utilisant les paths du tsconfig si il commence par \"#\"\n */\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Chercher la correspondance dans les paths\n for (const [pattern, mappings] of paths2) {\n // Remplacer * par une regex pour matcher\n const regexPattern = pattern.replace(/\\*/g, '(.*)');\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Prendre le premier mapping disponible\n const first = mappings[0];\n\n // Résoudre le chemin absolu\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace('*', match[1]);\n }\n\n // Calculer le chemin relatif depuis le fichier source actuel\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // S'assurer que le chemin relatif commence par ./ ou ../\n return relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n }\n }\n\n return moduleSpecifier;\n};\n\n/**\n * Analyse les imports d'un fichier\n */\nexport const analyzeImports = (sourceFile: SourceFile): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach(importDecl => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: 'default',\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: 'namespace',\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: 'named',\n namedImports: namedImports.map(ni => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (!defaultImport && !namespaceImport && namedImports.length === 0) {\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach(callExpr => {\n if (\n callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword\n ) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, '');\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: 'side-effect',\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map(imp => {\n switch (imp.kind) {\n case 'named': {\n const namedImports = imp.namedImports?.join(', ') || '';\n return `import ${imp.isTypeOnly ? 'type ' : ''}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case 'namespace':\n return `import ${imp.isTypeOnly ? 'type ' : ''}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case 'side-effect': {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case 'default':\n return `import ${imp.isTypeOnly ? 'type ' : ''}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return '';\n }\n });\n};\n"],"names":["join","relative","SyntaxKind"],"mappings":";;;;;AAIA;;AAEG;AACH,MAAM,sBAAsB,GAAG,CAC7B,UAAsB,EACtB,eAAuB,KACb;IACV,MAAM,KAAK,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC,kBAAkB,EAAE,CAAC,KAAK;AAEhE,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,OAAO,eAAe;IAElC,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC,kBAAkB,EAAE,CAAC,OAAO;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;;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W,GAAG,CAAC,eAAe,IAAI;YAC3C;AAEA,YAAA,KAAK,SAAS;gBACZ,OAAO,CAAA,OAAA,EAAU,GAAG,CAAC,UAAU,GAAG,OAAO,GAAG,EAAE,CAAA,EAAG,GAAG,CAAC,OAAO,UAAU,GAAG,CAAC,eAAe,CAAA,EAAA,CAAI;AAC/F,YAAA;AACE,gBAAA,OAAO,EAAE;;AAEf,IAAA,CAAC,CAAC;AACJ;;;;;"}
1
+ {"version":3,"file":"imports.cjs","names":["SyntaxKind"],"sources":["../src/imports.ts"],"sourcesContent":["import { join, relative } from \"node:path\";\nimport { SourceFile, SyntaxKind } from \"ts-morph\";\nimport type { ImportInfo } from \"./schemas\";\n\n/**\n * Résout le moduleSpecifier en utilisant les paths du tsconfig si il commence par \"#\"\n */\nconst resolveModuleSpecifier = (\n sourceFile: SourceFile,\n moduleSpecifier: string,\n): string => {\n const paths = sourceFile.getProject().getCompilerOptions().paths;\n\n if (!paths) return moduleSpecifier;\n\n const baseUrl = sourceFile.getProject().getCompilerOptions().baseUrl;\n const paths2 = Object.entries(paths);\n\n // Chercher la correspondance dans les paths\n for (const [pattern, mappings] of paths2) {\n // Remplacer * par une regex pour matcher\n const regexPattern = pattern.replace(/\\*/g, \"(.*)\");\n const regex = new RegExp(`^${regexPattern}$`);\n const match = moduleSpecifier.match(regex);\n\n if (match) {\n // Prendre le premier mapping disponible\n const first = mappings[0];\n\n // Résoudre le chemin absolu\n let relativedPath = baseUrl ? join(baseUrl, first) : first;\n\n if (match[1]) {\n relativedPath = relativedPath.replace(\"*\", match[1]);\n }\n\n // Calculer le chemin relatif depuis le fichier source actuel\n const sourceFileDir = relative(\n process.cwd(),\n sourceFile.getDirectoryPath(),\n );\n const relativePath = relative(sourceFileDir, relativedPath);\n\n // S'assurer que le chemin relatif commence par ./ ou ../\n return relativePath.startsWith(\".\") ? relativePath : `./${relativePath}`;\n }\n }\n\n return moduleSpecifier;\n};\n\n/**\n * Analyse les imports d'un fichier\n */\nexport const analyzeImports = (sourceFile: SourceFile): ImportInfo[] => {\n const imports: ImportInfo[] = [];\n\n // Import declarations (import ... from '...')\n sourceFile.getImportDeclarations().forEach((importDecl) => {\n // Determine if this is a type-only import\n const isTypeOnly = importDecl.isTypeOnly();\n\n const rawModuleSpecifier = importDecl.getModuleSpecifierValue();\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n\n // Import default\n const defaultImport = importDecl.getDefaultImport();\n if (defaultImport) {\n imports.push({\n moduleSpecifier,\n kind: \"default\",\n default: defaultImport.getText(),\n isTypeOnly,\n });\n }\n\n // Import namespace (* as name)\n const namespaceImport = importDecl.getNamespaceImport();\n if (namespaceImport) {\n imports.push({\n moduleSpecifier,\n kind: \"namespace\",\n default: namespaceImport.getText(),\n isTypeOnly,\n });\n }\n\n // Named imports ({ name1, name2 })\n const namedImports = importDecl.getNamedImports();\n if (namedImports.length > 0) {\n imports.push({\n moduleSpecifier,\n kind: \"named\",\n namedImports: namedImports.map((ni) => ni.getName()),\n isTypeOnly,\n });\n }\n\n // Side-effect import (import '...')\n if (!defaultImport && !namespaceImport && namedImports.length === 0) {\n imports.push({\n moduleSpecifier,\n kind: \"side-effect\",\n isTypeOnly,\n });\n }\n });\n\n // Dynamic imports (import('...'))\n sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .forEach((callExpr) => {\n if (callExpr.getExpression().getKind() === SyntaxKind.ImportKeyword) {\n const arg = callExpr.getArguments()[0];\n if (arg && arg.getKind() === SyntaxKind.StringLiteral) {\n const rawModuleSpecifier = arg.getText().replace(/['\"]/g, \"\");\n const moduleSpecifier = resolveModuleSpecifier(\n sourceFile,\n rawModuleSpecifier,\n );\n imports.push({\n moduleSpecifier,\n kind: \"side-effect\",\n isDynamic: true,\n });\n }\n }\n });\n\n return imports;\n};\n\nexport const buildImportStrings = (imports: ImportInfo[]) => {\n return imports.map((imp) => {\n switch (imp.kind) {\n case \"named\": {\n const namedImports = imp.namedImports?.join(\", \") || \"\";\n return `import ${imp.isTypeOnly ? \"type \" : \"\"}{ ${namedImports} } from '${imp.moduleSpecifier}';`;\n }\n case \"namespace\":\n return `import ${imp.isTypeOnly ? \"type \" : \"\"}* as ${imp.default} from '${imp.moduleSpecifier}';`;\n case \"side-effect\": {\n if (imp.isDynamic) {\n return `// Dynamic import: import('${imp.moduleSpecifier}')`;\n }\n return `import '${imp.moduleSpecifier}';`;\n }\n\n case \"default\":\n return `import ${imp.isTypeOnly ? \"type \" : \"\"}${imp.default} from '${imp.moduleSpecifier}';`;\n default:\n return \"\";\n }\n });\n};\n"],"mappings":";;;;;;;;AAOA,MAAM,0BACJ,YACA,oBACW;CACX,MAAM,QAAQ,WAAW,YAAY,CAAC,oBAAoB,CAAC;AAE3D,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,UAAU,WAAW,YAAY,CAAC,oBAAoB,CAAC;CAC7D,MAAM,SAAS,OAAO,QAAQ,MAAM;AAGpC,MAAK,MAAM,CAAC,SAAS,aAAa,QAAQ;EAExC,MAAM,eAAe,QAAQ,QAAQ,OAAO,OAAO;EACnD,MAAM,QAAQ,IAAI,OAAO,IAAI,aAAa,GAAG;EAC7C,MAAM,QAAQ,gBAAgB,MAAM,MAAM;AAE1C,MAAI,OAAO;GAET,MAAM,QAAQ,SAAS;GAGvB,IAAI,gBAAgB,WAAA,GAAA,KAAA,MAAe,SAAS,MAAM,GAAG;AAErD,OAAI,MAAM,GACR,iBAAgB,cAAc,QAAQ,KAAK,MAAM,GAAG;GAQtD,MAAM,gBAAA,GAAA,KAAA,WAAA,GAAA,KAAA,UAHJ,QAAQ,KAAK,EACb,WAAW,kBAAkB,CAC9B,EAC4C,cAAc;AAG3D,UAAO,aAAa,WAAW,IAAI,GAAG,eAAe,KAAK;;;AAI9D,QAAO;;;;;AAMT,MAAa,kBAAkB,eAAyC;CACtE,MAAM,UAAwB,EAAE;AAGhC,YAAW,uBAAuB,CAAC,SAAS,eAAe;EAEzD,MAAM,aAAa,WAA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AAG,OAAO,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GACjG,KAAK;AACH,QAAI,IAAI,UACN,QAAO,8BAA8B,IAAI,gBAAgB;AAE3D,WAAO,WAAW,IAAI,gBAAgB;GAGxC,KAAK,UACH,QAAO,UAAU,IAAI,aAAa,UAAU,KAAK,IAAI,QAAQ,SAAS,IAAI,gBAAgB;GAC5F,QACE,QAAO;;GAEX"}
package/lib/imports.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { SourceFile } from 'ts-morph';
2
- import type { ImportInfo } from './schemas';
1
+ import { SourceFile } from "ts-morph";
2
+ import type { ImportInfo } from "./schemas";
3
3
  /**
4
4
  * Analyse les imports d'un fichier
5
5
  */
6
6
  export declare const analyzeImports: (sourceFile: SourceFile) => ImportInfo[];
7
7
  export declare const buildImportStrings: (imports: ImportInfo[]) => string[];
8
- //# sourceMappingURL=imports.d.ts.map