Skip to content

Commit 7176ace

Browse files
committed
feat(alita): 完善--comp命令的支持
1 parent 38683b9 commit 7176ace

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

src/filewatch/index.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const eventEmitter = new events.EventEmitter();
1919
const DONE_EVENT = 'DONE_EVENT'
2020

2121
export default (ignored) => {
22-
const {INPUT_DIR, watchMode} = global.execArgs
22+
const {INPUT_DIR, watchMode, tranComp} = global.execArgs
2323

2424
const fileSet = new Set([])
2525
const watcher = chokidar.watch(INPUT_DIR,
@@ -50,12 +50,16 @@ export default (ignored) => {
5050
})
5151
.on('ready', () => {
5252
eventEmitter.once(DONE_EVENT, () => {
53-
if (watchMode) {
54-
successLog()
55-
console.log(`监听文件修改...`.info)
53+
54+
if (tranComp) {
55+
successCompLog()
5656
} else {
5757
successLog()
5858
}
59+
60+
if (watchMode) {
61+
console.log(`监听文件修改...`.info)
62+
}
5963
})
6064
})
6165
}
@@ -70,4 +74,15 @@ function successLog() {
7074
console.log(` • 从开发者工具构建npm: 工具 --> 构建npm`.black)
7175
console.log(` • 由于构建npm在导入项目之后,可能会出现找不到包的错误,此时需要重启开发者工具,或者重新导入项目`.warn)
7276
console.log('')
73-
}
77+
}
78+
79+
function successCompLog() {
80+
const {outdir} = global.execArgs
81+
console.log('')
82+
console.log('编译完成:'.info)
83+
console.log(` • cd ${outdir}`.black)
84+
console.log(` • npm publish`.black)
85+
console.log(` • 其他项目要使用这个npm包的时候, 需要正确配置其 alita.config.js`.black)
86+
console.log('')
87+
}
88+

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ if (enterO() && !options.outdir) {
147147
console.log('output dir must exists, check your -o argument'.error)
148148
process.exit()
149149
}
150-
const OUT_DIR = path.resolve(options.outdir)
150+
const OUT_DIR = path.resolve(options.outdir, options.component ? 'miniprogram_npm': '')
151151

152152
console.log(`输入目录: ${INPUT_DIR}`.info)
153153
console.log(`输出目录: ${OUT_DIR}`.info)
@@ -206,7 +206,7 @@ function main() {
206206
}
207207

208208
// 生成微信目录结构
209-
geneWXFileStruc(OUT_DIR)
209+
geneWXFileStruc(OUT_DIR, options.component)
210210

211211
// 生成微信package.json文件
212212
geneWXPackageJSON()

src/util/geneWXFileStruc.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import path from 'path'
1010
import fse from 'fs-extra'
1111

12-
export default function geneWXFileStruc(targetpath) {
12+
export default function geneWXFileStruc(targetpath, tranComp) {
1313
const mptempDir = path.resolve(__dirname, '..', '..', 'mptemp')
1414
fse.copySync(mptempDir, targetpath)
1515

@@ -20,6 +20,12 @@ export default function geneWXFileStruc(targetpath) {
2020
return
2121
}
2222

23+
if (tranComp) {
24+
// 转化组件,不需要project.config.json 文件
25+
return
26+
}
27+
28+
2329
// 生成 project.config.json 文件
2430
const {name, appid} = global.execArgs.configObj
2531
const pcjStr = `{

src/util/geneWXPackageJSON.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ export default function geneWXPackageJSON() {
1616
INPUT_DIR,
1717
configObj,
1818
OUT_DIR,
19+
tranComp
1920
} = global.execArgs
2021

22+
let packagePath = OUT_DIR
23+
if (tranComp) {
24+
// package.json 和miniprogram_npm 同级
25+
packagePath = path.resolve(OUT_DIR, "..")
26+
}
27+
2128

2229
const packJSONPath = path.resolve(INPUT_DIR, configObj.packageJSONPath)
2330
console.log('package.json路径:'.info, packJSONPath)
@@ -52,7 +59,7 @@ export default function geneWXPackageJSON() {
5259
})
5360
newPack.dependencies = newDep
5461
fse.writeFileSync(
55-
path.resolve(OUT_DIR, 'package.json'),
62+
path.resolve(packagePath, 'package.json'),
5663
JSON.stringify(newPack, null, '\t'),
5764
)
5865
} else {

0 commit comments

Comments
 (0)