Commit 795b6e9d authored by liupengfei's avatar liupengfei

开发环境搭建

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