-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathbuild-entry.js
90 lines (76 loc) · 2.18 KB
/
build-entry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* @Date: 2024-12-06 09:11:17
* @Description: Modify here please
*/
var Components = require("../components.json");
var fs = require("fs");
var render = require("json-templater/string");
var uppercamelcase = require("uppercamelcase");
var path = require("path");
var endOfLine = require("os").EOL;
var OUTPUT_PATH = path.join(__dirname, "../index.js");
var INSTALL_COMPONENT_TEMPLATE = " {{name}}";
var IMPORT_TEMPLATE = "import {{name}} from './packages/{{package}}/index.js';";
var MAIN_TEMPLATE = `/* 自动生成者来着 './build/build-entry.js' */
{{include}}
import locale from 'umy-ui/tools/locale';
// 引入u-table的locale
import tableLocale from 'umy-table/lib/locale'
import { interceptor } from "umy-table";
const components = [
{{install}}
];
const install = function(Vue, opts = {}) {
locale.use(opts.locale);
locale.i18n(opts.i18n);
// 设置u-table的语言
tableLocale.use(opts.locale);
components.forEach(component => {
Vue.component(component.name, component);
});
Vue.prototype.$UMYUI = {
size: opts.size || '',
zIndex: opts.zIndex || 2000
};
};
/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}
export default {
version: '{{version}}',
locale: locale.use,
i18n: locale.i18n,
install,
{{list}},
interceptor
};
`;
var ComponentNames = Object.keys(Components);
var includeComponentTemplate = [];
var installTemplate = [];
var listTemplate = [];
ComponentNames.forEach((name) => {
var componentName = uppercamelcase(name);
includeComponentTemplate.push(
render(IMPORT_TEMPLATE, {
name: componentName,
package: name,
})
);
installTemplate.push(
render(INSTALL_COMPONENT_TEMPLATE, {
name: componentName,
component: name,
})
);
if (componentName !== "Loading") listTemplate.push(` ${componentName}`);
});
var template = render(MAIN_TEMPLATE, {
include: includeComponentTemplate.join(endOfLine),
install: installTemplate.join("," + endOfLine),
version: process.env.VERSION || require("../package.json").version,
list: listTemplate.join("," + endOfLine),
});
fs.writeFileSync(OUTPUT_PATH, template);
console.log("[build entry] DONE:", OUTPUT_PATH);