-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Refactor(@cli/select): merge cli commands
config
and profile
t…
…o `select` command
- Loading branch information
1 parent
1eed703
commit 56528c4
Showing
6 changed files
with
73 additions
and
164 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export * from "./default"; | ||
export * from "./init"; | ||
export * from "./version"; | ||
export * from "./config"; | ||
export * from "./profile"; | ||
export * from "./category"; | ||
export * from "./select"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
import { program } from "commander"; | ||
import * as prompter from "@clack/prompts"; | ||
import chalk from "chalk"; | ||
import { resolve } from "path"; | ||
import { copyFiles, existFilePrompt } from "@/function"; | ||
import logging from "@/utils/logging"; | ||
import { join } from "path"; | ||
import { config } from "@/function/config"; | ||
import { scanDir } from "@/function"; | ||
|
||
const [state, setState] = config(); | ||
prompter | ||
.group( | ||
{ | ||
intro: () => { | ||
prompter.intro(chalk.bgCyan(" App installation ")); | ||
}, | ||
// configFinder: async () => {}, | ||
// userChoose: async () => {}, | ||
outro: () => { | ||
prompter.outro(chalk.bgGreen(" App has been installed! ")); | ||
} | ||
.group({ | ||
intro: () => { | ||
prompter.intro(chalk.bgCyan(" Select config ")); | ||
}, | ||
{ | ||
onCancel: () => { | ||
console.log(chalk.bgRed("Canceled")); | ||
process.exit(0); | ||
} | ||
currentlyChecked: () => { | ||
prompter.note(`Currently selected config:\n${state.config}`, chalk.bgBlue(" Info ")); | ||
}, | ||
selectedConfig: async () => { | ||
logging.debug("Config path: ", process.env.CONFIGPATH); | ||
const pathToScan = join(process.env.CONFIGPATH, "./config"); | ||
const configs = scanDir(pathToScan, "config"); | ||
logging.debug("Found Configs:", configs); | ||
const selected = await prompter.select({ | ||
message: "Select config", | ||
initialValue: state.config, | ||
options: configs.map(({ name }) => ({ label: name, value: name })) | ||
}); | ||
logging.debug("Selected config: ", selected); | ||
return selected; | ||
}, | ||
selecting: ({ results }) => { | ||
if (results.selectedConfig === state.config) return; | ||
setState(e => ({ ...e, config: results.selectedConfig!, profile: void 0 })); | ||
logging.debug("Config state: ", state); | ||
}, | ||
outro: () => { | ||
prompter.outro(chalk.bgGreen(" Config Selected! ")); | ||
} | ||
) | ||
}) | ||
.catch(e => { | ||
throw e; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,49 @@ | ||
import { program } from "commander"; | ||
import * as prompter from "@clack/prompts"; | ||
import chalk from "chalk"; | ||
import { resolve } from "path"; | ||
import { copyFiles, existFilePrompt } from "@/function"; | ||
import logging from "@/utils/logging"; | ||
import { join } from "path"; | ||
import { config } from "@/function/config"; | ||
import { scanDir } from "@/function"; | ||
|
||
const [state, setState] = config(); | ||
prompter | ||
.group( | ||
{ | ||
ConfirmProcess: async () => { | ||
prompter.note(`Initialize app at: \n'${chalk.blue(process.env.CONFIGPATH)}'`, chalk.bgGreen(" ACTIONS ")); | ||
const continueAction = await prompter.confirm({ message: "Do you want to continue?" }); | ||
if (prompter.isCancel(continueAction) || !continueAction) { | ||
prompter.cancel("Canceled."); | ||
process.exit(0); | ||
} | ||
}, | ||
Installation: async () => { | ||
const destination = process.env.CONFIGPATH!; | ||
const templatePath = resolve(process.env.PACKAGEPATH!, "./templates/app/installation/"); | ||
|
||
const InstallingProcess = prompter.spinner(); | ||
InstallingProcess.start("App is installing..."); | ||
await existFilePrompt(destination); | ||
const [data, isError] = copyFiles(templatePath, destination, true); | ||
if (isError) { | ||
InstallingProcess.stop(`❌ Error: ${data.message?.user}`, 1); | ||
process.exit(1); | ||
} | ||
InstallingProcess.stop("✅", 0); | ||
}, | ||
outro: async () => { | ||
prompter.outro(chalk.bgGreen(" App has been installed! ")); | ||
} | ||
.group({ | ||
intro: () => { | ||
prompter.intro(chalk.bgCyan(" Select profile ")); | ||
}, | ||
{ | ||
onCancel: () => { | ||
console.log(chalk.bgRed("Canceled")); | ||
process.exit(0); | ||
currentlyChecked: () => { | ||
prompter.note(`Currently selected profile:\n${state.profile}`, chalk.bgBlue(" Info ")); | ||
}, | ||
selectedprofile: async () => { | ||
if (state.config === void 0) { | ||
prompter.cancel("You need to select config first."); | ||
process.exit(1); | ||
} | ||
logging.debug("profile path: ", process.env.CONFIGPATH); | ||
|
||
const pathToScan = join(process.env.CONFIGPATH, "config", state.config, "profiles"); | ||
const profiles = scanDir(pathToScan, "profile"); | ||
|
||
logging.debug("Found Profiles:", profiles); | ||
const selected = await prompter.select({ | ||
message: "Select profile", | ||
initialValue: state.profile, | ||
options: profiles.map(({ name }) => ({ label: name, value: name })) | ||
}); | ||
logging.debug("Selected profile: ", selected); | ||
|
||
return selected; | ||
}, | ||
selecting: ({ results }) => { | ||
if (results.selectedprofile === state.profile) return void 0; | ||
setState(e => ({ ...e, profile: results.selectedprofile! })); | ||
logging.debug("Profile state: ", state); | ||
}, | ||
outro: () => { | ||
prompter.outro(chalk.bgGreen(" Profile Selected! ")); | ||
} | ||
) | ||
}) | ||
.catch(e => { | ||
throw e; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters