Skip to content

Commit

Permalink
feat(alita): 完善--comp命令的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Oct 27, 2019
1 parent 38683b9 commit 7176ace
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
25 changes: 20 additions & 5 deletions src/filewatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const eventEmitter = new events.EventEmitter();
const DONE_EVENT = 'DONE_EVENT'

export default (ignored) => {
const {INPUT_DIR, watchMode} = global.execArgs
const {INPUT_DIR, watchMode, tranComp} = global.execArgs

const fileSet = new Set([])
const watcher = chokidar.watch(INPUT_DIR,
Expand Down Expand Up @@ -50,12 +50,16 @@ export default (ignored) => {
})
.on('ready', () => {
eventEmitter.once(DONE_EVENT, () => {
if (watchMode) {
successLog()
console.log(`监听文件修改...`.info)

if (tranComp) {
successCompLog()
} else {
successLog()
}

if (watchMode) {
console.log(`监听文件修改...`.info)
}
})
})
}
Expand All @@ -70,4 +74,15 @@ function successLog() {
console.log(` • 从开发者工具构建npm: 工具 --> 构建npm`.black)
console.log(` • 由于构建npm在导入项目之后,可能会出现找不到包的错误,此时需要重启开发者工具,或者重新导入项目`.warn)
console.log('')
}
}

function successCompLog() {
const {outdir} = global.execArgs
console.log('')
console.log('编译完成:'.info)
console.log(` • cd ${outdir}`.black)
console.log(` • npm publish`.black)
console.log(` • 其他项目要使用这个npm包的时候, 需要正确配置其 alita.config.js`.black)
console.log('')
}

4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if (enterO() && !options.outdir) {
console.log('output dir must exists, check your -o argument'.error)
process.exit()
}
const OUT_DIR = path.resolve(options.outdir)
const OUT_DIR = path.resolve(options.outdir, options.component ? 'miniprogram_npm': '')

console.log(`输入目录: ${INPUT_DIR}`.info)
console.log(`输出目录: ${OUT_DIR}`.info)
Expand Down Expand Up @@ -206,7 +206,7 @@ function main() {
}

// 生成微信目录结构
geneWXFileStruc(OUT_DIR)
geneWXFileStruc(OUT_DIR, options.component)

// 生成微信package.json文件
geneWXPackageJSON()
Expand Down
8 changes: 7 additions & 1 deletion src/util/geneWXFileStruc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import path from 'path'
import fse from 'fs-extra'

export default function geneWXFileStruc(targetpath) {
export default function geneWXFileStruc(targetpath, tranComp) {
const mptempDir = path.resolve(__dirname, '..', '..', 'mptemp')
fse.copySync(mptempDir, targetpath)

Expand All @@ -20,6 +20,12 @@ export default function geneWXFileStruc(targetpath) {
return
}

if (tranComp) {
// 转化组件,不需要project.config.json 文件
return
}


// 生成 project.config.json 文件
const {name, appid} = global.execArgs.configObj
const pcjStr = `{
Expand Down
9 changes: 8 additions & 1 deletion src/util/geneWXPackageJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ export default function geneWXPackageJSON() {
INPUT_DIR,
configObj,
OUT_DIR,
tranComp
} = global.execArgs

let packagePath = OUT_DIR
if (tranComp) {
// package.json 和miniprogram_npm 同级
packagePath = path.resolve(OUT_DIR, "..")
}


const packJSONPath = path.resolve(INPUT_DIR, configObj.packageJSONPath)
console.log('package.json路径:'.info, packJSONPath)
Expand Down Expand Up @@ -52,7 +59,7 @@ export default function geneWXPackageJSON() {
})
newPack.dependencies = newDep
fse.writeFileSync(
path.resolve(OUT_DIR, 'package.json'),
path.resolve(packagePath, 'package.json'),
JSON.stringify(newPack, null, '\t'),
)
} else {
Expand Down

0 comments on commit 7176ace

Please sign in to comment.