|
| 1 | +import { Command, Flags } from '@oclif/core'; |
| 2 | +import { createIntegrationBoilerplate } from '../../domains/create/integration'; |
| 3 | +import { getPkgManager, log } from '../../utils'; |
| 4 | +import { |
| 5 | + handleDirectoryName, |
| 6 | + handleFrameworkName, |
| 7 | + installAppSdkDependencies, |
| 8 | + cleanUpRepositories |
| 9 | +} from '../../domains/create/integration/helpers'; |
| 10 | + |
| 11 | +import { intro, spinner } from '@clack/prompts'; |
| 12 | +import execa from 'execa'; |
| 13 | +import picocolors from 'picocolors'; |
| 14 | + |
| 15 | +export default class GenerateSDK extends Command { |
| 16 | + static override description = 'Generate integration boilerplate'; |
| 17 | + static override examples = ['<%= config.bin %> <%= command.id %>']; |
| 18 | + static override flags = { |
| 19 | + framework: Flags.string({ |
| 20 | + char: 't', |
| 21 | + description: 'Framework to use', |
| 22 | + options: ['nuxt', 'next'], |
| 23 | + aliases: ['template'] |
| 24 | + }) |
| 25 | + }; |
| 26 | + |
| 27 | + static override args = [ |
| 28 | + { |
| 29 | + name: 'name' |
| 30 | + } |
| 31 | + ]; |
| 32 | + |
| 33 | + async run(): Promise<void> { |
| 34 | + let projectDir = ''; |
| 35 | + let framework = ''; |
| 36 | + const sp = spinner(); |
| 37 | + |
| 38 | + const { flags } = await this.parse(GenerateSDK); |
| 39 | + if (flags.framework) { |
| 40 | + framework = flags.framework; |
| 41 | + } |
| 42 | + const { args } = await this.parse(GenerateSDK); |
| 43 | + // eslint-disable-next-line dot-notation |
| 44 | + if (args['name']) { |
| 45 | + // eslint-disable-next-line dot-notation |
| 46 | + projectDir = args['name']; |
| 47 | + } |
| 48 | + // greet the user |
| 49 | + intro('Welcome to Vue Storefront SDK Integration Boilerplate Generator!'); |
| 50 | + |
| 51 | + projectDir = await handleDirectoryName(projectDir); |
| 52 | + framework = await handleFrameworkName(framework); |
| 53 | + const packageManager = await getPkgManager(); |
| 54 | + |
| 55 | + await createIntegrationBoilerplate({ projectDir, framework }); |
| 56 | + await installAppSdkDependencies(projectDir, packageManager); |
| 57 | + |
| 58 | + // build the boilerplate |
| 59 | + sp.start('Building the boilerplate'); |
| 60 | + await execa(packageManager, ['run', 'build'], { cwd: projectDir }); |
| 61 | + sp.stop('Boilerplate has been built successfully!'); |
| 62 | + // clean up the git repository |
| 63 | + await cleanUpRepositories(projectDir); |
| 64 | + |
| 65 | + // exit the generator |
| 66 | + log('SDK integration boilerplate has been generated successfully!'); |
| 67 | + log('To start the development, run the following commands:'); |
| 68 | + log(picocolors.green(`cd ${projectDir}`)); |
| 69 | + log( |
| 70 | + picocolors.green( |
| 71 | + `${packageManager === 'yarn' ? 'yarn dev' : 'npm run dev'}` |
| 72 | + ) |
| 73 | + ); |
| 74 | + process.exit(0); |
| 75 | + } |
| 76 | +} |
0 commit comments