-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 添加上传腾讯云COS工具 * feat: 添加上传/预览小程序包工具
- Loading branch information
Showing
16 changed files
with
916 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,16 @@ | ||
*.log | ||
*.swp | ||
|
||
.github | ||
.cache | ||
.temp | ||
.idea | ||
.rn_temp | ||
.DS_Store | ||
|
||
CHANGELOG.md | ||
package-lock.json | ||
|
||
src | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,18 @@ | ||
# @antmjs/mini-upload | ||
|
||
### 安装 | ||
``` | ||
yarn add @antmjs/mini-upload --save-dev | ||
``` | ||
|
||
### 使用 | ||
|
||
``` | ||
上传 | ||
antm-mini-upload deploy --type [type] --appid [appid] | ||
预览 | ||
antm-mini-upload preview --type [type] --appid [appid] | ||
``` | ||
*注:* 项目根目录下需要添加private.[appid]文件 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
{ | ||
"name": "@antmjs/mini-upload", | ||
"version": "1.0.0", | ||
"description": "小程序预览及上传工具", | ||
"main": "utils/index.js", | ||
"bin": { | ||
"antm-mini-upload": "utils/index.js" | ||
}, | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"keywords": [ | ||
"miniprogram", | ||
"upload" | ||
], | ||
"repository": { | ||
"type": "https", | ||
"url": "https://github.com/AntmJS/antm.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/AntmJS/antm/issues/new" | ||
}, | ||
"engines": { | ||
"node": ">=12", | ||
"npm": ">=6.4", | ||
"yarn": ">=1.22" | ||
}, | ||
"browserslist": [ | ||
"Chrome >= 35", | ||
"ChromeAndroid >= 35", | ||
"iOS >= 8", | ||
"Safari >= 8", | ||
"Android >= 4.1", | ||
"QQAndroid >= 4.1", | ||
"UCAndroid >= 4.1" | ||
], | ||
"scripts": { | ||
"build": "", | ||
"test:watch": "", | ||
"test": "" | ||
}, | ||
"dependencies": { | ||
"alipay-dev": "^0.5.4", | ||
"commander": "^6.0.0", | ||
"miniprogram-ci": "1.1.5", | ||
"qrcode": "^1.4.4", | ||
"shelljs": "^0.8.4", | ||
"tt-ide-cli": "^0.0.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,46 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const npath = require('path') | ||
const sh = require('shelljs') | ||
const alipaydev = npath.join(__dirname, '../node_modules/.bin/alipaydev') | ||
|
||
function preview(appId) { | ||
const imagePath = './preview_alipay.png' | ||
try { | ||
sh.exec( | ||
`${alipaydev} mini preview -i ${appId} -p ./alipay -o ${imagePath}`, | ||
{ fatal: true }, | ||
) | ||
} catch (error) { | ||
throw new Error(`支付宝小程序预览异常: ${error}`) | ||
} | ||
} | ||
|
||
function upload(appId, version) { | ||
try { | ||
sh.exec( | ||
`${alipaydev} mini upload -c alipay -i ${appId} -p ./alipay -v ${version}`, | ||
{ fatal: true }, | ||
) | ||
} catch (error) { | ||
throw new Error(`支付宝小程序上传异常: ${error}`) | ||
} | ||
} | ||
|
||
module.exports = function alipay(appId, privateKey, type, toolId, version) { | ||
try { | ||
sh.exec(`${alipaydev} config set -i ${toolId} -k ${privateKey}`, { | ||
fatal: true, | ||
}) | ||
} catch (error) { | ||
throw new Error(`支付宝小程序配置异常: ${error}`) | ||
} | ||
|
||
switch (type) { | ||
case 'upload': | ||
upload(appId, version) | ||
break | ||
case 'preview': | ||
preview(appId) | ||
break | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,132 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const program = require('commander') | ||
const pkg = require('../package.json') | ||
|
||
function check(action, regex) { | ||
return function (v, vv) { | ||
if (regex) { | ||
if (regex.test(v)) { | ||
return v | ||
} | ||
console.error( | ||
`Fail to map (${regex}). Check the options by "antm-mini-upload ${action} --help"`, | ||
) | ||
process.exit(1) | ||
} else { | ||
if (!v) { | ||
return vv | ||
} | ||
|
||
return v | ||
} | ||
} | ||
} | ||
|
||
async function weapp(program) { | ||
const doWeapp = require('./weapp') | ||
await doWeapp( | ||
program.appid, | ||
program.privateKeyPath, | ||
program.type, | ||
program.desc, | ||
program.robotId, | ||
program.deployVersion, | ||
) | ||
} | ||
|
||
async function alipay(program) { | ||
const doAlipay = require('./alipay') | ||
doAlipay( | ||
program.appid, | ||
program.privateKey, | ||
program.type, | ||
program.toolId, | ||
program.deployVersion, | ||
) | ||
} | ||
|
||
async function tt(program) { | ||
const doTt = require('./tt') | ||
await doTt( | ||
program.email, | ||
program.password, | ||
program.type, | ||
program.deployVersion, | ||
) | ||
} | ||
|
||
program.version(pkg.version, '-v, --version') | ||
|
||
program | ||
.command('weapp') | ||
.description('CI weapp miniprogram.') | ||
.usage('[command] <options ...>') | ||
.option( | ||
'-t, --type <type>', | ||
'Choose a type. [eg: /^(preview)|(upload)$/]', | ||
check('weapp', /^(preview)|(upload)$/), | ||
'preview', | ||
) | ||
.option( | ||
'-rid, --robotId <robotId>', | ||
'Choose a robotId. [eg: /^([1-9])|([1-2][0-9])|30$/]', | ||
check('weapp', /^([1-9])|([1-2][0-9])|30$/), | ||
'1', | ||
) | ||
.requiredOption('-aid, --appid <appid>', 'appId') | ||
.requiredOption('-pkp, --privateKeyPath <pkp>', 'pkp') | ||
.requiredOption('-d, --desc <desc>', 'desc') | ||
.requiredOption('-dv, --deployVersion <deployVersion>', 'deployVersion') | ||
.action(weapp) | ||
.on('--help', () => { | ||
console.info('\n Example:') | ||
console.info( | ||
'\n $ antm-mini-upload weapp --type [preview|upload] --appid [appid] --privateKeyPath [./xxx.key] --desc [preview] --robotId [1] --deployVersion [1.0.0]', | ||
) | ||
}) | ||
|
||
program | ||
.command('alipay') | ||
.description('CI alipay miniprogram.') | ||
.usage('[command] <options ...>') | ||
.option( | ||
'-t, --type <type>', | ||
'Choose a type. [eg: /^(preview)|(upload)$/]', | ||
check('alipay', /^(preview)|(upload)$/), | ||
'preview', | ||
) | ||
.requiredOption('-i, --appid <appid>', 'appId') | ||
.requiredOption('-pk, --privateKey <pk>', 'pk') | ||
.requiredOption('-tid, --toolId <toolId>', 'toolId') | ||
.requiredOption('-dv, --deployVersion <deployVersion>', 'deployVersion') | ||
.action(alipay) | ||
.on('--help', () => { | ||
console.info('\n Example:') | ||
console.info( | ||
'\n $ antm-mini-upload alipay --type [preview|upload] --appid [appid] --privateKey [xxxx] --toolId [xxx] --deployVersion [1.0.0]', | ||
) | ||
}) | ||
|
||
program | ||
.command('tt') | ||
.description('CI tt miniprogram.') | ||
.usage('[command] <options ...>') | ||
.option( | ||
'-t, --type <type>', | ||
'Choose a type. [eg: /^(preview)|(upload)$/]', | ||
check('tt', /^(preview)|(upload)$/), | ||
'preview', | ||
) | ||
.requiredOption('-e, --email <email>', 'email') | ||
.requiredOption('-p, --password <password>', 'password') | ||
.requiredOption('-dv, --deployVersion <deployVersion>', 'deployVersion') | ||
.action(tt) | ||
.on('--help', () => { | ||
console.info('\n Example:') | ||
console.info( | ||
'\n $ antm-mini-upload tt --type [preview|upload] --email [email] --password [password] --deployVersion [1.0.0]', | ||
) | ||
}) | ||
|
||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,50 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const os = require('os') | ||
const fs = require('fs') | ||
const npath = require('path') | ||
const sh = require('shelljs') | ||
const QRCode = require('qrcode') | ||
const tma = npath.join(__dirname, '../node_modules/.bin/tma') | ||
|
||
async function preview() { | ||
const imagePath = './preview_tt.png' | ||
try { | ||
sh.exec(`${tma} preview -f`, { fatal: true }) | ||
const previewFilePath = npath.join(os.homedir(), '.tma-cli/preview.json') | ||
const currentResult = JSON.parse( | ||
fs.readFileSync(previewFilePath, 'utf-8') || '{}', | ||
) | ||
await QRCode.toFile(imagePath, currentResult.native, { | ||
width: 300, | ||
margin: 2, | ||
}) | ||
} catch (error) { | ||
throw new Error(`抖音小程序预览异常: ${error}`) | ||
} | ||
} | ||
|
||
function upload(version) { | ||
try { | ||
const msg = '更新了一些内容' | ||
sh.exec(`${tma} upload -v ${version} -c ${msg}`, { fatal: true }) | ||
} catch (error) { | ||
throw new Error(`抖音小程序上传异常: ${error}`) | ||
} | ||
} | ||
|
||
module.exports = async function tt(email, password, type, version) { | ||
try { | ||
sh.exec(`${tma} login-e ${email} ${password}`, { fatal: true }) | ||
} catch (error) { | ||
throw new Error(`抖音小程序登录异常: ${error}`) | ||
} | ||
|
||
switch (type) { | ||
case 'upload': | ||
upload(version) | ||
break | ||
case 'preview': | ||
await preview() | ||
break | ||
} | ||
} |
Oops, something went wrong.