2024-05-17 01:21:26 +02:00
|
|
|
import { generateSrcMainResources } from "./generateSrcMainResources";
|
2024-05-11 23:20:15 +02:00
|
|
|
import { join as pathJoin, relative as pathRelative, sep as pathSep } from "path";
|
2021-06-14 21:21:36 +02:00
|
|
|
import * as child_process from "child_process";
|
2022-01-18 18:52:52 +01:00
|
|
|
import * as fs from "fs";
|
2024-05-15 05:14:01 +02:00
|
|
|
import { readBuildOptions } from "../shared/buildOptions";
|
2024-05-20 02:27:40 +02:00
|
|
|
import { vitePluginSubScriptEnvNames, skipBuildJarsEnvName } from "../shared/constants";
|
2024-05-12 19:16:59 +02:00
|
|
|
import { buildJars } from "./buildJars";
|
2024-05-15 05:14:01 +02:00
|
|
|
import type { CliCommandOptions } from "../main";
|
2024-05-18 10:24:55 +02:00
|
|
|
import chalk from "chalk";
|
|
|
|
import { readThisNpmPackageVersion } from "../tools/readThisNpmPackageVersion";
|
2024-05-18 10:46:48 +02:00
|
|
|
import * as os from "os";
|
2021-06-14 21:21:36 +02:00
|
|
|
|
2024-05-15 05:14:01 +02:00
|
|
|
export async function command(params: { cliCommandOptions: CliCommandOptions }) {
|
2024-05-18 11:40:09 +02:00
|
|
|
exit_if_maven_not_installed: {
|
2024-05-18 10:46:48 +02:00
|
|
|
let commandOutput: Buffer | undefined = undefined;
|
|
|
|
|
|
|
|
try {
|
2024-05-20 15:48:51 +02:00
|
|
|
commandOutput = child_process.execSync("mvn --version", {
|
|
|
|
stdio: ["ignore", "pipe", "ignore"]
|
|
|
|
});
|
2024-05-18 10:46:48 +02:00
|
|
|
} catch {}
|
|
|
|
|
2024-05-19 04:44:38 +02:00
|
|
|
if (commandOutput?.toString("utf8").includes("Apache Maven")) {
|
2024-05-18 11:40:09 +02:00
|
|
|
break exit_if_maven_not_installed;
|
2024-05-18 10:46:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const installationCommand = (() => {
|
|
|
|
switch (os.platform()) {
|
|
|
|
case "darwin":
|
2024-05-19 04:44:38 +02:00
|
|
|
return "brew install mvn";
|
2024-05-18 10:46:48 +02:00
|
|
|
case "win32":
|
2024-05-19 04:44:38 +02:00
|
|
|
return "choco install mvn";
|
2024-05-18 10:46:48 +02:00
|
|
|
case "linux":
|
|
|
|
default:
|
2024-05-19 04:44:38 +02:00
|
|
|
return "sudo apt-get install mvn";
|
2024-05-18 10:46:48 +02:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
console.log(
|
|
|
|
`${chalk.red("Apache Maven required.")} Install it with \`${chalk.bold(
|
|
|
|
installationCommand
|
|
|
|
)}\` (for example)`
|
|
|
|
);
|
2024-05-18 10:46:48 +02:00
|
|
|
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2024-05-18 11:09:04 +02:00
|
|
|
const { cliCommandOptions } = params;
|
|
|
|
|
2024-05-15 05:14:01 +02:00
|
|
|
const buildOptions = readBuildOptions({ cliCommandOptions });
|
2021-06-23 18:03:49 +02:00
|
|
|
|
2024-05-18 10:24:55 +02:00
|
|
|
console.log(
|
|
|
|
[
|
|
|
|
chalk.cyan(`keycloakify v${readThisNpmPackageVersion()}`),
|
2024-05-20 15:48:51 +02:00
|
|
|
chalk.green(
|
|
|
|
`Building the keycloak theme in .${pathSep}${pathRelative(
|
|
|
|
process.cwd(),
|
|
|
|
buildOptions.keycloakifyBuildDirPath
|
|
|
|
)} ...`
|
|
|
|
)
|
2024-05-18 10:24:55 +02:00
|
|
|
].join(" ")
|
|
|
|
);
|
2024-05-16 09:20:37 +02:00
|
|
|
|
2024-05-18 10:24:55 +02:00
|
|
|
const startTime = Date.now();
|
2023-04-19 05:04:11 +02:00
|
|
|
|
2024-05-12 19:37:16 +02:00
|
|
|
{
|
2024-05-12 19:38:48 +02:00
|
|
|
if (!fs.existsSync(buildOptions.keycloakifyBuildDirPath)) {
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.mkdirSync(buildOptions.keycloakifyBuildDirPath, {
|
|
|
|
recursive: true
|
|
|
|
});
|
2024-05-12 19:38:48 +02:00
|
|
|
}
|
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
fs.writeFileSync(
|
|
|
|
pathJoin(buildOptions.keycloakifyBuildDirPath, ".gitignore"),
|
|
|
|
Buffer.from("*", "utf8")
|
|
|
|
);
|
2024-05-12 19:38:48 +02:00
|
|
|
}
|
|
|
|
|
2024-05-17 01:21:26 +02:00
|
|
|
await generateSrcMainResources({ buildOptions });
|
2024-05-12 19:38:48 +02:00
|
|
|
|
2024-03-05 19:42:49 +01:00
|
|
|
run_post_build_script: {
|
|
|
|
if (buildOptions.bundler !== "vite") {
|
|
|
|
break run_post_build_script;
|
2024-02-23 19:15:59 +01:00
|
|
|
}
|
2024-03-05 19:42:49 +01:00
|
|
|
|
|
|
|
child_process.execSync("npx vite", {
|
2024-05-20 15:48:51 +02:00
|
|
|
cwd: buildOptions.reactAppRootDirPath,
|
|
|
|
env: {
|
2024-03-05 19:42:49 +01:00
|
|
|
...process.env,
|
2024-05-20 15:48:51 +02:00
|
|
|
[vitePluginSubScriptEnvNames.runPostBuildScript]:
|
|
|
|
JSON.stringify(buildOptions)
|
2024-03-05 19:42:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-02-23 19:15:59 +01:00
|
|
|
|
2024-05-20 02:27:40 +02:00
|
|
|
build_jars: {
|
|
|
|
if (process.env[skipBuildJarsEnvName]) {
|
|
|
|
break build_jars;
|
|
|
|
}
|
|
|
|
|
|
|
|
await buildJars({ buildOptions });
|
|
|
|
}
|
2021-06-14 21:21:36 +02:00
|
|
|
|
2024-05-20 15:48:51 +02:00
|
|
|
console.log(
|
|
|
|
chalk.green(`✓ built in ${((Date.now() - startTime) / 1000).toFixed(2)}s`)
|
|
|
|
);
|
2021-06-14 21:21:36 +02:00
|
|
|
}
|