diff --git a/package.json b/package.json index 19a30e4..59dd777 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-formidable", - "version": "0.0.11", + "version": "0.0.12", "description": "The Formidable Framework Installer", "author": "Donald Pakkies @donaldp", "bin": { diff --git a/src/commands/index.ts b/src/commands/index.ts index c0bda22..3d56fad 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,7 +1,10 @@ import { Args, Command, Flags } from '@oclif/core' import { input } from '@inquirer/prompts' import { run } from '@formidablejs/installer' -import path = require('path') + +type Mapper = { + [key: string]: string +} export default class Create extends Command { static description = 'Create a new Formidable application' @@ -43,6 +46,27 @@ export default class Create extends Command { args.name = name } + if (!flags['use-pnpm'] && !flags['use-npm'] && !flags['use-yarn'] && !flags['use-bun'] && !flags.manager) { + const userAgent = process.env.npm_config_user_agent + + if (userAgent && typeof userAgent === 'string') { + const agent = userAgent.split('/')[0] + + const mapper: Mapper = { + 'npm': 'npm', + 'pnpm': 'pnpm', + 'yarn': 'yarn', + 'yarn@berry': 'yarn', + 'bun': 'bun', + 'pnpm@6': 'pnpm', + } + + if (agent !== '' && Object.keys(mapper).includes(agent)) { + flags.manager = mapper[agent] + } + } + } + const installerArgs = ['new', args.name] for (const [key, value] of Object.entries(flags)) {