From 0d505c99dea5a9ade437641ecdbb684c467aec87 Mon Sep 17 00:00:00 2001 From: David Yusta Date: Sat, 25 Nov 2023 15:39:29 +0100 Subject: [PATCH] refactor: use cuckoo schematics and add prompter and package manager utils --- .../cuckoojs-cli/src/commands/new.command.ts | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts b/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts index cff06c1..c4f6590 100644 --- a/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts +++ b/packages/@guidesmiths/cuckoojs-cli/src/commands/new.command.ts @@ -1,31 +1,19 @@ import {SchematicRunner} from '../lib/runners/schematic.runner'; import {GitRunner} from '../lib/runners/git.runner'; -import type {PackageEntry, ScriptEntry} from '../lib/runners/npm.runner'; -import {NpmRunner} from '../lib/runners/npm.runner'; import {messages} from '../lib/ui/ui'; import * as fs from 'fs'; import {join} from 'path'; -import {BashRunnerHusky} from '../lib/runners/bash.runner.husky'; import {AbstractCommand} from './abstract.command'; import {NestRunner} from '../lib/runners/nest.runner'; import Printer from '../lib/printer/printer'; +import {Prompter} from '../lib/utils/Prompter/Prompter'; +import {PackageManager} from '../lib/utils/PackageManager/PackageManager'; export class NewCommand extends AbstractCommand { private readonly schematicRunner: SchematicRunner = new SchematicRunner(); private readonly gitRunner: GitRunner = new GitRunner(); - private readonly npmRunner: NpmRunner = new NpmRunner(); - private readonly bashRunnerHusky: BashRunnerHusky = new BashRunnerHusky(); private readonly nestRunner: NestRunner = new NestRunner(); - private readonly initialPackages: PackageEntry[] = [ - {name: 'husky', version: '^8.0.1', section: 'devDependencies'}, - ]; - - private readonly initialScripts: ScriptEntry[] = [ - {name: 'prepare', value: 'husky install'}, - {name: 'postinstall', value: 'npx @guidesmiths/license-checker --outputFileName license-report --failOn /GPL/'}, - ]; - constructor( private readonly name: string, ) { @@ -42,25 +30,21 @@ export class NewCommand extends AbstractCommand { } try { - await this.nestRunner.generateNestApplication(this.name); - - await this.gitRunner.createBranch({folderName: this.name}); + const packageManager = await Prompter.promptPackageManager(); - await this.npmRunner.addPackages(this.name, this.initialPackages); + await this.nestRunner.generateNestApplication(this.name, packageManager); - await this.npmRunner.addScripts(this.name, this.initialScripts); + await this.gitRunner.createBranch({folderName: this.name}); - await this.schematicRunner.addCommitlint(this.name); + await this.schematicRunner.addBasicTooling(this.name); - await this.schematicRunner.addGitignoreFile(this.name); + await this.schematicRunner.addNestJsConfigModule(this.name); printer.startStep('Installing dependencies'); - await this.npmRunner.install(this.name); + await new PackageManager(this.name).install(packageManager); printer.endStep(); - await this.bashRunnerHusky.addHuskyCommitMsg(this.name); - - this.printSuccess(`\n šŸ¦ Your CuckooJS nest "${this.name}" is generated and ready to use šŸ¦`); + this.printSuccess(`\nšŸ¦ Your CuckooJS Nest "${this.name}" project is generated and ready to use šŸ¦`); } catch (error: unknown) { printer.load.fail(`Error generating new project: ${(error as Error).message}`); this.removeFolder();