uni-app vue-cli Jenkins通过CI构建到微信公众平台
发布于 3 年前 作者 wei95 3225 次浏览 来自 分享

uni-app vue-cli CI流程搭建

目前可用服务构建发布小程序,例如Jenkins等,可方便开发者手动点上传.

默认目录

其实就是正常的vue-cli的工程目录,其中的version.config.json,可用可不用,版本号在package.json中的version,对应的key是在微信公众后台可以下载的

npm run updata

对应的环境变量可自行添加

地址:https://github.com/gao18516823865/uni-app

有疑问留言,回复不及时谅解~

ci.js

const ci = require('miniprogram-ci')
const fs = require('fs');
const inquirer = require('inquirer');
const projectConfig = require('./project.config.json');
// const versionConfig = require('./version.config.json');
const pkg = require('./package.json');
/*ci实例*/
const project = new ci.Project({
    appid: projectConfig.appid,
    type: projectConfig.type,
    projectPath: projectConfig.projectPath,
    privateKeyPath: './ci-private.key',
    ignores: ['node_modules/**/*'],
})
/*ci上传*/
async function upload({ version = '0.0.0', versionDesc = 'test' }) {
    await ci.upload({
        project,
        version,
        desc: versionDesc,
        setting: {//可修改
            es7: true,
            minify: true,
            autoPrefixWXSS: true
        },
        onProgressUpdate: console.log,
    })
}
/** 增加版本号 */
function versionNext(array, idx) {
    let arr = [].concat(array);
    ++arr[idx];
    arr = arr.map((v, i) => i > idx ? 0 : v);
    if (!parseInt(arr[arr.length - 1])) arr.pop();
    return arr.join('.');
}
/** 获取版本选项 */
function getVersionChoices(version) {
    const vArrsDesc = ['raise major: ', 'raise minor: ', 'raise patch: ', 'raise alter: '];
    let vArrs = version.split('.');
    let choices = vArrsDesc.map((item, index, array) => {
        array.length > vArrs.length ? vArrs.push(0) : '';
        return vArrsDesc[index] + versionNext(vArrs, index)
    }).reverse();
    choices.unshift('no change');
    return choices;
}

function inquirerResult({
    version,
    versionDesc
} = {}) {
    return inquirer.prompt([
        // 设置版本号
        {
            type: 'list',
            name: 'version',
            message: `设置上传的版本号(当前版本号: ${version}):`,
            default: 1,
            choices: getVersionChoices(version),
            filter(opts) {
                if (opts === 'no change') {
                    return version;
                }
                return opts.split(': ')[1];
            }
        },
        // 设置上传描述
        {
            type: 'input',
            name: 'versionDesc',
            message: `写一个简单的介绍来描述这个版本的改动过:`,
        },
    ]);
}
/*ci入口函数*/
async function init() {
    // Get modification information
    let versionData = await inquirerResult(pkg);
    //upload
    await upload(versionData);
    fs.writeFileSync('./version.config.json', JSON.stringify(pkg), err => {
        if (err) {
            console.log('自动写入app.json文件失败,请手动填写,并检查错误');
        }
    });
}
init()

project.config.json

{
    "projectPath": "dist/dev/mp-weixin/",//上传目录可修改
    "description": "项目配置文件",
    "setting": {//可修改,目前这个是build可以在微信开发者工具中拿到
        "urlCheck": false,
        "es6": true,
        "enhance": true,
        "postcss": true,
        "preloadBackgroundData": false,
        "minified": false,
        "newFeature": false,
        "coverView": true,
        "nodeModules": false,
        "autoAudits": false,
        "showShadowRootInWxmlPanel": true,
        "scopeDataCheck": false,
        "uglifyFileName": false,
        "checkInvalidKey": true,
        "checkSiteMap": true,
        "uploadWithSourceMap": true,
        "compileHotReLoad": false,
        "lazyloadPlaceholderEnable": false,
        "useMultiFrameRuntime": true,
        "useApiHook": true,
        "useApiHostProcess": true,
        "babelSetting": {
            "ignore": [],
            "disablePlugins": [],
            "outputPath": ""
        },
        "enableEngineNative": false,
        "useIsolateContext": true,
        "userConfirmedBundleSwitch": false,
        "packNpmManually": false,
        "packNpmRelationList": [],
        "minifyWXSS": true,
        "disableUseStrict": false,
        "showES6CompileOption": false,
        "useCompilerPlugins": false
    },
    "type": "miniprogram",
    "appid": appid,
    "condition": {
        "search": {
            "list": []
        },
        "conversation": {
            "list": []
        },
        "game": {
            "list": []
        },
        "miniprogram": {
            "list": []
        }
    }
}
回到顶部