1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/zce-caz

Клонировать/Скачать
load.ts 1.3 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
汪磊 Отправлено 24.03.2022 13:33 79c085c
import ora from 'ora'
import { exec } from './core'
import { Context } from './types'
/**
* Load template config.
* @todo
* - Adapt to any repository?
* - Automatic install template dependencies.
* - Template dependencies not found.
* - Check template is available.
*/
export default async (ctx: Context): Promise<void> => {
// default template name
ctx.config.name = ctx.template
// Automatic install template dependencies.
const spinner = ora('Installing template dependencies...').start()
try {
/* istanbul ignore next */
const cmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
await exec(cmd, ['install', '--production'], { cwd: ctx.src })
spinner.succeed('Installing template dependencies complete.')
} catch {
spinner.fail('Install template dependencies failed.')
}
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mod = require(ctx.src)
if (Object.prototype.toString.call(mod) !== '[object Object]') {
throw new TypeError('template needs to expose an object.')
}
Object.assign(ctx.config, mod)
} catch (err) {
const e = err as NodeJS.ErrnoException
if (e.code === 'MODULE_NOT_FOUND') return
e.message = `Invalid template: ${e.message}`
throw e
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/zce-caz.git
git@api.gitlife.ru:oschina-mirror/zce-caz.git
oschina-mirror
zce-caz
zce-caz
main