@craftycodesmith/node-structure 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +54 -0
- package/package.json +16 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const commander_1 = require("commander");
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const getTemplate = (type, name) => {
|
|
20
|
+
const templates = {
|
|
21
|
+
controller: `export class ${name}Controller {\n // Logic for ${name}\n}`,
|
|
22
|
+
service: `export class ${name}Service {\n // Business logic for ${name}\n}`,
|
|
23
|
+
model: `export interface ${name} {\n id: string;\n}`,
|
|
24
|
+
tsconfig: `{\n "compilerOptions": {\n "target": "ESNext",\n "module": "CommonJS",\n "outDir": "./dist",\n "strict": true\n }\n}`
|
|
25
|
+
};
|
|
26
|
+
return templates[type] || '';
|
|
27
|
+
};
|
|
28
|
+
commander_1.program
|
|
29
|
+
.command('init')
|
|
30
|
+
.description('Initialize feature-based architecture')
|
|
31
|
+
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const folders = ['src/features', 'src/common', 'src/config'];
|
|
33
|
+
for (const folder of folders) {
|
|
34
|
+
yield fs_extra_1.default.ensureDir(path_1.default.join(process.cwd(), folder));
|
|
35
|
+
}
|
|
36
|
+
yield fs_extra_1.default.outputFile(path_1.default.join(process.cwd(), 'tsconfig.json'), getTemplate('tsconfig', ''));
|
|
37
|
+
console.log('Successfully initialized TypeScript feature-based structure.');
|
|
38
|
+
}));
|
|
39
|
+
commander_1.program
|
|
40
|
+
.command('res <name>')
|
|
41
|
+
.description('Generate a new feature module')
|
|
42
|
+
.action((name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const featureDir = path_1.default.join(process.cwd(), 'src/features', name.toLowerCase());
|
|
44
|
+
const files = [
|
|
45
|
+
{ name: `${name.toLowerCase()}.controller.ts`, type: 'controller' },
|
|
46
|
+
{ name: `${name.toLowerCase()}.service.ts`, type: 'service' },
|
|
47
|
+
{ name: `${name.toLowerCase()}.model.ts`, type: 'model' }
|
|
48
|
+
];
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
yield fs_extra_1.default.outputFile(path_1.default.join(featureDir, file.name), getTemplate(file.type, name));
|
|
51
|
+
}
|
|
52
|
+
console.log(`Module "${name}" generated in src/features/${name.toLowerCase()}`);
|
|
53
|
+
}));
|
|
54
|
+
commander_1.program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@craftycodesmith/node-structure",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Feature-based architecture generator",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"my-cli": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"prepare": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
]
|
|
16
|
+
}
|