diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 6cc5bae..9fe7331 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -1,8 +1,8 @@ import {red} from 'kleur'; +import {logHelpDev} from '../help/dev.help'; import {build} from '../services/build.services'; import {start, stop} from '../services/docker.services'; import {eject} from '../services/eject.services'; -import {helpDev} from './help'; export const dev = async (args?: string[]) => { const [subCommand] = args ?? []; @@ -22,6 +22,6 @@ export const dev = async (args?: string[]) => { break; default: console.log(`${red('Unknown subcommand.')}`); - console.log(helpDev); + logHelpDev(); } }; diff --git a/src/commands/help.ts b/src/commands/help.ts deleted file mode 100644 index 5793fc4..0000000 --- a/src/commands/help.ts +++ /dev/null @@ -1,159 +0,0 @@ -import {cyan, green, grey, magenta, yellow} from 'kleur'; -import {version} from '../../package.json'; - -const JUNO_LOGO = ` __ __ __ __ _ ____ -__) || | || \\| |/ \\ -\\___/ \\___/ |_|\\__|\\____/`; - -const TITLE = `${JUNO_LOGO} CLI ${grey(`v${version}`)}`; - -export const help = ` -${TITLE} - - -Usage: ${green('juno')} ${cyan('')} - -Commands: - ${cyan( - 'clear' - )} Clear existing dapp code by removing JavaScript, HTML, CSS, and other files from your satellite. - ${cyan('config')} Apply configuration to satellite. - ${cyan('deploy')} Deploy your dapp to your satellite. - ${cyan( - 'dev' - )} Handle development-related tasks such as building and deploying locally using Cargo and Docker. - ${cyan('init')} Configure the current directory as a satellite. - ${cyan('help')} Display help information. - ${cyan('login')} Generate an authentication for use in non-interactive environments. - ${cyan('logout')} Log out of the current device using the CLI. - ${cyan('open')} Open your satellite in your browser. - ${cyan('upgrade')} Upgrade your satellite to a specific version code. - ${cyan('use')} Switch between multiple profiles. - ${cyan('version')} Check the version of a satellite, mission control and cli. - ${cyan('whoami')} Display the current controller. - -Options: - ${grey('--headless')} Run the CLI in non-interactive mode (enabled automatically if JUNO_TOKEN is set). -`; - -export const helpMode = `${yellow('-m, --mode')} Set env mode. For example production or a custom string. Default is production.`; - -export const helpUpgrade = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('upgrade')} ${yellow('[options]')} - -Options: - ${yellow('-t, --target')} What type of segment should be upgraded. Valid targets are ${magenta('satellite')}, ${magenta('mission-control')} or ${magenta('orbiter')}. - ${yellow('-s, --src')} A local gzipped wasm file for the upgrade. - ${yellow('-r, --reset')} Reset to the initial state. - ${yellow('-n, --nocheck')} Skip assertions and execute upgrade without prompts. - ${helpMode} - ${yellow('-h, --help')} Output usage information. - -Notes: - -- Resetting a mission control is not possible. -- Disabling checks bypasses the verification of the target hash and skips the validation for build types. -- Targets can be shortened to ${magenta('s')} for satellite, ${magenta('m')} for mission-control and ${magenta('o')} for orbiter. -`; - -export const helpCommand = (command: string) => ` -${TITLE} - -Usage: ${green('juno')} ${cyan(command)} ${yellow('[options]')} - -Options: - ${yellow('-h, --help')} Output usage information. -`; - -export const helpCommandWithMode = (command: string) => ` -${helpCommand(command)} ${helpMode} -`; - -export const helpLogin = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('login')} ${yellow('[options]')} - -Options: - ${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge. - ${yellow('-h, --help')} Output usage information. -`; - -export const helpUse = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('use')} ${yellow('[options]')} - -Options: - ${yellow('-p, --profile')} The profile that should be use. - ${yellow('-l, --list')} What are the available profiles. - ${yellow('-h, --help')} Output usage information. -`; - -export const helpOpen = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('open')} ${yellow('[options]')} - -Options: - ${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge. - ${yellow('-c, --console')} Open satellite in the console. - ${helpMode} - ${yellow('-h, --help')} Output usage information. -`; - -export const helpDeploy = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')} - -Options: - ${yellow('-c, --clear')} Clear existing dapp files before proceeding with deployment. - ${helpMode} - ${yellow('-h, --help')} Output usage information. -`; - -export const helpClear = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('clear')} ${yellow('[options]')} - -Options: - ${yellow('-f, --fullPath')} Clear a particular file of your dapp. - ${helpMode} - ${yellow('-h, --help')} Output usage information. -`; - -export const helpConfig = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('config')} ${yellow('[options]')} - -Options: - ${helpMode} - ${yellow('-h, --help')} Output usage information. -`; - -const helpDevBuild = `${magenta('build')} Compile satellite features using Cargo.`; -const helpDevStart = `${magenta( - 'start' -)} Start a local Internet Computer network, encapsulated in a Docker environment.`; - -export const helpDevContinue = `${helpDevBuild} - ${helpDevStart}`; - -export const helpDev = ` -${TITLE} - -Usage: ${green('juno')} ${cyan('dev')} ${magenta('')} - -Subcommands: - ${helpDevBuild} - ${magenta( - 'eject' - )} Create a Rust template for custom satellite feature hooks and extensions. - ${helpDevStart} - ${magenta('stop')} Stop the Docker environment. -`; diff --git a/src/commands/upgrade.ts b/src/commands/upgrade.ts index 296b731..c0f7012 100644 --- a/src/commands/upgrade.ts +++ b/src/commands/upgrade.ts @@ -1,9 +1,9 @@ import {nextArg} from '@junobuild/cli-tools'; import {red} from 'kleur'; +import {logHelpUpgrade} from '../help/upgrade.help'; import {upgradeMissionControl} from '../services/upgrade/upgrade.mission-control.services'; import {upgradeOrbiters} from '../services/upgrade/upgrade.orbiter.services'; import {upgradeSatellite} from '../services/upgrade/upgrade.satellite.services'; -import {helpUpgrade} from './help'; export const upgrade = async (args?: string[]) => { const target = nextArg({args, option: '-t'}) ?? nextArg({args, option: '--target'}); @@ -23,6 +23,6 @@ export const upgrade = async (args?: string[]) => { break; default: console.log(`${red('Unknown target.')}`); - console.log(helpUpgrade); + logHelpUpgrade(); } }; diff --git a/src/help/clear.help.ts b/src/help/clear.help.ts new file mode 100644 index 0000000..169c689 --- /dev/null +++ b/src/help/clear.help.ts @@ -0,0 +1,28 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +export const CLEAR_DESCRIPTION = + 'Clear existing dapp code by removing JavaScript, HTML, CSS, and other files from your satellite.'; + +const usage = `Usage: ${green('juno')} ${cyan('clear')} ${yellow('[options]')} + +Options: + ${yellow('-f, --fullPath')} Clear a particular file of your dapp. + ${helpMode} + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${CLEAR_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpClear = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/config.help.ts b/src/help/config.help.ts new file mode 100644 index 0000000..a770acb --- /dev/null +++ b/src/help/config.help.ts @@ -0,0 +1,26 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +export const CONFIG_DESCRIPTION = 'Apply configuration to satellite.'; + +const usage = `Usage: ${green('juno')} ${cyan('config')} ${yellow('[options]')} + +Options: + ${helpMode} + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${CONFIG_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpConfig = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/deploy.help.ts b/src/help/deploy.help.ts new file mode 100644 index 0000000..3d00b36 --- /dev/null +++ b/src/help/deploy.help.ts @@ -0,0 +1,27 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +export const DEPLOY_DESCRIPTION = 'Deploy your dapp to your satellite.'; + +const usage = `Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')} + +Options: + ${yellow('-c, --clear')} Clear existing dapp files before proceeding with deployment. + ${helpMode} + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${DEPLOY_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpDeploy = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/dev.help.ts b/src/help/dev.help.ts new file mode 100644 index 0000000..7c132b9 --- /dev/null +++ b/src/help/dev.help.ts @@ -0,0 +1,39 @@ +import {cyan, green, magenta} from 'kleur'; +import {helpOutput, TITLE} from './help'; + +export const DEV_DESCRIPTION = + 'Handle development-related tasks such as building and deploying locally using Cargo and Docker.'; + +const helpDevBuild = `${magenta('build')} Compile satellite features using Cargo.`; +const helpDevStart = `${magenta( + 'start' +)} Start a local Internet Computer network, encapsulated in a Docker environment.`; + +export const helpDevContinue = `${helpDevBuild} + ${helpDevStart}`; + +const usage = `Usage: ${green('juno')} ${cyan('dev')} ${magenta('')} + +Subcommands: + ${helpDevBuild} + ${magenta( + 'eject' + )} Create a Rust template for custom satellite feature hooks and extensions. + ${helpDevStart} + ${magenta('stop')} Stop the Docker environment.`; + +const doc = `${DEV_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpDev = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/generic.help.ts b/src/help/generic.help.ts new file mode 100644 index 0000000..ce8a29a --- /dev/null +++ b/src/help/generic.help.ts @@ -0,0 +1,39 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +const usage = ( + command: string +): string => `Usage: ${green('juno')} ${cyan(command)} ${yellow('[options]')} + +Options: + ${yellow('-h, --help')} Output usage information.`; + +const help = (command: string) => `${TITLE} + +${usage(command)} +`; + +const helpWithMode = (command: string) => `${TITLE} + +${usage(command)} + ${helpMode} +`; + +const doc = (command: string) => `\`\`\`bash +${usage(command)} +\`\`\` +`; + +const docWithMode = (command: string) => `\`\`\`bash +${usage(command)} + ${helpMode} +\`\`\` +`; + +export const logHelp = ({args, command}: {args?: string[]; command: string}) => { + console.log(helpOutput(args) === 'doc' ? doc(command) : help(command)); +}; + +export const logHelpWithMode = ({args, command}: {args?: string[]; command: string}) => { + console.log(helpOutput(args) === 'doc' ? docWithMode(command) : helpWithMode(command)); +}; diff --git a/src/help/help.ts b/src/help/help.ts new file mode 100644 index 0000000..636883a --- /dev/null +++ b/src/help/help.ts @@ -0,0 +1,47 @@ +import {hasArgs} from '@junobuild/cli-tools'; +import {cyan, green, grey, yellow} from 'kleur'; +import {version} from '../../package.json'; +import {CLEAR_DESCRIPTION} from './clear.help'; +import {CONFIG_DESCRIPTION} from './config.help'; +import {DEPLOY_DESCRIPTION} from './deploy.help'; +import {DEV_DESCRIPTION} from './dev.help'; +import {LOGIN_DESCRIPTION} from './login.help'; +import {OPEN_DESCRIPTION} from './open.help'; +import {UPGRADE_DESCRIPTION} from './upgrade.help'; +import {USE_DESCRIPTION} from './use.help'; + +const JUNO_LOGO = ` __ __ __ __ _ ____ +__) || | || \\| |/ \\ +\\___/ \\___/ |_|\\__|\\____/`; + +export const TITLE = `${JUNO_LOGO} CLI ${grey(`v${version}`)}`; + +export const help = ` +${TITLE} + + +Usage: ${green('juno')} ${cyan('')} + +Commands: + ${cyan('clear')} ${CLEAR_DESCRIPTION} + ${cyan('config')} ${CONFIG_DESCRIPTION} + ${cyan('deploy')} ${DEPLOY_DESCRIPTION} + ${cyan('dev')} ${DEV_DESCRIPTION} + ${cyan('init')} Configure the current directory as a satellite. + ${cyan('help')} Display help information. + ${cyan('login')} ${LOGIN_DESCRIPTION} + ${cyan('logout')} Log out of the current device using the CLI. + ${cyan('open')} ${OPEN_DESCRIPTION} + ${cyan('upgrade')} ${UPGRADE_DESCRIPTION} + ${cyan('use')} ${USE_DESCRIPTION} + ${cyan('version')} Check the version of a satellite, mission control and cli. + ${cyan('whoami')} Display the current controller. + +Options: + ${grey('--headless')} Run the CLI in non-interactive mode (enabled automatically if JUNO_TOKEN is set). +`; + +export const helpMode = `${yellow('-m, --mode')} Set env mode. For example production or a custom string. Default is production.`; + +export const helpOutput = (args?: string[]): 'doc' | 'cli' => + hasArgs({args, options: ['-d', '--doc']}) ? 'doc' : 'cli'; diff --git a/src/help/login.help.ts b/src/help/login.help.ts new file mode 100644 index 0000000..62e771f --- /dev/null +++ b/src/help/login.help.ts @@ -0,0 +1,27 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpOutput, TITLE} from './help'; + +export const LOGIN_DESCRIPTION = + 'Generate an authentication for use in non-interactive environments.'; + +const usage = `Usage: ${green('juno')} ${cyan('login')} ${yellow('[options]')} + +Options: + ${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge. + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${LOGIN_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpLogin = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/open.help.ts b/src/help/open.help.ts new file mode 100644 index 0000000..d0bfa5b --- /dev/null +++ b/src/help/open.help.ts @@ -0,0 +1,28 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +export const OPEN_DESCRIPTION = 'Open your satellite in your browser.'; + +const usage = `Usage: ${green('juno')} ${cyan('open')} ${yellow('[options]')} + +Options: + ${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge. + ${yellow('-c, --console')} Open satellite in the console. + ${helpMode} + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${OPEN_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpOpen = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/upgrade.help.ts b/src/help/upgrade.help.ts new file mode 100644 index 0000000..b71f0dd --- /dev/null +++ b/src/help/upgrade.help.ts @@ -0,0 +1,36 @@ +import {cyan, green, magenta, yellow} from 'kleur'; +import {helpMode, helpOutput, TITLE} from './help'; + +export const UPGRADE_DESCRIPTION = 'Upgrade your satellite to a specific version code.'; + +const usage = `Usage: ${green('juno')} ${cyan('upgrade')} ${yellow('[options]')} + +Options: + ${yellow('-t, --target')} What type of segment should be upgraded. Valid targets are ${magenta('satellite')}, ${magenta('mission-control')} or ${magenta('orbiter')}. + ${yellow('-s, --src')} A local gzipped wasm file for the upgrade. + ${yellow('-r, --reset')} Reset to the initial state. + ${yellow('-n, --nocheck')} Skip assertions and execute upgrade without prompts. + ${helpMode} + ${yellow('-h, --help')} Output usage information. + +Notes: + +- Resetting a mission control is not possible. +- Disabling checks bypasses the verification of the target hash and skips the validation for build types. +- Targets can be shortened to ${magenta('s')} for satellite, ${magenta('m')} for mission-control and ${magenta('o')} for orbiter.`; + +const doc = `${UPGRADE_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpUpgrade = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/use.help.ts b/src/help/use.help.ts new file mode 100644 index 0000000..c70e76b --- /dev/null +++ b/src/help/use.help.ts @@ -0,0 +1,27 @@ +import {cyan, green, yellow} from 'kleur'; +import {helpOutput, TITLE} from './help'; + +export const USE_DESCRIPTION = 'Switch between multiple profiles.'; + +const usage = `Usage: ${green('juno')} ${cyan('use')} ${yellow('[options]')} + +Options: + ${yellow('-p, --profile')} The profile that should be use. + ${yellow('-l, --list')} What are the available profiles. + ${yellow('-h, --help')} Output usage information.`; + +const doc = `${USE_DESCRIPTION} + +\`\`\`bash +${usage} +\`\`\` +`; + +const help = `${TITLE} + +${usage} +`; + +export const logHelpUse = (args?: string[]) => { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/index.ts b/src/index.ts index 951da01..9b8e960 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,25 +5,21 @@ import {clear} from './commands/clear'; import {config} from './commands/config'; import {deploy} from './commands/deploy'; import {dev} from './commands/dev'; -import { - help, - helpClear, - helpCommand, - helpCommandWithMode, - helpConfig, - helpDeploy, - helpDev, - helpLogin, - helpOpen, - helpUpgrade, - helpUse -} from './commands/help'; import {init} from './commands/init'; import {open} from './commands/open'; import {upgrade} from './commands/upgrade'; import {use} from './commands/use'; import {version as versionCommand} from './commands/version'; import {whoami} from './commands/whoami'; +import {logHelpClear} from './help/clear.help'; +import {logHelpConfig} from './help/config.help'; +import {logHelpDeploy} from './help/deploy.help'; +import {logHelp, logHelpWithMode} from './help/generic.help'; +import {help} from './help/help'; +import {logHelpLogin} from './help/login.help'; +import {logHelpOpen} from './help/open.help'; +import {logHelpUpgrade} from './help/upgrade.help'; +import {logHelpUse} from './help/use.help'; import {checkNodeVersion} from './utils/env.utils'; export const run = async () => { @@ -55,35 +51,35 @@ export const run = async () => { if (hasArgs({args, options: ['-h', '--help']})) { switch (cmd) { case 'login': - console.log(helpLogin); + logHelpLogin(args); break; case 'upgrade': - console.log(helpUpgrade); + logHelpUpgrade(args); break; case 'open': - console.log(helpOpen); + logHelpOpen(args); break; case 'use': - console.log(helpUse); + logHelpUse(args); break; case 'clear': - console.log(helpClear); + logHelpClear(args); break; case 'config': - console.log(helpConfig); + logHelpConfig(args); break; case 'deploy': - console.log(helpDeploy); + logHelpDeploy(args); break; case 'dev': - console.log(helpDev); + logHelpDeploy(args); break; case 'version': case 'whoami': - console.log(helpCommandWithMode(cmd)); + logHelpWithMode({command: cmd, args}); break; default: - console.log(helpCommand(cmd)); + logHelp({command: cmd, args}); } return; } diff --git a/src/services/eject.services.ts b/src/services/eject.services.ts index 7b6c5ed..633d746 100644 --- a/src/services/eject.services.ts +++ b/src/services/eject.services.ts @@ -1,12 +1,12 @@ import {cyan, green, magenta, yellow} from 'kleur'; import {mkdir} from 'node:fs/promises'; import {join} from 'node:path'; -import {helpDevContinue} from '../commands/help'; import { DEVELOPER_PROJECT_SATELLITE_PATH, TEMPLATE_PATH, TEMPLATE_SATELLITE_PATH } from '../constants/dev.constants'; +import {helpDevContinue} from '../help/dev.help'; import {copySatelliteDid} from '../utils/did.utils'; import {checkRustVersion} from '../utils/env.utils'; import {copyTemplateFile} from '../utils/fs.utils';