feat: 生成的配置文件增加 build 字段

This commit is contained in:
Luke 2025-06-24 17:06:39 +08:00
parent 707967e62c
commit 0a236d914d
4 changed files with 37 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package org.jcnc.snow.cli.commands;
import org.jcnc.snow.cli.api.CLICommand;
import org.jcnc.snow.cli.utils.ProjectCloudExample;
import java.nio.file.Files;
import java.nio.file.Path;
@ -60,14 +61,7 @@ public final class InitCommand implements CLICommand {
Path dir = Paths.get(".").toAbsolutePath();
Path dsl = dir.resolve("project.cloud");
if (Files.notExists(dsl)) {
Files.writeString(dsl, """
# Generated by snow init
project {
group = "com.example"
artifact = "demo-app"
version = "0.0.1-SNAPSHOT"
}
""");
Files.writeString(dsl, ProjectCloudExample.getProjectCloud());
System.out.println("[init] created " + dsl);
} else {
System.out.println("[init] project.cloud already exists");

View File

@ -0,0 +1,31 @@
package org.jcnc.snow.cli.utils;
public class ProjectCloudExample {
/**
* 工具类构造方法禁止实例化
*/
private ProjectCloudExample() {
// 工具类不允许实例化
}
/**
* 获取 main.snow 示例模块的内容字符串
*
* @return main.snow 示例模块的完整代码
*/
public static String getProjectCloud() {
return """
# Generated by snow init
project {
group = "com.example"
artifact = "demo-app"
version = "0.0.1-SNAPSHOT"
}
build {
srcDir = "src"
output = "build/demo-app"
}
""";
}
}

View File

@ -1,7 +1,7 @@
package org.jcnc.snow.pkg.tasks;
import org.jcnc.snow.pkg.model.Project;
import org.jcnc.snow.pkg.utils.SnowExampleTemplate;
import org.jcnc.snow.pkg.utils.SnowExample;
import java.io.IOException;
import java.nio.file.Files;
@ -69,7 +69,7 @@ public final class GenerateTask implements Task {
// 创建 src/main.snow 示例入口文件
Path mainSnow = root.resolve("src").resolve("main.snow");
if (Files.notExists(mainSnow)) {
Files.writeString(mainSnow, SnowExampleTemplate.getMainModule());
Files.writeString(mainSnow, SnowExample.getMainModule());
System.out.println("[generate] created src/main.snow");
}

View File

@ -6,12 +6,12 @@ package org.jcnc.snow.pkg.utils;
* 用于项目脚手架生成或帮助用户快速上手 .snow 语言
* </p>
*/
public final class SnowExampleTemplate {
public final class SnowExample {
/**
* 工具类构造方法禁止实例化
*/
private SnowExampleTemplate() {
private SnowExample() {
// 工具类不允许实例化
}