Compare commits
1 Commits
v0.2.0
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
![]() |
eb8b105d1b |
25
CHANGELOG.md
25
CHANGELOG.md
@@ -9,28 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
||||||
### Deprecated
|
|
||||||
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
|
|
||||||
### Security
|
|
||||||
|
|
||||||
|
|
||||||
## [0.2.0]
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Add pre release building to release workflow on dev/* branches an version changes.
|
- Add pre release building to release workflow on dev/* branches an version changes.
|
||||||
- feat: Introduced a new CLI command `tsinjex-generate` to automate the generation of import statements for registered dependencies.
|
|
||||||
The command scans `.ts` files for `@Register` and `@RegisterInstance` decorators and generates an `auto-imports.ts` file.
|
|
||||||
This ensures that all registered dependencies are automatically included without requiring manual imports.
|
|
||||||
The CLI can be executed via `npx tsinjex-generate` or added as a script in `package.json` for easier integration.
|
|
||||||
|
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
@@ -44,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
|
||||||
## [0.0.14]
|
## [0.0.14]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -75,5 +55,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
---
|
---
|
||||||
|
|
||||||
[unreleased]: https://github.com/PxaMMaxP/TSinjex/compare/0.0.14...HEAD
|
[unreleased]: https://github.com/PxaMMaxP/TSinjex/compare/0.0.14...HEAD
|
||||||
[0.0.14]: https://github.com/PxaMMaxP/TSinjex/compare/0.0.13...v0.0.14
|
[0.0.14]: https://github.com/PxaMMaxP/TSinjex/compare/0.0.13...v0.0.14
|
||||||
[0.2.00]: https://github.com/PxaMMaxP/TSinjex/compare/0.0.14...v0.2.0
|
|
@@ -1,111 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const yargs = require('yargs');
|
|
||||||
|
|
||||||
// CLI argument parsing
|
|
||||||
const argv = yargs
|
|
||||||
.option('src', {
|
|
||||||
alias: 's',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Directory to search for files',
|
|
||||||
default: 'src',
|
|
||||||
})
|
|
||||||
.option('output', {
|
|
||||||
alias: 'o',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Path to the output file',
|
|
||||||
default: 'src/auto-imports.ts',
|
|
||||||
})
|
|
||||||
.option('pattern', {
|
|
||||||
alias: 'p',
|
|
||||||
type: 'string',
|
|
||||||
description: 'File pattern to search for (e.g., .ts, .js)',
|
|
||||||
default: '.ts',
|
|
||||||
})
|
|
||||||
.help()
|
|
||||||
.argv;
|
|
||||||
|
|
||||||
// Fixed RegEx patterns for decorator detection
|
|
||||||
const SEARCH_PATTERNS = [
|
|
||||||
/^@Register(?:<(.+)?>)?\(\s*["']{1}(.+)?["']{1}\s*,?\s*(true|false)?\s*\)/m, // Matches @Register(...)
|
|
||||||
/^@RegisterInstance(?:<(.+)?>)?\(\s*["']{1}(.+)?["']{1}\s*,?\s*(.+)?\s*\)/m, // Matches @RegisterInstance(...)
|
|
||||||
];
|
|
||||||
|
|
||||||
const FILE_PATTERN = argv.pattern.startsWith('.') ? argv.pattern : `.${argv.pattern}`; // Ensure the pattern starts with a dot
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively searches for all files in a directory matching the specified pattern.
|
|
||||||
* @param {string} dirPath - The directory to search.
|
|
||||||
* @returns {string[]} - List of matching files.
|
|
||||||
*/
|
|
||||||
function getAllFiles(dirPath) {
|
|
||||||
let files = fs.readdirSync(dirPath);
|
|
||||||
let arrayOfFiles = [];
|
|
||||||
|
|
||||||
files.forEach((file) => {
|
|
||||||
const fullPath = path.join(dirPath, file);
|
|
||||||
if (fs.statSync(fullPath).isDirectory()) {
|
|
||||||
arrayOfFiles = arrayOfFiles.concat(getAllFiles(fullPath));
|
|
||||||
} else if (file.endsWith(FILE_PATTERN)) {
|
|
||||||
arrayOfFiles.push(fullPath);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return arrayOfFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filters files that contain at least one of the specified regex patterns.
|
|
||||||
* @param {string[]} files - List of files to check.
|
|
||||||
* @returns {string[]} - Files that contain at least one of the specified patterns.
|
|
||||||
*/
|
|
||||||
function findFilesWithPattern(files) {
|
|
||||||
return files.filter((file) => {
|
|
||||||
const content = fs.readFileSync(file, 'utf8');
|
|
||||||
return SEARCH_PATTERNS.some((pattern) => pattern.test(content));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates an import file containing imports for all found files.
|
|
||||||
* @param {string[]} files - List of relevant files.
|
|
||||||
* @returns {string} - Generated import code.
|
|
||||||
*/
|
|
||||||
function generateImports(files) {
|
|
||||||
return files.map((file) => `import '${file.replace(/\\/g, '/')}';`).join('\n') + '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main function that executes the script.
|
|
||||||
*/
|
|
||||||
function main() {
|
|
||||||
try {
|
|
||||||
const srcDir = path.resolve(process.cwd(), argv.src);
|
|
||||||
const outputFile = path.resolve(process.cwd(), argv.output);
|
|
||||||
|
|
||||||
if (!fs.existsSync(srcDir)) {
|
|
||||||
console.error(`❌ Error: The directory '${srcDir}' does not exist.`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const allFiles = getAllFiles(srcDir);
|
|
||||||
const filesWithPattern = findFilesWithPattern(allFiles);
|
|
||||||
|
|
||||||
if (filesWithPattern.length === 0) {
|
|
||||||
console.log(`ℹ️ No ${FILE_PATTERN} files found matching the specified decorator patterns.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const importContent = generateImports(filesWithPattern);
|
|
||||||
fs.writeFileSync(outputFile, importContent);
|
|
||||||
|
|
||||||
console.log(`✅ Imports successfully generated: ${outputFile}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ An error occurred:', error.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
50
package-lock.json
generated
50
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ts-injex",
|
"name": "ts-injex",
|
||||||
"version": "0.0.9",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ts-injex",
|
"name": "ts-injex",
|
||||||
"version": "0.0.9",
|
"version": "0.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"eslint-plugin-prettier": "^5.2.1",
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"@typescript-eslint/parser": "^8.1.0",
|
"@typescript-eslint/parser": "^8.1.0",
|
||||||
"axios": "^1.7.2",
|
"axios": "^1.7.2",
|
||||||
"eslint-plugin-deprecation": "^3.0.0",
|
"eslint-plugin-deprecation": "^3.0.0",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.31.0",
|
||||||
"eslint-plugin-jsdoc": "^50.2.2",
|
"eslint-plugin-jsdoc": "^50.2.2",
|
||||||
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
|
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
|
||||||
"istanbul-badges-readme": "^1.9.0",
|
"istanbul-badges-readme": "^1.9.0",
|
||||||
@@ -1187,6 +1187,12 @@
|
|||||||
"url": "https://opencollective.com/unts"
|
"url": "https://opencollective.com/unts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@rtsao/scc": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@shikijs/core": {
|
"node_modules/@shikijs/core": {
|
||||||
"version": "1.13.0",
|
"version": "1.13.0",
|
||||||
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.13.0.tgz",
|
||||||
@@ -2995,9 +3001,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-module-utils": {
|
"node_modules/eslint-module-utils": {
|
||||||
"version": "2.8.1",
|
"version": "2.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.12.0.tgz",
|
||||||
"integrity": "sha512-rXDXR3h7cs7dy9RNpUlQf80nX31XWJEyGq1tRMo+6GsO5VmTe4UTwtmonAD4ZkAsrfMVDA2wlGJ3790Ys+D49Q==",
|
"integrity": "sha512-wALZ0HFoytlyh/1+4wuZ9FJCD/leWHQzzrxJ8+rebyReSLk7LApMyd3WJaLVoN+D5+WIdJyDK1c6JnE65V4Zyg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"debug": "^3.2.7"
|
"debug": "^3.2.7"
|
||||||
@@ -3157,34 +3163,36 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-import": {
|
"node_modules/eslint-plugin-import": {
|
||||||
"version": "2.29.1",
|
"version": "2.31.0",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.29.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.31.0.tgz",
|
||||||
"integrity": "sha512-BbPC0cuExzhiMo4Ff1BTVwHpjjv28C5R+btTOGaCRC7UEz801up0JadwkeSk5Ued6TG34uaczuVuH6qyy5YUxw==",
|
"integrity": "sha512-ixmkI62Rbc2/w8Vfxyh1jQRTdRTF52VxwRVHl/ykPAmqG+Nb7/kNn+byLP0LxPgI7zWA16Jt82SybJInmMia3A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"array-includes": "^3.1.7",
|
"@rtsao/scc": "^1.1.0",
|
||||||
"array.prototype.findlastindex": "^1.2.3",
|
"array-includes": "^3.1.8",
|
||||||
|
"array.prototype.findlastindex": "^1.2.5",
|
||||||
"array.prototype.flat": "^1.3.2",
|
"array.prototype.flat": "^1.3.2",
|
||||||
"array.prototype.flatmap": "^1.3.2",
|
"array.prototype.flatmap": "^1.3.2",
|
||||||
"debug": "^3.2.7",
|
"debug": "^3.2.7",
|
||||||
"doctrine": "^2.1.0",
|
"doctrine": "^2.1.0",
|
||||||
"eslint-import-resolver-node": "^0.3.9",
|
"eslint-import-resolver-node": "^0.3.9",
|
||||||
"eslint-module-utils": "^2.8.0",
|
"eslint-module-utils": "^2.12.0",
|
||||||
"hasown": "^2.0.0",
|
"hasown": "^2.0.2",
|
||||||
"is-core-module": "^2.13.1",
|
"is-core-module": "^2.15.1",
|
||||||
"is-glob": "^4.0.3",
|
"is-glob": "^4.0.3",
|
||||||
"minimatch": "^3.1.2",
|
"minimatch": "^3.1.2",
|
||||||
"object.fromentries": "^2.0.7",
|
"object.fromentries": "^2.0.8",
|
||||||
"object.groupby": "^1.0.1",
|
"object.groupby": "^1.0.3",
|
||||||
"object.values": "^1.1.7",
|
"object.values": "^1.2.0",
|
||||||
"semver": "^6.3.1",
|
"semver": "^6.3.1",
|
||||||
|
"string.prototype.trimend": "^1.0.8",
|
||||||
"tsconfig-paths": "^3.15.0"
|
"tsconfig-paths": "^3.15.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
|
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/eslint-plugin-import/node_modules/debug": {
|
"node_modules/eslint-plugin-import/node_modules/debug": {
|
||||||
@@ -4153,9 +4161,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/is-core-module": {
|
"node_modules/is-core-module": {
|
||||||
"version": "2.15.0",
|
"version": "2.15.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz",
|
||||||
"integrity": "sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA==",
|
"integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"hasown": "^2.0.2"
|
"hasown": "^2.0.2"
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "ts-injex",
|
"name": "ts-injex",
|
||||||
"version": "0.2.0",
|
"version": "0.1.0",
|
||||||
"description": "Simple boilerplate code free dependency injection system for TypeScript.",
|
"description": "Simple boilerplate code free dependency injection system for TypeScript.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"bin": {
|
|
||||||
"tsinjex-generate": "./bin/generate-imports.cjs"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "npm run build",
|
"prepare": "npm run build",
|
||||||
"build": "npm run build:tsc",
|
"build": "npm run build:tsc",
|
||||||
@@ -43,7 +40,7 @@
|
|||||||
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
||||||
"@typescript-eslint/parser": "^8.1.0",
|
"@typescript-eslint/parser": "^8.1.0",
|
||||||
"eslint-plugin-deprecation": "^3.0.0",
|
"eslint-plugin-deprecation": "^3.0.0",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.31.0",
|
||||||
"eslint-plugin-jsdoc": "^50.2.2",
|
"eslint-plugin-jsdoc": "^50.2.2",
|
||||||
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
|
"eslint-plugin-override": "https://github.com/PxaMMaxP/eslint-plugin-override",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
@@ -63,4 +60,4 @@
|
|||||||
"LICENSE",
|
"LICENSE",
|
||||||
"package.json"
|
"package.json"
|
||||||
]
|
]
|
||||||
}
|
}
|
Reference in New Issue
Block a user