feat: add tt-ide-cli

This commit is contained in:
seepine 2024-03-22 18:25:25 +08:00
parent cfeb1f9e74
commit 3b085a9e01
11 changed files with 27455 additions and 3375 deletions

View File

@ -6,6 +6,10 @@ inputs:
required: false
description: 'ci模式,默认upload,可选preview'
default: 'upload'
platform:
required: false
description: '平台,默认wechat,可选douyin'
default: 'wechat'
type:
required: false
description: '小程序类型,默认miniProgram,可选miniProgram/miniProgramPlugin/miniGame/miniGamePlugin'

30636
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

51
dist/licenses.txt generated vendored
View File

@ -35,6 +35,28 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@fastify/busboy
MIT
Copyright Brian White. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
@jimp/bmp
MIT
MIT License
@ -1767,7 +1789,7 @@ sax
ISC
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -1786,7 +1808,7 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
`String.fromCodePoint` by Mathias Bynens used according to terms of MIT
License, as follows:
Copyright Mathias Bynens <https://mathiasbynens.be/>
Copyright (c) 2010-2022 Mathias Bynens <https://mathiasbynens.be/>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@ -1912,6 +1934,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
undici
MIT
MIT License
Copyright (c) Matteo Collina and Undici contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
utif2
MIT
MIT License

View File

@ -24,23 +24,24 @@
"author": "seepine",
"license": "MIT",
"dependencies": {
"@actions/core": "~1.10.0",
"jimp": "~0.22.10",
"jsqr": "~1.4.0",
"qrcode-terminal": "~0.12.0"
"@actions/core": "1.10.0",
"jimp": "0.22.10",
"jsqr": "1.4.0",
"miniprogram-ci": "1.9.8",
"qrcode-terminal": "0.12.0",
"tt-ide-cli": "0.1.25"
},
"devDependencies": {
"@types/node": "~18.16.3",
"@typescript-eslint/parser": "~5.59.2",
"@vercel/ncc": "~0.36.1",
"eslint": "~8.39.0",
"eslint-plugin-github": "~4.7.0",
"eslint-plugin-jest": "~27.2.1",
"jest": "~29.5.0",
"js-yaml": "~4.1.0",
"miniprogram-ci": "~1.9.8",
"prettier": "~2.8.8",
"ts-jest": "~29.1.0",
"typescript": "~5.0.4"
"@types/node": "18.16.3",
"@typescript-eslint/parser": "5.59.2",
"@vercel/ncc": "0.36.1",
"eslint": "8.39.0",
"eslint-plugin-github": "4.7.0",
"eslint-plugin-jest": "27.2.1",
"jest": "29.5.0",
"js-yaml": "4.1.0",
"prettier": "2.8.8",
"ts-jest": "29.1.0",
"typescript": "5.0.4"
}
}

41
src/douyin/preview.ts Normal file
View File

@ -0,0 +1,41 @@
import {Preview} from '../type'
import * as core from '@actions/core'
import {generate, getQrCode} from '../utils/qrcode'
import fs from 'fs'
import {getArgs} from './utils'
import * as cp from 'child_process'
export const preview = async (option: Preview): Promise<string> => {
cp.execSync(
[
'npx',
'tma',
'set-app-config',
option.appid,
'--token',
option.privateKey
].join(' ')
)
const command = [
'npx',
'tma',
'preview',
...getArgs(option),
'--qrcode-output',
option.qrcodeOutputDest,
option.projectPath
].join(' ')
core.info('Command:')
core.info(` ${command}`)
cp.execSync(command)
cp.execSync('npx tma logout')
if (option.qrcodeFormat === 'terminal') {
const qrcodeData = await getQrCode(option.qrcodeOutputDest)
const qrcode = await generate(qrcodeData)
core.info(`Generate terminal qrcode:\n${qrcode}`)
fs.promises.unlink(option.qrcodeOutputDest)
return qrcode
}
return ''
}

28
src/douyin/upload.ts Normal file
View File

@ -0,0 +1,28 @@
import {Upload} from '../type'
import * as core from '@actions/core'
import {getArgs} from './utils'
import * as cp from 'child_process'
export const upload = async (option: Upload): Promise<void> => {
cp.execSync(
[
'npx',
'tma',
'set-app-config',
option.appid,
'--token',
option.privateKey
].join(' ')
)
const command = [
'npx',
'tma',
'upload',
...getArgs(option),
option.projectPath
].join(' ')
core.info('Command:')
core.info(` ${command}`)
cp.execSync(command)
cp.execSync('npx tma logout')
}

14
src/douyin/utils.ts Normal file
View File

@ -0,0 +1,14 @@
import {CiOption} from '../type'
import * as core from '@actions/core'
export const getArgs = (option: CiOption): string[] => {
const args = []
if (option.version) {
args.push(...[' --app-version', `'${option.version}'`])
}
if (option.desc) {
args.push(...['--app-changelog', `'${option.desc}'`])
}
core.debug(args.toString())
return args
}

View File

@ -11,6 +11,7 @@ import {
import {
CiOption,
filterMode,
filterPlatform,
filterQrcodeFormat,
filterType,
Preview
@ -20,6 +21,8 @@ import * as fs from 'fs'
import * as os from 'os'
import {upload} from './ci/upload'
import {preview} from './ci/preview'
import {upload as dyUpload} from './douyin/upload'
import {preview as dyPreview} from './douyin/preview'
const defaultPrivateKeyPath = '../private.key'
@ -34,6 +37,7 @@ async function run(): Promise<void> {
option = {
mode: filterMode(getInput(Inputs.mode)),
platform: filterPlatform(getInput(Inputs.platform)),
appid: '',
type: filterType(getInput(Inputs.type)),
projectPath: getInput(Inputs.projectPath) || '',
@ -97,7 +101,11 @@ async function run(): Promise<void> {
} else if (option.mode === 'upload') {
core.info('Options:')
core.info(`${stringify(option)}`)
upload(option)
if (option.platform === 'wechat') {
await upload(option)
} else {
await dyUpload(option)
}
} else if (option.mode === 'preview') {
const previewOption: Preview = {
...option,
@ -115,7 +123,11 @@ async function run(): Promise<void> {
)
core.info('Options:')
core.info(`${stringify(previewOption)}`)
qrcode = await preview(previewOption)
if (option.platform === 'wechat') {
qrcode = await preview(previewOption)
} else {
qrcode = await dyPreview(previewOption)
}
}
if (autoPrivateKey) {
fs.promises.unlink(option.privateKeyPath)

View File

@ -22,8 +22,12 @@ export const filterMode = (type?: string): Mode => {
return 'upload'
}
export const filterPlatform = (val?: string): 'wechat' | 'douyin' => {
return val === 'douyin' ? 'douyin' : 'wechat'
}
export type CiOption = {
mode: Mode
platform: 'wechat' | 'douyin'
appid: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
setting?: any

View File

@ -1,6 +1,7 @@
/* eslint-disable no-shadow */
export enum Inputs {
mode = 'mode',
platform = 'platform',
type = 'type',
projectPath = 'project-path',
privateKey = 'private-key',