2024-05-19 05:29:20 +02:00
|
|
|
import * as fs from "fs";
|
2024-10-24 23:21:12 +00:00
|
|
|
import { join as pathJoin, sep as pathSep } from "path";
|
2024-09-22 20:12:11 +02:00
|
|
|
import { run } from "./shared/run";
|
2024-10-24 23:21:12 +00:00
|
|
|
import cliSelect from "cli-select";
|
|
|
|
import { getThisCodebaseRootDirPath } from "../src/bin/tools/getThisCodebaseRootDirPath";
|
|
|
|
import chalk from "chalk";
|
|
|
|
import { removeNodeModules } from "./tools/removeNodeModules";
|
|
|
|
import { startRebuildOnSrcChange } from "./shared/startRebuildOnSrcChange";
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const parentDirPath = pathJoin(getThisCodebaseRootDirPath(), "..");
|
|
|
|
|
|
|
|
const { starterName } = await (async () => {
|
|
|
|
const starterNames = fs
|
|
|
|
.readdirSync(parentDirPath)
|
|
|
|
.filter(
|
|
|
|
basename =>
|
|
|
|
basename.includes("starter") &&
|
|
|
|
basename.includes("angular") &&
|
|
|
|
fs.statSync(pathJoin(parentDirPath, basename)).isDirectory()
|
|
|
|
);
|
2024-08-14 07:10:48 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
if (starterNames.length === 0) {
|
|
|
|
console.log(
|
|
|
|
chalk.red(
|
|
|
|
`No starter found. Keycloakify Angular starter found in ${parentDirPath}`
|
|
|
|
)
|
|
|
|
);
|
|
|
|
process.exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const starterName = await (async () => {
|
|
|
|
if (starterNames.length === 1) {
|
|
|
|
return starterNames[0];
|
2024-08-14 07:10:48 +02:00
|
|
|
}
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
console.log(chalk.cyan(`\nSelect a starter to link in:`));
|
|
|
|
|
|
|
|
const { value } = await cliSelect<string>({
|
|
|
|
values: starterNames.map(starterName => `..${pathSep}${starterName}`)
|
|
|
|
}).catch(() => {
|
|
|
|
process.exit(-1);
|
|
|
|
});
|
|
|
|
|
|
|
|
return value.split(pathSep)[1];
|
|
|
|
})();
|
|
|
|
|
|
|
|
return { starterName };
|
|
|
|
})();
|
|
|
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
console.log(chalk.cyan(`\n\nLinking in ..${pathSep}${starterName}...`));
|
|
|
|
|
|
|
|
removeNodeModules({
|
|
|
|
nodeModulesDirPath: pathJoin(getThisCodebaseRootDirPath(), "node_modules")
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.rmSync(pathJoin(getThisCodebaseRootDirPath(), "dist"), {
|
|
|
|
recursive: true,
|
|
|
|
force: true
|
|
|
|
});
|
|
|
|
fs.rmSync(pathJoin(getThisCodebaseRootDirPath(), ".yarn_home"), {
|
|
|
|
recursive: true,
|
|
|
|
force: true
|
|
|
|
});
|
|
|
|
|
|
|
|
run("yarn install");
|
|
|
|
run("yarn build");
|
|
|
|
|
|
|
|
const starterDirPath = pathJoin(parentDirPath, starterName);
|
|
|
|
|
|
|
|
removeNodeModules({
|
|
|
|
nodeModulesDirPath: pathJoin(starterDirPath, "node_modules")
|
|
|
|
});
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
run("yarn install", { cwd: starterDirPath });
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
run(`npx tsx ${pathJoin("scripts", "link-in-app.ts")} ${starterName}`);
|
2024-06-23 20:54:08 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
const durationSeconds = Math.round((Date.now() - startTime) / 1000);
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
startRebuildOnSrcChange();
|
2024-05-19 05:29:20 +02:00
|
|
|
|
2024-10-24 23:21:12 +00:00
|
|
|
console.log(chalk.green(`\n\nLinked in ${starterName} in ${durationSeconds}s`));
|
|
|
|
})();
|