create-moost 0.5.23 → 0.5.25
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/package.json +3 -3
- package/templates/cli/README.md +116 -0
- package/templates/cli/src/main.ts +12 -4
- package/templates/http/README.md +13 -0
- package/templates/common/README.md +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-moost",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.25",
|
|
4
4
|
"description": "create-moost",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@prostojs/rewrite": "^0.1.1",
|
|
47
47
|
"@wooksjs/event-cli": "^0.5.25",
|
|
48
48
|
"prompts": "^2.4.2",
|
|
49
|
-
"@moostjs/event-cli": "^0.5.
|
|
50
|
-
"moost": "^0.5.
|
|
49
|
+
"@moostjs/event-cli": "^0.5.25",
|
|
50
|
+
"moost": "^0.5.25"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@moostjs/vite": "^0.5.21",
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# {{ projectName }}
|
|
2
|
+
|
|
3
|
+
## Moost CLI Template
|
|
4
|
+
|
|
5
|
+
This template provides a simple CLI application using Moost CLI. It demonstrates how to define commands with decorators, build the project with Rolldown, and run it in different environments.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- Node.js (v18 or later)
|
|
10
|
+
- A package manager like [npm](https://www.npmjs.com/)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
This template is installed via:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm create moost@latest -- --cli
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
After the setup, navigate into the project folder and install dependencies:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
cd {{ packageName }}
|
|
24
|
+
npm install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Running Locally
|
|
28
|
+
|
|
29
|
+
You can test the CLI in multiple ways:
|
|
30
|
+
|
|
31
|
+
### 1. Using `npx` (Recommended for testing)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm run build
|
|
35
|
+
npx <project_name> <command> [options]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx {{ packageName }} hello world
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This method does not require global installation but runs slightly slower.
|
|
45
|
+
|
|
46
|
+
### 2. Running in Development Mode
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm run dev <command> [options]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This command builds the project and runs it directly.
|
|
53
|
+
|
|
54
|
+
### 3. Running a Built Version
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm run build
|
|
58
|
+
node ./dist/main.js <command> [options]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This method is useful for testing the production build.
|
|
62
|
+
|
|
63
|
+
## Building for Production
|
|
64
|
+
|
|
65
|
+
To compile the CLI for production, run:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This uses [Rolldown](https://github.com/rolldownjs/rolldown) with the SWC plugin to generate an optimized output in `dist/main.js`.
|
|
72
|
+
The **SWC plugin** is specifically included to support **decorators**, required for Moost.
|
|
73
|
+
|
|
74
|
+
## CLI Usage
|
|
75
|
+
|
|
76
|
+
Once built, you can use the CLI as follows:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
node ./dist/main.js <command> [options]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
node ./dist/main.js hello world
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Output:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Hello, world!
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To use uppercase:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
node ./dist/main.js hello world -u
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Output:
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
HELLO, WORLD!
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Files Overview
|
|
107
|
+
|
|
108
|
+
- **`src/main.ts`** – Defines CLI commands using decorators.
|
|
109
|
+
- **`bin.js`** – CLI entry point with a shebang for execution.
|
|
110
|
+
- **`rolldown.config.ts`** – Build configuration (including SWC for decorators).
|
|
111
|
+
- **`package.json`** – Contains scripts, dependencies, and CLI entry configuration.
|
|
112
|
+
|
|
113
|
+
## Customization
|
|
114
|
+
|
|
115
|
+
- **Add New Commands:** Edit `src/main.ts` and use `@Cli`, `@Param`, `@CliOption`, etc.
|
|
116
|
+
- **Modify Help Options:** Adjust `.useHelp()` and `.useOptions()` in `main.ts`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliApp, Controller, Cli, Param, CliExample, CliOption } from '@moostjs/event-cli'
|
|
1
|
+
import { CliApp, Controller, Cli, Param, CliExample, CliOption, Description } from '@moostjs/event-cli'
|
|
2
2
|
|
|
3
3
|
@Controller()
|
|
4
4
|
class Commands {
|
|
@@ -6,18 +6,26 @@ class Commands {
|
|
|
6
6
|
@CliExample('hello world -u', 'Prints "HELLO, WORLD!"')
|
|
7
7
|
@Cli('hello/:name')
|
|
8
8
|
greet(
|
|
9
|
-
@
|
|
10
|
-
@
|
|
9
|
+
@Description('A name to greet')
|
|
10
|
+
@Param('name')
|
|
11
|
+
name: string,
|
|
12
|
+
|
|
13
|
+
@Description('Whether to print the greeting in uppercase')
|
|
14
|
+
@CliOption('uppercase', 'u')
|
|
15
|
+
uppercase: boolean,
|
|
11
16
|
) {
|
|
12
17
|
const output = `Hello, ${name}!`
|
|
13
18
|
return uppercase ? output.toUpperCase() : output
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
/**
|
|
23
|
+
* npm run dev hello world
|
|
24
|
+
*/
|
|
17
25
|
function run() {
|
|
18
26
|
new CliApp()
|
|
19
27
|
.controllers(Commands)
|
|
20
|
-
.useHelp({ name: '{{ packageName }}'})
|
|
28
|
+
.useHelp({ name: '{{ packageName }}', title: ''})
|
|
21
29
|
.useOptions([{ keys: ['help'], description: 'Display instructions for the command.' }])
|
|
22
30
|
.start()
|
|
23
31
|
}
|