@bemedev/codebase 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -70,6 +70,8 @@ codebase -o output.json node_modules dist
70
70
 
71
71
  ### Programmatic API
72
72
 
73
+ #### Analyzing and generating the codebase JSON
74
+
73
75
  ```typescript
74
76
  import { generate, analyze } from '@bemedev/codebase';
75
77
 
@@ -83,6 +85,29 @@ await generate({
83
85
  });
84
86
  ```
85
87
 
88
+ #### Managing dependencies programmatically
89
+
90
+ You can also use the programmatic API to initialize workspace
91
+ configurations and selectively add/remove files using their regular
92
+ slash-separated paths (instead of dot-parsed notation).
93
+
94
+ ```typescript
95
+ import { init, add, remove } from '@bemedev/codebase';
96
+ import analysis from './codebase.json';
97
+
98
+ // Initialize the project workspace
99
+ init(analysis.CODEBASE_ANALYSIS, {
100
+ root: 'my-project-src',
101
+ json: '.project-codebase.json',
102
+ });
103
+
104
+ // Add files dynamically using regular slash-separated paths
105
+ add(analysis.CODEBASE_ANALYSIS, 'nested/Tooltip');
106
+
107
+ // Remove files dynamically using regular slash-separated paths
108
+ remove(analysis.CODEBASE_ANALYSIS, 'nested/Tooltip');
109
+ ```
110
+
86
111
  ### Configuration
87
112
 
88
113
  You can also customize the global configuration used by the programmatic
@@ -11,7 +11,7 @@ const processFileAnalysis = (analysis, cwd, additionals, pathsEntries, files, CO
11
11
  const relativePath = analysis.relativePath;
12
12
  const keys = Object.keys(CODEBASE_ANALYSIS);
13
13
  analysis.imports.forEach(({ moduleSpecifier }) => {
14
- const _path = (0, path.relative)(cwd, (0, path.resolve)((0, path.dirname)(relativePath), moduleSpecifier)).replaceAll("/", ".");
14
+ const _path = (0, path.relative)(cwd, (0, path.resolve)((0, path.dirname)(relativePath), moduleSpecifier));
15
15
  const all = additionals.concat(pathsEntries).map(([key]) => key).concat(files);
16
16
  if (!all.every((p) => p !== _path)) return;
17
17
  const toAdd = CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];
@@ -1 +1 @@
1
- {"version":3,"file":"add.cjs","names":["transformModule","config","FILES_PROPERTY","getFolderPath","PATH_PROPERTY","writeFileAnalysis"],"sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis, type FileAnalysis } from '../schemas';\nimport type { NOmit } from '../types';\n\nconst processFileAnalysis = (\n analysis: NOmit<FileAnalysis, 'exports'>,\n cwd: string,\n additionals: [string, NOmit<FileAnalysis, 'exports'>][],\n pathsEntries: [string, NOmit<FileAnalysis, 'exports'>][],\n files: string[],\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const relativePath = analysis.relativePath;\n\n const keys = Object.keys(CODEBASE_ANALYSIS);\n analysis.imports.forEach(({ moduleSpecifier }) => {\n const _path = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n ).replaceAll('/', '.');\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\n\n const canAdd = all.every(p => p !== _path);\n if (!canAdd) return;\n\n const toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n all.push(_path);\n\n const imports = toAdd.imports.filter(({ moduleSpecifier }) => {\n const _path = transformModule({\n cwd,\n relativePath: toAdd.relativePath,\n moduleSpecifier,\n });\n\n const array = [_path, `${_path}.index`].filter(p =>\n keys.includes(p),\n );\n\n if (array.length < 1) return false;\n\n return array.every(p => !all.includes(p));\n });\n\n const toAdd2 = { ...toAdd, imports };\n const canRecurse = toAdd2.imports.length > 0;\n\n if (canRecurse) {\n processFileAnalysis(\n toAdd2,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n }\n });\n};\n\nexport const add = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for addition.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, config.json);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const files = file.get(FILES_PROPERTY) as string[];\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n\n // Release resources\n\n const additionals: [string, NOmit<FileAnalysis, 'exports'>][] = [];\n\n const pathsEntries = Object.entries(CODEBASE_ANALYSIS)\n .filter(([key]) => paths.some(p => key.startsWith(p)))\n .filter(([key]) => !files.includes(key));\n\n pathsEntries.forEach(([, analysis]) => {\n processFileAnalysis(\n analysis,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n });\n\n const entries = new Set(\n pathsEntries.concat(additionals).filter(([, val]) => !!val),\n );\n\n consoleStars();\n console.log(`🔧 Creation of files (${entries.size} files)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, root);\n if (_path) {\n files.push(_path);\n success++;\n }\n });\n\n file.set(FILES_PROPERTY, files);\n file.save();\n console.log(`✅ Files created! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error during file creation`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;AAaA,MAAM,uBACJ,UACA,KACA,aACA,cACA,OACA,sBACG;CACH,MAAM,eAAe,SAAS;CAE9B,MAAM,OAAO,OAAO,KAAK,iBAAiB;CAC1C,SAAS,QAAQ,SAAS,EAAE,sBAAsB;EAChD,MAAM,SAAA,GAAA,KAAA,SAAA,CACJ,MAAA,GAAA,KAAA,QAAA,EAAA,GAAA,KAAA,QAAA,CACgB,YAAY,GAAG,eAAe,CAChD,CAAC,CAA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C,CACnD,QAAQ,CAAC,SAAS,MAAM,MAAK,MAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CACrD,QAAQ,CAAC,SAAS,CAAC,MAAM,SAAS,GAAG,CAAC;EAEzC,aAAa,SAAS,GAAG,cAAc;GACrC,oBACE,UACA,KACA,aACA,cACA,OACA,iBACF;EACF,CAAC;EAED,MAAM,UAAU,IAAI,IAClB,aAAa,OAAO,WAAW,CAAC,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG,CAC5D;EAEA,gBAAA,aAAa;EACb,QAAQ,IAAI,yBAAyB,QAAQ,KAAK,WAAW;EAE7D,IAAI,UAAU;EACd,MAAM,SAAS,QAAQ;EAEvB,QAAQ,SAAS,GAAG,kBAAkB;GACpC,MAAM,QAAQC,gBAAAA,kBAAkB,cAAc,IAAI;GAClD,IAAI,OAAO;IACT,MAAM,KAAK,KAAK;IAChB;GACF;EACF,CAAC;EAED,KAAK,IAAIH,kBAAAA,gBAAgB,KAAK;EAC9B,KAAK,KAAK;EACV,QAAQ,IAAI,qBAAqB,QAAQ,GAAG,OAAO,EAAE;EACrD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,OAAO;CACT;CAEA,gBAAA,aAAa;CACb,OAAO;AACT"}
1
+ {"version":3,"file":"add.cjs","names":["transformModule","config","FILES_PROPERTY","getFolderPath","PATH_PROPERTY","writeFileAnalysis"],"sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis, type FileAnalysis } from '../schemas';\nimport type { NOmit } from '../types';\n\nconst processFileAnalysis = (\n analysis: NOmit<FileAnalysis, 'exports'>,\n cwd: string,\n additionals: [string, NOmit<FileAnalysis, 'exports'>][],\n pathsEntries: [string, NOmit<FileAnalysis, 'exports'>][],\n files: string[],\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const relativePath = analysis.relativePath;\n\n const keys = Object.keys(CODEBASE_ANALYSIS);\n analysis.imports.forEach(({ moduleSpecifier }) => {\n const _path = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n );\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\n\n const canAdd = all.every(p => p !== _path);\n if (!canAdd) return;\n\n const toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n all.push(_path);\n\n const imports = toAdd.imports.filter(({ moduleSpecifier }) => {\n const _path = transformModule({\n cwd,\n relativePath: toAdd.relativePath,\n moduleSpecifier,\n });\n\n const array = [_path, `${_path}.index`].filter(p =>\n keys.includes(p),\n );\n\n if (array.length < 1) return false;\n\n return array.every(p => !all.includes(p));\n });\n\n const toAdd2 = { ...toAdd, imports };\n const canRecurse = toAdd2.imports.length > 0;\n\n if (canRecurse) {\n processFileAnalysis(\n toAdd2,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n }\n });\n};\n\nexport const add = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for addition.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, config.json);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const files = file.get(FILES_PROPERTY) as string[];\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n\n // Release resources\n\n const additionals: [string, NOmit<FileAnalysis, 'exports'>][] = [];\n\n const pathsEntries = Object.entries(CODEBASE_ANALYSIS)\n .filter(([key]) => paths.some(p => key.startsWith(p)))\n .filter(([key]) => !files.includes(key));\n\n pathsEntries.forEach(([, analysis]) => {\n processFileAnalysis(\n analysis,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n });\n\n const entries = new Set(\n pathsEntries.concat(additionals).filter(([, val]) => !!val),\n );\n\n consoleStars();\n console.log(`🔧 Creation of files (${entries.size} files)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, root);\n if (_path) {\n files.push(_path);\n success++;\n }\n });\n\n file.set(FILES_PROPERTY, files);\n file.save();\n console.log(`✅ Files created! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error during file creation`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;AAaA,MAAM,uBACJ,UACA,KACA,aACA,cACA,OACA,sBACG;CACH,MAAM,eAAe,SAAS;CAE9B,MAAM,OAAO,OAAO,KAAK,iBAAiB;CAC1C,SAAS,QAAQ,SAAS,EAAE,sBAAsB;EAChD,MAAM,SAAA,GAAA,KAAA,SAAA,CACJ,MAAA,GAAA,KAAA,QAAA,EAAA,GAAA,KAAA,QAAA,CACgB,YAAY,GAAG,eAAe,CAChD;EAEA,MAAM,MAAM,YACT,OAAO,YAAY,CAAC,CACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CACnB,OAAO,KAAK;EAGf,IAAI,CADW,IAAI,OAAM,MAAK,MAAM,KAC1B,GAAG;EAEb,MAAM,QACJ,kBAAkB,UAAU,kBAAkB,GAAG,MAAM;EACzD,IAAI,CAAC,OAAO;EAEZ,YAAY,KAAK,CAAC,OAAO,KAAK,CAAC;EAC/B,IAAI,KAAK,KAAK;EAEd,MAAM,UAAU,MAAM,QAAQ,QAAQ,EAAE,sBAAsB;GAC5D,MAAM,QAAQA,gBAAAA,gBAAgB;IAC5B;IACA,cAAc,MAAM;IACpB;GACF,CAAC;GAED,MAAM,QAAQ,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,QAAO,MAC7C,KAAK,SAAS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AO;IACT,MAAM,KAAK,KAAK;IAChB;GACF;EACF,CAAC;EAED,KAAK,IAAIH,kBAAAA,gBAAgB,KAAK;EAC9B,KAAK,KAAK;EACV,QAAQ,IAAI,qBAAqB,QAAQ,GAAG,OAAO,EAAE;EACrD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,OAAO;CACT;CAEA,gBAAA,aAAa;CACb,OAAO;AACT"}
@@ -8,7 +8,7 @@ const processFileAnalysis = (analysis, cwd, additionals, pathsEntries, files, CO
8
8
  const relativePath = analysis.relativePath;
9
9
  const keys = Object.keys(CODEBASE_ANALYSIS);
10
10
  analysis.imports.forEach(({ moduleSpecifier }) => {
11
- const _path = relative(cwd, resolve(dirname(relativePath), moduleSpecifier)).replaceAll("/", ".");
11
+ const _path = relative(cwd, resolve(dirname(relativePath), moduleSpecifier));
12
12
  const all = additionals.concat(pathsEntries).map(([key]) => key).concat(files);
13
13
  if (!all.every((p) => p !== _path)) return;
14
14
  const toAdd = CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];
@@ -1 +1 @@
1
- {"version":3,"file":"add.js","names":[],"sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis, type FileAnalysis } from '../schemas';\nimport type { NOmit } from '../types';\n\nconst processFileAnalysis = (\n analysis: NOmit<FileAnalysis, 'exports'>,\n cwd: string,\n additionals: [string, NOmit<FileAnalysis, 'exports'>][],\n pathsEntries: [string, NOmit<FileAnalysis, 'exports'>][],\n files: string[],\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const relativePath = analysis.relativePath;\n\n const keys = Object.keys(CODEBASE_ANALYSIS);\n analysis.imports.forEach(({ moduleSpecifier }) => {\n const _path = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n ).replaceAll('/', '.');\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\n\n const canAdd = all.every(p => p !== _path);\n if (!canAdd) return;\n\n const toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n all.push(_path);\n\n const imports = toAdd.imports.filter(({ moduleSpecifier }) => {\n const _path = transformModule({\n cwd,\n relativePath: toAdd.relativePath,\n moduleSpecifier,\n });\n\n const array = [_path, `${_path}.index`].filter(p =>\n keys.includes(p),\n );\n\n if (array.length < 1) return false;\n\n return array.every(p => !all.includes(p));\n });\n\n const toAdd2 = { ...toAdd, imports };\n const canRecurse = toAdd2.imports.length > 0;\n\n if (canRecurse) {\n processFileAnalysis(\n toAdd2,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n }\n });\n};\n\nexport const add = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for addition.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, config.json);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const files = file.get(FILES_PROPERTY) as string[];\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n\n // Release resources\n\n const additionals: [string, NOmit<FileAnalysis, 'exports'>][] = [];\n\n const pathsEntries = Object.entries(CODEBASE_ANALYSIS)\n .filter(([key]) => paths.some(p => key.startsWith(p)))\n .filter(([key]) => !files.includes(key));\n\n pathsEntries.forEach(([, analysis]) => {\n processFileAnalysis(\n analysis,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n });\n\n const entries = new Set(\n pathsEntries.concat(additionals).filter(([, val]) => !!val),\n );\n\n consoleStars();\n console.log(`🔧 Creation of files (${entries.size} files)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, root);\n if (_path) {\n files.push(_path);\n success++;\n }\n });\n\n file.set(FILES_PROPERTY, files);\n file.save();\n console.log(`✅ Files created! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error during file creation`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;AAaA,MAAM,uBACJ,UACA,KACA,aACA,cACA,OACA,sBACG;CACH,MAAM,eAAe,SAAS;CAE9B,MAAM,OAAO,OAAO,KAAK,iBAAiB;CAC1C,SAAS,QAAQ,SAAS,EAAE,sBAAsB;EAChD,MAAM,QAAQ,SACZ,KACA,QAAQ,QAAQ,YAAY,GAAG,eAAe,CAChD,CAAC,CAAC,WAAW,KAAK,GAAG;EAErB,MAAM,MAAM,YACT,OAAO,YAAY,CAAC,CACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CACnB,OAAO,KAAK;EAGf,IAAI,CADW,IAAI,OAAM,MAAK,MAAM,KAC1B,GAAG;EAEb,MAAM,QACJ,kBAAkB,UAAU,kBAAkB,GAAG,MAAM;EACzD,IAAI,CAAC,OAAO;EAEZ,YAAY,KAAK,CAAC,OAAO,KAAK,CAAC;EAC/B,IAAI,KAAK,KAAK;EAEd,MAAM,UAAU,MAAM,QAAQ,QAAQ,EAAE,sBAAsB;GAC5D,MAAM,QAAQ,gBAAgB;IAC5B;IACA,cAAc,MAAM;IACpB;GACF,CAAC;GAED,MAAM,QAAQ,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,QAAO,MAC7C,KAAK,SAAS,CAAC,CACjB;GAEA,IAAI,MAAM,SAAS,GAAG,OAAO;GAE7B,OAAO,MAAM,OAAM,MAAK,CAAC,IAAI,SAAS,CAAC,CAAC;EAC1C,CAAC;EAED,MAAM,SAAS;GAAE,GAAG;GAAO;EAAQ;EAGnC,IAFmB,OAAO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add.js","names":[],"sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis, type FileAnalysis } from '../schemas';\nimport type { NOmit } from '../types';\n\nconst processFileAnalysis = (\n analysis: NOmit<FileAnalysis, 'exports'>,\n cwd: string,\n additionals: [string, NOmit<FileAnalysis, 'exports'>][],\n pathsEntries: [string, NOmit<FileAnalysis, 'exports'>][],\n files: string[],\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const relativePath = analysis.relativePath;\n\n const keys = Object.keys(CODEBASE_ANALYSIS);\n analysis.imports.forEach(({ moduleSpecifier }) => {\n const _path = relative(\n cwd,\n resolve(dirname(relativePath), moduleSpecifier),\n );\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\n\n const canAdd = all.every(p => p !== _path);\n if (!canAdd) return;\n\n const toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n all.push(_path);\n\n const imports = toAdd.imports.filter(({ moduleSpecifier }) => {\n const _path = transformModule({\n cwd,\n relativePath: toAdd.relativePath,\n moduleSpecifier,\n });\n\n const array = [_path, `${_path}.index`].filter(p =>\n keys.includes(p),\n );\n\n if (array.length < 1) return false;\n\n return array.every(p => !all.includes(p));\n });\n\n const toAdd2 = { ...toAdd, imports };\n const canRecurse = toAdd2.imports.length > 0;\n\n if (canRecurse) {\n processFileAnalysis(\n toAdd2,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n }\n });\n};\n\nexport const add = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n ...paths: string[]\n) => {\n const isEmpty = paths.length === 0;\n if (isEmpty) return console.warn('No files specified for addition.');\n try {\n const cwd = process.cwd();\n const json = join(cwd, config.json);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const files = file.get(FILES_PROPERTY) as string[];\n const root = getFolderPath(file.get(PATH_PROPERTY) as string);\n\n // Release resources\n\n const additionals: [string, NOmit<FileAnalysis, 'exports'>][] = [];\n\n const pathsEntries = Object.entries(CODEBASE_ANALYSIS)\n .filter(([key]) => paths.some(p => key.startsWith(p)))\n .filter(([key]) => !files.includes(key));\n\n pathsEntries.forEach(([, analysis]) => {\n processFileAnalysis(\n analysis,\n cwd,\n additionals,\n pathsEntries,\n files,\n CODEBASE_ANALYSIS,\n );\n });\n\n const entries = new Set(\n pathsEntries.concat(additionals).filter(([, val]) => !!val),\n );\n\n consoleStars();\n console.log(`🔧 Creation of files (${entries.size} files)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, root);\n if (_path) {\n files.push(_path);\n success++;\n }\n });\n\n file.set(FILES_PROPERTY, files);\n file.save();\n console.log(`✅ Files created! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error during file creation`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;AAaA,MAAM,uBACJ,UACA,KACA,aACA,cACA,OACA,sBACG;CACH,MAAM,eAAe,SAAS;CAE9B,MAAM,OAAO,OAAO,KAAK,iBAAiB;CAC1C,SAAS,QAAQ,SAAS,EAAE,sBAAsB;EAChD,MAAM,QAAQ,SACZ,KACA,QAAQ,QAAQ,YAAY,GAAG,eAAe,CAChD;EAEA,MAAM,MAAM,YACT,OAAO,YAAY,CAAC,CACpB,KAAK,CAAC,SAAS,GAAG,CAAC,CACnB,OAAO,KAAK;EAGf,IAAI,CADW,IAAI,OAAM,MAAK,MAAM,KAC1B,GAAG;EAEb,MAAM,QACJ,kBAAkB,UAAU,kBAAkB,GAAG,MAAM;EACzD,IA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,GAAG,CAC5D;EAEA,aAAa;EACb,QAAQ,IAAI,yBAAyB,QAAQ,KAAK,WAAW;EAE7D,IAAI,UAAU;EACd,MAAM,SAAS,QAAQ;EAEvB,QAAQ,SAAS,GAAG,kBAAkB;GACpC,MAAM,QAAQ,kBAAkB,cAAc,IAAI;GAClD,IAAI,OAAO;IACT,MAAM,KAAK,KAAK;IAChB;GACF;EACF,CAAC;EAED,KAAK,IAAI,gBAAgB,KAAK;EAC9B,KAAK,KAAK;EACV,QAAQ,IAAI,qBAAqB,QAAQ,GAAG,OAAO,EAAE;EACrD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,OAAO;CACT;CAEA,aAAa;CACb,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.cjs","names":["writeFileAnalysis","DEFAULT_PATH_KEY","DEFAULT_CLI_NAME","path","getFolderPath","PROPERTIES"],"sources":["../../src/functions/init.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { config } from '../config';\nimport {\n DEFAULT_CLI_NAME,\n DEFAULT_PATH_KEY,\n PROPERTIES,\n} from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Custom location for the .bemedev folder\n * Default: 'src/.bemedev' if src exists, otherwise '.bemedev' at the root\n */\n root: string;\n json: string;\n path?: string;\n bin?: 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 `🔧 Creating types structure (${entries.length} files)...`,\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(`✅ Types structure successfully created!`);\n return PATHS;\n};\n\nconst initConfig = ({\n root,\n json,\n path = DEFAULT_PATH_KEY,\n bin = DEFAULT_CLI_NAME,\n}: InitOptions) => {\n config.bin = bin;\n config.json = json;\n config.tsConfigPath = path;\n config.root = root;\n\n return { root, json, path, bin };\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n options: InitOptions,\n) => {\n const { root, json, path, bin } = initConfig(options);\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Create the folder\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Folder ${bin} created in: ${root}`);\n } catch (error) {\n console.error(`❌ Error creating the folder ${bin}:`, error);\n return false;\n }\n\n // eslint-disable-next-line no-useless-assignment\n let files: string[] = [];\n // 1.5. Create the types files structure\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(`❌ Error creating the types structure:`);\n return false;\n }\n\n // 2. Update 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 // Initialize compilerOptions and paths if they do not exist\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Add the 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 // // If baseUrl is defined, calculate the relative path with respect to baseUrl\n // relativePath = relative(baseUrl, relativePath);\n // } else {\n // // If baseUrl is not defined, use the absolute path\n // tsconfig.compilerOptions.baseUrl = '.';\n // }\n }\n\n tsconfig.compilerOptions.paths[path] = [`./${relativePath}/*`];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`✅ Path ${path} added to tsconfig.json`);\n } catch (error) {\n console.error(`❌ Error updating tsconfig.json:`, error);\n return false;\n }\n } else {\n console.warn(`⚠️ File tsconfig.json not found, path not added`);\n }\n\n // 3. Create the .bemedev.json file at the root\n\n const jsonConfig = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(\n configFile,\n JSON.stringify(jsonConfig, null, 2),\n 'utf8',\n );\n console.log(`✅ File ${json} created at the root of the project`);\n } catch (error) {\n console.error(`❌ Error creating the file ${json}:`, error);\n return false;\n }\n\n console.log(`🎉 Bemedev initialization completed successfully!`);\n return true;\n};\n"],"mappings":";;;;;;;AAsBA,MAAa,wBACX,YACA,sBACG;CACH,MAAM,UAAU,OAAO,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAAS;EAClE,OAAO,IAAI,SAAS,OAAO,KAAK,IAAI,SAAS,WAAW;CAC1D,CAAC;CAED,MAAM,QAAkB,CAAC;CAEzB,QAAQ,IACN,gCAAgC,QAAQ,OAAO,WACjD;CAEA,KAAK,MAAM,GAAG,iBAAiB,SAAS;EACtC,MAAM,OAAOA,gBAAAA,kBAAkB,cAAc,UAAU;EACvD,IAAI,MAAM,MAAM,KAAK,IAAI;CAC3B;CAEA,QAAQ,IAAI,yCAAyC;CACrD,OAAO;AACT;AAEA,MAAM,cAAc,EAClB,MACA,MACA,MAAA,SAAOC,kBAAAA,kBACP,MAAMC,kBAAAA,uBACW;CACjB,eAAA,OAAO,MAAM;CACb,eAAA,OAAO,OAAO;CACd,eAAA,OAAO,eAAeC;CACtB,eAAA,OAAO,OAAO;CAEd,OAAO;EAAE;EAAM;EAAM,MAAA;EAAM;CAAI;AACjC;AAEA,MAAa,QACX,mBACA,YACG;CACH,MAAM,EAAE,MAAM,MAAM,MAAA,QAAM,QAAQ,WAAW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kBAAAA,WAAW,OAAO;GAClBA,kBAAAA,WAAW,QAAQ;CACtB;CAEA,IAAI;EACF,CAAA,GAAA,GAAA,cAAA,CACE,YACA,KAAK,UAAU,YAAY,MAAM,CAAC,GAClC,MACF;EACA,QAAQ,IAAI,UAAU,KAAK,oCAAoC;CACjE,SAAS,OAAO;EACd,QAAQ,MAAM,6BAA6B,KAAK,IAAI,KAAK;EACzD,OAAO;CACT;CAEA,QAAQ,IAAI,mDAAmD;CAC/D,OAAO;AACT"}
1
+ {"version":3,"file":"init.cjs","names":["writeFileAnalysis","DEFAULT_PATH_KEY","DEFAULT_CLI_NAME","path","getFolderPath","PROPERTIES"],"sources":["../../src/functions/init.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { config } from '../config';\nimport {\n DEFAULT_CLI_NAME,\n DEFAULT_PATH_KEY,\n PROPERTIES,\n} from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Custom location for the .bemedev folder\n * Default: 'src/.bemedev' if src exists, otherwise '.bemedev' at the root\n */\n root: string;\n json: string;\n path?: string;\n bin?: 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 `🔧 Creating types structure (${entries.length} files)...`,\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(`✅ Types structure successfully created!`);\n return PATHS;\n};\n\nconst initConfig = ({\n root,\n json,\n path = DEFAULT_PATH_KEY,\n bin = DEFAULT_CLI_NAME,\n}: InitOptions) => {\n config.bin = bin;\n config.json = json;\n config.tsConfigPath = path;\n config.root = root;\n\n return { root, json, path, bin };\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n options: InitOptions,\n) => {\n const { root, json, path, bin } = initConfig(options);\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Create the folder\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Folder ${bin} created in: ${root}`);\n } catch (error) {\n console.error(`❌ Error creating the folder ${bin}:`, error);\n return false;\n }\n\n // eslint-disable-next-line no-useless-assignment\n let files: string[] = [];\n // 1.5. Create the types files structure\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(`❌ Error creating the types structure:`);\n return false;\n }\n\n // 2. Update 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 // Initialize compilerOptions and paths if they do not exist\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Add the path #bemedev/*\n const relativePath = relative(process.cwd(), folderPath);\n\n tsconfig.compilerOptions.paths[path] = [`./${relativePath}/*`];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`✅ Path ${path} added to tsconfig.json`);\n } catch (error) {\n console.error(`❌ Error updating tsconfig.json:`, error);\n return false;\n }\n } else {\n console.warn(`⚠️ File tsconfig.json not found, path not added`);\n }\n\n // 3. Create the .bemedev.json file at the root\n\n const jsonConfig = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(\n configFile,\n JSON.stringify(jsonConfig, null, 2),\n 'utf8',\n );\n console.log(`✅ File ${json} created at the root of the project`);\n } catch (error) {\n console.error(`❌ Error creating the file ${json}:`, error);\n return false;\n }\n\n console.log(`🎉 Bemedev initialization completed successfully!`);\n return true;\n};\n"],"mappings":";;;;;;;AAsBA,MAAa,wBACX,YACA,sBACG;CACH,MAAM,UAAU,OAAO,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAAS;EAClE,OAAO,IAAI,SAAS,OAAO,KAAK,IAAI,SAAS,WAAW;CAC1D,CAAC;CAED,MAAM,QAAkB,CAAC;CAEzB,QAAQ,IACN,gCAAgC,QAAQ,OAAO,WACjD;CAEA,KAAK,MAAM,GAAG,iBAAiB,SAAS;EACtC,MAAM,OAAOA,gBAAAA,kBAAkB,cAAc,UAAU;EACvD,IAAI,MAAM,MAAM,KAAK,IAAI;CAC3B;CAEA,QAAQ,IAAI,yCAAyC;CACrD,OAAO;AACT;AAEA,MAAM,cAAc,EAClB,MACA,MACA,MAAA,SAAOC,kBAAAA,kBACP,MAAMC,kBAAAA,uBACW;CACjB,eAAA,OAAO,MAAM;CACb,eAAA,OAAO,OAAO;CACd,eAAA,OAAO,eAAeC;CACtB,eAAA,OAAO,OAAO;CAEd,OAAO;EAAE;EAAM;EAAM,MAAA;EAAM;CAAI;AACjC;AAEA,MAAa,QACX,mBACA,YACG;CACH,MAAM,EAAE,MAAM,MAAM,MAAA,QAAM,QAAQ,WAAW,OAAO;CACpD,MAAM,MAAM,QAAQ,IAAI;CACxB,MAAM,cAAA,GAAA,KAAA,KAAA,CAAkB,KAAK,IAAI;CAEjC,KAAA,GAAA,GAAA,WAAA,CADgC,UACjB,GAAG,OAAO;CACzB,MAAM,aAAaC,gBAAAA,cAAc,IAAI;CAGrC,IAAI;EACF,CAAA,GAAA,GAAA,UAAA,CAAU,YAAY,EAAE,WAAW,KAAK,CAAC;EACzC,QAAQ,IAAI,YAAY,IAAI,eAAe,MAAM;CACnD,SAAS,OAAO;EACd,QAAQ,MAAM,+BAA+B,IAAI,IAAI,KAAK;EAC1D,OAAO;CAC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"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,mBAAmB,gBAAgB,aAmBpC,CAAC;AAgBF,eAAO,MAAM,IAAI,GACf,mBAAmB,gBAAgB,EACnC,SAAS,WAAW,YAkGrB,CAAC"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/functions/init.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,mBAAmB,gBAAgB,aAmBpC,CAAC;AAgBF,eAAO,MAAM,IAAI,GACf,mBAAmB,gBAAgB,EACnC,SAAS,WAAW,YAsFrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":[],"sources":["../../src/functions/init.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { config } from '../config';\nimport {\n DEFAULT_CLI_NAME,\n DEFAULT_PATH_KEY,\n PROPERTIES,\n} from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Custom location for the .bemedev folder\n * Default: 'src/.bemedev' if src exists, otherwise '.bemedev' at the root\n */\n root: string;\n json: string;\n path?: string;\n bin?: 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 `🔧 Creating types structure (${entries.length} files)...`,\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(`✅ Types structure successfully created!`);\n return PATHS;\n};\n\nconst initConfig = ({\n root,\n json,\n path = DEFAULT_PATH_KEY,\n bin = DEFAULT_CLI_NAME,\n}: InitOptions) => {\n config.bin = bin;\n config.json = json;\n config.tsConfigPath = path;\n config.root = root;\n\n return { root, json, path, bin };\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n options: InitOptions,\n) => {\n const { root, json, path, bin } = initConfig(options);\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Create the folder\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Folder ${bin} created in: ${root}`);\n } catch (error) {\n console.error(`❌ Error creating the folder ${bin}:`, error);\n return false;\n }\n\n // eslint-disable-next-line no-useless-assignment\n let files: string[] = [];\n // 1.5. Create the types files structure\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(`❌ Error creating the types structure:`);\n return false;\n }\n\n // 2. Update 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 // Initialize compilerOptions and paths if they do not exist\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Add the 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 // // If baseUrl is defined, calculate the relative path with respect to baseUrl\n // relativePath = relative(baseUrl, relativePath);\n // } else {\n // // If baseUrl is not defined, use the absolute path\n // tsconfig.compilerOptions.baseUrl = '.';\n // }\n }\n\n tsconfig.compilerOptions.paths[path] = [`./${relativePath}/*`];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`✅ Path ${path} added to tsconfig.json`);\n } catch (error) {\n console.error(`❌ Error updating tsconfig.json:`, error);\n return false;\n }\n } else {\n console.warn(`⚠️ File tsconfig.json not found, path not added`);\n }\n\n // 3. Create the .bemedev.json file at the root\n\n const jsonConfig = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(\n configFile,\n JSON.stringify(jsonConfig, null, 2),\n 'utf8',\n );\n console.log(`✅ File ${json} created at the root of the project`);\n } catch (error) {\n console.error(`❌ Error creating the file ${json}:`, error);\n return false;\n }\n\n console.log(`🎉 Bemedev initialization completed successfully!`);\n return true;\n};\n"],"mappings":";;;;;;AAsBA,MAAa,wBACX,YACA,sBACG;CACH,MAAM,UAAU,OAAO,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAAS;EAClE,OAAO,IAAI,SAAS,OAAO,KAAK,IAAI,SAAS,WAAW;CAC1D,CAAC;CAED,MAAM,QAAkB,CAAC;CAEzB,QAAQ,IACN,gCAAgC,QAAQ,OAAO,WACjD;CAEA,KAAK,MAAM,GAAG,iBAAiB,SAAS;EACtC,MAAM,OAAO,kBAAkB,cAAc,UAAU;EACvD,IAAI,MAAM,MAAM,KAAK,IAAI;CAC3B;CAEA,QAAQ,IAAI,yCAAyC;CACrD,OAAO;AACT;AAEA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;CACT;MAEA,QAAQ,KAAK,iDAAiD;CAKhE,MAAM,aAAa;EACjB,SAAS;GACR,WAAW,OAAO;GAClB,WAAW,QAAQ;CACtB;CAEA,IAAI;EACF,cACE,YACA,KAAK,UAAU,YAAY,MAAM,CAAC,GAClC,MACF;EACA,QAAQ,IAAI,UAAU,KAAK,oCAAoC;CACjE,SAAS,OAAO;EACd,QAAQ,MAAM,6BAA6B,KAAK,IAAI,KAAK;EACzD,OAAO;CACT;CAEA,QAAQ,IAAI,mDAAmD;CAC/D,OAAO;AACT"}
1
+ {"version":3,"file":"init.js","names":[],"sources":["../../src/functions/init.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { config } from '../config';\nimport {\n DEFAULT_CLI_NAME,\n DEFAULT_PATH_KEY,\n PROPERTIES,\n} from '../constants';\nimport { getFolderPath, writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Custom location for the .bemedev folder\n * Default: 'src/.bemedev' if src exists, otherwise '.bemedev' at the root\n */\n root: string;\n json: string;\n path?: string;\n bin?: 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 `🔧 Creating types structure (${entries.length} files)...`,\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(`✅ Types structure successfully created!`);\n return PATHS;\n};\n\nconst initConfig = ({\n root,\n json,\n path = DEFAULT_PATH_KEY,\n bin = DEFAULT_CLI_NAME,\n}: InitOptions) => {\n config.bin = bin;\n config.json = json;\n config.tsConfigPath = path;\n config.root = root;\n\n return { root, json, path, bin };\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n options: InitOptions,\n) => {\n const { root, json, path, bin } = initConfig(options);\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n if (configExists) return true;\n const folderPath = getFolderPath(root);\n\n // 1. Create the folder\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`✅ Folder ${bin} created in: ${root}`);\n } catch (error) {\n console.error(`❌ Error creating the folder ${bin}:`, error);\n return false;\n }\n\n // eslint-disable-next-line no-useless-assignment\n let files: string[] = [];\n // 1.5. Create the types files structure\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(`❌ Error creating the types structure:`);\n return false;\n }\n\n // 2. Update 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 // Initialize compilerOptions and paths if they do not exist\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Add the path #bemedev/*\n const relativePath = relative(process.cwd(), folderPath);\n\n tsconfig.compilerOptions.paths[path] = [`./${relativePath}/*`];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`✅ Path ${path} added to tsconfig.json`);\n } catch (error) {\n console.error(`❌ Error updating tsconfig.json:`, error);\n return false;\n }\n } else {\n console.warn(`⚠️ File tsconfig.json not found, path not added`);\n }\n\n // 3. Create the .bemedev.json file at the root\n\n const jsonConfig = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(\n configFile,\n JSON.stringify(jsonConfig, null, 2),\n 'utf8',\n );\n console.log(`✅ File ${json} created at the root of the project`);\n } catch (error) {\n console.error(`❌ Error creating the file ${json}:`, error);\n return false;\n }\n\n console.log(`🎉 Bemedev initialization completed successfully!`);\n return true;\n};\n"],"mappings":";;;;;;AAsBA,MAAa,wBACX,YACA,sBACG;CACH,MAAM,UAAU,OAAO,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAAS;EAClE,OAAO,IAAI,SAAS,OAAO,KAAK,IAAI,SAAS,WAAW;CAC1D,CAAC;CAED,MAAM,QAAkB,CAAC;CAEzB,QAAQ,IACN,gCAAgC,QAAQ,OAAO,WACjD;CAEA,KAAK,MAAM,GAAG,iBAAiB,SAAS;EACtC,MAAM,OAAO,kBAAkB,cAAc,UAAU;EACvD,IAAI,MAAM,MAAM,KAAK,IAAI;CAC3B;CAEA,QAAQ,IAAI,yCAAyC;CACrD,OAAO;AACT;AAEA,MAAM,cAAc,EAClB,MACA,MACA,OAAO,kBACP,MAAM,uBACW;CACjB,OAAO,MAAM;CACb,OAAO,OAAO;CACd,OAAO,eAAe;CACtB,OAAO,OAAO;CAEd,OAAO;EAAE;EAAM;EAAM;EAAM;CAAI;AACjC;AAEA,MAAa,QACX,mBACA,YACG;CACH,MAAM,EAAE,MAAM,MAAM,MAAM,QAAQ,WAAW,OAAO;CACpD,MAAM,MAAM,QAAQ,IAAI;CACxB,MAAM,aAAa,KAAK,KAAK,IAAI;CAEjC,IADqB,WAAW,UACjB,GAAG,OAAO;CACzB,MAAM,aAAa,cAAc,IAAI;CAGrC,IAAI;EACF,UAAU,YAAY,EAAE,WAAW,KAAK,CAAC;EACzC,QAAQ,IAAI,YAAY,IAAI,eAAe,MAAM;CACnD,SAAS,OAAO;EACd,QAAQ,MAAM,+BAA+B,IAAI,IAAI,KAAK;EAC1D,OAAO;CACT;CAGA,IAAI,QAAkB,CAAC;CAEvB,IAAI;EACF,QAAQ,qBAAqB,YAAY,iBAAiB;CAC5D,QAAQ;EACN,QAAQ,MAAM,uCAAuC;EACrD,OAAO;CACT;CAGA,MAAM,eAAe,KAAK,KAAK,eAAe;CAE9C,IAAI,WAAW,YAAY,GACzB,IAAI;EACF,MAAM,kBAAkB,aAAa,cAAc,MAAM;EACzD,MAAM,WAAW,KAAK,MAAM,eAAe;EAG3C,IAAI,CAAC,SAAS,iBACZ,SAAS,kBAAkB,CAAC;EAG9B,IAAI,CAAC,SAAS,gBAAgB,OAC5B,SAAS,gBAAgB,QAAQ,CAAC;EAIpC,MAAM,eAAe,SAAS,QAAQ,IAAI,GAAG,UAAU;EAEvD,SAAS,gBAAgB,MAAM,QAAQ,CAAC,KAAK,aAAa,GAAG;EAE7D,cACE,cACA,KAAK,UAAU,UAAU,MAAM,CAAC,GAChC,MACF;EACA,QAAQ,IAAI,UAAU,KAAK,wBAAwB;CACrD,SAAS,OAAO;EACd,QAAQ,MAAM,mCAAmC,KAAK;EACtD,OAAO;CACT;MAEA,QAAQ,KAAK,iDAAiD;CAKhE,MAAM,aAAa;EACjB,SAAS;GACR,WAAW,OAAO;GAClB,WAAW,QAAQ;CACtB;CAEA,IAAI;EACF,cACE,YACA,KAAK,UAAU,YAAY,MAAM,CAAC,GAClC,MACF;EACA,QAAQ,IAAI,UAAU,KAAK,oCAAoC;CACjE,SAAS,OAAO;EACd,QAAQ,MAAM,6BAA6B,KAAK,IAAI,KAAK;EACzD,OAAO;CACT;CAEA,QAAQ,IAAI,mDAAmD;CAC/D,OAAO;AACT"}
@@ -45,7 +45,7 @@ const remove = (CODEBASE_ANALYSIS, ...paths) => {
45
45
  return safesToRemove.push(key);
46
46
  });
47
47
  require_helpers.consoleStars();
48
- console.log(`🔧 Deleting of files (${entries.length} files)...`);
48
+ console.log(`🔧 Deletion of files (${entries.length} files)...`);
49
49
  if (cannotsRemove.length > 0) {
50
50
  const len = cannotsRemove.length;
51
51
  console.warn(`⚠️ ${len} ${len === 1 ? "file cannot be deleted (imported in other files)" : "files cannot be deleted (imported in other files)"} :`);
@@ -59,7 +59,7 @@ const remove = (CODEBASE_ANALYSIS, ...paths) => {
59
59
  return require_helpers.consoleStars();
60
60
  }
61
61
  const formatteds = safesToRemove.map((key) => {
62
- const _path = CODEBASE_ANALYSIS[`${key.replaceAll(".", "/")}`].relativePath;
62
+ const _path = CODEBASE_ANALYSIS[key].relativePath;
63
63
  return [key, (0, path.join)(root, _path)];
64
64
  });
65
65
  console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);
@@ -1 +1 @@
1
- {"version":3,"file":"remove.cjs","names":["transformModule","config","getFolderPath","PATH_PROPERTY","FILES_PROPERTY","consoleStars","path"],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} 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`]) // Add .index variants\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, config.json);\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 // Check dependencies before deletion\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(`🔧 Deleting of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path =\n CODEBASE_ANALYSIS[`${key.replaceAll('.', '/')}`].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\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(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,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CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,gBAAA,aAAa;EACb,OAAO;CACT;CACA,gBAAA,aAAa;CACb,OAAO;AACT"}
1
+ {"version":3,"file":"remove.cjs","names":["transformModule","config","getFolderPath","PATH_PROPERTY","FILES_PROPERTY","consoleStars","path"],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} 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`]) // Add .index variants\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, config.json);\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 // Check dependencies before deletion\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(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\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(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,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.ts","sourceRoot":"","sources":["../../src/functions/remove.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,YAAY,CAAC;AA+B5D,eAAO,MAAM,MAAM,GACjB,mBAAmB,gBAAgB,EACnC,GAAG,OAAO,MAAM,EAAE,mBAkGnB,CAAC"}
1
+ {"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../src/functions/remove.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,YAAY,CAAC;AA+B5D,eAAO,MAAM,MAAM,GACjB,mBAAmB,gBAAgB,EACnC,GAAG,OAAO,MAAM,EAAE,mBAiGnB,CAAC"}
@@ -42,7 +42,7 @@ const remove = (CODEBASE_ANALYSIS, ...paths) => {
42
42
  return safesToRemove.push(key);
43
43
  });
44
44
  consoleStars();
45
- console.log(`🔧 Deleting of files (${entries.length} files)...`);
45
+ console.log(`🔧 Deletion of files (${entries.length} files)...`);
46
46
  if (cannotsRemove.length > 0) {
47
47
  const len = cannotsRemove.length;
48
48
  console.warn(`⚠️ ${len} ${len === 1 ? "file cannot be deleted (imported in other files)" : "files cannot be deleted (imported in other files)"} :`);
@@ -56,7 +56,7 @@ const remove = (CODEBASE_ANALYSIS, ...paths) => {
56
56
  return consoleStars();
57
57
  }
58
58
  const formatteds = safesToRemove.map((key) => {
59
- const _path = CODEBASE_ANALYSIS[`${key.replaceAll(".", "/")}`].relativePath;
59
+ const _path = CODEBASE_ANALYSIS[key].relativePath;
60
60
  return [key, join(root, _path)];
61
61
  });
62
62
  console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);
@@ -1 +1 @@
1
- {"version":3,"file":"remove.js","names":[],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} 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`]) // Add .index variants\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, config.json);\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 // Check dependencies before deletion\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(`🔧 Deleting of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path =\n CODEBASE_ANALYSIS[`${key.replaceAll('.', '/')}`].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\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(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;AAYA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;GAC5B,OAAO,gBAAgB;IACrB;IACA;IACA;GACF,CAAC;EACH,CAAC,CAAC,CACD,KAAI,UAAS,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,CACvC,KAAK,CAAC,CACN,QAAO,MAAK,MAAM,SAAS,CAAC,CAAC;EAEhC,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,UAAU,CAAC,CAAC;CAC9C,CAEO;AACX;AAEA,MAAa,UACX,mBACA,GAAG,UACA;CAEH,IADgB,MAAM,WAAW,GACpB,O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4B;GACzC,OAAO,aAAa;EACtB;EAEA,MAAM,aAAa,cAAc,KAAI,QAAO;GAC1C,MAAM,QACJ,kBAAkB,GAAG,IAAI,WAAW,KAAK,GAAG,IAAI,CAAC;GAEnD,OAAO,CAAC,KADS,KAAK,MAAM,KACR,CAAC;EACvB,CAAC;EAED,QAAQ,IAAI,uBAAuB,cAAc,OAAO,WAAW;EAEnE,IAAI,UAAU;EACd,MAAM,SAAS,WAAW;EAE1B,WAAW,SAAS,CAAC,KAAK,UAAU;GAClC,IAAI;IACF,WAAW,IAAI;IACf,QAAQ,IAAI,WAAW,KAAK;IAC5B,MAAM,IACJ,gBACA,MAAM,QAAO,SAAQ,SAAS,GAAG,CACnC;IACA;GACF,QAAQ;IACN,QAAQ,MAAM,gBAAgB,IAAI,GAAG;GACvC;EACF,CAAC;EAED,KAAK,KAAK;EACV,QAAQ,IAAI,uBAAuB,QAAQ,GAAG,OAAO,EAAE;EACvD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,aAAa;EACb,OAAO;CACT;CACA,aAAa;CACb,OAAO;AACT"}
1
+ {"version":3,"file":"remove.js","names":[],"sources":["../../src/functions/remove.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { unlinkSync } from 'fs';\nimport { join } from 'path';\nimport { config } from '../config';\nimport { FILES_PROPERTY, PATH_PROPERTY } from '../constants';\nimport {\n consoleStars,\n getFolderPath,\n transformModule,\n} 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`]) // Add .index variants\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, config.json);\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 // Check dependencies before deletion\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(`🔧 Deletion of files (${entries.length} files)...`);\n\n // Display files that cannot be deleted\n if (cannotsRemove.length > 0) {\n const len = cannotsRemove.length;\n const one = 'file cannot be deleted (imported in other files)';\n const many = 'files cannot be deleted (imported in other files)';\n\n console.warn(`⚠️ ${len} ${len === 1 ? one : many} :`);\n cannotsRemove.forEach(([key, modules]) => {\n console.warn(` - ⚠️ ${key} imported by:`);\n modules.forEach(m => console.warn(` -> 📌 ${m}`));\n });\n }\n\n if (safesToRemove.length === 0) {\n console.warn('❌ No files can be deleted.');\n return consoleStars();\n }\n\n const formatteds = safesToRemove.map(key => {\n const _path = CODEBASE_ANALYSIS[key].relativePath;\n const absolute = join(root, _path);\n return [key, absolute] as const;\n });\n\n console.log(`🗑️ Deleting files (${safesToRemove.length} files)...`);\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(` - ❌ Error, ${key} :`);\n }\n });\n\n file.save();\n console.log(`🗑️ Files deleted! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`❌ Error while deleting files`);\n consoleStars();\n return false;\n }\n consoleStars();\n return true;\n};\n"],"mappings":";;;;;;;AAYA,MAAM,oBACJ,SACA,GAAG,UACA;CACH,MAAM,MAAM,QAAQ,IAAI;CAsBxB,OArBY,QACT,KACE,CAAC,KAAK,EAAE,SAAS,oBAChB;EAAC;EAAK;EAAc;CAAO,CAC/B,CAAC,CACA,KAAK,CAAC,KAAK,cAAc,aAAa;EACrC,MAAM,aAAa,QAChB,KAAK,EAAE,sBAAsB;GAC5B,OAAO,gBAAgB;IACrB;IACA;IACA;GACF,CAAC;EACH,CAAC,CAAC,CACD,KAAI,UAAS,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,CAAC,CACvC,KAAK,CAAC,CACN,QAAO,MAAK,MAAM,SAAS,CAAC,CAAC;EAEhC,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,IAAI,UAAU,CAAC,CAAC;CAC9C,CAEO;AACX;AAEA,MAAa,UACX,mBACA,GAAG,UACA;CAEH,IADgB,MAAM,WAAW,GACpB,OAAO,QAAQ,KAAK,iCAAiC;CAClE,IAAI;EAGF,IAAI,OAA+B,KADtB,KADD,QAAQ,IACA,GAAG,OAAO,IACa,CAAC;EAE5C,IAAI,CAAC,MAAM;EAEX,MAAM,OAAO,cAAc,KAAK,IAAI,aAAa,CAAW;EAC5D,MAAM,QAAQ,KAAK,IAAI,cAAc;EAErC,MAAM,WAAW,OAAO,QAAQ,iBAAiB,CAAC,CAAC,QAAQ,CAAC,SAC1D,MAAM,SAAS,GAAG,CACpB;EAEA,MAAM,UAAU,SAAS,QAAQ,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K;IAC5B,MAAM,IACJ,gBACA,MAAM,QAAO,SAAQ,SAAS,GAAG,CACnC;IACA;GACF,QAAQ;IACN,QAAQ,MAAM,gBAAgB,IAAI,GAAG;GACvC;EACF,CAAC;EAED,KAAK,KAAK;EACV,QAAQ,IAAI,uBAAuB,QAAQ,GAAG,OAAO,EAAE;EACvD,OAAO,KAAA;CACT,QAAQ;EACN,QAAQ,MAAM,8BAA8B;EAC5C,aAAa;EACb,OAAO;CACT;CACA,aAAa;CACb,OAAO;AACT"}
package/lib/helpers.cjs CHANGED
@@ -4,7 +4,13 @@ let path = require("path");
4
4
  let fs = require("fs");
5
5
  //#region src/helpers.ts
6
6
  const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier }) => {
7
- return (0, path.relative)(cwd, (0, path.resolve)((0, path.dirname)(relativePath), moduleSpecifier)).replaceAll("/", ".");
7
+ return (0, path.relative)(cwd, (0, path.resolve)((0, path.dirname)(relativePath), moduleSpecifier));
8
+ };
9
+ const pathToJsonKey = (relativePath, name) => {
10
+ const parts = relativePath.split("/");
11
+ parts.pop();
12
+ parts.push(name);
13
+ return parts.join("/");
8
14
  };
9
15
  const writeFileAnalysis = (fileAnalysis, folderPath) => {
10
16
  const relativePath = fileAnalysis.relativePath;
@@ -18,7 +24,7 @@ const writeFileAnalysis = (fileAnalysis, folderPath) => {
18
24
  });
19
25
  (0, fs.writeFileSync)(destPath, fileContent, "utf8");
20
26
  console.log(` ✅ ${relativePath}`);
21
- return parsed.name.replaceAll("/", ".");
27
+ return pathToJsonKey(relativePath, parsed.name);
22
28
  } catch (error) {
23
29
  return console.error(` ❌ Error for ${relativePath}:`, error);
24
30
  }
@@ -38,6 +44,7 @@ const getFolderPath = (root) => {
38
44
  //#endregion
39
45
  exports.consoleStars = consoleStars;
40
46
  exports.getFolderPath = getFolderPath;
47
+ exports.pathToJsonKey = pathToJsonKey;
41
48
  exports.toArray = toArray;
42
49
  exports.transformModule = transformModule;
43
50
  exports.writeFileAnalysis = writeFileAnalysis;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { dirname, join, relative, resolve, parse } from '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 // Create the destination path in .bemedev maintaining the structure\n const destPath = join(folderPath, relativePath);\n const parsed = parse(destPath);\n\n try {\n // Create the destination folder if necessary\n mkdirSync(parsed.dir, { recursive: true });\n let fileContent = fileAnalysis.text;\n\n REPLACERS.init.forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Write the types file content\n writeFileSync(destPath, fileContent, 'utf8');\n console.log(` ✅ ${relativePath}`);\n const out = parsed.name.replaceAll('/', '.');\n return out;\n } catch (error) {\n return console.error(` ❌ Error for ${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\n ? join(cwd, 'src', root)\n : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,IAAI,GAClB,cACA,sBACyB;CAMzB,QAAA,GAAA,KAAA,SAAA,CAJE,MAAA,GAAA,KAA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import { dirname, join, relative, resolve, parse } from '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 );\n\n return out;\n};\n\nexport const pathToJsonKey = (relativePath: string, name: string) => {\n const parts = relativePath.split('/');\n parts.pop();\n parts.push(name);\n return parts.join('/');\n};\n\nexport const writeFileAnalysis = (\n fileAnalysis: FileAnalysis,\n folderPath: string,\n) => {\n const relativePath = fileAnalysis.relativePath;\n // Create the destination path in root maintaining the structure\n const destPath = join(folderPath, relativePath);\n const parsed = parse(destPath);\n\n try {\n // Create the destination folder if necessary\n mkdirSync(parsed.dir, { recursive: true });\n let fileContent = fileAnalysis.text;\n\n REPLACERS.init.forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Write the types file content\n writeFileSync(destPath, fileContent, 'utf8');\n console.log(` ✅ ${relativePath}`);\n return pathToJsonKey(relativePath, parsed.name);\n } catch (error) {\n return console.error(` ❌ Error for ${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\n ? join(cwd, 'src', root)\n : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,IAAI,GAClB,cACA,sBACyB;CAMzB,QAAA,GAAA,KAAA,SAAA,CAJE,MAAA,GAAA,KAAA,QAAA,EAAA,GAAA,KAAA,QAAA,CACgB,YAAY,GAAG,eA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,7 @@ export type TransformModuleArgs = {
5
5
  moduleSpecifier: string;
6
6
  };
7
7
  export declare const transformModule: ({ cwd, relativePath, moduleSpecifier, }: TransformModuleArgs) => string;
8
+ export declare const pathToJsonKey: (relativePath: string, name: string) => string;
8
9
  export declare const writeFileAnalysis: (fileAnalysis: FileAnalysis, folderPath: string) => string | void;
9
10
  export declare const consoleStars: () => void;
10
11
  export declare const toArray: <T>(value?: T | T[]) => T[];
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,yCAI7B,mBAAmB,WAOrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,cAAc,YAAY,EAC1B,YAAY,MAAM,kBAwBnB,CAAC;AAEF,eAAO,MAAM,YAAY,YAIxB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAG,CAAC,EAE7C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,WAQzC,CAAC"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,yCAI7B,mBAAmB,WAOrB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,cAAc,MAAM,EAAE,MAAM,MAAM,WAK/D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,cAAc,YAAY,EAC1B,YAAY,MAAM,kBAuBnB,CAAC;AAEF,eAAO,MAAM,YAAY,YAIxB,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAG,CAAC,EAE7C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,WAQzC,CAAC"}
package/lib/helpers.js CHANGED
@@ -3,7 +3,13 @@ import { dirname, join, parse, relative, resolve } from "path";
3
3
  import { existsSync, mkdirSync, writeFileSync } from "fs";
4
4
  //#region src/helpers.ts
5
5
  const transformModule = ({ cwd = process.cwd(), relativePath, moduleSpecifier }) => {
6
- return relative(cwd, resolve(dirname(relativePath), moduleSpecifier)).replaceAll("/", ".");
6
+ return relative(cwd, resolve(dirname(relativePath), moduleSpecifier));
7
+ };
8
+ const pathToJsonKey = (relativePath, name) => {
9
+ const parts = relativePath.split("/");
10
+ parts.pop();
11
+ parts.push(name);
12
+ return parts.join("/");
7
13
  };
8
14
  const writeFileAnalysis = (fileAnalysis, folderPath) => {
9
15
  const relativePath = fileAnalysis.relativePath;
@@ -17,7 +23,7 @@ const writeFileAnalysis = (fileAnalysis, folderPath) => {
17
23
  });
18
24
  writeFileSync(destPath, fileContent, "utf8");
19
25
  console.log(` ✅ ${relativePath}`);
20
- return parsed.name.replaceAll("/", ".");
26
+ return pathToJsonKey(relativePath, parsed.name);
21
27
  } catch (error) {
22
28
  return console.error(` ❌ Error for ${relativePath}:`, error);
23
29
  }
@@ -35,6 +41,6 @@ const getFolderPath = (root) => {
35
41
  return existsSync(join(cwd, "src")) ? join(cwd, "src", root) : join(cwd, root);
36
42
  };
37
43
  //#endregion
38
- export { consoleStars, getFolderPath, toArray, transformModule, writeFileAnalysis };
44
+ export { consoleStars, getFolderPath, pathToJsonKey, toArray, transformModule, writeFileAnalysis };
39
45
 
40
46
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { dirname, join, relative, resolve, parse } from '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 // Create the destination path in .bemedev maintaining the structure\n const destPath = join(folderPath, relativePath);\n const parsed = parse(destPath);\n\n try {\n // Create the destination folder if necessary\n mkdirSync(parsed.dir, { recursive: true });\n let fileContent = fileAnalysis.text;\n\n REPLACERS.init.forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Write the types file content\n writeFileSync(destPath, fileContent, 'utf8');\n console.log(` ✅ ${relativePath}`);\n const out = parsed.name.replaceAll('/', '.');\n return out;\n } catch (error) {\n return console.error(` ❌ Error for ${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\n ? join(cwd, 'src', root)\n : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,IAAI,GAClB,cACA,sBACyB;CAMzB,OALY,SACV,KACA,QAAQ,QAAQ,YAAY,GAAG,eAAe,CAChD,CAAC,CAAC,WAAW,KAAK,GAET;AACX;AAEA,MAAa,qBACX,cACA,eACG;CACH,MAAM,eAAe,aAAa;CAElC,MAAM,WAAW,KAAK,YAAY,YAAY;CAC9C,MAAM,SAAS,MAAM,QAAQ;CAE7B,IAAI;EAEF,UAAU,OAAO,KAAK,EAAE,WAAW,KAAK,CAAC;EACzC,IAAI,cAAc,aAAa;EAE/B,UAAU,KAAK,SAAS,CAAC,QAAQ,aAAa;GAC5C,cAAc,YAAY,WAAW,QAAQ,OAAO;EACtD,CAAC;EAGD,cAAc,UAAU,aAAa,MAAM;EAC3C,QAAQ,IAAI,OAAO,cAAc;EAEjC,OADY,OAAO,KAAK,WAAW,KAAK,GAC/B;CACX,SAAS,OAAO;EACd,OAAO,QAAQ,MAAM,iBAAiB,aAAa,IAAI,KAAK;CAC9D;AACF;AAEA,MAAa,qBAAqB;CAChC,QAAQ,IAAI;CACZ,QAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;CAC1B,QAAQ,IAAI;AACd;AAEA,MAAa,WAAc,UAAyB;CAClD,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK;AAC5D;AAEA,MAAa,iBAAiB,SAAiB;CAC7C,MAAM,MAAM,QAAQ,IAAI;CAMxB,OALkB,WAAW,KAAK,KAAK,KAAK,CACjB,IACvB,KAAK,KAAK,OAAO,IAAI,IACrB,KAAK,KAAK,IAAI;AAGpB"}
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { dirname, join, relative, resolve, parse } from '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 );\n\n return out;\n};\n\nexport const pathToJsonKey = (relativePath: string, name: string) => {\n const parts = relativePath.split('/');\n parts.pop();\n parts.push(name);\n return parts.join('/');\n};\n\nexport const writeFileAnalysis = (\n fileAnalysis: FileAnalysis,\n folderPath: string,\n) => {\n const relativePath = fileAnalysis.relativePath;\n // Create the destination path in root maintaining the structure\n const destPath = join(folderPath, relativePath);\n const parsed = parse(destPath);\n\n try {\n // Create the destination folder if necessary\n mkdirSync(parsed.dir, { recursive: true });\n let fileContent = fileAnalysis.text;\n\n REPLACERS.init.forEach(([search, replace]) => {\n fileContent = fileContent.replaceAll(search, replace);\n });\n\n // Write the types file content\n writeFileSync(destPath, fileContent, 'utf8');\n console.log(` ✅ ${relativePath}`);\n return pathToJsonKey(relativePath, parsed.name);\n } catch (error) {\n return console.error(` ❌ Error for ${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\n ? join(cwd, 'src', root)\n : join(cwd, root);\n\n return folderPath;\n};\n"],"mappings":";;;;AAWA,MAAa,mBAAmB,EAC9B,MAAM,QAAQ,IAAI,GAClB,cACA,sBACyB;CAMzB,OALY,SACV,KACA,QAAQ,QAAQ,YAAY,GAAG,eAAe,CAGvC;AACX;AAEA,MAAa,iBAAiB,cAAsB,SAAiB;CACnE,MAAM,QAAQ,aAAa,MAAM,GAAG;CACpC,MAAM,IAAI;CACV,MAAM,KAAK,IAAI;CACf,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,MAAa,qBACX,cACA,eACG;CACH,MAAM,eAAe,aAAa;CAElC,MAAM,WAAW,KAAK,YAAY,YAAY;CAC9C,MAAM,SAAS,MAAM,QAAQ;CAE7B,IAAI;EAEF,UAAU,OAAO,KAAK,EAAE,WAAW,KAAK,CAAC;EACzC,IAAI,cAAc,aAAa;EAE/B,UAAU,KAAK,SAAS,CAAC,QAAQ,aAAa;GAC5C,cAAc,YAAY,WAAW,QAAQ,OAAO;EACtD,CAAC;EAGD,cAAc,UAAU,aAAa,MAAM;EAC3C,QAAQ,IAAI,OAAO,cAAc;EACjC,OAAO,cAAc,cAAc,OAAO,IAAI;CAChD,SAAS,OAAO;EACd,OAAO,QAAQ,MAAM,iBAAiB,aAAa,IAAI,KAAK;CAC9D;AACF;AAEA,MAAa,qBAAqB;CAChC,QAAQ,IAAI;CACZ,QAAQ,IAAI,IAAI,OAAO,EAAE,CAAC;CAC1B,QAAQ,IAAI;AACd;AAEA,MAAa,WAAc,UAAyB;CAClD,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK;AAC5D;AAEA,MAAa,iBAAiB,SAAiB;CAC7C,MAAM,MAAM,QAAQ,IAAI;CAMxB,OALkB,WAAW,KAAK,KAAK,KAAK,CACjB,IACvB,KAAK,KAAK,OAAO,IAAI,IACrB,KAAK,KAAK,IAAI;AAGpB"}
package/lib/utils.cjs CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
5
5
  * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'
6
6
  */
7
7
  function pathToDotNotation(filePath) {
8
- return filePath.replace(/\.ts$/, "").replace(/\.tsx$/, "").replace(/\//g, ".");
8
+ return filePath.replace(/\.ts$/, "").replace(/\.tsx$/, "");
9
9
  }
10
10
  //#endregion
11
11
  exports.pathToDotNotation = pathToDotNotation;
package/lib/utils.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Converts a file path to a dot notation key as in .manifest.ts\n * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'\n */\nexport function pathToDotNotation(filePath: string): string {\n return filePath\n .replace(/\\.ts$/, '') // Remove the .ts extension\n .replace(/\\.tsx$/, '') // Remove the .tsx extension\n .replace(/\\//g, '.'); // Replace / with .\n}\n"],"mappings":";;;;;;AAIA,SAAgB,kBAAkB,UAA0B;CAC1D,OAAO,SACJ,QAAQ,SAAS,EAAE,CAAC,CACpB,QAAQ,UAAU,EAAE,CAAC,CACrB,QAAQ,OAAO,GAAG;AACvB"}
1
+ {"version":3,"file":"utils.cjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Converts a file path to a dot notation key as in .manifest.ts\n * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'\n */\nexport function pathToDotNotation(filePath: string): string {\n return filePath\n .replace(/\\.ts$/, '') // Remove the .ts extension\n .replace(/\\.tsx$/, ''); // Remove the .tsx extension\n}\n"],"mappings":";;;;;;AAIA,SAAgB,kBAAkB,UAA0B;CAC1D,OAAO,SACJ,QAAQ,SAAS,EAAE,CAAC,CACpB,QAAQ,UAAU,EAAE;AACzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK1D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI1D"}
package/lib/utils.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'
5
5
  */
6
6
  function pathToDotNotation(filePath) {
7
- return filePath.replace(/\.ts$/, "").replace(/\.tsx$/, "").replace(/\//g, ".");
7
+ return filePath.replace(/\.ts$/, "").replace(/\.tsx$/, "");
8
8
  }
9
9
  //#endregion
10
10
  export { pathToDotNotation };
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Converts a file path to a dot notation key as in .manifest.ts\n * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'\n */\nexport function pathToDotNotation(filePath: string): string {\n return filePath\n .replace(/\\.ts$/, '') // Remove the .ts extension\n .replace(/\\.tsx$/, '') // Remove the .tsx extension\n .replace(/\\//g, '.'); // Replace / with .\n}\n"],"mappings":";;;;;AAIA,SAAgB,kBAAkB,UAA0B;CAC1D,OAAO,SACJ,QAAQ,SAAS,EAAE,CAAC,CACpB,QAAQ,UAAU,EAAE,CAAC,CACrB,QAAQ,OAAO,GAAG;AACvB"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Converts a file path to a dot notation key as in .manifest.ts\n * Ex: 'features/arrays/castings/all.ts' -> 'features.arrays.castings.all'\n */\nexport function pathToDotNotation(filePath: string): string {\n return filePath\n .replace(/\\.ts$/, '') // Remove the .ts extension\n .replace(/\\.tsx$/, ''); // Remove the .tsx extension\n}\n"],"mappings":";;;;;AAIA,SAAgB,kBAAkB,UAA0B;CAC1D,OAAO,SACJ,QAAQ,SAAS,EAAE,CAAC,CACpB,QAAQ,UAAU,EAAE;AACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemedev/codebase",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "The CLI for to generate codebase, and import partially a library. From @bemedev.",
5
5
  "author": {
6
6
  "email": "bri_lvi@icloud.com",