All files / src/commands update.ts

80.77% Statements 21/26
52.94% Branches 9/17
100% Functions 2/2
86.36% Lines 19/22

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 38 39 40 41 42 43 44 45 461x 1x 1x                     2x 2x 2x 2x 2x   2x   2x   2x 2x   2x                   2x   2x 2x 2x   2x 2x    
import { Project, Resource, Effect, EffectOptions } from '@/internal'
import { recursiveExecte, logger, checkWorkDir } from '@/utils'
import semver from 'semver'
 
 
interface UpdateOptions {
  cwd?: string
  noDeps?: boolean
  version?: string
  force?: boolean
  effect?: EffectOptions
}
 
export default recursiveExecte(async(options: UpdateOptions): Promise<void> => {
  const cwd = options.cwd || process.cwd()
  const noDeps = options.noDeps || false
  const version = options.version
  const force = options.force || false
 
  Effect.replace(options.effect)
 
  Eif (!force) await checkWorkDir(cwd)
 
  const project = await Project.load(cwd)
  const repo = await project.getTemplateRepo()
 
  Iif (version && repo.version && semver.lt(version, repo.version)) {
    const message = [
      'The version number setted is lower than the current template version.',
      "If you're sure you want to run this command, rerun it with --force.",
    ].join('\n')
 
    if (force) logger.warn(message)
    else throw new Error(message)
  }
 
  Iif (version) await repo.checkout(version)
 
  const template = await repo.install({ noDeps })
  const resource = new Resource('update', project, template)
  const compiler = await resource.compile()
 
  await compiler.render()
  await compiler.emit('updated')
})