@ultikits/cli 1.0.1 → 1.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.
@@ -7,11 +7,12 @@ import { registerInitCommand } from '../src/commands/init.js';
7
7
  import { registerPublishCommand } from '../src/commands/publish.js';
8
8
  import { registerModulesCommand } from '../src/commands/modules.js';
9
9
  import { registerVersionsCommand } from '../src/commands/versions.js';
10
+ import { registerCreateCommand } from '../src/commands/create.js';
10
11
  const program = new Command();
11
12
  program
12
13
  .name('ultikits')
13
14
  .description('CLI for publishing UltiTools plugin modules to UltiCloud')
14
- .version('1.0.1');
15
+ .version('1.1.0');
15
16
  registerLoginCommand(program);
16
17
  registerLogoutCommand(program);
17
18
  registerWhoamiCommand(program);
@@ -19,5 +20,6 @@ registerInitCommand(program);
19
20
  registerPublishCommand(program);
20
21
  registerModulesCommand(program);
21
22
  registerVersionsCommand(program);
23
+ registerCreateCommand(program);
22
24
  program.parse();
23
25
  //# sourceMappingURL=ultikits.js.map
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerCreateCommand(program: Command): void;
@@ -0,0 +1,95 @@
1
+ import inquirer from 'inquirer';
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import * as log from '../lib/logger.js';
6
+ import { derivePackageName, generatePomXml, generatePluginYml, generateMainClass, generateEnLang, generateZhLang, generateReadme, generateGitignore, } from '../lib/templates.js';
7
+ function getGitUserName() {
8
+ try {
9
+ return execFileSync('git', ['config', 'user.name'], { encoding: 'utf-8' }).trim();
10
+ }
11
+ catch {
12
+ return '';
13
+ }
14
+ }
15
+ export function registerCreateCommand(program) {
16
+ program
17
+ .command('create')
18
+ .argument('[directory]', 'Target directory name (defaults to module name)')
19
+ .description('Scaffold a new UltiTools module project')
20
+ .action(async (directory) => {
21
+ const answers = await inquirer.prompt([
22
+ {
23
+ type: 'input',
24
+ name: 'moduleName',
25
+ message: 'Module name (e.g., UltiHome):',
26
+ validate: (v) => /^[A-Z][a-zA-Z0-9]+$/.test(v)
27
+ ? true
28
+ : 'Must start with uppercase letter, alphanumeric only',
29
+ },
30
+ {
31
+ type: 'input',
32
+ name: 'packageName',
33
+ message: 'Java package name:',
34
+ default: (prev) => derivePackageName(prev.moduleName),
35
+ validate: (v) => /^[a-z][a-z0-9_.]*[a-z0-9]$/.test(v)
36
+ ? true
37
+ : 'Must be a valid Java package name (lowercase, dots)',
38
+ },
39
+ {
40
+ type: 'input',
41
+ name: 'description',
42
+ message: 'Short description:',
43
+ validate: (v) => (v.trim().length > 0 ? true : 'Required'),
44
+ },
45
+ {
46
+ type: 'input',
47
+ name: 'author',
48
+ message: 'Author:',
49
+ default: getGitUserName(),
50
+ validate: (v) => (v.trim().length > 0 ? true : 'Required'),
51
+ },
52
+ {
53
+ type: 'input',
54
+ name: 'apiVersion',
55
+ message: 'UltiTools-API version:',
56
+ default: '6.2.2',
57
+ },
58
+ ]);
59
+ const params = answers;
60
+ const targetDir = join(process.cwd(), directory ?? params.moduleName);
61
+ if (existsSync(targetDir)) {
62
+ log.error(`Directory already exists: ${targetDir}`);
63
+ return;
64
+ }
65
+ const spin = log.spinner('Creating project...');
66
+ spin.start();
67
+ const packagePath = params.packageName.replace(/\./g, '/');
68
+ const srcMain = join(targetDir, 'src/main/java', packagePath);
69
+ const srcTest = join(targetDir, 'src/test/java', packagePath);
70
+ const resources = join(targetDir, 'src/main/resources');
71
+ const langDir = join(resources, 'lang');
72
+ mkdirSync(srcMain, { recursive: true });
73
+ mkdirSync(srcTest, { recursive: true });
74
+ mkdirSync(langDir, { recursive: true });
75
+ writeFileSync(join(targetDir, 'pom.xml'), generatePomXml(params));
76
+ writeFileSync(join(resources, 'plugin.yml'), generatePluginYml(params));
77
+ writeFileSync(join(srcMain, `${params.moduleName}.java`), generateMainClass(params));
78
+ writeFileSync(join(langDir, 'en.yml'), generateEnLang(params));
79
+ writeFileSync(join(langDir, 'zh.yml'), generateZhLang(params));
80
+ writeFileSync(join(targetDir, 'README.md'), generateReadme(params));
81
+ writeFileSync(join(targetDir, '.gitignore'), generateGitignore());
82
+ try {
83
+ execFileSync('git', ['init'], { cwd: targetDir, stdio: 'ignore' });
84
+ }
85
+ catch {
86
+ log.warn('Could not initialize git repository');
87
+ }
88
+ spin.stop();
89
+ log.success(`Created ${params.moduleName} at ${targetDir}`);
90
+ log.info('Next steps:');
91
+ log.info(` cd ${directory ?? params.moduleName}`);
92
+ log.info(' mvn compile');
93
+ });
94
+ }
95
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1,9 @@
1
+ import type { CreateParams } from '../types.js';
2
+ export declare function derivePackageName(moduleName: string): string;
3
+ export declare function generatePomXml(params: CreateParams): string;
4
+ export declare function generatePluginYml(params: CreateParams): string;
5
+ export declare function generateMainClass(params: CreateParams): string;
6
+ export declare function generateEnLang(params: CreateParams): string;
7
+ export declare function generateZhLang(params: CreateParams): string;
8
+ export declare function generateReadme(params: CreateParams): string;
9
+ export declare function generateGitignore(): string;
@@ -0,0 +1,251 @@
1
+ export function derivePackageName(moduleName) {
2
+ const lower = moduleName.toLowerCase();
3
+ const suffix = lower.startsWith('ulti') ? lower.slice(4) : lower;
4
+ return `com.ultikits.plugins.${suffix}`;
5
+ }
6
+ export function generatePomXml(params) {
7
+ const mv = (name) => '${' + name + '}';
8
+ return `<?xml version="1.0" encoding="UTF-8"?>
9
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
10
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
12
+ <modelVersion>4.0.0</modelVersion>
13
+
14
+ <groupId>com.ultikits.plugins</groupId>
15
+ <artifactId>${params.moduleName}</artifactId>
16
+ <version>1.0.0</version>
17
+ <packaging>jar</packaging>
18
+
19
+ <name>${params.moduleName}</name>
20
+ <description>${params.description}</description>
21
+
22
+ <properties>
23
+ <java.version>1.8</java.version>
24
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25
+ <ultitools.version>${params.apiVersion}</ultitools.version>
26
+ </properties>
27
+
28
+ <repositories>
29
+ <repository>
30
+ <id>spigot-repo</id>
31
+ <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
32
+ </repository>
33
+ </repositories>
34
+
35
+ <dependencies>
36
+ <dependency>
37
+ <groupId>org.spigotmc</groupId>
38
+ <artifactId>spigot-api</artifactId>
39
+ <version>1.20.1-R0.1-SNAPSHOT</version>
40
+ <scope>provided</scope>
41
+ </dependency>
42
+ <dependency>
43
+ <groupId>com.ultikits</groupId>
44
+ <artifactId>UltiTools-API</artifactId>
45
+ <version>${mv('ultitools.version')}</version>
46
+ <scope>provided</scope>
47
+ </dependency>
48
+ <dependency>
49
+ <groupId>org.projectlombok</groupId>
50
+ <artifactId>lombok</artifactId>
51
+ <version>1.18.30</version>
52
+ <scope>provided</scope>
53
+ </dependency>
54
+
55
+ <!-- Test dependencies -->
56
+ <dependency>
57
+ <groupId>org.junit.jupiter</groupId>
58
+ <artifactId>junit-jupiter-engine</artifactId>
59
+ <version>5.10.0</version>
60
+ <scope>test</scope>
61
+ </dependency>
62
+ <dependency>
63
+ <groupId>org.junit.jupiter</groupId>
64
+ <artifactId>junit-jupiter-api</artifactId>
65
+ <version>5.10.0</version>
66
+ <scope>test</scope>
67
+ </dependency>
68
+ <dependency>
69
+ <groupId>org.junit.jupiter</groupId>
70
+ <artifactId>junit-jupiter-params</artifactId>
71
+ <version>5.10.0</version>
72
+ <scope>test</scope>
73
+ </dependency>
74
+ <dependency>
75
+ <groupId>org.mockito</groupId>
76
+ <artifactId>mockito-core</artifactId>
77
+ <version>5.5.0</version>
78
+ <scope>test</scope>
79
+ </dependency>
80
+ <dependency>
81
+ <groupId>org.mockito</groupId>
82
+ <artifactId>mockito-junit-jupiter</artifactId>
83
+ <version>5.5.0</version>
84
+ <scope>test</scope>
85
+ </dependency>
86
+ <dependency>
87
+ <groupId>org.assertj</groupId>
88
+ <artifactId>assertj-core</artifactId>
89
+ <version>3.24.2</version>
90
+ <scope>test</scope>
91
+ </dependency>
92
+ </dependencies>
93
+
94
+ <build>
95
+ <resources>
96
+ <resource>
97
+ <directory>src/main/resources</directory>
98
+ <filtering>true</filtering>
99
+ </resource>
100
+ </resources>
101
+ <plugins>
102
+ <plugin>
103
+ <groupId>org.apache.maven.plugins</groupId>
104
+ <artifactId>maven-compiler-plugin</artifactId>
105
+ <version>3.11.0</version>
106
+ <configuration>
107
+ <source>${mv('java.version')}</source>
108
+ <target>${mv('java.version')}</target>
109
+ <annotationProcessorPaths>
110
+ <path>
111
+ <groupId>org.projectlombok</groupId>
112
+ <artifactId>lombok</artifactId>
113
+ <version>1.18.30</version>
114
+ </path>
115
+ </annotationProcessorPaths>
116
+ </configuration>
117
+ </plugin>
118
+ <plugin>
119
+ <groupId>org.apache.maven.plugins</groupId>
120
+ <artifactId>maven-surefire-plugin</artifactId>
121
+ <version>3.1.2</version>
122
+ </plugin>
123
+ <plugin>
124
+ <groupId>org.jacoco</groupId>
125
+ <artifactId>jacoco-maven-plugin</artifactId>
126
+ <version>0.8.11</version>
127
+ <executions>
128
+ <execution>
129
+ <goals>
130
+ <goal>prepare-agent</goal>
131
+ </goals>
132
+ </execution>
133
+ <execution>
134
+ <id>report</id>
135
+ <phase>test</phase>
136
+ <goals>
137
+ <goal>report</goal>
138
+ </goals>
139
+ </execution>
140
+ </executions>
141
+ </plugin>
142
+ </plugins>
143
+ </build>
144
+ </project>
145
+ `;
146
+ }
147
+ export function generatePluginYml(params) {
148
+ return `name: ${params.moduleName}
149
+ version: '\${project.version}'
150
+ main: ${params.packageName}.${params.moduleName}
151
+ authors:
152
+ - ${params.author}
153
+ - UltiKits Team
154
+ description: ${params.description}
155
+ api-version: 620
156
+ loadAfter: []
157
+ `;
158
+ }
159
+ export function generateMainClass(params) {
160
+ return `package ${params.packageName};
161
+
162
+ import com.ultikits.ultitools.abstracts.UltiToolsPlugin;
163
+ import com.ultikits.ultitools.annotations.UltiToolsModule;
164
+
165
+ import java.util.List;
166
+ import java.util.Arrays;
167
+
168
+ @UltiToolsModule(scanBasePackages = "${params.packageName}")
169
+ public class ${params.moduleName} extends UltiToolsPlugin {
170
+
171
+ @Override
172
+ public boolean registerSelf() {
173
+ return true;
174
+ }
175
+
176
+ @Override
177
+ public void unregisterSelf() {
178
+ }
179
+
180
+ @Override
181
+ public void reloadSelf() {
182
+ }
183
+
184
+ @Override
185
+ public List<String> supported() {
186
+ return Arrays.asList("en", "zh");
187
+ }
188
+ }
189
+ `;
190
+ }
191
+ export function generateEnLang(params) {
192
+ return `# ${params.moduleName} - English language file
193
+
194
+ module_enabled: "${params.moduleName} has been enabled."
195
+ module_disabled: "${params.moduleName} has been disabled."
196
+ `;
197
+ }
198
+ export function generateZhLang(params) {
199
+ return `# ${params.moduleName} - 中文语言文件
200
+
201
+ module_enabled: "${params.moduleName} 已启用。"
202
+ module_disabled: "${params.moduleName} 已禁用。"
203
+ `;
204
+ }
205
+ export function generateReadme(params) {
206
+ return `# ${params.moduleName}
207
+
208
+ ${params.description}
209
+
210
+ ## Installation
211
+
212
+ 1. Download the latest release JAR
213
+ 2. Place it in \`plugins/UltiTools/plugins/\` directory
214
+ 3. Restart the server
215
+
216
+ ## 安装
217
+
218
+ 1. 下载最新版本的 JAR 文件
219
+ 2. 将其放入 \`plugins/UltiTools/plugins/\` 目录
220
+ 3. 重启服务器
221
+
222
+ ## Requirements
223
+
224
+ - Minecraft 1.21+
225
+ - UltiTools-API ${params.apiVersion}+
226
+
227
+ ## License
228
+
229
+ MIT
230
+ `;
231
+ }
232
+ export function generateGitignore() {
233
+ return `target/
234
+ *.class
235
+ *.jar
236
+ *.log
237
+
238
+ # IDE
239
+ .idea/
240
+ *.iml
241
+ .vscode/
242
+ .settings/
243
+ .project
244
+ .classpath
245
+
246
+ # OS
247
+ .DS_Store
248
+ Thumbs.db
249
+ `;
250
+ }
251
+ //# sourceMappingURL=templates.js.map
@@ -36,3 +36,10 @@ export interface ApiResponse<T = any> {
36
36
  msg: string;
37
37
  data?: T;
38
38
  }
39
+ export interface CreateParams {
40
+ moduleName: string;
41
+ packageName: string;
42
+ description: string;
43
+ author: string;
44
+ apiVersion: string;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultikits/cli",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "CLI tool for publishing UltiTools plugin modules to UltiCloud marketplace",
5
5
  "type": "module",
6
6
  "bin": {