Commit 795b6e9d authored by liupengfei's avatar liupengfei

开发环境搭建

parent 8f00741f
/*
* @Author: flyharvest
* @Date: 2020-07-14 10:15:41
* @LastEditTime: 2020-07-14 10:43:04
* @LastEditTime: 2020-07-14 12:11:34
* @LastEditors: flyharvest
*/
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
function error (message) {
return new Error({
message
})
}
function commandArgs (string) {
return process.env[string]
}
......@@ -17,7 +23,7 @@ function access (path) {
return new Promise((resolve, reject) => {
fs.access(path, (err) => {
if (err) {
reject(`没有找到对应文件 ${path}`)
reject(error(`没有找到对应文件 ${path}`))
} else {
resolve(true)
}
......@@ -30,7 +36,7 @@ function writeFile (path, content) {
return new Promise((resolve, reject) => {
fs.writeFile(path, content, { encoding: 'utf8' }, (err) => {
if (err) {
reject(`写入文件失败 ${path}`)
reject(error(`写入文件失败 ${path}`))
} else {
resolve(content)
}
......@@ -62,9 +68,10 @@ const env = process.env.NODE_ENV
const autoWriteFileName = `${env} scripts`
// 获取入口文件
async function getEntry() {
async function getEntry () {
if (!lib) {
return Promise.reject(`开发模式下,必须指定包名 \n lib = xxx yarn serve`)
const message = '开发模式下,必须指定包名 \n lib = xxx yarn serve'
return Promise.reject(error(message))
} else {
const devPath = path.resolve(__dirname, '../test', lib, './index.js')
let devHtml = path.resolve(__dirname, '../test', lib, './index.html')
......@@ -74,9 +81,9 @@ async function getEntry() {
devHtml = path.resolve(__dirname, '../test/public/index.html')
}
if (has[0] === false) {
return Promise.reject(`dev 下未找到${lib}/index.js`)
return Promise.reject(error(`test 下未找到${lib}/index.js`))
} else if (has[2] === false) {
return Promise.reject(`src 下未找到${lib}/index.js`)
return Promise.reject(error(`src 下未找到${lib}/index.js`))
}
return [devPath, devHtml]
}
......@@ -108,9 +115,10 @@ function buildEntry () {
.then(() => {
buildInStep('入口文件构建完成, 开始 rollup 构建')
})
.catch (err => {
buildError(err)
.catch(err => {
const { message = '未知错误' } = err
buildError(message)
})
}
module.exports = buildEntry
\ No newline at end of file
module.exports = buildEntry
/*
* @Author: flyharvest
* @Date: 2020-07-08 17:22:20
* @LastEditTime: 2020-07-14 11:56:05
* @LastEditTime: 2020-07-14 12:30:10
* @LastEditors: flyharvest
*/
const { dotenv } = require('./util')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment