All files / src/commands upgrade.ts

78.26% Statements 18/23
58.33% Branches 7/12
100% Functions 2/2
76.19% Lines 16/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 381x 1x               1x 1x 1x 1x   1x   1x 1x   1x                   1x 1x 1x   1x   1x 1x  
import { Project, Resource } from '@/internal'
import { logger, checkWorkDir } from '@/utils'
 
interface UpgradeOptions {
  cwd?: string
  noDeps?: boolean
  force?: boolean
}
 
export default async(options: UpgradeOptions): Promise<void> => {
  const cwd = options.cwd || process.cwd()
  const noDeps = options.noDeps || false
  const force = options.force || false
 
  Eif (!force) await checkWorkDir(cwd)
 
  const project = await Project.load(cwd)
  const repo = await project.getTemplateRepo()
 
  Iif (await repo.isLatest()) {
    const message = 'The template is already the latest version'
    if (!force) {
      logger.info(message)
      return
    }
 
    logger.warn(message)
  }
 
  await repo.checkout('latest')
  const template = await repo.install({ noDeps })
  const resource = new Resource('upgrade', project, template)
 
  const compiler = await resource.compile()
 
  await compiler.render()
  await compiler.emit('upgraded')
}