小红书小程序官方提供的小程序命令行工具 / 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.setGlobalConfig({
proxy: 'http://127.0.0.1:8888' // 此地址仅为示例,具体地址需根据实际代理服务器确定。
});
// 清空配置/恢复默认配置
await xmc.setGlobalConfig({});
主要用于设置小程序/小游戏的配置等,如配置免密登陆秘钥(代码上传秘钥)等
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 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);