2022-05-08 18:04:21 +00:00
|
|
|
#!/usr/bin/env dub
|
|
|
|
/+ dub.sdl:
|
|
|
|
dependency "dsh" version="~>1.6.1"
|
2022-06-03 08:46:26 +00:00
|
|
|
dependency "dxml" version="~>0.4.3"
|
|
|
|
dependency "requests" version="~>2.0.8"
|
2022-05-08 18:04:21 +00:00
|
|
|
+/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This script will build the Rail Signal Vue app, then bundle it into this
|
|
|
|
* Spring project's files under src/main/resources/app/, and will then build
|
|
|
|
* this project into a jar file.
|
|
|
|
*/
|
|
|
|
module build_system;
|
|
|
|
|
|
|
|
import dsh;
|
2022-06-03 08:46:26 +00:00
|
|
|
import dxml.dom;
|
|
|
|
import dxml.util;
|
|
|
|
|
2022-05-30 22:47:11 +00:00
|
|
|
import std.stdio;
|
|
|
|
import std.string;
|
2022-06-03 08:46:26 +00:00
|
|
|
import std.algorithm;
|
|
|
|
import std.uni;
|
2022-05-08 18:04:21 +00:00
|
|
|
|
|
|
|
const DIST = "./src/main/resources/app";
|
2022-05-24 08:38:42 +00:00
|
|
|
const DIST_ORIGIN = "./quasar-app/dist/spa";
|
2022-06-03 08:46:26 +00:00
|
|
|
const APP_DIR = "./quasar-app";
|
2022-05-24 08:38:42 +00:00
|
|
|
const APP_BUILD = "quasar build -m spa";
|
2022-05-30 22:47:11 +00:00
|
|
|
const API_BUILD = "mvn clean package spring-boot:repackage -DskipTests=true";
|
2022-05-08 18:04:21 +00:00
|
|
|
|
2022-06-03 08:46:26 +00:00
|
|
|
const LOG_DIR = "./log";
|
|
|
|
const API_LOG = LOG_DIR ~ "/api_build.txt";
|
|
|
|
const APP_LOG = LOG_DIR ~ "/app_build.txt";
|
|
|
|
|
|
|
|
int main(string[] args) {
|
|
|
|
string ver = getVersion();
|
|
|
|
if (ver is null) {
|
|
|
|
error("Could not determine version.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
removeIfExists(LOG_DIR);
|
|
|
|
mkdir(LOG_DIR);
|
|
|
|
print("Building Rail Signal v%s", ver);
|
|
|
|
|
|
|
|
if (args.length >= 2) {
|
|
|
|
string command = args[1].strip.toLower;
|
|
|
|
if (command == "app") {
|
|
|
|
buildApp();
|
|
|
|
} else if (command == "api") {
|
|
|
|
buildApi(ver);
|
|
|
|
} else if (command == "all") {
|
|
|
|
buildApp();
|
|
|
|
buildApi(ver);
|
|
|
|
if (args.length >= 3 && args[2].strip.toLower == "release") {
|
|
|
|
if (args.length >= 4) {
|
|
|
|
string token = args[3].strip();
|
|
|
|
print("Are you sure you want to create a GitHub release for version %s?", ver);
|
|
|
|
string response = readln().strip.toLower;
|
|
|
|
if (response == "yes" || response == "y") createRelease(token, ver);
|
|
|
|
} else {
|
|
|
|
error("Missing required personal access token to create a GitHub release.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buildApp();
|
|
|
|
buildApi(ver);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the production version of the frontend app and injects it into the
|
|
|
|
* API's resources to serve statically.
|
|
|
|
*/
|
|
|
|
void buildApp() {
|
|
|
|
chdir(APP_DIR);
|
2022-05-08 18:04:21 +00:00
|
|
|
print("Building app...");
|
2022-06-03 08:46:26 +00:00
|
|
|
runOrQuit(APP_BUILD, "." ~ APP_LOG); // Use an extra dot because we moved into app dir.
|
2022-05-24 08:38:42 +00:00
|
|
|
print("Copying dist from %s to %s", DIST_ORIGIN, DIST);
|
2022-05-08 18:04:21 +00:00
|
|
|
chdir("..");
|
|
|
|
removeIfExists(DIST);
|
|
|
|
mkdir(DIST);
|
2022-05-24 08:38:42 +00:00
|
|
|
copyDir(DIST_ORIGIN, DIST);
|
2022-06-03 08:46:26 +00:00
|
|
|
}
|
2022-05-30 22:47:11 +00:00
|
|
|
|
2022-06-03 08:46:26 +00:00
|
|
|
/**
|
|
|
|
* Builds the production version of the backend API.
|
|
|
|
*/
|
|
|
|
void buildApi(string ver) {
|
2022-05-08 18:04:21 +00:00
|
|
|
print("Building API...");
|
2022-06-03 08:46:26 +00:00
|
|
|
runOrQuit(API_BUILD, API_LOG);
|
|
|
|
string[] jars = findFilesByExtension("target", ".jar", false);
|
|
|
|
string jarFile = jars[0];
|
|
|
|
string finalJarFile = "./target/rail-signal-" ~ ver ~ ".jar";
|
|
|
|
// Clean up the jar file name.
|
|
|
|
copy(jarFile, finalJarFile);
|
|
|
|
print("Build complete. Created %s", finalJarFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the version of the system from the pom file.
|
|
|
|
* Returns: The version string, or null if it couldn't be found.
|
|
|
|
*/
|
|
|
|
string getVersion() {
|
|
|
|
auto data = parseDOM!simpleXML(readText("pom.xml"));
|
|
|
|
auto root = data.children[0];
|
|
|
|
foreach (child; root.children) {
|
|
|
|
if (child.name == "version") {
|
|
|
|
return child.children[0].text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2022-05-08 18:04:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 08:46:26 +00:00
|
|
|
void createRelease(string token, string ver) {
|
|
|
|
|
|
|
|
}
|