Command line interface for micro app development
npm install tt-ide-cli> tma 是抖音小程序官方提供的命令行工具

- 安装
- 使用
- 设置全局配置
- 创建新项目
- 打开已有项目
- 登录
- 通过 email 登录
- 登出(清除本地 session)
- 本地项目体积
- 预览小程序
- 上传项目
- 小程序 host
- 小程序提审
- 获取小程序信息
- 构建 NPM
建议在全局安装 tma
```
npm install -g tt-ide-cli
设置小程序的 token, 用于替代登录态
#### 命令行使用
`
Usage: tma set-app-config
Example: tma set-app-config ttxxxxxxx --token 123123123
`
#### 代码调用
`js`
const tma = require('tt-ide-cli');
tma.setAppConfig({
appId: 'ttxxxxxx',
config: {
token: '123123123',
},
});
主要用于配置工具的全局代理
#### 命令行使用
`
Usage: tma set-config [options]
Set tt-ide-cli config
Options:
--proxy
--default Use default(恢复为默认配置)
`
#### 代码调用
`js`
const tma = require('tt-ide-cli');
await tma.setConfig({
proxy: 'http://127.0.0.1:8899';
});
在当前目录下,以给定的项目名字创建一个空白的小程序项目
#### 命令行使用
`
Usage: tma create [options]
Create a new project with given name in current folder
Options:
-f, --force Overwrite target directory if it exists
--template rich | empty (default: empty)
--type
--targetDir
`
#### 代码调用
`js`
const tma = require('tt-ide-cli');
await tma.create({
projectName: 'projectName',
force: false, // 是否覆盖目标文件夹
template: 'rich', // 'rich' | 'empty'
// rich 为小程序能力展示 DEMO
// empty 为小程序空项目
targetDir: '/path/to/targetDir',
type: 'js', // 'js' | 'ts'
// js 为 js 小程序
// ts 为 ts 小程序
});
在小程序开发者工具中打开给定目录的项目,如果给定的目录不存在,则仅打开开发者工具
#### 命令行使用
`
Usage: tma open
Open target project by path
Options:
--mode
`
#### 代码调用
`js`
const tma = require('tt-ide-cli');
await tma.open({
project: {
path: 'projectPath',
mode: 'lite',
},
});
登录到开发者平台
#### 命令行使用
`
Usage: tma login [options]
Login to the developer platform
Options:
-m, --mobile Login by mobile
-e, --email Login by email
-p, --proxy
-h, --help Output usage information
`
#### 命令行使用
`
Usage: tma login-e [email] [password]
Login to the developer platform by E-mail
Options:
-p, --proxy
-h, --help Output usage information
`
#### 代码调用
`js`
const tma = require('tt-ide-cli');
await tma.loginByEmail({
email: 'email',
password: 'password',
});
> 通过调用tma.sendVerificationCodeToPhone({ phoneNumber: 'phoneNumber' })可以发送验证码
#### 代码调用
`js`
const tma = require('tt-ide-cli');
await tma.loginByPhone({
phoneNumber: 'phoneNumber',
code: 'code',
});
#### 命令行使用
`
Usage: tma logout
Logout and clear the session.
`
#### 代码使用
`js`
const tma = require('tt-ide-cli');
await tma.logout();
查看本地项目的文件体积
#### 命令行使用
`bash
Usage: tma project-size [--json] entry
Output current project package size information.
Options:
--json Output as JSON string
`
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
const result = await tma.getProjectSize(projectPath);
将项目上传后,扫码二维码来预览小程序(如果要设置 miniapp-query, miniapp-scene 等启动参数需要同时设置 miniapp-path 参数,否则将不会生效)。
#### 命令行使用
`
Usage: tma preview [options] [entry]
Preview project by remote
Options:
--disable-cache Preview project without local cache
-s, --small Use small QR Code, it may fail in some environments
-c, --copy Copy remote url to clipboard
-p, --proxy
--miniapp-path
--miniapp-query
--miniapp-scene
--miniapp-launch-from
--miniapp-location
--qrcode-output
`
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
// previewResult 返回值
interface ProjectQRCode {
expireTime: number; // 二维码过期时间
shortUrl: string; // 二维码短链
originSchema: string; // 二维码 schema
qrcodeSVG?: string; // 二维码 SVG
qrcodeFilePath?: string; // 二维码存储路径
useCache: boolean; // 是否命中并使用缓存
}
const previewResult: ProjectQRCode = await tma.preview({
project: {
path: 'projectPath', // 项目地址
},
page: {
path: '', // 小程序打开页面
query: '', // 小程序打开 query
scene: '', // 小程序打开场景值
launchFrom: '', // 小程序打开场景(未知可填空字符串)
location: '', // 小程序打开位置(未知可填空字符串)
},
qrcode: {
format: 'imageSVG', // imageSVG | imageFile | null | terminal
// imageSVG 用于产出二维码 SVG
// imageFile 用于将二维码存储到某个路径
// terminal 用于将二维码在控制台输出
// null 则不产出二维码
output: '', // 只在 imageFile 生效,填写图片输出绝对路径
options: {
small: false, // 使用小二维码,主要用于 terminal
},
},
cache: true, // 是否使用缓存
copyToClipboard: true, // 是否将产出的二维码链接复制到剪切板
});
把项目上传到开发者平台进行发布
#### 命令行使用
- app-changelog 为必填参数,其余为可选参数,其中 app-version 的默认值为前序版本号末位加一。
`
Usage: tma upload [options] [entry]
Upload project to the developer platform
Options:
-v, --app-version
-c, --app-changelog
-p, --proxy
-cp, --copy Copy remote url to clipboard
--qrcode-output
--channel
`
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
// uploadResult 返回值
interface ProjectQRCode {
expireTime: number; // 二维码过期时间
shortUrl: string; // 二维码短链
originSchema: string; // 二维码 schema
qrcodeSVG?: string; // 二维码 SVG
qrcodeFilePath?: string; // 二维码存储路径
useCache: boolean; // 是否命中并使用缓存
}
const uploadResult: ProjectQRCode = await tma.upload({
project: {
path: 'projectPath', // 项目地址
},
qrcode: {
format: 'imageSVG', // imageSVG | imageFile | null | terminal
// imageSVG 用于产出二维码 SVG
// imageFile 用于将二维码存储到某个路径
// terminal 用于将二维码在控制台输出
// null 则不产出二维码
output: '', // 只在 imageFile 生效,填写图片输出绝对路径
options: {
small: false, // 使用小二维码,主要用于 terminal
},
},
copyToClipboard: true, // 是否将产出的二维码链接复制到剪切板
changeLog: 'changelog', // 本次更新日志
version: '1.0.0', // 本次更新版本,可选参数,默认值为前序版本号末位加一
needUploadSourcemap: true, // 是否上传后生成 sourcemap,推荐使用 true,否则开发者后台解析错误时将不能展示原始代码
channel: '1', // 可选项,测试通道,不传该参数时为默认通道
});
查询小程序支持的 host 。
#### 命令行使用
`
Usage: tma hosts [appid]
Get Audit Host List
`
`bash`
tma hosts tt07e3715e98c9xxxx
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
await tma.getAuditHostsList({ appid: '' });
小程序提审
- 小程序首次提审,需要通过 defaultSsUrl 属性给定一个截图路径;
> 推荐首次提审时,到开发者平台上传合规截图;
- 后续提审会复用前一次提审的截图;
- 现在支持的 host 参数已有
- douyintoutiao
- douyin_lite
- tt_lite
- tma hosts [appid]
- 更多 host 可以通过 的命令查询
#### 命令行使用
`
Usage: tma audit [options] [appid]
Audit project in the developer platform
Options:
--host
--auto-publish
--channel
`
`bash`使用示范
tma audit --host douyin,toutiao,tt_lite tt07e3715e98c9xxxx
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
// 提审
await tma.audit({
appid: '',
host: [], // douyin,toutiao,tt_lite
autoPublish: true, // 是否审核通过后自动发布
defaultSsUrl: '/tmp/picture/default.png',
});
#### 命令行使用
`
Usage: tma get-meta [options] [appid]
Get appid meta
`
#### 代码调用
`typescript`
const tma = require('tt-ide-cli');
// metaResult 返回值
interface MiniappMetaInfo {
version: String; // 线上小程序版本号
}
const metaResult: MiniappMetaInfo = await tma.getMeta({
appid: 'appid',
});
对应开发者工具 构建 NPM 功能
#### 命令行使用
`
Usage: tma build-npm [options]
Build npm
Options:
--project-path Project path
`
#### 代码调用
`typescript``
const tma = require('tt-ide-cli');
await tma.buildNpm({
project: {
path: 'projectPath',
},
});