2016-07-27 14:15:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
process.on('exit', () => {
|
|
|
|
console.log();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!process.argv[2]) {
|
|
|
|
console.error('[组件名]必填.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const fileSave = require('file-save');
|
|
|
|
const uppercamelcase = require('uppercamelcase');
|
|
|
|
const componentname = process.argv[2];
|
|
|
|
const chineseName = process.argv[3] || componentname;
|
|
|
|
const ComponentName = uppercamelcase(componentname);
|
2016-10-13 17:51:14 +08:00
|
|
|
const PackagePath = path.resolve(__dirname, '../../packages', componentname);
|
2016-07-27 14:15:02 +08:00
|
|
|
const Files = [
|
|
|
|
{
|
|
|
|
filename: 'index.js',
|
|
|
|
content: `const ${ComponentName} = require('./src/main');
|
|
|
|
|
2016-10-30 13:37:32 +08:00
|
|
|
/* istanbul ignore next */
|
2016-07-27 14:15:02 +08:00
|
|
|
${ComponentName}.install = function(Vue) {
|
|
|
|
Vue.component(${ComponentName}.name, ${ComponentName});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ${ComponentName};`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'cooking.conf.js',
|
|
|
|
content: `var cooking = require('cooking');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
cooking.set({
|
|
|
|
entry: {
|
|
|
|
index: path.join(__dirname, 'index.js')
|
|
|
|
},
|
|
|
|
dist: path.join(__dirname, 'lib'),
|
|
|
|
template: false,
|
|
|
|
format: 'umd',
|
|
|
|
moduleName: 'El${ComponentName}',
|
2016-10-19 22:48:35 +08:00
|
|
|
extends: ['vue2'],
|
|
|
|
alias: config.alias,
|
|
|
|
externals: { vue: config.vue }
|
2016-07-27 14:15:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = cooking.resolve();`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'package.json',
|
|
|
|
content: `{
|
|
|
|
"name": "el-${componentname}",
|
|
|
|
"version": "0.0.0",
|
|
|
|
"description": "A ${componentname} component for Vue.js.",
|
|
|
|
"keywords": [
|
|
|
|
"element",
|
|
|
|
"vue",
|
|
|
|
"component"
|
|
|
|
],
|
|
|
|
"main": "./lib/index.js",
|
2016-11-06 12:26:14 +08:00
|
|
|
"repository": "https://github.com/ElemeFE/element/tree/master/packages/${componentname}",
|
2016-07-27 14:15:02 +08:00
|
|
|
"author": "elemefe",
|
|
|
|
"license": "MIT",
|
|
|
|
"dependencies": {}
|
|
|
|
}`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
filename: 'src/main.vue',
|
|
|
|
content: `<template>
|
|
|
|
<div class="el-${componentname}"></div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'el-${componentname}'
|
|
|
|
};
|
|
|
|
</script>`
|
|
|
|
},
|
|
|
|
{
|
2016-11-07 16:54:20 +08:00
|
|
|
filename: path.join('../../examples/docs/zh-CN', `${componentname}.md`),
|
2016-09-09 11:51:28 +08:00
|
|
|
content: `## ${chineseName}`
|
2016-07-27 14:15:02 +08:00
|
|
|
}
|
2016-09-09 11:51:28 +08:00
|
|
|
];
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
// 添加到 components.json
|
2016-09-26 19:01:53 +08:00
|
|
|
const componentsFile = require('../../components.json');
|
2016-07-27 14:15:02 +08:00
|
|
|
if (componentsFile[componentname]) {
|
|
|
|
console.error(`${componentname} 已存在.`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-09-27 14:55:37 +08:00
|
|
|
componentsFile[componentname] = `./packages/${componentname}/index.js`;
|
2016-09-26 19:01:53 +08:00
|
|
|
fileSave(path.join(__dirname, '../../components.json'))
|
2016-07-27 14:15:02 +08:00
|
|
|
.write(JSON.stringify(componentsFile, null, ' '), 'utf8')
|
2016-09-09 11:51:28 +08:00
|
|
|
.end('\n');
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
// 创建 package
|
|
|
|
Files.forEach(file => {
|
|
|
|
fileSave(path.join(PackagePath, file.filename))
|
|
|
|
.write(file.content, 'utf8')
|
2016-09-09 11:51:28 +08:00
|
|
|
.end('\n');
|
|
|
|
});
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
// 添加到 nav.config.json
|
2016-09-26 19:01:53 +08:00
|
|
|
const navConfigFile = require('../../examples/nav.config.json');
|
2016-10-17 15:55:12 +08:00
|
|
|
|
|
|
|
navConfigFile[2].groups[navConfigFile[2].groups.length - 1].list.push({
|
2016-07-27 14:15:02 +08:00
|
|
|
path: `/${componentname}`,
|
|
|
|
name: `${chineseName} (${componentname})`,
|
2016-09-09 11:51:28 +08:00
|
|
|
title: componentname === chineseName
|
|
|
|
? componentname
|
|
|
|
: `${componentname} ${chineseName}`
|
2016-07-27 14:15:02 +08:00
|
|
|
});
|
|
|
|
|
2016-09-26 19:01:53 +08:00
|
|
|
fileSave(path.join(__dirname, '../../examples/nav.config.json'))
|
2016-07-27 14:15:02 +08:00
|
|
|
.write(JSON.stringify(navConfigFile, null, ' '), 'utf8')
|
2016-09-09 11:51:28 +08:00
|
|
|
.end('\n');
|
2016-07-27 14:15:02 +08:00
|
|
|
|
|
|
|
console.log('DONE!');
|