2016-09-26 19:01:53 +08:00
|
|
|
var Components = require('../../components.json');
|
2016-09-09 11:51:28 +08:00
|
|
|
var fs = require('fs');
|
|
|
|
var render = require('json-templater/string');
|
|
|
|
var uppercamelcase = require('uppercamelcase');
|
|
|
|
var path = require('path');
|
2017-04-25 22:30:08 +08:00
|
|
|
var endOfLine = require('os').EOL;
|
2016-09-09 11:51:28 +08:00
|
|
|
|
2016-09-26 19:01:53 +08:00
|
|
|
var OUTPUT_PATH = path.join(__dirname, '../../src/index.js');
|
2017-03-20 11:38:03 +08:00
|
|
|
var IMPORT_TEMPLATE = 'import {{name}} from \'../packages/{{package}}/index.js\';';
|
2017-01-13 16:13:50 +08:00
|
|
|
var INSTALL_COMPONENT_TEMPLATE = ' {{name}}';
|
2017-08-22 12:46:22 +08:00
|
|
|
var MAIN_TEMPLATE = `/* Automatically generated by './build/bin/build-entry.js' */
|
2016-11-04 12:24:57 +08:00
|
|
|
|
|
|
|
{{include}}
|
2016-10-27 17:31:22 +08:00
|
|
|
import locale from 'element-ui/src/locale';
|
2017-03-23 17:57:14 +08:00
|
|
|
import CollapseTransition from 'element-ui/src/transitions/collapse-transition';
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2017-01-13 16:13:50 +08:00
|
|
|
const components = [
|
2017-03-23 17:57:14 +08:00
|
|
|
{{install}},
|
|
|
|
CollapseTransition
|
2017-01-13 16:13:50 +08:00
|
|
|
];
|
|
|
|
|
2016-10-27 17:31:22 +08:00
|
|
|
const install = function(Vue, opts = {}) {
|
|
|
|
locale.use(opts.locale);
|
2017-01-04 12:22:27 +08:00
|
|
|
locale.i18n(opts.i18n);
|
2016-07-27 17:05:28 +08:00
|
|
|
|
2018-08-01 11:50:01 +08:00
|
|
|
components.forEach(component => {
|
2017-01-13 16:13:50 +08:00
|
|
|
Vue.component(component.name, component);
|
|
|
|
});
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-11-15 20:29:33 +08:00
|
|
|
Vue.use(Loading.directive);
|
2016-08-15 11:51:25 +08:00
|
|
|
|
2018-05-21 18:57:40 +08:00
|
|
|
Vue.prototype.$ELEMENT = {
|
|
|
|
size: opts.size || '',
|
|
|
|
zIndex: opts.zIndex || 2000
|
|
|
|
};
|
2017-10-12 17:50:06 +08:00
|
|
|
|
2016-11-15 20:29:33 +08:00
|
|
|
Vue.prototype.$loading = Loading.service;
|
2016-08-15 11:51:25 +08:00
|
|
|
Vue.prototype.$msgbox = MessageBox;
|
|
|
|
Vue.prototype.$alert = MessageBox.alert;
|
|
|
|
Vue.prototype.$confirm = MessageBox.confirm;
|
|
|
|
Vue.prototype.$prompt = MessageBox.prompt;
|
|
|
|
Vue.prototype.$notify = Notification;
|
|
|
|
Vue.prototype.$message = Message;
|
2017-10-12 17:50:06 +08:00
|
|
|
|
2016-07-27 14:15:02 +08:00
|
|
|
};
|
|
|
|
|
2016-10-18 19:07:43 +08:00
|
|
|
/* istanbul ignore if */
|
2016-07-27 14:15:02 +08:00
|
|
|
if (typeof window !== 'undefined' && window.Vue) {
|
|
|
|
install(window.Vue);
|
2018-01-23 18:25:49 +08:00
|
|
|
}
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2019-01-23 11:34:19 +08:00
|
|
|
export default {
|
2016-09-21 11:44:47 +08:00
|
|
|
version: '{{version}}',
|
2016-11-09 13:49:12 +08:00
|
|
|
locale: locale.use,
|
2017-01-04 12:22:27 +08:00
|
|
|
i18n: locale.i18n,
|
2016-07-27 14:15:02 +08:00
|
|
|
install,
|
2017-03-23 17:57:14 +08:00
|
|
|
CollapseTransition,
|
2016-11-17 14:30:25 +08:00
|
|
|
Loading,
|
2016-07-27 14:15:02 +08:00
|
|
|
{{list}}
|
|
|
|
};
|
2016-09-09 11:51:28 +08:00
|
|
|
`;
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-09-09 11:51:28 +08:00
|
|
|
delete Components.font;
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-09-09 11:51:28 +08:00
|
|
|
var ComponentNames = Object.keys(Components);
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-09-09 11:51:28 +08:00
|
|
|
var includeComponentTemplate = [];
|
|
|
|
var installTemplate = [];
|
|
|
|
var listTemplate = [];
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
ComponentNames.forEach(name => {
|
2016-09-09 11:51:28 +08:00
|
|
|
var componentName = uppercamelcase(name);
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
includeComponentTemplate.push(render(IMPORT_TEMPLATE, {
|
|
|
|
name: componentName,
|
|
|
|
package: name
|
2016-09-09 11:51:28 +08:00
|
|
|
}));
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-10-08 22:47:28 +08:00
|
|
|
if (['Loading', 'MessageBox', 'Notification', 'Message'].indexOf(componentName) === -1) {
|
|
|
|
installTemplate.push(render(INSTALL_COMPONENT_TEMPLATE, {
|
2016-07-27 14:15:02 +08:00
|
|
|
name: componentName,
|
|
|
|
component: name
|
2016-09-09 11:51:28 +08:00
|
|
|
}));
|
2016-07-27 14:15:02 +08:00
|
|
|
}
|
|
|
|
|
2016-11-15 20:29:33 +08:00
|
|
|
if (componentName !== 'Loading') listTemplate.push(` ${componentName}`);
|
2016-09-09 11:51:28 +08:00
|
|
|
});
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
var template = render(MAIN_TEMPLATE, {
|
2017-04-25 22:30:08 +08:00
|
|
|
include: includeComponentTemplate.join(endOfLine),
|
|
|
|
install: installTemplate.join(',' + endOfLine),
|
2016-09-26 19:01:53 +08:00
|
|
|
version: process.env.VERSION || require('../../package.json').version,
|
2017-04-25 22:30:08 +08:00
|
|
|
list: listTemplate.join(',' + endOfLine)
|
2016-09-09 11:51:28 +08:00
|
|
|
});
|
2016-07-27 14:15:02 +08:00
|
|
|
|
2016-09-09 11:51:28 +08:00
|
|
|
fs.writeFileSync(OUTPUT_PATH, template);
|
|
|
|
console.log('[build entry] DONE:', OUTPUT_PATH);
|
2016-07-27 14:15:02 +08:00
|
|
|
|