@bemedev/codebase 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/lib/analyse.cjs +68 -0
- package/lib/analyse.cjs.map +1 -0
- package/lib/analyse.d.ts +10 -0
- package/lib/analyse.d.ts.map +1 -0
- package/lib/analyse.js +66 -0
- package/lib/analyse.js.map +1 -0
- package/lib/analyse.utils.cjs +240 -0
- package/lib/analyse.utils.cjs.map +1 -0
- package/lib/analyse.utils.d.ts +30 -0
- package/lib/analyse.utils.d.ts.map +1 -0
- package/lib/analyse.utils.js +232 -0
- package/lib/analyse.utils.js.map +1 -0
- package/lib/cli/cli.cjs +27 -0
- package/lib/cli/cli.cjs.map +1 -0
- package/lib/cli/cli.d.ts +12 -0
- package/lib/cli/cli.d.ts.map +1 -0
- package/lib/cli/cli.js +25 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/constants.cjs +6 -0
- package/lib/cli/constants.cjs.map +1 -0
- package/lib/cli/constants.d.ts +2 -0
- package/lib/cli/constants.d.ts.map +1 -0
- package/lib/cli/constants.js +4 -0
- package/lib/cli/constants.js.map +1 -0
- package/lib/cli/index.cjs +8 -0
- package/lib/cli/index.cjs.map +1 -0
- package/lib/cli/index.d.ts +3 -0
- package/lib/cli/index.d.ts.map +1 -0
- package/lib/cli/index.js +6 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/constants.cjs +40 -0
- package/lib/constants.cjs.map +1 -0
- package/lib/constants.d.ts +17 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +31 -0
- package/lib/constants.js.map +1 -0
- package/lib/exports.cjs +75 -0
- package/lib/exports.cjs.map +1 -0
- package/lib/exports.d.ts +4 -0
- package/lib/exports.d.ts.map +1 -0
- package/lib/exports.js +73 -0
- package/lib/exports.js.map +1 -0
- package/lib/functions/add.cjs +85 -0
- package/lib/functions/add.cjs.map +1 -0
- package/lib/functions/add.d.ts +3 -0
- package/lib/functions/add.d.ts.map +1 -0
- package/lib/functions/add.js +83 -0
- package/lib/functions/add.js.map +1 -0
- package/lib/functions/generate.cjs +61 -0
- package/lib/functions/generate.cjs.map +1 -0
- package/lib/functions/generate.d.ts +25 -0
- package/lib/functions/generate.d.ts.map +1 -0
- package/lib/functions/generate.js +58 -0
- package/lib/functions/generate.js.map +1 -0
- package/lib/functions/index.cjs +16 -0
- package/lib/functions/index.cjs.map +1 -0
- package/lib/functions/index.d.ts +5 -0
- package/lib/functions/index.d.ts.map +1 -0
- package/lib/functions/index.js +5 -0
- package/lib/functions/index.js.map +1 -0
- package/lib/functions/init.cjs +104 -0
- package/lib/functions/init.cjs.map +1 -0
- package/lib/functions/init.d.ts +12 -0
- package/lib/functions/init.d.ts.map +1 -0
- package/lib/functions/init.js +101 -0
- package/lib/functions/init.js.map +1 -0
- package/lib/functions/remove.cjs +108 -0
- package/lib/functions/remove.cjs.map +1 -0
- package/lib/functions/remove.d.ts +3 -0
- package/lib/functions/remove.d.ts.map +1 -0
- package/lib/functions/remove.js +106 -0
- package/lib/functions/remove.js.map +1 -0
- package/lib/helpers.cjs +47 -0
- package/lib/helpers.cjs.map +1 -0
- package/lib/helpers.d.ts +11 -0
- package/lib/helpers.d.ts.map +1 -0
- package/lib/helpers.js +42 -0
- package/lib/helpers.js.map +1 -0
- package/lib/imports.cjs +128 -0
- package/lib/imports.cjs.map +1 -0
- package/lib/imports.d.ts +8 -0
- package/lib/imports.d.ts.map +1 -0
- package/lib/imports.js +125 -0
- package/lib/imports.js.map +1 -0
- package/lib/index.cjs +16 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/schemas.cjs +80 -0
- package/lib/schemas.cjs.map +1 -0
- package/lib/schemas.d.ts +90 -0
- package/lib/schemas.d.ts.map +1 -0
- package/lib/schemas.js +53 -0
- package/lib/schemas.js.map +1 -0
- package/lib/types.d.ts +43 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils.cjs +14 -0
- package/lib/utils.cjs.map +1 -0
- package/lib/utils.d.ts +6 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +12 -0
- package/lib/utils.js.map +1 -0
- package/package.json +125 -0
package/lib/exports.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SyntaxKind } from 'ts-morph';
|
|
2
|
+
|
|
3
|
+
const analyzeExports = (sourceFile) => {
|
|
4
|
+
const exports = [];
|
|
5
|
+
// Export declarations (export ...)
|
|
6
|
+
sourceFile.getExportDeclarations().forEach(exportDecl => {
|
|
7
|
+
const moduleSpecifier = exportDecl.getModuleSpecifierValue();
|
|
8
|
+
const exportText = exportDecl.getText();
|
|
9
|
+
// Named exports
|
|
10
|
+
const namedExports = exportDecl.getNamedExports();
|
|
11
|
+
namedExports.forEach(namedExport => {
|
|
12
|
+
exports.push({
|
|
13
|
+
name: namedExport.getName(),
|
|
14
|
+
kind: 'named',
|
|
15
|
+
text: exportText,
|
|
16
|
+
moduleSpecifier,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
// Namespace export (export * from '...')
|
|
20
|
+
if (exportDecl.isNamespaceExport()) {
|
|
21
|
+
exports.push({
|
|
22
|
+
name: '*',
|
|
23
|
+
kind: 'namespace',
|
|
24
|
+
text: exportText,
|
|
25
|
+
moduleSpecifier,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
// Export assignments (export = ...)
|
|
30
|
+
sourceFile.getExportAssignments().forEach(exportAssignment => {
|
|
31
|
+
if (exportAssignment.isExportEquals()) {
|
|
32
|
+
exports.push({
|
|
33
|
+
name: 'default',
|
|
34
|
+
kind: 'default',
|
|
35
|
+
text: exportAssignment.getText(),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// Exported declarations (export function, export class, etc.)
|
|
40
|
+
sourceFile.getExportedDeclarations().forEach((declarations, name) => {
|
|
41
|
+
declarations.forEach(decl => {
|
|
42
|
+
let declarationKind;
|
|
43
|
+
if (decl.getKind() === SyntaxKind.FunctionDeclaration) {
|
|
44
|
+
declarationKind = 'function';
|
|
45
|
+
}
|
|
46
|
+
else if (decl.getKind() === SyntaxKind.ClassDeclaration) {
|
|
47
|
+
declarationKind = 'class';
|
|
48
|
+
}
|
|
49
|
+
else if (decl.getKind() === SyntaxKind.InterfaceDeclaration) {
|
|
50
|
+
declarationKind = 'interface';
|
|
51
|
+
}
|
|
52
|
+
else if (decl.getKind() === SyntaxKind.TypeAliasDeclaration) {
|
|
53
|
+
declarationKind = 'type';
|
|
54
|
+
}
|
|
55
|
+
else if (decl.getKind() === SyntaxKind.VariableDeclaration) {
|
|
56
|
+
declarationKind = 'variable';
|
|
57
|
+
}
|
|
58
|
+
else if (decl.getKind() === SyntaxKind.EnumDeclaration) {
|
|
59
|
+
declarationKind = 'enum';
|
|
60
|
+
}
|
|
61
|
+
exports.push({
|
|
62
|
+
name,
|
|
63
|
+
kind: name === 'default' ? 'default' : 'named',
|
|
64
|
+
text: decl.getText(),
|
|
65
|
+
declarationKind,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
return exports;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { analyzeExports };
|
|
73
|
+
//# sourceMappingURL=exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sources":["../src/exports.ts"],"sourcesContent":["import { SourceFile, SyntaxKind } from 'ts-morph';\nimport type { ExportInfo } from './types';\n\nexport const analyzeExports = (sourceFile: SourceFile) => {\n const exports: ExportInfo[] = [];\n\n // Export declarations (export ...)\n sourceFile.getExportDeclarations().forEach(exportDecl => {\n const moduleSpecifier = exportDecl.getModuleSpecifierValue();\n const exportText = exportDecl.getText();\n\n // Named exports\n const namedExports = exportDecl.getNamedExports();\n namedExports.forEach(namedExport => {\n exports.push({\n name: namedExport.getName(),\n kind: 'named',\n text: exportText,\n moduleSpecifier,\n });\n });\n\n // Namespace export (export * from '...')\n if (exportDecl.isNamespaceExport()) {\n exports.push({\n name: '*',\n kind: 'namespace',\n text: exportText,\n moduleSpecifier,\n });\n }\n });\n\n // Export assignments (export = ...)\n sourceFile.getExportAssignments().forEach(exportAssignment => {\n if (exportAssignment.isExportEquals()) {\n exports.push({\n name: 'default',\n kind: 'default',\n text: exportAssignment.getText(),\n });\n }\n });\n\n // Exported declarations (export function, export class, etc.)\n sourceFile.getExportedDeclarations().forEach((declarations, name) => {\n declarations.forEach(decl => {\n let declarationKind: ExportInfo['declarationKind'];\n\n if (decl.getKind() === SyntaxKind.FunctionDeclaration) {\n declarationKind = 'function';\n } else if (decl.getKind() === SyntaxKind.ClassDeclaration) {\n declarationKind = 'class';\n } else if (decl.getKind() === SyntaxKind.InterfaceDeclaration) {\n declarationKind = 'interface';\n } else if (decl.getKind() === SyntaxKind.TypeAliasDeclaration) {\n declarationKind = 'type';\n } else if (decl.getKind() === SyntaxKind.VariableDeclaration) {\n declarationKind = 'variable';\n } else if (decl.getKind() === SyntaxKind.EnumDeclaration) {\n declarationKind = 'enum';\n }\n\n exports.push({\n name,\n kind: name === 'default' ? 'default' : 'named',\n text: decl.getText(),\n declarationKind,\n });\n });\n });\n\n return exports;\n};\n"],"names":[],"mappings":";;AAGO,MAAM,cAAc,GAAG,CAAC,UAAsB,KAAI;IACvD,MAAM,OAAO,GAAiB,EAAE;;IAGhC,UAAU,CAAC,qBAAqB,EAAE,CAAC,OAAO,CAAC,UAAU,IAAG;AACtD,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,uBAAuB,EAAE;AAC5D,QAAA,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,EAAE;;AAGvC,QAAA,MAAM,YAAY,GAAG,UAAU,CAAC,eAAe,EAAE;AACjD,QAAA,YAAY,CAAC,OAAO,CAAC,WAAW,IAAG;YACjC,OAAO,CAAC,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AC,oBAAoB,EAAE;gBAC7D,eAAe,GAAG,MAAM;YAC1B;iBAAO,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,UAAU,CAAC,mBAAmB,EAAE;gBAC5D,eAAe,GAAG,UAAU;YAC9B;iBAAO,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,UAAU,CAAC,eAAe,EAAE;gBACxD,eAAe,GAAG,MAAM;YAC1B;YAEA,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI;gBACJ,IAAI,EAAE,IAAI,KAAK,SAAS,GAAG,SAAS,GAAG,OAAO;AAC9C,gBAAA,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;gBACpB,eAAe;AAChB,aAAA,CAAC;AACJ,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,OAAO;AAChB;;;;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var edit = require('edit-json-file');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var constants = require('../constants.cjs');
|
|
6
|
+
var helpers = require('../helpers.cjs');
|
|
7
|
+
|
|
8
|
+
const processFileAnalysis = (analysis, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS) => {
|
|
9
|
+
const relativePath = analysis.relativePath;
|
|
10
|
+
const keys = Object.keys(CODEBASE_ANALYSIS);
|
|
11
|
+
analysis.imports.forEach(({ moduleSpecifier }) => {
|
|
12
|
+
const _path = path.relative(cwd, path.resolve(path.dirname(relativePath), moduleSpecifier)).replaceAll('/', '.');
|
|
13
|
+
const toAdd = CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];
|
|
14
|
+
if (!toAdd)
|
|
15
|
+
return;
|
|
16
|
+
additionals.push([_path, toAdd]);
|
|
17
|
+
const all = additionals
|
|
18
|
+
.concat(pathsEntries)
|
|
19
|
+
.map(([key]) => key)
|
|
20
|
+
.concat(files);
|
|
21
|
+
const imports = toAdd.imports.filter(({ moduleSpecifier }) => {
|
|
22
|
+
const _path = helpers.transformModule({
|
|
23
|
+
cwd,
|
|
24
|
+
relativePath: toAdd.relativePath,
|
|
25
|
+
moduleSpecifier,
|
|
26
|
+
});
|
|
27
|
+
const array = [_path, `${_path}.index`].filter(p => keys.includes(p));
|
|
28
|
+
if (array.length < 1)
|
|
29
|
+
return false;
|
|
30
|
+
return array.every(p => !all.includes(p));
|
|
31
|
+
});
|
|
32
|
+
const toAdd2 = { ...toAdd, imports };
|
|
33
|
+
const canRecurse = toAdd2.imports.length > 0;
|
|
34
|
+
if (canRecurse) {
|
|
35
|
+
processFileAnalysis(toAdd2, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const add = (CODEBASE_ANALYSIS, ...files) => {
|
|
40
|
+
const isEmpty = files.length === 0;
|
|
41
|
+
if (isEmpty)
|
|
42
|
+
return console.warn('No files specified for addition.');
|
|
43
|
+
try {
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
const json = path.join(cwd, constants.JSON_FILE_NAME);
|
|
46
|
+
let file = edit(json);
|
|
47
|
+
if (!file)
|
|
48
|
+
return;
|
|
49
|
+
const path$1 = file.get(constants.PATH_PROPERTY);
|
|
50
|
+
const files = file.get(constants.FILES_PROPERTY);
|
|
51
|
+
// Release resources
|
|
52
|
+
const additionals = [];
|
|
53
|
+
const pathsEntries = Object.entries(CODEBASE_ANALYSIS)
|
|
54
|
+
.filter(([key]) => files.some(p => key.startsWith(p)))
|
|
55
|
+
.filter(([key]) => !files.includes(key));
|
|
56
|
+
pathsEntries.forEach(([, analysis]) => {
|
|
57
|
+
processFileAnalysis(analysis, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS);
|
|
58
|
+
});
|
|
59
|
+
const entries = new Set(pathsEntries.concat(additionals).filter(([, val]) => !!val));
|
|
60
|
+
helpers.consoleStars();
|
|
61
|
+
console.log(`đ§ CrĂ©ation des fichiers (${entries.size} fichiers)...`);
|
|
62
|
+
let success = 0;
|
|
63
|
+
const length = entries.size;
|
|
64
|
+
entries.forEach(([, fileAnalysis]) => {
|
|
65
|
+
const _path = helpers.writeFileAnalysis(fileAnalysis, path$1);
|
|
66
|
+
if (_path) {
|
|
67
|
+
files.push(_path);
|
|
68
|
+
file?.set(constants.FILES_PROPERTY, files);
|
|
69
|
+
success++;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
file.save();
|
|
73
|
+
console.log(`â
Fichiers créés! (${success}/${length})`);
|
|
74
|
+
file = undefined;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
console.error(`â Erreur lors de la crĂ©ation des fichiers`);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
helpers.consoleStars();
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.add = add;
|
|
85
|
+
//# sourceMappingURL=add.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.cjs","sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport {\n FILES_PROPERTY,\n JSON_FILE_NAME,\n PATH_PROPERTY,\n} from '../constants';\nimport {\n consoleStars,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\nimport type { FileAnalysis, 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 toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\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 ...files: string[]\n) => {\n const isEmpty = files.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, JSON_FILE_NAME);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const path = file.get(PATH_PROPERTY) as string;\n const files = file.get(FILES_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]) => files.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(`đ§ CrĂ©ation des fichiers (${entries.size} fichiers)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, path);\n if (_path) {\n files.push(_path);\n file?.set(FILES_PROPERTY, files);\n success++;\n }\n });\n\n file.save();\n console.log(`â
Fichiers créés! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`â Erreur lors de la crĂ©ation des fichiers`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"names":["relative","resolve","dirname","transformModule","join","JSON_FILE_NAME","path","PATH_PROPERTY","FILES_PROPERTY","consoleStars","writeFileAnalysis"],"mappings":";;;;;;;AAeA,MAAM,mBAAmB,GAAG,CAC1B,QAAwC,EACxC,GAAW,EACX,WAAuD,EACvD,YAAwD,EACxD,KAAe,EACf,iBAAmC,KACjC;AACF,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY;IAE1C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;QAC/C,MAAM,KAAK,GAAGA,aAAQ,CACpB,GAAG,EACHC,YAAO,CAACC,YAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAChD,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;AAEtB,QAAA,MAAM,KAAK,GACT,iBAAiB,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,CAAA,EAAG,KAAK,CAAA,MAAA,CAAQ,CAAC;AACjE,QAAA,IAAI,CAAC,KAAK;YAAE;QAEZ,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAEhC,MAAM,GAAG,GAAG;aACT,MAAM,CAAC,YAAY;aACnB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG;aAClB,MAAM,CAAC,KAAK,CAAC;AAEhB,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;YAC3D,MAAM,KAAK,GAAG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AAC,CAAC;QAEF,IAAI,CAAC,IAAI,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,CAAA,mBAAA,EAAsB,OAAO,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,CAAG,CAAC;QACvD,IAAI,GAAG,SAAS;IAClB;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,CAAC,KAAK,CAAC,CAAA,yCAAA,CAA2C,CAAC;AAC1D,QAAA,OAAO,KAAK;IACd;AAEA,IAAAC,oBAAY,EAAE;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/functions/add.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA+D9C,eAAO,MAAM,GAAG,GACd,mBAAmB,gBAAgB,EACnC,GAAG,OAAO,MAAM,EAAE,mBA8DnB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import edit from 'edit-json-file';
|
|
2
|
+
import { join, relative, resolve, dirname } from 'path';
|
|
3
|
+
import { JSON_FILE_NAME, PATH_PROPERTY, FILES_PROPERTY } from '../constants.js';
|
|
4
|
+
import { consoleStars, writeFileAnalysis, transformModule } from '../helpers.js';
|
|
5
|
+
|
|
6
|
+
const processFileAnalysis = (analysis, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS) => {
|
|
7
|
+
const relativePath = analysis.relativePath;
|
|
8
|
+
const keys = Object.keys(CODEBASE_ANALYSIS);
|
|
9
|
+
analysis.imports.forEach(({ moduleSpecifier }) => {
|
|
10
|
+
const _path = relative(cwd, resolve(dirname(relativePath), moduleSpecifier)).replaceAll('/', '.');
|
|
11
|
+
const toAdd = CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];
|
|
12
|
+
if (!toAdd)
|
|
13
|
+
return;
|
|
14
|
+
additionals.push([_path, toAdd]);
|
|
15
|
+
const all = additionals
|
|
16
|
+
.concat(pathsEntries)
|
|
17
|
+
.map(([key]) => key)
|
|
18
|
+
.concat(files);
|
|
19
|
+
const imports = toAdd.imports.filter(({ moduleSpecifier }) => {
|
|
20
|
+
const _path = transformModule({
|
|
21
|
+
cwd,
|
|
22
|
+
relativePath: toAdd.relativePath,
|
|
23
|
+
moduleSpecifier,
|
|
24
|
+
});
|
|
25
|
+
const array = [_path, `${_path}.index`].filter(p => keys.includes(p));
|
|
26
|
+
if (array.length < 1)
|
|
27
|
+
return false;
|
|
28
|
+
return array.every(p => !all.includes(p));
|
|
29
|
+
});
|
|
30
|
+
const toAdd2 = { ...toAdd, imports };
|
|
31
|
+
const canRecurse = toAdd2.imports.length > 0;
|
|
32
|
+
if (canRecurse) {
|
|
33
|
+
processFileAnalysis(toAdd2, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const add = (CODEBASE_ANALYSIS, ...files) => {
|
|
38
|
+
const isEmpty = files.length === 0;
|
|
39
|
+
if (isEmpty)
|
|
40
|
+
return console.warn('No files specified for addition.');
|
|
41
|
+
try {
|
|
42
|
+
const cwd = process.cwd();
|
|
43
|
+
const json = join(cwd, JSON_FILE_NAME);
|
|
44
|
+
let file = edit(json);
|
|
45
|
+
if (!file)
|
|
46
|
+
return;
|
|
47
|
+
const path = file.get(PATH_PROPERTY);
|
|
48
|
+
const files = file.get(FILES_PROPERTY);
|
|
49
|
+
// Release resources
|
|
50
|
+
const additionals = [];
|
|
51
|
+
const pathsEntries = Object.entries(CODEBASE_ANALYSIS)
|
|
52
|
+
.filter(([key]) => files.some(p => key.startsWith(p)))
|
|
53
|
+
.filter(([key]) => !files.includes(key));
|
|
54
|
+
pathsEntries.forEach(([, analysis]) => {
|
|
55
|
+
processFileAnalysis(analysis, cwd, additionals, pathsEntries, files, CODEBASE_ANALYSIS);
|
|
56
|
+
});
|
|
57
|
+
const entries = new Set(pathsEntries.concat(additionals).filter(([, val]) => !!val));
|
|
58
|
+
consoleStars();
|
|
59
|
+
console.log(`đ§ CrĂ©ation des fichiers (${entries.size} fichiers)...`);
|
|
60
|
+
let success = 0;
|
|
61
|
+
const length = entries.size;
|
|
62
|
+
entries.forEach(([, fileAnalysis]) => {
|
|
63
|
+
const _path = writeFileAnalysis(fileAnalysis, path);
|
|
64
|
+
if (_path) {
|
|
65
|
+
files.push(_path);
|
|
66
|
+
file?.set(FILES_PROPERTY, files);
|
|
67
|
+
success++;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
file.save();
|
|
71
|
+
console.log(`â
Fichiers créés! (${success}/${length})`);
|
|
72
|
+
file = undefined;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
console.error(`â Erreur lors de la crĂ©ation des fichiers`);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
consoleStars();
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export { add };
|
|
83
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","sources":["../../src/functions/add.ts"],"sourcesContent":["import edit, { JsonEditor } from 'edit-json-file';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport {\n FILES_PROPERTY,\n JSON_FILE_NAME,\n PATH_PROPERTY,\n} from '../constants';\nimport {\n consoleStars,\n transformModule,\n writeFileAnalysis,\n} from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\nimport type { FileAnalysis, 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 toAdd =\n CODEBASE_ANALYSIS[_path] ?? CODEBASE_ANALYSIS[`${_path}.index`];\n if (!toAdd) return;\n\n additionals.push([_path, toAdd]);\n\n const all = additionals\n .concat(pathsEntries)\n .map(([key]) => key)\n .concat(files);\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 ...files: string[]\n) => {\n const isEmpty = files.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, JSON_FILE_NAME);\n let file: JsonEditor | undefined = edit(json);\n\n if (!file) return;\n\n const path = file.get(PATH_PROPERTY) as string;\n const files = file.get(FILES_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]) => files.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(`đ§ CrĂ©ation des fichiers (${entries.size} fichiers)...`);\n\n let success = 0;\n const length = entries.size;\n\n entries.forEach(([, fileAnalysis]) => {\n const _path = writeFileAnalysis(fileAnalysis, path);\n if (_path) {\n files.push(_path);\n file?.set(FILES_PROPERTY, files);\n success++;\n }\n });\n\n file.save();\n console.log(`â
Fichiers créés! (${success}/${length})`);\n file = undefined;\n } catch {\n console.error(`â Erreur lors de la crĂ©ation des fichiers`);\n return false;\n }\n\n consoleStars();\n return true;\n};\n"],"names":[],"mappings":";;;;;AAeA,MAAM,mBAAmB,GAAG,CAC1B,QAAwC,EACxC,GAAW,EACX,WAAuD,EACvD,YAAwD,EACxD,KAAe,EACf,iBAAmC,KACjC;AACF,IAAA,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY;IAE1C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;QAC/C,MAAM,KAAK,GAAG,QAAQ,CACpB,GAAG,EACH,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,CAChD,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;AAEtB,QAAA,MAAM,KAAK,GACT,iBAAiB,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,CAAA,EAAG,KAAK,CAAA,MAAA,CAAQ,CAAC;AACjE,QAAA,IAAI,CAAC,KAAK;YAAE;QAEZ,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAEhC,MAAM,GAAG,GAAG;aACT,MAAM,CAAC,YAAY;aACnB,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG;aAClB,MAAM,CAAC,KAAK,CAAC;AAEhB,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,eAAe,EAAE,KAAI;YAC3D,MAAM,KAAK,GAAG,eAAe,CAAC;gBAC5B,GAAG;gBACH,YAAY,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,GAAG,CAAC,CAAA,mBAAA,EAAsB,OAAO,CAAA,CAAA,EAAI,MAAM,CAAA,CAAA,CAAG,CAAC;QACvD,IAAI,GAAG,SAAS;IAClB;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,CAAC,KAAK,CAAC,CAAA,yCAAA,CAA2C,CAAC;AAC1D,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,YAAY,EAAE;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var constants = require('../constants.cjs');
|
|
6
|
+
var analyse = require('../analyse.cjs');
|
|
7
|
+
|
|
8
|
+
const transformJSON = (data) => {
|
|
9
|
+
let imports = 0;
|
|
10
|
+
let exports = 0;
|
|
11
|
+
let files = 0;
|
|
12
|
+
const entries = Object.entries(data).map(([key, { imports: _imports, relativePath, text, exports: _exports },]) => {
|
|
13
|
+
imports += _imports.length;
|
|
14
|
+
exports += _exports.length;
|
|
15
|
+
files++;
|
|
16
|
+
const value = {
|
|
17
|
+
imports: _imports,
|
|
18
|
+
relativePath,
|
|
19
|
+
text,
|
|
20
|
+
};
|
|
21
|
+
return [key, value];
|
|
22
|
+
});
|
|
23
|
+
const CODEBASE_ANALYSIS = Object.fromEntries(entries);
|
|
24
|
+
const STATS = {
|
|
25
|
+
files,
|
|
26
|
+
imports,
|
|
27
|
+
exports,
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
STATS,
|
|
31
|
+
CODEBASE_ANALYSIS,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Fonction principale d'exécution
|
|
36
|
+
*/
|
|
37
|
+
const generate = ({ output = constants.CODEBASE_FILE, excludes, src = constants.SRC_DIR, } = {}) => {
|
|
38
|
+
const _output = output.endsWith('codebase.json')
|
|
39
|
+
? output
|
|
40
|
+
: `${output}.codebase.json`;
|
|
41
|
+
try {
|
|
42
|
+
const analysis = analyse.analyze({ src, excludes });
|
|
43
|
+
const transformed = transformJSON(analysis);
|
|
44
|
+
const json = JSON.stringify(transformed, null, 2);
|
|
45
|
+
fs.writeFileSync(_output, json);
|
|
46
|
+
console.log(`đ Analyse sauvegardĂ©e dans: ${path.relative(process.cwd(), _output)}`);
|
|
47
|
+
console.log(`đ Statistiques:`);
|
|
48
|
+
console.log(` - Fichiers analysés: ${transformed.STATS.files}`);
|
|
49
|
+
console.log(` - Total imports: ${transformed.STATS.imports}`);
|
|
50
|
+
console.log(` - Total exports: ${transformed.STATS.exports}`);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error("â Erreur lors de l'analyse du codebase:", error);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.generate = generate;
|
|
60
|
+
exports.transformJSON = transformJSON;
|
|
61
|
+
//# sourceMappingURL=generate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.cjs","sources":["../../src/functions/generate.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { relative } from 'node:path';\nimport { CODEBASE_FILE, SRC_DIR } from 'src/constants';\nimport { analyze } from '../analyse';\nimport { CodebaseAnalysis } from '../types';\n\nexport const transformJSON = (data: CodebaseAnalysis) => {\n let imports = 0;\n let exports = 0;\n let files = 0;\n\n const entries = Object.entries(data).map(\n ([\n key,\n { imports: _imports, relativePath, text, exports: _exports },\n ]) => {\n imports += _imports.length;\n exports += _exports.length;\n files++;\n\n const value = {\n imports: _imports,\n relativePath,\n text,\n };\n return [key, value] as const;\n },\n );\n\n const CODEBASE_ANALYSIS = Object.fromEntries(entries);\n\n const STATS = {\n files,\n imports,\n exports,\n };\n\n return {\n STATS,\n CODEBASE_ANALYSIS,\n };\n};\n\nexport type GenerateOptions = {\n output?: string;\n excludes?: string[] | string;\n src?: string;\n};\n\n/**\n * Fonction principale d'exĂ©cution\n */\nexport const generate = ({\n output = CODEBASE_FILE,\n excludes,\n src = SRC_DIR,\n}: GenerateOptions = {}) => {\n const _output = output.endsWith('codebase.json')\n ? output\n : `${output}.codebase.json`;\n\n try {\n const analysis = analyze({ src, excludes });\n const transformed = transformJSON(analysis);\n\n const json = JSON.stringify(transformed, null, 2);\n writeFileSync(_output, json);\n\n console.log(\n `đ Analyse sauvegardĂ©e dans: ${relative(process.cwd(), _output)}`,\n );\n console.log(`đ Statistiques:`);\n console.log(` - Fichiers analysĂ©s: ${transformed.STATS.files}`);\n console.log(` - Total imports: ${transformed.STATS.imports}`);\n console.log(` - Total exports: ${transformed.STATS.exports}`);\n } catch (error) {\n console.error(\"â Erreur lors de l'analyse du codebase:\", error);\n process.exit(1);\n }\n\n return true;\n};\n"],"names":["CODEBASE_FILE","SRC_DIR","analyze","writeFileSync","relative"],"mappings":";;;;;;;AAMO,MAAM,aAAa,GAAG,CAAC,IAAsB,KAAI;IACtD,IAAI,OAAO,GAAG,CAAC;IACf,IAAI,OAAO,GAAG,CAAC;IACf,IAAI,KAAK,GAAG,CAAC;AAEb,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CACtC,CAAC,CACC,GAAG,EACH,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAC7D,KAAI;AACH,QAAA,OAAO,IAAI,QAAQ,CAAC,MAAM;AAC1B,QAAA,OAAO,IAAI,QAAQ,CAAC,MAAM;AAC1B,QAAA,KAAK,EAAE;AAEP,QAAA,MAAM,KAAK,GAAG;AACZ,YAAA,OAAO,EAAE,QAAQ;YACjB,YAAY;YACZ,IAAI;SACL;AACD,QAAA,OAAO,CAAC,GAAG,EAAE,KAAK,CAAU;AAC9B,IAAA,CAAC,CACF;IAED,MAAM,iBAAiB,GAAG,MAAM,CA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KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC;AAC/D,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjB;AAEA,IAAA,OAAO,IAAI;AACb;;;;;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CodebaseAnalysis } from '../types';
|
|
2
|
+
export declare const transformJSON: (data: CodebaseAnalysis) => {
|
|
3
|
+
STATS: {
|
|
4
|
+
files: number;
|
|
5
|
+
imports: number;
|
|
6
|
+
exports: number;
|
|
7
|
+
};
|
|
8
|
+
CODEBASE_ANALYSIS: {
|
|
9
|
+
[k: string]: {
|
|
10
|
+
imports: import("../types").ImportInfo[];
|
|
11
|
+
relativePath: string;
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type GenerateOptions = {
|
|
17
|
+
output?: string;
|
|
18
|
+
excludes?: string[] | string;
|
|
19
|
+
src?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Fonction principale d'exécution
|
|
23
|
+
*/
|
|
24
|
+
export declare const generate: ({ output, excludes, src, }?: GenerateOptions) => boolean;
|
|
25
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/functions/generate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,aAAa,GAAI,MAAM,gBAAgB;;;;;;;;;;;;;CAmCnD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,6BAItB,eAAoB,YAyBtB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
2
|
+
import { relative } from 'path';
|
|
3
|
+
import { CODEBASE_FILE, SRC_DIR } from '../constants.js';
|
|
4
|
+
import { analyze } from '../analyse.js';
|
|
5
|
+
|
|
6
|
+
const transformJSON = (data) => {
|
|
7
|
+
let imports = 0;
|
|
8
|
+
let exports = 0;
|
|
9
|
+
let files = 0;
|
|
10
|
+
const entries = Object.entries(data).map(([key, { imports: _imports, relativePath, text, exports: _exports },]) => {
|
|
11
|
+
imports += _imports.length;
|
|
12
|
+
exports += _exports.length;
|
|
13
|
+
files++;
|
|
14
|
+
const value = {
|
|
15
|
+
imports: _imports,
|
|
16
|
+
relativePath,
|
|
17
|
+
text,
|
|
18
|
+
};
|
|
19
|
+
return [key, value];
|
|
20
|
+
});
|
|
21
|
+
const CODEBASE_ANALYSIS = Object.fromEntries(entries);
|
|
22
|
+
const STATS = {
|
|
23
|
+
files,
|
|
24
|
+
imports,
|
|
25
|
+
exports,
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
STATS,
|
|
29
|
+
CODEBASE_ANALYSIS,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Fonction principale d'exécution
|
|
34
|
+
*/
|
|
35
|
+
const generate = ({ output = CODEBASE_FILE, excludes, src = SRC_DIR, } = {}) => {
|
|
36
|
+
const _output = output.endsWith('codebase.json')
|
|
37
|
+
? output
|
|
38
|
+
: `${output}.codebase.json`;
|
|
39
|
+
try {
|
|
40
|
+
const analysis = analyze({ src, excludes });
|
|
41
|
+
const transformed = transformJSON(analysis);
|
|
42
|
+
const json = JSON.stringify(transformed, null, 2);
|
|
43
|
+
writeFileSync(_output, json);
|
|
44
|
+
console.log(`đ Analyse sauvegardĂ©e dans: ${relative(process.cwd(), _output)}`);
|
|
45
|
+
console.log(`đ Statistiques:`);
|
|
46
|
+
console.log(` - Fichiers analysés: ${transformed.STATS.files}`);
|
|
47
|
+
console.log(` - Total imports: ${transformed.STATS.imports}`);
|
|
48
|
+
console.log(` - Total exports: ${transformed.STATS.exports}`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error("â Erreur lors de l'analyse du codebase:", error);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { generate, transformJSON };
|
|
58
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sources":["../../src/functions/generate.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { relative } from 'node:path';\nimport { CODEBASE_FILE, SRC_DIR } from 'src/constants';\nimport { analyze } from '../analyse';\nimport { CodebaseAnalysis } from '../types';\n\nexport const transformJSON = (data: CodebaseAnalysis) => {\n let imports = 0;\n let exports = 0;\n let files = 0;\n\n const entries = Object.entries(data).map(\n ([\n key,\n { imports: _imports, relativePath, text, exports: _exports },\n ]) => {\n imports += _imports.length;\n exports += _exports.length;\n files++;\n\n const value = {\n imports: _imports,\n relativePath,\n text,\n };\n return [key, value] as const;\n },\n );\n\n const CODEBASE_ANALYSIS = Object.fromEntries(entries);\n\n const STATS = {\n files,\n imports,\n exports,\n };\n\n return {\n STATS,\n CODEBASE_ANALYSIS,\n };\n};\n\nexport type GenerateOptions = {\n output?: string;\n excludes?: string[] | string;\n src?: string;\n};\n\n/**\n * Fonction principale d'exĂ©cution\n */\nexport const generate = ({\n output = CODEBASE_FILE,\n excludes,\n src = SRC_DIR,\n}: GenerateOptions = {}) => {\n const _output = output.endsWith('codebase.json')\n ? output\n : `${output}.codebase.json`;\n\n try {\n const analysis = analyze({ src, excludes });\n const transformed = transformJSON(analysis);\n\n const json = JSON.stringify(transformed, null, 2);\n writeFileSync(_output, json);\n\n console.log(\n `đ Analyse sauvegardĂ©e dans: ${relative(process.cwd(), _output)}`,\n );\n console.log(`đ Statistiques:`);\n console.log(` - Fichiers analysĂ©s: ${transformed.STATS.files}`);\n console.log(` - Total imports: ${transformed.STATS.imports}`);\n console.log(` - Total exports: ${transformed.STATS.exports}`);\n } catch (error) {\n console.error(\"â Erreur lors de l'analyse du codebase:\", error);\n process.exit(1);\n }\n\n return true;\n};\n"],"names":[],"mappings":";;;;;AAMO,MAAM,aAAa,GAAG,CAAC,IAAsB,KAAI;IACtD,IAAI,OAAO,GAAG,CAAC;IACf,IAAI,OAAO,GAAG,CAAC;IACf,IAAI,KAAK,GAAG,CAAC;AAEb,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CACtC,CAAC,CACC,GAAG,EACH,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAC7D,KAAI;AACH,QAAA,OAAO,IAAI,QAAQ,CAAC,MAAM;AAC1B,QAAA,OAAO,IAAI,QAAQ,CAAC,MAAM;AAC1B,QAAA,KAAK,EAAE;AAEP,QAAA,MAAM,KAAK,GAAG;AACZ,YAAA,OAAO,EAAE,QAAQ;YACjB,YAAY;YACZ,IAAI;SACL;AACD,QAAA,OAAO,CAAC,GAAG,EAAE,KAAK,CAAU;AAC9B,IAAA,CAAC,CACF;IAED,MAAM,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;AAErD,IAAA,MAAM,KAAK,GAAG;QACZ,KAAK;QACL,OAAO;QACP,OAAO;KACR;IAED,OAAO;QACL,KAAK;QACL,iBAAiB;KAClB;AACH;AAQA;;AAEG;AACI,MAAM,QAAQ,GAAG,CAAC,EACvB,MAAM,GAAG,aAAa,EACtB,QAAQ,EACR,GAAG,GAAG,OAAO,GAAA,GACM,EAAE,KAAI;AACzB,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe;AAC7C,UAAE;AACF,UAAE,CAAA,EAAG,MAAM,CAAA,cAAA,CAAgB;AAE7B,IAAA,IAAI;QACF,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC3C,QAAA,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC;AAE3C,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;AACjD,QAAA,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC;AAE5B,QAAA,OAAO,CAAC,GAAG,CACT,CAAA,6BAAA,EAAgC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAA,CAAE,CACnE;AACD,QAAA,OAAO,CAAC,GAAG,CAAC,CAAA,gBAAA,CAAkB,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,CAAA,wBAAA,EAA2B,WAAW,CAAC,KAAK,CAAC,KAAK,CAAA,CAAE,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,CAAA,oBAAA,EAAuB,WAAW,CAAC,KAAK,CAAC,OAAO,CAAA,CAAE,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,CAAA,oBAAA,EAAuB,WAAW,CAAC,KAAK,CAAC,OAAO,CAAA,CAAE,CAAC;IACjE;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC;AAC/D,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjB;AAEA,IAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var functions_add = require('./add.cjs');
|
|
4
|
+
var functions_generate = require('./generate.cjs');
|
|
5
|
+
var functions_init = require('./init.cjs');
|
|
6
|
+
var functions_remove = require('./remove.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.add = functions_add.add;
|
|
11
|
+
exports.generate = functions_generate.generate;
|
|
12
|
+
exports.transformJSON = functions_generate.transformJSON;
|
|
13
|
+
exports.createTypesStructure = functions_init.createTypesStructure;
|
|
14
|
+
exports.init = functions_init.init;
|
|
15
|
+
exports.remove = functions_remove.remove;
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var constants = require('../constants.cjs');
|
|
6
|
+
var helpers = require('../helpers.cjs');
|
|
7
|
+
|
|
8
|
+
const createTypesStructure = (folderPath, CODEBASE_ANALYSIS) => {
|
|
9
|
+
const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {
|
|
10
|
+
return key.endsWith('types') || key.endsWith('constants');
|
|
11
|
+
});
|
|
12
|
+
const PATHS = [];
|
|
13
|
+
console.log(`đ§ CrĂ©ation de la structure de types (${entries.length} fichiers)...`);
|
|
14
|
+
for (const [, fileAnalysis] of entries) {
|
|
15
|
+
const file = helpers.writeFileAnalysis(fileAnalysis, folderPath);
|
|
16
|
+
if (file)
|
|
17
|
+
PATHS.push(file);
|
|
18
|
+
}
|
|
19
|
+
console.log(`â
Structure de types créée avec succÚs!`);
|
|
20
|
+
return PATHS;
|
|
21
|
+
};
|
|
22
|
+
const init = (CODEBASE_ANALYSIS, { root, json }) => {
|
|
23
|
+
const cwd = process.cwd();
|
|
24
|
+
const configFile = path.join(cwd, json);
|
|
25
|
+
const configExists = fs.existsSync(configFile);
|
|
26
|
+
if (configExists)
|
|
27
|
+
return true;
|
|
28
|
+
const srcExists = fs.existsSync(path.join(cwd, 'src'));
|
|
29
|
+
const folderPath = srcExists ? path.join(cwd, 'src', root) : path.join(cwd, root);
|
|
30
|
+
// 1. Créer le dossier
|
|
31
|
+
try {
|
|
32
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
|
33
|
+
console.log(`â
Dossier .bemedev créé dans: ${root}`);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(`â Erreur lors de la crĂ©ation du dossier .bemedev:`, error);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
let files = [];
|
|
40
|
+
// 1.5. Créer la structure des fichiers types
|
|
41
|
+
try {
|
|
42
|
+
files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
console.error(`â Erreur lors de la crĂ©ation de la structure de types:`);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// 2. Mettre Ă jour le tsconfig.json
|
|
49
|
+
const tsconfigPath = path.join(cwd, 'tsconfig.json');
|
|
50
|
+
if (fs.existsSync(tsconfigPath)) {
|
|
51
|
+
try {
|
|
52
|
+
const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf8');
|
|
53
|
+
const tsconfig = JSON.parse(tsconfigContent);
|
|
54
|
+
// Initialiser compilerOptions et paths si ils n'existent pas
|
|
55
|
+
if (!tsconfig.compilerOptions) {
|
|
56
|
+
tsconfig.compilerOptions = {};
|
|
57
|
+
}
|
|
58
|
+
if (!tsconfig.compilerOptions.paths) {
|
|
59
|
+
tsconfig.compilerOptions.paths = {};
|
|
60
|
+
}
|
|
61
|
+
// Ajouter le path #bemedev/*
|
|
62
|
+
let relativePath = root;
|
|
63
|
+
const baseUrl = tsconfig.compilerOptions.baseUrl;
|
|
64
|
+
if (typeof baseUrl === 'string') {
|
|
65
|
+
// Si baseUrl est défini, calculer le chemin relatif par rapport à baseUrl
|
|
66
|
+
relativePath = path.join(baseUrl, relativePath);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Si baseUrl n'est pas défini, utiliser le chemin absolu
|
|
70
|
+
tsconfig.compilerOptions.baseUrl = '.';
|
|
71
|
+
}
|
|
72
|
+
tsconfig.compilerOptions.paths[constants.PATH_KEY] = [`${relativePath}/*`];
|
|
73
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2), 'utf8');
|
|
74
|
+
console.log(`â
Path #bemedev/* ajouté au tsconfig.json`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error(`â Erreur lors de la mise Ă jour du tsconfig.json:`, error);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.warn(`â ïž Fichier tsconfig.json introuvable, path non ajoutĂ©`);
|
|
83
|
+
}
|
|
84
|
+
// 3. Créer le fichier .bemedev.json à la racine
|
|
85
|
+
const config = {
|
|
86
|
+
version: '1.0.0',
|
|
87
|
+
[constants.PROPERTIES.PATH]: root,
|
|
88
|
+
[constants.PROPERTIES.FILES]: files,
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
fs.writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
92
|
+
console.log(`â
Fichier .bemedev.json créé à la racine du projet`);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error(`â Erreur lors de la crĂ©ation du fichier .bemedev.json:`, error);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
console.log(`đ Initialisation de bemedev terminĂ©e avec succĂšs!`);
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.createTypesStructure = createTypesStructure;
|
|
103
|
+
exports.init = init;
|
|
104
|
+
//# sourceMappingURL=init.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.cjs","sources":["../../src/functions/init.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from 'node:fs';\nimport { join } from 'node:path';\nimport { PATH_KEY, PROPERTIES } from '../constants';\nimport { writeFileAnalysis } from '../helpers';\nimport { CodebaseAnalysis } from '../schemas';\n\nexport interface InitOptions {\n /**\n * Emplacement personnalisĂ© pour le dossier .bemedev\n * Par dĂ©faut: 'src/.bemedev' si src existe, sinon '.bemedev' Ă la racine\n */\n root: string;\n json: string;\n}\n\nexport const createTypesStructure = (\n folderPath: string,\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n) => {\n const entries = Object.entries(CODEBASE_ANALYSIS).filter(([key]) => {\n return key.endsWith('types') || key.endsWith('constants');\n });\n\n const PATHS: string[] = [];\n\n console.log(\n `đ§ CrĂ©ation de la structure de types (${entries.length} fichiers)...`,\n );\n\n for (const [, fileAnalysis] of entries) {\n const file = writeFileAnalysis(fileAnalysis, folderPath);\n if (file) PATHS.push(file);\n }\n\n console.log(`â
Structure de types créée avec succĂšs!`);\n return PATHS;\n};\n\nexport const init = (\n CODEBASE_ANALYSIS: CodebaseAnalysis,\n { root, json }: InitOptions,\n) => {\n const cwd = process.cwd();\n const configFile = join(cwd, json);\n const configExists = existsSync(configFile);\n\n if (configExists) return true;\n const srcExists = existsSync(join(cwd, 'src'));\n const folderPath = srcExists ? join(cwd, 'src', root) : join(cwd, root);\n\n // 1. CrĂ©er le dossier\n try {\n mkdirSync(folderPath, { recursive: true });\n console.log(`â
Dossier .bemedev créé dans: ${root}`);\n } catch (error) {\n console.error(\n `â Erreur lors de la crĂ©ation du dossier .bemedev:`,\n error,\n );\n return false;\n }\n\n let files: string[] = [];\n // 1.5. CrĂ©er la structure des fichiers types\n try {\n files = createTypesStructure(folderPath, CODEBASE_ANALYSIS);\n } catch {\n console.error(\n `â Erreur lors de la crĂ©ation de la structure de types:`,\n );\n return false;\n }\n\n // 2. Mettre Ă jour le tsconfig.json\n const tsconfigPath = join(cwd, 'tsconfig.json');\n\n if (existsSync(tsconfigPath)) {\n try {\n const tsconfigContent = readFileSync(tsconfigPath, 'utf8');\n const tsconfig = JSON.parse(tsconfigContent);\n\n // Initialiser compilerOptions et paths si ils n'existent pas\n if (!tsconfig.compilerOptions) {\n tsconfig.compilerOptions = {};\n }\n\n if (!tsconfig.compilerOptions.paths) {\n tsconfig.compilerOptions.paths = {};\n }\n\n // Ajouter le path #bemedev/*\n let relativePath = root;\n const baseUrl = tsconfig.compilerOptions.baseUrl;\n\n if (typeof baseUrl === 'string') {\n // Si baseUrl est dĂ©fini, calculer le chemin relatif par rapport Ă baseUrl\n\n relativePath = join(baseUrl, relativePath);\n } else {\n // Si baseUrl n'est pas dĂ©fini, utiliser le chemin absolu\n tsconfig.compilerOptions.baseUrl = '.';\n }\n\n tsconfig.compilerOptions.paths[PATH_KEY] = [`${relativePath}/*`];\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(tsconfig, null, 2),\n 'utf8',\n );\n console.log(`â
Path #bemedev/* ajoutĂ© au tsconfig.json`);\n } catch (error) {\n console.error(\n `â Erreur lors de la mise Ă jour du tsconfig.json:`,\n error,\n );\n return false;\n }\n } else {\n console.warn(`â ïž Fichier tsconfig.json introuvable, path non ajoutĂ©`);\n }\n\n // 3. CrĂ©er le fichier .bemedev.json Ă la racine\n\n const config = {\n version: '1.0.0',\n [PROPERTIES.PATH]: root,\n [PROPERTIES.FILES]: files,\n };\n\n try {\n writeFileSync(configFile, JSON.stringify(config, null, 2), 'utf8');\n console.log(`â
Fichier .bemedev.json créé Ă la racine du projet`);\n } catch (error) {\n console.error(\n `â Erreur lors de la crĂ©ation du fichier .bemedev.json:`,\n error,\n );\n return false;\n }\n\n console.log(`đ Initialisation de bemedev terminĂ©e avec succĂšs!`);\n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seAnalysis } from '../schemas';
|
|
2
|
+
export interface InitOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Emplacement personnalisé pour le dossier .bemedev
|
|
5
|
+
* Par défaut: 'src/.bemedev' si src existe, sinon '.bemedev' à la racine
|
|
6
|
+
*/
|
|
7
|
+
root: string;
|
|
8
|
+
json: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const createTypesStructure: (folderPath: string, CODEBASE_ANALYSIS: CodebaseAnalysis) => string[];
|
|
11
|
+
export declare const init: (CODEBASE_ANALYSIS: CodebaseAnalysis, { root, json }: InitOptions) => boolean;
|
|
12
|
+
//# sourceMappingURL=init.d.ts.map
|