From e5e9c2692c8c0229773dcb6d91e699b652479cea Mon Sep 17 00:00:00 2001 From: canonical Date: Tue, 21 Jan 2025 20:13:09 +0800 Subject: [PATCH] =?UTF-8?q?nop-cli=20gen=E5=A2=9E=E5=8A=A0input=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/nop/cli/commands/CliGenCommand.java | 10 ++++++++++ .../java/io/nop/cli/commands/CliGenFileCommand.java | 6 +++--- .../java/io/nop/cli/commands/CliWatchCommand.java | 12 +++++++++++- .../src/test/resources/application.yaml | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 nop-dyn/nop-dyn-service/src/test/resources/application.yaml diff --git a/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenCommand.java b/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenCommand.java index 2077fe9ba..e0bd5c127 100644 --- a/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenCommand.java +++ b/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenCommand.java @@ -14,6 +14,7 @@ import io.nop.commons.util.FileHelper; import io.nop.commons.util.StringHelper; import io.nop.core.lang.eval.IEvalScope; +import io.nop.core.lang.json.JsonTool; import io.nop.core.resource.IResource; import io.nop.core.resource.ResourceHelper; import io.nop.core.resource.VirtualFileSystem; @@ -25,6 +26,7 @@ import picocli.CommandLine; import java.io.File; +import java.util.Map; import java.util.concurrent.Callable; @CommandLine.Command( @@ -40,6 +42,9 @@ public class CliGenCommand implements Callable { description = "模板文件路径,至少需要指定一个模板。") String[] templates; + @CommandLine.Option(names = {"-i", "--input"}, description = "输入参数") + String input; + @CommandLine.Option(names = {"-o", "--output"}, description = "输出目录,缺省为当前目录") File outputDir; @@ -54,6 +59,11 @@ public Integer call() { try { IResource resource = ResourceHelper.resolveRelativePathResource(file); IEvalScope scope = XLang.newEvalScope(); + if (input != null) { + Map map = (Map) JsonTool.parseNonStrict(null, input); + scope.setLocalValues(map); + } + scope.setLocalValue(null, CodeGenConstants.VAR_CODE_GEN_MODEL_PATH, resource.getPath()); ComponentModelConfig config = ResourceComponentManager.instance().getModelConfigByModelPath(resource.getPath()); diff --git a/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenFileCommand.java b/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenFileCommand.java index 34afca886..ebdaaed47 100644 --- a/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenFileCommand.java +++ b/nop-cli-core/src/main/java/io/nop/cli/commands/CliGenFileCommand.java @@ -75,12 +75,14 @@ public Integer call() { } } + IEvalScope scope = XLang.newEvalScope(); + scope.setLocalValues(json); + if (template.endsWith(".xdef")) { DslModelHelper.saveDslModel(template, json, new FileResource(outputFile)); } else if (template.endsWith(".imp.xml")) { ExcelWorkbook xptModel = ExcelReportHelper.buildXptModelFromImpModel(template); - IEvalScope scope = XLang.newEvalScope(); scope.setLocalValue(null, XptConstants.VAR_ENTITY, json); String renderType = StringHelper.fileExt(outputFile.getName()); @@ -89,7 +91,6 @@ public Integer call() { // 报表模板 IResource tplResource = ResourceHelper.resolveRelativePathResource(template); ExcelWorkbook xptModel = new XptModelLoader().loadModelFromResource(tplResource); - IEvalScope scope = XLang.newEvalScope(); scope.setLocalValue(null, XptConstants.VAR_ENTITY, json); String renderType = StringHelper.fileExt(outputFile.getName()); @@ -98,7 +99,6 @@ public Integer call() { // Word模板 IResource tplResource = ResourceHelper.resolveRelativePathResource(template); WordTemplate tpl = new WordTemplateParser().parseFromResource(tplResource); - IEvalScope scope = XLang.newEvalScope(); scope.setLocalValue(null, XptConstants.VAR_ENTITY, json); tpl.generateToFile(outputFile, scope); } else { diff --git a/nop-cli-core/src/main/java/io/nop/cli/commands/CliWatchCommand.java b/nop-cli-core/src/main/java/io/nop/cli/commands/CliWatchCommand.java index aecbb2f85..0eb28a983 100644 --- a/nop-cli-core/src/main/java/io/nop/cli/commands/CliWatchCommand.java +++ b/nop-cli-core/src/main/java/io/nop/cli/commands/CliWatchCommand.java @@ -10,6 +10,7 @@ import io.nop.api.core.exceptions.NopException; import io.nop.commons.util.FileHelper; import io.nop.core.lang.eval.IEvalScope; +import io.nop.core.lang.json.JsonTool; import io.nop.core.resource.IResource; import io.nop.core.resource.ResourceHelper; import io.nop.core.resource.watch.FileChangeEvent; @@ -17,11 +18,11 @@ import io.nop.xlang.api.XLang; import io.nop.xlang.api.XplModel; import io.nop.xlang.ast.XLangOutputMode; +import jakarta.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine; -import jakarta.inject.Inject; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -55,6 +56,9 @@ public class CliWatchCommand implements Callable { @CommandLine.Option(names = {"-w", "--wait"}, description = "延迟处理等待间隔,缺省为100毫秒") int debounceWait = 100; + @CommandLine.Option(names = {"-i", "--input"}, description = "输入参数") + String input; + @Inject FileWatcherFactory fileWatcherFactory; @@ -91,6 +95,12 @@ public Integer call() { private void processEvents(XplModel xpl, Collection events, Map state) { IEvalScope scope = XLang.newEvalScope(); + + if (input != null) { + Map map = (Map) JsonTool.parseNonStrict(null, input); + scope.setLocalValues(map); + } + scope.setLocalValue("changeEvents", events); scope.setLocalValue("globalState", state); scope.setLocalValue("watchDirs", watchDirs); diff --git a/nop-dyn/nop-dyn-service/src/test/resources/application.yaml b/nop-dyn/nop-dyn-service/src/test/resources/application.yaml new file mode 100644 index 000000000..ed1ccea9a --- /dev/null +++ b/nop-dyn/nop-dyn-service/src/test/resources/application.yaml @@ -0,0 +1,2 @@ +nop: + debug: true \ No newline at end of file