UNPKG

@sanpjs/cmd-init

Version:

Sanp init command

49 lines 2.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const fs_extra_1 = __importDefault(require("fs-extra")); const utils_1 = require("@sanpjs/utils"); exports.default = (template, dest, options) => { return async (ctx, task) => { task.info('Check the status of the template'); const useCache = !options.noCache; // 输入本地路径 if ((0, utils_1.isLocalPath)(template)) { const localAbsolutePath = path_1.default.resolve(template); if (fs_extra_1.default.existsSync(localAbsolutePath)) { // 使用本地路径直接复制 ctx.localTemplatePath = localAbsolutePath; return task.complete(); } } // 先检查本地和临时目录 cwd/.templates let isLocal = false; let tmpPath = path_1.default.resolve('.templates', template); isLocal = fs_extra_1.default.existsSync(tmpPath); // 再检查github缓存目录~/.sanp/templates if (!isLocal) { tmpPath = (0, utils_1.getLocalTplPath)(template); isLocal = useCache && fs_extra_1.default.existsSync(tmpPath); } if (isLocal) { ctx.localTemplatePath = tmpPath; // 优先使用缓存 task.skip('Discover local cache from', tmpPath); task.complete(); } // 尝试拉取远程仓库的模板 else { task.info('Pulling template from the remote repository...'); (0, utils_1.downloadRepo)(template, tmpPath, options) .then(() => { ctx.localTemplatePath = tmpPath; task.complete(); }) .catch(errMessage => task.error(errMessage)); } }; }; //# sourceMappingURL=getTemplate.js.map