Skip to content

Commit

Permalink
added logic to quick start admin theme
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Jan de Wit <[email protected]>
  • Loading branch information
edewit committed Dec 3, 2024
1 parent 1e45edb commit 0262289
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions js/apps/create-keycloak-theme/create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import chalk from "chalk";
import { Command } from "commander";
import { Command, InvalidArgumentError } from "commander";
import fs from "fs-extra";
import Mustache from "mustache";
import { mkdtemp } from "node:fs";
Expand All @@ -26,12 +26,22 @@ function main() {
.option(
"-t, --type <name>",
"the type of ui to be created either `account` or `admin` ",
"account",
(value) => {
if (value !== "account" && value !== "admin") {
throw new InvalidArgumentError(
"It should be either account or admin",
);
}
return value;
},
)
.action(async (name, options) => {
console.log(`Creating a new ${chalk.green(name)} project`);
const type = options.type || "account";
console.log(
`Creating a new ${chalk.green(name)} project of type ${chalk.green(type)}`,
);

await createProject(name, options.type);
await createProject(name, type);
done(name);
})
.on("--help", () => {
Expand All @@ -48,7 +58,7 @@ function main() {
.parse(process.argv);
}

function cloneQuickstart() {
function cloneQuickstart(type) {
return new Promise((resolve, reject) => {
mkdtemp(join(tmpdir(), "template-"), async (err, dir) => {
if (err) return reject(err);
Expand All @@ -58,14 +68,14 @@ function cloneQuickstart() {
"--branch": "main",
})
.then(() =>
resolve(join(dir, "extension/extend-account-console-node")),
resolve(join(dir, `extension/extend-${type}-console-node`)),
);
});
});
}

async function createProject(name, type) {
const templateProjectDir = await cloneQuickstart();
const templateProjectDir = await cloneQuickstart(type);
const projectDir = join(resolve(), name);
await fs.mkdir(projectDir);
await fs.copy(templateProjectDir, projectDir);
Expand Down

0 comments on commit 0262289

Please sign in to comment.