xhs-mp-cli v2.0.6
小程序命令行工具
小红书小程序官方提供的小程序命令行工具 / CI 工具,可以通过该工具箱进行登录、预览、上传等操作,支持命令行方式以及 NPM 直接调用方式。
安装
# 全局安装
npm install -g xhs-mp-cli
# 局部安装
npm install xhs-mp-cli
# 使用
xmc --help
使用
命令行通用参数
Usage: xmc --help
# --project 项目路径
# --verbose 显示详细日志
设置全局配置
主要用于配置全局代理等
命令行使用
Usage: xmc set-config [options]
Set xmc config
Options:
--proxy <proxy> Set global proxy(配置全局代理)
--default Use default(恢复为默认配置)
代码调用
const xmc = require('xhs-mp-cli');
// 设置代理配置
await xmc.setConfig({
proxy: 'http://127.0.0.1:8888' // 此地址仅为示例,具体地址需根据实际代理服务器确定。
});
// 清空配置/恢复默认配置
await xmc.setConfig({});
设置应用配置
主要用于设置小程序/小游戏的配置等,如配置免密登陆秘钥(代码上传秘钥)等
命令行使用
Usage: xmc set-app-config [options]
Set xmc app config
Options:
--appid 小程序配置
--token 代码上传秘钥
--default Use default(恢复为默认配置)
代码调用
const xmc = require('xhs-mp-cli');
// 设置代码上传秘钥
await xmc.setAppConfig({
appId: 'xxxxxx',
config: {
token: 'xxxxx'
}
});
// 清空配置/恢复默认配置
await xmc.setAppConfig({});
登陆
如果不使用代码上传秘钥进行免密登陆,可以采用扫码登录的方式。 登陆并保持会话。目前仅支持二维码扫码登陆
命令行使用
Usage: xmc login
Login to the developer platform
Options:
--type <type> Login Type (登陆方式),默认只支持 qrcode
代码调用
const xmc = require('xhs-mp-cli');
// 设置代理配置
await xmc.login({
type: 'qrcode'
});
登出(清除本地 session)
退出登陆
命令行使用
Usage: xmc logout
Logout and clear the session.
代码调用
const xmc = require('xhs-mp-cli');
await xmc.logout();
预览
小程序/小游戏预览,可以真机扫码体验。
命令行使用
Usage: xmc preview [options]
Preivew the miniprogram/minigame
Options:
--path <path> The entry page path, 入口页面路径
--query <query> 页面参数,如a=x&b=xx
--launchMode <launchMode> 启动方式,default或halfPageNativeFunctionalized
# 示例
xmc preview --project xxx --path entry/api/api --query x=xxx&y=xxx --launchMode default
xmc preview --project xxx --path entry/api/api --query x=xxx&y=xxx --launchMode halfPageNativeFunctionalized
代码调用
const xmc = require('xhs-mp-cli');
interface IPreviewOptions {
project: {
projectPath: string
}
entry?: {
path: string
query?: string
launchMode?: string
}
}
interface IPreviewRes {
qrcodeUrl: string
}
const res:IPreviewRes = await xmc.preview({
project: {
projectPath: 'xxx',
},
entry: {
path: ""
query: ""
launchMode: ""
}
} as IPreviewOptions);
上传
把项目上传到专业号平台/服务商平台进行发布。
命令行使用
Usage: xmc upload [Options]
Upload project to the developer platform
Options:
--version <version> Version(版本),如1.0.0
--desc <desc> 版本描述
代码调用
const xmc = require('xhs-mp-cli');
interface IUploadOptions {
project: {
projectPath: string
}
version: string
desc: string
}
// 设置代理配置
await xmc.upload({
project: {
projectPath: 'xxx',
},
version: "1.0.1",
desc: "test"
} as IUploadOptions);
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
8 months ago
10 months ago
9 months ago
1 year ago
11 months ago
11 months ago
1 year ago
12 months ago
1 year ago
1 year ago
11 months ago
12 months ago
1 year ago
12 months ago
12 months ago
10 months ago
1 year ago
10 months ago
12 months ago
10 months ago
12 months ago
10 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago