create-moost 0.5.22 → 0.5.24

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