83 lines
2.8 KiB
TypeScript
Raw Normal View History

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