fastnode-cli 0.1.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/README.md +108 -0
- package/dist/index.js +82 -0
- package/package.json +34 -0
- package/src/index.ts +97 -0
- package/tsconfig.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# π§ͺ fastnode-cli
|
|
2
|
+
|
|
3
|
+
**The official CLI tool for scaffolding and managing FastNode projects** β bringing the simplicity of FastAPI to the Node.js ecosystem with NestJS under the hood.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## π Features
|
|
8
|
+
|
|
9
|
+
- π¦ Instantly scaffold a FastNode-based project
|
|
10
|
+
- π§± Generate modules, services, controllers, and more
|
|
11
|
+
- βοΈ Built-in support for TypeScript
|
|
12
|
+
- π Clean project structure inspired by FastAPI
|
|
13
|
+
- π§ͺ Easy to extend and integrate with `fastnode-core`
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## π¦ Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g fastnode-cli
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## π οΈ Usage
|
|
26
|
+
|
|
27
|
+
### Create a new project
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
fastnode new my-app
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This creates a new FastNode project in the `my-app` folder.
|
|
34
|
+
|
|
35
|
+
### Generate a module
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
fastnode generate module user
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Creates a `user` module with its own folder, service, and controller.
|
|
42
|
+
|
|
43
|
+
### Generate a service
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
fastnode generate service auth
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Generate a controller
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
fastnode generate controller auth
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## π Folder Structure
|
|
58
|
+
|
|
59
|
+
Hereβs what a typical FastNode project looks like:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
src/
|
|
63
|
+
βββ app.module.ts
|
|
64
|
+
βββ main.ts
|
|
65
|
+
βββ modules/
|
|
66
|
+
βββ user/
|
|
67
|
+
β βββ user.controller.ts
|
|
68
|
+
β βββ user.module.ts
|
|
69
|
+
β βββ user.service.ts
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## π§ Configuration
|
|
75
|
+
|
|
76
|
+
You can customize the CLI's behavior with a `.fastnoderc` config file (coming soon).
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## π Documentation
|
|
81
|
+
|
|
82
|
+
See the core framework:
|
|
83
|
+
π [`fastnode-core`](https://www.npmjs.com/package/fastnode-core)
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## π€ Contributing
|
|
88
|
+
|
|
89
|
+
Pull requests are welcome! Please open an issue first to discuss what youβd like to change.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## π License
|
|
94
|
+
|
|
95
|
+
MIT License
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## π‘ Inspiration
|
|
100
|
+
|
|
101
|
+
Inspired by how fast and intuitive **FastAPI** is for Python developers, `fastnode` aims to bring that same DX (developer experience) to the **Node.js/NestJS** world.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## π Links
|
|
106
|
+
|
|
107
|
+
- CLI: [fastnode-cli on npm](https://www.npmjs.com/package/fastnode-cli)
|
|
108
|
+
- Core: [fastnode-core on npm](https://www.npmjs.com/package/fastnode-core)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const [, , command, arg] = process.argv;
|
|
11
|
+
if (command === "create" && arg) {
|
|
12
|
+
const projectDir = path_1.default.resolve(arg);
|
|
13
|
+
const moduleDir = path_1.default.join(projectDir, "src", arg);
|
|
14
|
+
fs_1.default.mkdirSync(moduleDir, { recursive: true });
|
|
15
|
+
// 1οΈβ£ main.ts
|
|
16
|
+
const mainFile = path_1.default.join(moduleDir, "main.ts");
|
|
17
|
+
fs_1.default.writeFileSync(mainFile, `import "reflect-metadata";
|
|
18
|
+
import { Controller, Get, Module, createApp } from "@fastnode/core";
|
|
19
|
+
|
|
20
|
+
@Controller("/${arg}")
|
|
21
|
+
class ${capitalize(arg)}Controller {
|
|
22
|
+
@Get("/")
|
|
23
|
+
hello() {
|
|
24
|
+
return { message: "Hello from ${arg}" };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Module({ controllers: [${capitalize(arg)}Controller] })
|
|
29
|
+
class ${capitalize(arg)}Module {}
|
|
30
|
+
|
|
31
|
+
createApp([${capitalize(arg)}Module]).listen(3000);
|
|
32
|
+
`);
|
|
33
|
+
// 2οΈβ£ tsconfig.json
|
|
34
|
+
fs_1.default.writeFileSync(path_1.default.join(projectDir, "tsconfig.json"), `{
|
|
35
|
+
"compilerOptions": {
|
|
36
|
+
"target": "ES2020",
|
|
37
|
+
"module": "CommonJS",
|
|
38
|
+
"rootDir": "./src",
|
|
39
|
+
"outDir": "./dist",
|
|
40
|
+
"strict": true,
|
|
41
|
+
"esModuleInterop": true,
|
|
42
|
+
"experimentalDecorators": true,
|
|
43
|
+
"emitDecoratorMetadata": true,
|
|
44
|
+
"useDefineForClassFields": false
|
|
45
|
+
},
|
|
46
|
+
"include": ["src"]
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
// 3οΈβ£ package.json
|
|
50
|
+
fs_1.default.writeFileSync(path_1.default.join(projectDir, "package.json"), `{
|
|
51
|
+
"name": "${arg}",
|
|
52
|
+
"version": "1.0.0",
|
|
53
|
+
"type": "commonjs",
|
|
54
|
+
"main": "dist/index.js",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "tsx src/${arg}/main.ts",
|
|
57
|
+
"build": "tsc",
|
|
58
|
+
"start": "node dist/${arg}/main.js"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@fastnode/core": "latest",
|
|
62
|
+
"reflect-metadata": "^0.1.13"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"tsx": "^4.7.0",
|
|
66
|
+
"typescript": "^5.0.0"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`);
|
|
70
|
+
console.log(`β Project '${arg}' created at ${projectDir}`);
|
|
71
|
+
}
|
|
72
|
+
if (command === "serve" && arg) {
|
|
73
|
+
const entry = path_1.default.resolve(process.cwd(), `src/${arg}/main.ts`);
|
|
74
|
+
if (!fs_1.default.existsSync(entry)) {
|
|
75
|
+
console.error(`β Cannot find module at ${entry}`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
(0, child_process_1.execSync)(`npx tsx ${entry}`, { stdio: "inherit" });
|
|
79
|
+
}
|
|
80
|
+
function capitalize(str) {
|
|
81
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
82
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fastnode-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A CLI tool for generating and managing FastNode projects using NestJS, inspired by FastAPI.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"fastnode": "./bin/index.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "bin/index.js",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node bin/index.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"cli",
|
|
15
|
+
"fastapi",
|
|
16
|
+
"nestjs",
|
|
17
|
+
"nodejs",
|
|
18
|
+
"scaffolding",
|
|
19
|
+
"generator",
|
|
20
|
+
"fastnode"
|
|
21
|
+
],
|
|
22
|
+
"author": "Valentine Emmanuel Ikechukwu",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"commander": "^11.0.0",
|
|
26
|
+
"chalk": "^5.3.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const [, , command, arg] = process.argv;
|
|
7
|
+
|
|
8
|
+
if (command === "create" && arg) {
|
|
9
|
+
const projectDir = path.resolve(arg);
|
|
10
|
+
const moduleDir = path.join(projectDir, "src", arg);
|
|
11
|
+
|
|
12
|
+
fs.mkdirSync(moduleDir, { recursive: true });
|
|
13
|
+
|
|
14
|
+
// 1οΈβ£ main.ts
|
|
15
|
+
const mainFile = path.join(moduleDir, "main.ts");
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
mainFile,
|
|
18
|
+
`import "reflect-metadata";
|
|
19
|
+
import { Controller, Get, Module, createApp } from "fastnode-core";
|
|
20
|
+
|
|
21
|
+
@Controller("/${arg}")
|
|
22
|
+
class ${capitalize(arg)}Controller {
|
|
23
|
+
@Get("/")
|
|
24
|
+
hello() {
|
|
25
|
+
return { message: "Hello from ${arg}" };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Module({ controllers: [${capitalize(arg)}Controller] })
|
|
30
|
+
class ${capitalize(arg)}Module {}
|
|
31
|
+
|
|
32
|
+
createApp([${capitalize(arg)}Module]).listen(3000);
|
|
33
|
+
`
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// 2οΈβ£ tsconfig.json
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
path.join(projectDir, "tsconfig.json"),
|
|
39
|
+
`{
|
|
40
|
+
"compilerOptions": {
|
|
41
|
+
"target": "ES2020",
|
|
42
|
+
"module": "CommonJS",
|
|
43
|
+
"rootDir": "./src",
|
|
44
|
+
"outDir": "./dist",
|
|
45
|
+
"strict": true,
|
|
46
|
+
"esModuleInterop": true,
|
|
47
|
+
"experimentalDecorators": true,
|
|
48
|
+
"emitDecoratorMetadata": true,
|
|
49
|
+
"useDefineForClassFields": false
|
|
50
|
+
},
|
|
51
|
+
"include": ["src"]
|
|
52
|
+
}
|
|
53
|
+
`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// 3οΈβ£ package.json
|
|
57
|
+
fs.writeFileSync(
|
|
58
|
+
path.join(projectDir, "package.json"),
|
|
59
|
+
`{
|
|
60
|
+
"name": "${arg}",
|
|
61
|
+
"version": "1.0.0",
|
|
62
|
+
"type": "commonjs",
|
|
63
|
+
"main": "dist/index.js",
|
|
64
|
+
"scripts": {
|
|
65
|
+
"dev": "tsx src/${arg}/main.ts",
|
|
66
|
+
"build": "tsc",
|
|
67
|
+
"start": "node dist/${arg}/main.js"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"fastnode-core": "latest",
|
|
71
|
+
"reflect-metadata": "^0.1.13"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"tsx": "^4.7.0",
|
|
75
|
+
"typescript": "^5.0.0"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
console.log(`β Project '${arg}' created at ${projectDir}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (command === "serve" && arg) {
|
|
85
|
+
const entry = path.resolve(process.cwd(), `src/${arg}/main.ts`);
|
|
86
|
+
|
|
87
|
+
if (!fs.existsSync(entry)) {
|
|
88
|
+
console.error(`β Cannot find module at ${entry}`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
execSync(`npx tsx ${entry}`, { stdio: "inherit" });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function capitalize(str: string): string {
|
|
96
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
97
|
+
}
|