diff --git a/src/index.ts b/src/index.ts index 0224bbd4..4ba1fd57 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,36 +1,23 @@ #!/usr/bin/env node - import { Command } from 'commander'; import { createCommand } from './commands/create.js'; -import chalk from 'chalk'; - -const program = new Command(); - -program - .name('celo-composer') - .description('CLI tool for generating customizable Celo blockchain starter kits') - .version('1.0.0'); +import getChalk from './utils/getChalk.js'; -program - .command('create') - .description('Create a new Celo project') - .argument('[project-name]', 'Name of the project') - .option('-d, --description ', 'Project description') - .option('-t, --template ', 'Template type (basic, farcaster-miniapp, minipay, ai-chat)') - .option('--wallet-provider ', 'Wallet provider (rainbowkit, thirdweb, none)') - .option('-c, --contracts ', 'Smart contract framework (hardhat, foundry, none)') - .option('--skip-install', 'Skip package installation') - .option('-y, --yes', 'Skip all prompts and use defaults') - .action(createCommand); +(async function main() { + const chalk = await getChalk(); + + const program = new Command(); -program.on('command:*', () => { - console.error(chalk.red(`Invalid command: ${program.args.join(' ')}`)); - console.log(chalk.yellow('See --help for a list of available commands.')); - process.exit(1); -}); + program + .name('celo-composer') + .description('CLI tool for generating customizable Celo blockchain starter kits') + .version('1.0.0'); -if (process.argv.length === 2) { - program.help(); -} + program.on('command:*', () => { + console.error(chalk.red('Invalid command: ' + program.args.join(' '))); + console.log(chalk.yellow('See --help for a list of available commands.')); + process.exit(1); + }); -program.parse(process.argv); + await program.parseAsync(process.argv); +})(); diff --git a/src/utils/getChalk.ts b/src/utils/getChalk.ts new file mode 100644 index 00000000..58b332bb --- /dev/null +++ b/src/utils/getChalk.ts @@ -0,0 +1,22 @@ +// Lightweight dynamic loader for ESM-only 'chalk'. +// Returns the chalk default export (or a minimal no-op shim if import fails). +export default async function getChalk(): Promise { + try { + const mod = await import('chalk'); + return mod && (mod.default || mod); + } catch (err) { + // Minimal shim preserving common style functions. + const noop = (s: any) => String(s); + const base = { + bold: noop, dim: noop, red: noop, green: noop, yellow: noop, + blue: noop, cyan: noop, magenta: noop, white: noop, gray: noop + }; + return new Proxy(base, { + get(target: any, prop: string) { + if (prop in target) return target[prop]; + // allow chalk.green.bold('x') — return function that returns the string + return (s: any) => String(s); + } + }); + } +}