WeChat applet cli scaffolding. The author is usually a little busy. If any students are interested in this project, they can maintain and develop it together.
Currently provided:
Note: Custom instructions can be used with release hooks to do more interesting things, such as changing environment variables in the configuration file below, submitting version commits , etc.
If you find it useful, I hope you can give it a star~ ???
Install globally using npm
npm install -g xdk-cli
After the installation is successful, you can use it to view the current version number.
xdk-cli -v
Use -h to view the currently provided feature introduction
xdk-cli -h
# 目录结构
- app(小程序目录)
- pages
- app.js
- app.json
- project.config.json
- template
- page
- page.js
- page.json
- page.wxml
- page.wxss
- component
- component.js
...
- xdk.config.js
- xdk.verison.json
# xdk.config.js 设置
module.exports = {
entry: './app'
}
# 目录结构
- dist
- src(小程序目录)
- pages
- app.js
- app.json
- project.config.json
- template
- page
...
- component
...
- xdk.config.js
- xdk.verison.json
# xdk.config.js 设置
module.exports = {
entry: './src',
output: './dist'
}
xdk.config.js needs to be created in the project directory
module.exports = {
// 小程序路径(可选,默认当前目录)
entry: './src',
// 小程序输出文件(可选,默认等于entry)
// 使用gulp,webpack等打包工具开发会导致开发者编辑文件目录和微信编辑器使用目录不同,需要手动进行指定
output: './dist'
// 模版文件夹目录(可选,默认使用cli默认模版,使用默认模版情况下false即可)
template: './template',
// 发布体验版功能的钩子
publishHook: {
// 发布之前(注:必须返回一个Promise对象)
// 参数answer 为之前回答一系列问题的结果
before(answer) {
this.spawnSync('gulp', [`--env=${answer.isRelease ?'online' : 'stage'}`]);
return Promise.resolve();
},
// 发布之后(注:必须返回一个Promise对象)
after(answer) {
// 是否提交git commit
let {isCommitGitLog} = await inquirerGitCommit.call(this);
// 当为正式版本时进行的操作
if (!!answer.isRelease) {
// 修改本地version code
await rewriteVersionCode.call(this);
// 提交git log
!!isCommitGitLog && await commitGitLog.call(this);
}
return Promise.resolve();
}
},
// 自定义命令
// 自定义指令需要用 run 来执行,例如 xdk-cli run dev
customScripts: [
{
name: 'dev',
desc: '开发模式',
async callback() {
let {env} = await inquirerEnvAsync.call(this);
this.spawn('gulp', [`--env=${env}`, '--watch']);
return Promise.resolve();
}
},
{
name: 'sassDoc',
desc: '生成sass文档',
async callback() {
// 生成文档
await sassdoc([`./src/stylesheets/**/*.scss`, `./src/stylesheets/*.scss`], {
dest: './sassdoc',
verbose: true,
display: {
access: ['public'],
alias: true,
},
autofill: ["requires", "throws", "content"],
});
// 自动打开文件
if (process.platform === 'darwin'){
this.spawnSync('open', [`./sassdoc/index.html`]);
}else {
this.log(`目前自动打开浏览器功能只支持darwin内核, 当前内核为: ${process.platform}`);
this.log(`请打开当前路径下html,路径:./sassdoc/index.html`);
}
return Promise.resolve();
}
}
],
};
// 询问是否提交git记录
function inquirerGitCommit() {
return this.inquirer.prompt([
{
type: 'confirm',
name: 'isCommitGitLog',
message: '是否提交git log ?'
}
])
}
// 提交git commit 到log
function commitGitLog() {
return new Promise((resolve, reject) => {
this.spawnSync('git', ['add', '.']);
this.spawnSync('git', ['commit', '-m', `docs: 更改版本号为${versionConf.version}`]);
resolve();
});
}
Provides the function of automatically identifying subcontracts and pages and adding them to app.json, ${page}.json
# 输入创建命令
xdk-cli create
# 选择创建模式
? 选择你想生成的模版类型:(Use arrow keys)
❯ page
component
# 输入页面名称
? 设置 page 的名字 (例如: index):
# 选择所属分包(none为主包)
? 设置页面所属的分包 (Use arrow keys or type to search)
# 创建成功
>> createPage success
# 输入组件名称
? 设置 component 的名字 (例如: swiper-card):
# 选择组件所属范围
? 设置组件所属的作用域 (Use arrow keys)
❯ global
module
page
# 选择所属页面/分包/全局范围
?设置组件所属的页面
❯ index
logs
user
# 创建成功
>> createComponent success
Each project may require different templates. xdk-cli provides a folder slot to facilitate customizing the templates you need to use.
// 在xcli.config.js 中配置模版目录
module . exports = {
// 模版文件夹
template : './template'
} ;
For details on the directory structure of the mini program, see [ Project Directory Structure ] above.
Currently only the mac version is supported. The author lacks a windows development environment (relatively lazy). Welcome to add more.
{
"version" : " 0.1.9 " ,
"versionDesc" : "版本描述"
}
xdk-cli publish
# 正式版本会修改本地的xdk.config.json文件, 非正式版本不会,且体验版版本号默认为0.0.0
? 是否为正式发布版本? Yes
# 设置版本号
? 设置上传的版本号 (当前版本号: 0.1.9.4): raise alter: 0.1.9
# 设置版本描述
? 写一个简单的介绍来描述这个版本的改动过: 提交了一个正式版
Initializing...
idePortFile: /Users/xuan/Library/Application Support/微信开发者工具/Default/.ide
IDE server has started, listening on http://127.0.0.1:27563
initialization finished
uploading project...
upload success
>> 上传体验版成功, 登录微信公众平台 https://mp.weixin.qq.com 获取体验版二维码
if failed
xdk.config.js
Make settings publishHook : {
// 发布之前(注:必须返回一个Promise对象)
before ( answer ) {
console . log ( '要开始发布了' ) ;
return Promise . resolve ( ) ;
} ,
// 发布之后(注:必须返回一个Promise对象)
after ( answer ) {
console . log ( '发布结束了' ) ;
return Promise . resolve ( ) ;
}
} ,
The this points inside all function bodies inherit some basic methods inside the cli.
// this.spawn
// @param - String 命令行
// @param - Args 参数
// @param - Any 默认'ingerit' ['inherit' | null ]
publishHook: {
before ( answer ) {
this . spawn ( 'gulp' , [ `--env= ${ env } ` , '--watch' ] ) ;
return Promise . resolve ( ) ;
} ,
}
// this.spawnSync
// @param - String 命令行
// @param - Args 参数
// @param - Any 默认'ingerit' ['inherit' | null ]
publishHook: {
before ( answer ) {
this . spawnSync ( 'git' , [ 'add' , '.' ] ) ;
this . spawnSync ( 'git' , [ 'commit' , '-m' , `docs: 更改版本号为${ versionConf . version } ` ] ) ;
return Promise . resolve ( ) ;
} ,
}
// this.log
// @param - String 文本内容
// @param - String 类型 success | error
publishHook: {
after ( answer ) {
this . log ( '成功了~' ) ;
this . log ( '成功了~' , 'error' ) ;
return Promise . resolve ( ) ;
} ,
}
See https://github.com/SBoudrias/Inquirer.js for details
publishHook: {
async after ( answer ) {
// 是否提交git commit
let { isCommitGitLog } = await inquirerGitCommit . call ( this ) ;
return Promise . resolve ( ) ;
}
}
function inquirerEnvAsync ( ) {
return this . inquirer . prompt ( [
{
type : 'list' ,
name : 'env' ,
message : '选择当前所使用的环境:' ,
choices : [
'online' ,
'stage' ,
] ,
}
] ) ;
}
If you have any good comments or suggestions, please scan the QR code below to communicate?