Commit bb62bd71 authored by 前端-许佳敏's avatar 前端-许佳敏

feat:新增编译脚本

parent cad9acb7
......@@ -3,4 +3,10 @@
### 为数商云&醒电构建项目提供react脚手架模板
- god页面模板, 依赖于[umi](https://umijs.org/), 更多配置可以查看
- god组件库[文档](http://10.0.0.22:8080/)
\ No newline at end of file
- god组件库[文档](http://10.0.0.22:8080/)
### scripts 所需依赖
- gulp 流程工具
- chalk 控制台样式控制工具
- fs-extra 扩展fs模块
- ora 控制台加载中样式
\ No newline at end of file
{"global":{"logo":"","countryList":[{"name":"简体中文-ZH","key":"cn","icon":""},{"name":"English-EN","key":"en","icon":""},{"name":"日本語-JP","key":"jp","icon":""},{"name":"한국어-KO","key":"ko","icon":""}]}}
const globalConfig = {
menu: {
logo: 'xxx',
title: 'xxx'
}
}
export default globalConfig
\ No newline at end of file
const mockData = {
message: '',
code: 1000,
data: {
global: {
logo: '',
countryList: [
{
name: '简体中文-ZH',
key: 'cn',
icon: ''
},
{
name: 'English-EN',
key: 'en',
icon: ''
},
{
name: '日本語-JP',
key: 'jp',
icon: ''
},
{
name: '한국어-KO',
key: 'ko',
icon: ''
}
]
}
}
}
exports.fetchConfig = async () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(mockData)
}, 2* 1000)
})
}
\ No newline at end of file
{
"global": {
"hi": 1
}
}
\ No newline at end of file
{
"name": "god-template",
"scripts": {
"scripts:build": "node scripts/index",
"scripts:build": "node scripts/run",
"start:analyze": "ANALYZE=1 umi dev",
"start": "umi dev",
"build": "umi build",
......@@ -35,6 +35,9 @@
"yorkie": "^2.0.0"
},
"devDependencies": {
"gulp": "^4.0.2"
"chalk": "^4.1.0",
"fs-extra": "^9.0.1",
"gulp": "^4.0.2",
"ora": "^4.0.4"
}
}
const path = require('path')
const Logs = require('./utils/log')
const fse = require('fs-extra')
const Type = require('./utils/type')
const fetchConfig = require('../demo').fetchConfig
const gulp = require('gulp')
const outputPath = path.resolve(__dirname, '../', 'config/base.config.json')
Logs.start('gulp start')
gulp.task('start', gulp.series(done => {
getAsyncConfig(done)
}))
/**
* 生成对应json文件
*/
function genarateBaseJson(obj, done) {
if (Type.isObject(obj)) {
fse.ensureFile(outputPath).then(() => {
fse.writeJson(outputPath, obj).then(() => {
Logs.success('\nstart genarate config json')
Logs.success('write success')
Logs.stop('Configuration has arrived locally', 'success')
done()
}).catch(err => {
Logs.error(err)
done()
})
})
} else {
Logs.error('!!!!!! value is not a object !!!!!')
Logs.error(`here is your value, the type is ${typeof obj}`)
console.log(obj)
Logs.stop('Append error!!!', 'fail')
done()
}
}
/**
* 异步获取远程配置
* @todo
*/
async function getAsyncConfig(done) {
const data = await fetchConfig()
genarateBaseJson(data.data, done)
}
\ No newline at end of file
const gulp = require('gulp')
function runTask(toRun) {
const metadata = { task: toRun };
// Gulp >= 4.0.0 (doesn't support events)
const taskInstance = gulp.task(toRun);
if (taskInstance === undefined) {
gulp.emit('task_not_found', metadata);
return;
}
const start = process.hrtime();
gulp.emit('task_start', metadata);
try {
taskInstance.apply(gulp);
metadata.hrDuration = process.hrtime(start);
gulp.emit('task_stop', metadata);
gulp.emit('stop');
} catch (err) {
err.hrDuration = process.hrtime(start);
err.task = metadata.task;
gulp.emit('task_err', err);
}
}
require('./gulpfile')
runTask('start')
\ No newline at end of file
const chalk = require('chalk')
const ora = require('ora')
const spinner = ora('Loading remote configuration')
const log = console.log
const Logs = {
success(msg) {
log(chalk.green(msg))
},
error(msg) {
log(chalk.red(msg))
},
start() {
spinner.start()
},
stop(msg, type) {
const instance = spinner.stop()
type === 'success' ? instance.succeed(msg) : instance.fail(msg)
}
}
module.exports = Logs
\ No newline at end of file
const Type = {
isObject(data) {
return Object.prototype.toString.call(data) === '[object Object]'
}
}
module.exports = Type
\ No newline at end of file
......@@ -2,9 +2,6 @@ import { IRoutes } from '.';
import { history, RequestConfig } from 'umi';
import React from 'react'
import MobxProvider from './store'
import 'mobx-react-lite/batchingForReactDom'
import globalConfig from '../config/base.config'
let extraRoutes: never[] = []
......@@ -106,6 +103,6 @@ export function rootContainer(container: any) {
* @date 2020-06-10
* @export
*/
export async function getInitialState():Promise<{menu: {title: string, logo: string}}> {
return globalConfig
}
\ No newline at end of file
// export async function getInitialState():Promise<{menu: {title: string, logo: string}}> {
// return globalConfig
// }
\ No newline at end of file
......@@ -2,7 +2,6 @@ import React, {Component} from 'react';
class Index extends Component<{}, {}> {
render() {
return <div>
index
</div>
......
......@@ -7,3 +7,7 @@ declare module '*.svg' {
const url: string
export default url
}
declare interface GLOBAL_CONFIG {
menu: string
}
\ No newline at end of file
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