UNPKG

@lcap/builder

Version:
94 lines (93 loc) 3.96 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const fast_glob_1 = __importDefault(require("fast-glob")); const logger_1 = __importDefault(require("../utils/logger")); const exec_1 = require("../utils/exec"); function concatCommand(command, config) { const commands = [command]; if (config.platform) { commands.push(`--platform ${config.platform}`); } if (config.bucket) { commands.push(`--bucket ${config.bucket}`); } if (config.username) { commands.push(`--username ${config.username}`); } if (config.password) { commands.push(`--password ${config.password}`); } return commands.join(' '); } function deployTgz(rootPath, config) { const pkgInfo = fs_extra_1.default.readJSONSync(path_1.default.join(rootPath, 'package.json')); const tgz = `${pkgInfo.name.replace('@lcap/', 'lcap-')}-${pkgInfo.version}.tgz`; // tgz 是否存在 if (!fs_extra_1.default.existsSync(tgz)) { logger_1.default.error(`${tgz} not found`); process.exit(1); } // zip.tgz 是否存在 if (fs_extra_1.default.existsSync('zip.tgz')) { fs_extra_1.default.unlinkSync('zip.tgz'); } // 复制tgz到zip.tgz fs_extra_1.default.copyFileSync(tgz, 'zip.tgz'); (0, exec_1.execSync)(concatCommand('npx lcap deploy zip.tgz', config)); logger_1.default.success(`update success ${tgz}`); // 删除zip.tgz fs_extra_1.default.unlinkSync('zip.tgz'); } function deployImages(rootPath, config) { const imageFloders = []; const imageFilePaths = fast_glob_1.default.sync(['assets/*', 'src/**/screenshots/*', 'src/**/drawings/*', 'src-vusion/**/screenshots/*', 'src-vusion/**/drawings/*'], { cwd: rootPath, absolute: true }); imageFilePaths.forEach((filePath) => { const deployPath = filePath.substring(rootPath.length + 1, filePath.lastIndexOf('/')); if (!imageFloders.includes(deployPath)) { imageFloders.push(deployPath); } }); imageFloders.forEach((folder) => { (0, exec_1.execSync)(concatCommand(`npx lcap deploy ${folder}`, config)); logger_1.default.success(`update success ${folder}`); }); } exports.default = (rootPath, _a) => { var { images } = _a, commandArgs = __rest(_a, ["images"]); const lcapCliConfig = Object.assign({}, commandArgs); const configPath = path_1.default.resolve(rootPath, '.lcaprc'); if (fs_extra_1.default.existsSync(configPath)) { const config = fs_extra_1.default.readJSONSync(configPath); Object.keys(config).forEach((key) => { if (config[key] && !lcapCliConfig[key]) { lcapCliConfig[key] = config[key]; } }); } deployTgz(rootPath, lcapCliConfig); (0, exec_1.execSync)(concatCommand('npx lcap deploy dist-theme', lcapCliConfig)); const manifestPath = path_1.default.resolve(rootPath, 'manifest.json'); if (fs_extra_1.default.existsSync(manifestPath)) { (0, exec_1.execSync)(concatCommand('npx lcap deploy manifest.json', lcapCliConfig)); } if (images) { deployImages(rootPath, lcapCliConfig); } logger_1.default.success('Deploy successed!'); };