UNPKG

@notadd/cli

Version:

notadd core none dependence

34 lines (33 loc) 1.42 kB
import { Command } from "@notadd/cli-core"; import { NotaddService } from "../service/notadd"; import { Controller, Args } from '@notadd/core'; @Controller() export class AddCommand { constructor(private notadd: NotaddService) { } @Command() async add(@Args('name') name: string) { if (name) { const lock = this.notadd.lock; const version = Reflect.get(lock, name); if (!version) { const newVersion = await this.notadd.getVersion(name) if (newVersion) { await this.notadd.savePackage(name, newVersion) Reflect.set(lock, name, newVersion) await this.notadd.updateLock(lock) await this.notadd.updatePackageJson(name, newVersion) } console.log(`add success ${name}@${newVersion}`) } else { const newVersion = await this.notadd.getVersion(name) if (newVersion !== version) { await this.notadd.savePackage(name, newVersion) Reflect.set(lock, name, newVersion) await this.notadd.updateLock(lock) await this.notadd.updatePackageJson(name, newVersion) } console.log(`add success ${name}@${newVersion}`) } } } }