@craftycodesmith/node-structure 1.0.0 → 1.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.
Files changed (2) hide show
  1. package/dist/index.js +51 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,54 +1,66 @@
1
1
  #!/usr/bin/env node
2
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
3
  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"));
4
+ const node_child_process_1 = require("node:child_process");
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const node_util_1 = require("node:util");
8
+ const { values, positionals } = (0, node_util_1.parseArgs)({
9
+ allowPositionals: true,
10
+ options: {
11
+ help: { type: 'boolean', short: 'h' }
12
+ }
13
+ });
14
+ const command = positionals[0];
15
+ const root = process.cwd();
19
16
  const getTemplate = (type, name) => {
20
17
  const templates = {
21
18
  controller: `export class ${name}Controller {\n // Logic for ${name}\n}`,
22
19
  service: `export class ${name}Service {\n // Business logic for ${name}\n}`,
23
20
  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}`
21
+ tsconfig: `{\n "compilerOptions": {\n "target": "ESNext",\n "module": "NodeNext",\n "outDir": "./dist",\n "strict": true\n }\n}`
25
22
  };
26
23
  return templates[type] || '';
27
24
  };
28
- commander_1.program
29
- .command('init')
30
- .description('Initialize feature-based architecture')
31
- .action(() => __awaiter(void 0, void 0, void 0, function* () {
25
+ // --- Command Handlers ---
26
+ const init = () => {
27
+ console.log('Initializing feature-based structure...');
32
28
  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));
29
+ folders.forEach(folder => {
30
+ (0, node_fs_1.mkdirSync)((0, node_path_1.join)(root, folder), { recursive: true });
31
+ });
32
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, 'tsconfig.json'), getTemplate('tsconfig', ''));
33
+ if (!(0, node_fs_1.existsSync)((0, node_path_1.join)(root, 'package.json'))) {
34
+ (0, node_child_process_1.execSync)('npm init -y', { stdio: 'inherit' });
35
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());
36
+ (0, node_child_process_1.execSync)('npm install -D typescript @types/node ts-node', { stdio: 'inherit' });
37
+ console.log('Project initialized successfully.');
38
+ };
39
+ const generateResource = (name) => {
40
+ if (!name) {
41
+ console.error('Error: Please provide a resource name.');
42
+ process.exit(1);
43
+ }
44
+ const featureDir = (0, node_path_1.join)(root, 'src/features', name.toLowerCase());
45
+ (0, node_fs_1.mkdirSync)(featureDir, { recursive: true });
44
46
  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' }
47
+ { fileName: `${name.toLowerCase()}.controller.ts`, type: 'controller' },
48
+ { fileName: `${name.toLowerCase()}.service.ts`, type: 'service' },
49
+ { fileName: `${name.toLowerCase()}.model.ts`, type: 'model' }
48
50
  ];
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);
51
+ files.forEach(file => {
52
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(featureDir, file.fileName), getTemplate(file.type, name));
53
+ });
54
+ console.log(`Module "${name}" generated in ${featureDir}`);
55
+ };
56
+ // --- Simple Router ---
57
+ switch (command) {
58
+ case 'init':
59
+ init();
60
+ break;
61
+ case 'res':
62
+ generateResource(positionals[1]);
63
+ break;
64
+ default:
65
+ console.log('Usage: npx your-tool <command> [args]\nCommands: init, res [name]');
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craftycodesmith/node-structure",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Feature-based architecture generator",
5
5
  "main": "dist/index.js",
6
6
  "bin": {