forked from loafle/openapi-generator-original
Rename Env variable for Elm post process file (#1094)
This commit is contained in:
parent
8fb3b707a1
commit
e3b26372cd
@ -165,22 +165,31 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public void processOpts() {
|
public void processOpts() {
|
||||||
super.processOpts();
|
super.processOpts();
|
||||||
|
|
||||||
if (StringUtils.isEmpty(System.getenv("ELM_FORMAT_PATH"))) {
|
|
||||||
LOGGER.info("Environment variable ELM_FORMAT_PATH not defined so the Elm code may not be properly formatted. To define it, try 'export ELM_FORMAT_PATH=/usr/local/bin/elm-format' (Linux/Mac)");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (additionalProperties.containsKey(ELM_VERSION)) {
|
if (additionalProperties.containsKey(ELM_VERSION)) {
|
||||||
final String version = (String) additionalProperties.get(ELM_VERSION);
|
final String version = (String) additionalProperties.get(ELM_VERSION);
|
||||||
if ("0.18".equals(version)) {
|
if ("0.18".equals(version)) {
|
||||||
elmVersion = ElmVersion.ELM_018;
|
elmVersion = ElmVersion.ELM_018;
|
||||||
|
} else {
|
||||||
|
elmVersion = ElmVersion.ELM_019;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(System.getenv("ELM_POST_PROCESS_FILE"))) {
|
||||||
|
if (elmVersion.equals(ElmVersion.ELM_018)) { // 0.18
|
||||||
|
LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.18");
|
||||||
|
} else { // 0.19
|
||||||
|
LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.19");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (elmVersion) {
|
switch (elmVersion) {
|
||||||
case ELM_018:
|
case ELM_018:
|
||||||
|
LOGGER.info("Elm version = 0.18");
|
||||||
additionalProperties.put("isElm018", true);
|
additionalProperties.put("isElm018", true);
|
||||||
break;
|
break;
|
||||||
case ELM_019:
|
case ELM_019:
|
||||||
|
LOGGER.info("Elm version = 0.19");
|
||||||
additionalProperties.put("isElm019", true);
|
additionalProperties.put("isElm019", true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -640,26 +649,24 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String elmFmtPath = System.getenv("ELM_FORMAT_PATH");
|
String elmPostProcessFile = System.getenv("ELM_POST_PROCESS_FILE");
|
||||||
if (StringUtils.isEmpty(elmFmtPath)) {
|
if (StringUtils.isEmpty(elmPostProcessFile)) {
|
||||||
return; // skip if ELM_FORMAT_PATH env variable is not defined
|
return; // skip if ELM_POST_PROCESS_FILE env variable is not defined
|
||||||
}
|
}
|
||||||
|
|
||||||
// only process files with elm extension
|
// only process files with elm extension
|
||||||
if ("elm".equals(FilenameUtils.getExtension(file.toString()))) {
|
if ("elm".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||||
// currently only support "elm-format -w yourcode.elm"
|
// e.g. elm-format -w yourcode.elm
|
||||||
String command = elmFmtPath + " --yes " + file.toString();
|
String command = elmPostProcessFile + " " + file.toString();
|
||||||
if (ElmVersion.ELM_018.equals(elmVersion)) {
|
|
||||||
command += " --elm-version=0.18";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Process p = Runtime.getRuntime().exec(command);
|
Process p = Runtime.getRuntime().exec(command);
|
||||||
p.waitFor();
|
int exitValue = p.waitFor();
|
||||||
if (p.exitValue() != 0) {
|
if (exitValue != 0) {
|
||||||
LOGGER.error("Error running the command ({}). Exit code: {}", command, p.exitValue());
|
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Successfully executed: " + command);
|
||||||
}
|
}
|
||||||
LOGGER.info("Successfully executed: " + command);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user