@wechat-mp/cli
Version:
微信小程序脚手架,集成 Taro、uniapp 第三方模版,支持小程序 CI 上传,预览,发布
42 lines (35 loc) • 1.12 kB
JavaScript
const colors = require("colors");
const userHome = require("user-home");
const pathExists = require("path-exists").sync;
const pkg = require("../package.json");
const { log, getNpmSemverVersion } = require("@wechat-mp/utils");
async function prepare() {
checkPkgVersion();
checkRoot();
checkUserHome();
// await checkGlobalUpdate();
}
function checkPkgVersion() {
log.info("cli", pkg.version);
}
function checkRoot() {
const rootCheck = require("root-check");
rootCheck();
}
function checkUserHome() {
if (!userHome || !pathExists(userHome)) {
throw new Error(colors.red("当前登录用户主目录不存在!"));
}
}
async function checkGlobalUpdate() {
const currentVersion = pkg.version;
const npmName = pkg.name;
const lastVersion = await getNpmSemverVersion(currentVersion, npmName);
if (lastVersion && semver.gt(lastVersion, currentVersion)) {
log.warn(
colors.yellow(`请手动更新 ${npmName},当前版本:${currentVersion},最新版本:${lastVersion}
更新命令: npm install -g ${npmName}`)
);
}
}
module.exports = prepare;