UNPKG

@iyowei/create-esm

Version:

这是一个命令行工具,给到 ESM 源码文件路径后,自动创建一个项目、打包、发布,确保一个指令即可在项目中安装使用,进而支持跨项目使用。

66 lines (49 loc) 1.8 kB
import shell from 'shelljs'; export const TASK_NAME_UPDATE_CHANGELOG = '发布更新日志'; // TODO: 使用 "模板方法模式" 组织代码 export default { name: TASK_NAME_UPDATE_CHANGELOG, async excute({ ctx, task }) { if (!ctx.error) { const PART_NAME = '切换到新创建好的项目'; task.title = PART_NAME; if (shell.cd(ctx.payload.get('newProjectPath')).code !== 0) { ctx.error = true; ctx.message = `"${TASK_NAME_UPDATE_CHANGELOG}" 任务在 "${PART_NAME}" 环节出错`; } } const FIRST_VERSION = 'v1.0.0'; if (!ctx.error) { const PART_NAME = `贴标签:${FIRST_VERSION}`; task.title = PART_NAME; const cmdTag = `git tag ${FIRST_VERSION}`; if (shell.exec(cmdTag, { silent: true }).code !== 0) { ctx.error = true; ctx.message = `"${TASK_NAME_UPDATE_CHANGELOG}" 任务在 "${PART_NAME}" 环节出错`; } } if (!ctx.error) { const PART_NAME = '推送标签'; task.title = PART_NAME; const cmdPushTags = 'git push --tags'; if (shell.exec(cmdPushTags, { silent: true }).code !== 0) { ctx.error = true; ctx.message = `"${TASK_NAME_UPDATE_CHANGELOG}" 任务在 "${PART_NAME}" 环节出错`; } } if (!ctx.error) { const PART_NAME = '推送更新日志'; task.title = PART_NAME; const cmdRelease = `gh release create ${FIRST_VERSION} --generate-notes`; if (shell.exec(cmdRelease, { silent: true }).code !== 0) { ctx.error = true; ctx.message = `"${TASK_NAME_UPDATE_CHANGELOG}" 任务在 "${PART_NAME}" 环节出错`; } } if (ctx.error) { task.skip('未能发布更新日志'); } else { task.title = '已发布更新日志'; } }, };