mirror of
https://github.com/ElemeFE/element.git
synced 2025-12-13 11:34:02 +08:00
Initial commit
This commit is contained in:
70
bin/build-entry.js
Normal file
70
bin/build-entry.js
Normal file
@@ -0,0 +1,70 @@
|
||||
var Components = require('../components.json')
|
||||
var fs = require('fs')
|
||||
var render = require('json-templater/string')
|
||||
var uppercamelcase = require('uppercamelcase')
|
||||
var path = require('path')
|
||||
|
||||
var OUTPUT_PATH = path.join(__dirname, '../src/index.js')
|
||||
var IMPORT_TEMPLATE = `import {{name}} from '../packages/{{package}}/index.js';`
|
||||
var ISNTALL_COMPONENT_TEMPLATE = ` Vue.component({{name}}.name, {{name}});`
|
||||
var MAIN_TEMPLATE = `{{include}}
|
||||
|
||||
const install = function(Vue) {
|
||||
{{install}}
|
||||
|
||||
Vue.use(Loading);
|
||||
|
||||
Vue.prototype.$msgbox = MessageBox;
|
||||
Vue.prototype.$alert = MessageBox.alert;
|
||||
Vue.prototype.$confirm = MessageBox.confirm;
|
||||
Vue.prototype.$prompt = MessageBox.prompt;
|
||||
Vue.prototype.$notify = Notification;
|
||||
};
|
||||
|
||||
// auto install
|
||||
if (typeof window !== 'undefined' && window.Vue) {
|
||||
install(window.Vue);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
install,
|
||||
{{list}}
|
||||
};
|
||||
`
|
||||
|
||||
delete Components.font
|
||||
|
||||
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
|
||||
}))
|
||||
|
||||
|
||||
if (['Loading', 'MessageBox', 'Notification'].indexOf(componentName) === -1) {
|
||||
installTemplate.push(render(ISNTALL_COMPONENT_TEMPLATE, {
|
||||
name: componentName,
|
||||
component: name
|
||||
}))
|
||||
}
|
||||
|
||||
listTemplate.push(` ${componentName}`)
|
||||
})
|
||||
|
||||
var template = render(MAIN_TEMPLATE, {
|
||||
include: includeComponentTemplate.join('\n'),
|
||||
install: installTemplate.join('\n'),
|
||||
list: listTemplate.join(',\n')
|
||||
})
|
||||
|
||||
fs.writeFileSync(OUTPUT_PATH, template)
|
||||
console.log('[build entry] DONE:', OUTPUT_PATH)
|
||||
|
||||
Reference in New Issue
Block a user