UNPKG

@iyowei/create-esm

Version:

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

43 lines (32 loc) 1.01 kB
import shell from 'shelljs'; export const TASK_NAME_PUBLISH = '发布到 NPM'; // TODO: 使用 "模板方法模式" 组织代码 export default { name: TASK_NAME_PUBLISH, 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_PUBLISH}" 任务在 "${PART_NAME}" 环节出错`; } } if (!ctx.error) { const PART_NAME = '发布中'; task.title = PART_NAME; const excuted = shell.exec('npm publish', { silent: true }); if (excuted.code !== 0) { ctx.error = true; ctx.message = [ `"${TASK_NAME_PUBLISH}" 任务在 "${PART_NAME}" 环节出错,`, ].concat(excuted.stderr.split('\n')); } } if (ctx.error) { task.skip('未能成功发布'); } else { task.title = '成功发布'; } }, };