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

feat:全局配置注入

parent bb62bd71
export interface CountryList {
name: string;
key: string;
icon: string;
}
export interface Global {
logo: string;
countryList: CountryList[];
}
export interface RootObject {
global: Global;
}
\ No newline at end of file
......@@ -38,6 +38,7 @@
"chalk": "^4.1.0",
"fs-extra": "^9.0.1",
"gulp": "^4.0.2",
"json2ts": "^0.0.7",
"ora": "^4.0.4"
}
}
......@@ -4,8 +4,12 @@ const fse = require('fs-extra')
const Type = require('./utils/type')
const fetchConfig = require('../demo').fetchConfig
const gulp = require('gulp')
const json2ts = require('json2ts')
const outputPath = path.resolve(__dirname, '../', 'config/base.config.json')
const rootPath = '../';
const outputPath = path.resolve(__dirname, rootPath, 'config/base.config.json')
const outputDts = path.resolve(__dirname, rootPath, 'global.d.ts')
Logs.start('gulp start')
......@@ -24,7 +28,7 @@ function genarateBaseJson(obj, done) {
Logs.success('write success')
Logs.stop('Configuration has arrived locally', 'success')
done()
genarateDtsFile(JSON.stringify(obj), done)
}).catch(err => {
Logs.error(err)
done()
......@@ -39,6 +43,13 @@ function genarateBaseJson(obj, done) {
}
}
function genarateDtsFile(json, done) {
const dtsResult = json2ts.convert(json)
fse.outputFile(outputDts, dtsResult).then(() => {
done()
})
}
/**
* 异步获取远程配置
* @todo
......
/**
*
* **********
* 脚本注入全局配置
*
* **********
*/
import SELF_CONFIG from '../../config/base.config.json'
import { RootObject } from '../../global'
export const GlobalConfig: RootObject = SELF_CONFIG
......@@ -2,12 +2,9 @@ declare module '*.css';
declare module '*.less';
declare module "*.png";
declare module "classnames";
declare module "*.json";
declare module '*.svg' {
export function ReactComponent(props: React.SVGProps<SVGSVGElement>): React.ReactElement
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