Skip to content

Commit

Permalink
feat: 添加上传腾讯云COS的包和上传小程序的包 (#64)
Browse files Browse the repository at this point in the history
* feat: 添加上传腾讯云COS工具
* feat: 添加上传/预览小程序包工具
  • Loading branch information
hisanshao authored Nov 19, 2021
1 parent 6edf62f commit 49a4a73
Show file tree
Hide file tree
Showing 16 changed files with 916 additions and 8 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 11,13 @@
- [@antmjs/plugin-mini-fix](https://www.npmjs.com/package/@antmjs/plugin-mini-fix)
- [@antmjs/plugin-icestark](https://www.npmjs.com/package/@antmjs/plugin-icestark)
- [@antmjs/plugin-vantui](https://www.npmjs.com/package/@antmjs/plugin-vantui)
- @antmjs/config
- @antmjs/web-deploy(antm.config.js)
- @antmjs/mini-deploy(antm.config.js)
- [@antmjs/warning(antm.config.js)](https://www.npmjs.com/package/@antmjs/warning)
- [@antmjs/rapper(antm.config.js)](https://www.npmjs.com/package/@antmjs/rapper)
- [@antmjs/upload-tencent](https://www.npmjs.com/package/@antmjs/upload-tencent)
- [@antmjs/mini-deploy](https://www.npmjs.com/package/@antmjs/mini-deploy)
- [@antmjs/warning](https://www.npmjs.com/package/@antmjs/warning)
- [@antmjs/rapper](https://www.npmjs.com/package/@antmjs/rapper)
- [@antmjs/unite](https://www.npmjs.com/package/@antmjs/unite)
- [@antmjs/global-state](https://www.npmjs.com/package/@antmjs/global-state)
- [@antmjs/cache](https://www.npmjs.com/package/@antmjs/cache)
- [@antmjs/trace](https://www.npmjs.com/package/@antmjs/trace)
- [@antmjs/utils](https://www.npmjs.com/package/@antmjs/utils)
- [@antmjs/antmui](https://www.npmjs.com/package/@antmjs/antmui)
- [@antmjs/vantui](https://www.npmjs.com/package/@antmjs/vantui)
16 changes: 16 additions & 0 deletions packages/mini-upload/.npmignore
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
18 changes: 18 additions & 0 deletions packages/mini-upload/README.md
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]文件

52 changes: 52 additions & 0 deletions packages/mini-upload/package.json
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"
}
}
46 changes: 46 additions & 0 deletions packages/mini-upload/utils/alipay.js
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
}
}
132 changes: 132 additions & 0 deletions packages/mini-upload/utils/index.js
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)
50 changes: 50 additions & 0 deletions packages/mini-upload/utils/tt.js
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
}
}
Loading

0 comments on commit 49a4a73

Please sign in to comment.