first
This commit is contained in:
99
build/bin/build-entry.js
Normal file
99
build/bin/build-entry.js
Normal file
@ -0,0 +1,99 @@
|
||||
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, '../../src/index.js');
|
||||
var IMPORT_TEMPLATE = 'import {{name}} from \'../packages/{{package}}/index.js\';';
|
||||
var INSTALL_COMPONENT_TEMPLATE = ' {{name}}';
|
||||
var MAIN_TEMPLATE = `/* Automatically generated by './build/bin/build-entry.js' */
|
||||
|
||||
{{include}}
|
||||
import locale from 'element-ui/src/locale';
|
||||
import CollapseTransition from 'element-ui/src/transitions/collapse-transition';
|
||||
|
||||
const components = [
|
||||
{{install}},
|
||||
CollapseTransition
|
||||
];
|
||||
|
||||
const install = function(Vue, opts = {}) {
|
||||
locale.use(opts.locale);
|
||||
locale.i18n(opts.i18n);
|
||||
|
||||
components.forEach(component => {
|
||||
Vue.component(component.name, component);
|
||||
});
|
||||
|
||||
Vue.use(InfiniteScroll);
|
||||
Vue.use(Loading.directive);
|
||||
|
||||
Vue.prototype.$ELEMENT = {
|
||||
size: opts.size || '',
|
||||
zIndex: opts.zIndex || 2000
|
||||
};
|
||||
|
||||
Vue.prototype.$loading = Loading.service;
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
/* istanbul ignore if */
|
||||
if (typeof window !== 'undefined' && window.Vue) {
|
||||
install(window.Vue);
|
||||
}
|
||||
|
||||
export default {
|
||||
version: '{{version}}',
|
||||
locale: locale.use,
|
||||
i18n: locale.i18n,
|
||||
install,
|
||||
CollapseTransition,
|
||||
Loading,
|
||||
{{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', 'Message', 'InfiniteScroll'].indexOf(componentName) === -1) {
|
||||
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);
|
||||
|
39
build/bin/build-locale.js
Normal file
39
build/bin/build-locale.js
Normal file
@ -0,0 +1,39 @@
|
||||
var fs = require('fs');
|
||||
var save = require('file-save');
|
||||
var resolve = require('path').resolve;
|
||||
var basename = require('path').basename;
|
||||
var localePath = resolve(__dirname, '../../src/locale/lang');
|
||||
var fileList = fs.readdirSync(localePath);
|
||||
|
||||
var transform = function(filename, name, cb) {
|
||||
require('babel-core').transformFile(resolve(localePath, filename), {
|
||||
plugins: [
|
||||
'add-module-exports',
|
||||
['transform-es2015-modules-umd', {loose: true}]
|
||||
],
|
||||
moduleId: name
|
||||
}, cb);
|
||||
};
|
||||
|
||||
fileList
|
||||
.filter(function(file) {
|
||||
return /\.js$/.test(file);
|
||||
})
|
||||
.forEach(function(file) {
|
||||
var name = basename(file, '.js');
|
||||
|
||||
transform(file, name, function(err, result) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
var code = result.code;
|
||||
|
||||
code = code
|
||||
.replace('define(\'', 'define(\'element/locale/')
|
||||
.replace('global.', 'global.ELEMENT.lang = global.ELEMENT.lang || {}; \n global.ELEMENT.lang.');
|
||||
save(resolve(__dirname, '../../lib/umd/locale', file)).write(code);
|
||||
|
||||
console.log(file);
|
||||
}
|
||||
});
|
||||
});
|
32
build/bin/gen-cssfile.js
Normal file
32
build/bin/gen-cssfile.js
Normal file
@ -0,0 +1,32 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Components = require('../../components.json');
|
||||
var themes = [
|
||||
'theme-chalk'
|
||||
];
|
||||
Components = Object.keys(Components);
|
||||
var basepath = path.resolve(__dirname, '../../packages/');
|
||||
|
||||
function fileExists(filePath) {
|
||||
try {
|
||||
return fs.statSync(filePath).isFile();
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
themes.forEach((theme) => {
|
||||
var isSCSS = theme !== 'theme-default';
|
||||
var indexContent = isSCSS ? '@import "./base.scss";\n' : '@import "./base.css";\n';
|
||||
Components.forEach(function(key) {
|
||||
if (['icon', 'option', 'option-group'].indexOf(key) > -1) return;
|
||||
var fileName = key + (isSCSS ? '.scss' : '.css');
|
||||
indexContent += '@import "./' + fileName + '";\n';
|
||||
var filePath = path.resolve(basepath, theme, 'src', fileName);
|
||||
if (!fileExists(filePath)) {
|
||||
fs.writeFileSync(filePath, '', 'utf8');
|
||||
console.log(theme, ' 创建遗漏的 ', fileName, ' 文件');
|
||||
}
|
||||
});
|
||||
fs.writeFileSync(path.resolve(basepath, theme, 'src', isSCSS ? 'index.scss' : 'index.css'), indexContent);
|
||||
});
|
58
build/bin/gen-indices.js
Normal file
58
build/bin/gen-indices.js
Normal file
@ -0,0 +1,58 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const algoliasearch = require('algoliasearch');
|
||||
const slugify = require('transliteration').slugify;
|
||||
const key = require('./algolia-key');
|
||||
|
||||
const client = algoliasearch('4C63BTGP6S', key);
|
||||
const langs = {
|
||||
'zh-CN': 'element-zh',
|
||||
'en-US': 'element-en',
|
||||
'es': 'element-es',
|
||||
'fr-FR': 'element-fr'
|
||||
};
|
||||
|
||||
['zh-CN', 'en-US', 'es', 'fr-FR'].forEach(lang => {
|
||||
const indexName = langs[lang];
|
||||
const index = client.initIndex(indexName);
|
||||
index.clearIndex(err => {
|
||||
if (err) return;
|
||||
fs.readdir(path.resolve(__dirname, `../../examples/docs/${ lang }`), (err, files) => {
|
||||
if (err) return;
|
||||
let indices = [];
|
||||
files.forEach(file => {
|
||||
const component = file.replace('.md', '');
|
||||
const content = fs.readFileSync(path.resolve(__dirname, `../../examples/docs/${ lang }/${ file }`), 'utf8');
|
||||
const matches = content
|
||||
.replace(/:::[\s\S]*?:::/g, '')
|
||||
.replace(/```[\s\S]*?```/g, '')
|
||||
.match(/#{2,4}[^#]*/g)
|
||||
.map(match => match.replace(/\n+/g, '\n').split('\n').filter(part => !!part))
|
||||
.map(match => {
|
||||
const length = match.length;
|
||||
if (length > 2) {
|
||||
const desc = match.slice(1, length).join('');
|
||||
return [match[0], desc];
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
indices = indices.concat(matches.map(match => {
|
||||
const isComponent = match[0].indexOf('###') < 0;
|
||||
const title = match[0].replace(/#{2,4}/, '').trim();
|
||||
const index = { component, title };
|
||||
index.ranking = isComponent ? 2 : 1;
|
||||
index.anchor = slugify(title);
|
||||
index.content = (match[1] || title).replace(/<[^>]+>/g, '');
|
||||
return index;
|
||||
}));
|
||||
});
|
||||
|
||||
index.addObjects(indices, (err, res) => {
|
||||
console.log(err, res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
26
build/bin/i18n.js
Normal file
26
build/bin/i18n.js
Normal file
@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var langConfig = require('../../examples/i18n/page.json');
|
||||
|
||||
langConfig.forEach(lang => {
|
||||
try {
|
||||
fs.statSync(path.resolve(__dirname, `../../examples/pages/${ lang.lang }`));
|
||||
} catch (e) {
|
||||
fs.mkdirSync(path.resolve(__dirname, `../../examples/pages/${ lang.lang }`));
|
||||
}
|
||||
|
||||
Object.keys(lang.pages).forEach(page => {
|
||||
var templatePath = path.resolve(__dirname, `../../examples/pages/template/${ page }.tpl`);
|
||||
var outputPath = path.resolve(__dirname, `../../examples/pages/${ lang.lang }/${ page }.vue`);
|
||||
var content = fs.readFileSync(templatePath, 'utf8');
|
||||
var pairs = lang.pages[page];
|
||||
|
||||
Object.keys(pairs).forEach(key => {
|
||||
content = content.replace(new RegExp(`<%=\\s*${ key }\\s*>`, 'g'), pairs[key]);
|
||||
});
|
||||
|
||||
fs.writeFileSync(outputPath, content);
|
||||
});
|
||||
});
|
22
build/bin/iconInit.js
Normal file
22
build/bin/iconInit.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var postcss = require('postcss');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var fontFile = fs.readFileSync(path.resolve(__dirname, '../../packages/theme-chalk/src/icon.scss'), 'utf8');
|
||||
var nodes = postcss.parse(fontFile).nodes;
|
||||
var classList = [];
|
||||
|
||||
nodes.forEach((node) => {
|
||||
var selector = node.selector || '';
|
||||
var reg = new RegExp(/\.el-icon-([^:]+):before/);
|
||||
var arr = selector.match(reg);
|
||||
|
||||
if (arr && arr[1]) {
|
||||
classList.push(arr[1]);
|
||||
}
|
||||
});
|
||||
|
||||
classList.reverse(); // 希望按 css 文件顺序倒序排列
|
||||
|
||||
fs.writeFile(path.resolve(__dirname, '../../examples/icon.json'), JSON.stringify(classList), () => {});
|
60
build/bin/new-lang.js
Normal file
60
build/bin/new-lang.js
Normal file
@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
console.log();
|
||||
process.on('exit', () => {
|
||||
console.log();
|
||||
});
|
||||
|
||||
if (!process.argv[2]) {
|
||||
console.error('[language] is required!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var fs = require('fs');
|
||||
const path = require('path');
|
||||
const fileSave = require('file-save');
|
||||
const lang = process.argv[2];
|
||||
// const configPath = path.resolve(__dirname, '../../examples/i18n', lang);
|
||||
|
||||
// 添加到 components.json
|
||||
const componentFile = require('../../examples/i18n/component.json');
|
||||
if (componentFile.some(item => item.lang === lang)) {
|
||||
console.error(`${lang} already exists.`);
|
||||
process.exit(1);
|
||||
}
|
||||
let componentNew = Object.assign({}, componentFile.filter(item => item.lang === 'en-US')[0], { lang });
|
||||
componentFile.push(componentNew);
|
||||
fileSave(path.join(__dirname, '../../examples/i18n/component.json'))
|
||||
.write(JSON.stringify(componentFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 添加到 page.json
|
||||
const pageFile = require('../../examples/i18n/page.json');
|
||||
let pageNew = Object.assign({}, pageFile.filter(item => item.lang === 'en-US')[0], { lang });
|
||||
pageFile.push(pageNew);
|
||||
fileSave(path.join(__dirname, '../../examples/i18n/page.json'))
|
||||
.write(JSON.stringify(pageFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 添加到 route.json
|
||||
const routeFile = require('../../examples/i18n/route.json');
|
||||
routeFile.push({ lang });
|
||||
fileSave(path.join(__dirname, '../../examples/i18n/route.json'))
|
||||
.write(JSON.stringify(routeFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 添加到 nav.config.json
|
||||
const navFile = require('../../examples/nav.config.json');
|
||||
navFile[lang] = navFile['en-US'];
|
||||
fileSave(path.join(__dirname, '../../examples/nav.config.json'))
|
||||
.write(JSON.stringify(navFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// docs 下新建对应文件夹
|
||||
try {
|
||||
fs.statSync(path.resolve(__dirname, `../../examples/docs/${ lang }`));
|
||||
} catch (e) {
|
||||
fs.mkdirSync(path.resolve(__dirname, `../../examples/docs/${ lang }`));
|
||||
}
|
||||
|
||||
console.log('DONE!');
|
155
build/bin/new.js
Normal file
155
build/bin/new.js
Normal file
@ -0,0 +1,155 @@
|
||||
'use strict';
|
||||
|
||||
console.log();
|
||||
process.on('exit', () => {
|
||||
console.log();
|
||||
});
|
||||
|
||||
if (!process.argv[2]) {
|
||||
console.error('[组件名]必填 - Please enter new component name');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fileSave = require('file-save');
|
||||
const uppercamelcase = require('uppercamelcase');
|
||||
const componentname = process.argv[2];
|
||||
const chineseName = process.argv[3] || componentname;
|
||||
const ComponentName = uppercamelcase(componentname);
|
||||
const PackagePath = path.resolve(__dirname, '../../packages', componentname);
|
||||
const Files = [
|
||||
{
|
||||
filename: 'index.js',
|
||||
content: `import ${ComponentName} from './src/main';
|
||||
|
||||
/* istanbul ignore next */
|
||||
${ComponentName}.install = function(Vue) {
|
||||
Vue.component(${ComponentName}.name, ${ComponentName});
|
||||
};
|
||||
|
||||
export default ${ComponentName};`
|
||||
},
|
||||
{
|
||||
filename: 'src/main.vue',
|
||||
content: `<template>
|
||||
<div class="el-${componentname}"></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'El${ComponentName}'
|
||||
};
|
||||
</script>`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../examples/docs/zh-CN', `${componentname}.md`),
|
||||
content: `## ${ComponentName} ${chineseName}`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../examples/docs/en-US', `${componentname}.md`),
|
||||
content: `## ${ComponentName}`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../examples/docs/es', `${componentname}.md`),
|
||||
content: `## ${ComponentName}`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../examples/docs/fr-FR', `${componentname}.md`),
|
||||
content: `## ${ComponentName}`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../test/unit/specs', `${componentname}.spec.js`),
|
||||
content: `import { createTest, destroyVM } from '../util';
|
||||
import ${ComponentName} from 'packages/${componentname}';
|
||||
|
||||
describe('${ComponentName}', () => {
|
||||
let vm;
|
||||
afterEach(() => {
|
||||
destroyVM(vm);
|
||||
});
|
||||
|
||||
it('create', () => {
|
||||
vm = createTest(${ComponentName}, true);
|
||||
expect(vm.$el).to.exist;
|
||||
});
|
||||
});
|
||||
`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../packages/theme-chalk/src', `${componentname}.scss`),
|
||||
content: `@import "mixins/mixins";
|
||||
@import "common/var";
|
||||
|
||||
@include b(${componentname}) {
|
||||
}`
|
||||
},
|
||||
{
|
||||
filename: path.join('../../types', `${componentname}.d.ts`),
|
||||
content: `import { ElementUIComponent } from './component'
|
||||
|
||||
/** ${ComponentName} Component */
|
||||
export declare class El${ComponentName} extends ElementUIComponent {
|
||||
}`
|
||||
}
|
||||
];
|
||||
|
||||
// 添加到 components.json
|
||||
const componentsFile = require('../../components.json');
|
||||
if (componentsFile[componentname]) {
|
||||
console.error(`${componentname} 已存在.`);
|
||||
process.exit(1);
|
||||
}
|
||||
componentsFile[componentname] = `./packages/${componentname}/index.js`;
|
||||
fileSave(path.join(__dirname, '../../components.json'))
|
||||
.write(JSON.stringify(componentsFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 添加到 index.scss
|
||||
const sassPath = path.join(__dirname, '../../packages/theme-chalk/src/index.scss');
|
||||
const sassImportText = `${fs.readFileSync(sassPath)}@import "./${componentname}.scss";`;
|
||||
fileSave(sassPath)
|
||||
.write(sassImportText, 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 添加到 element-ui.d.ts
|
||||
const elementTsPath = path.join(__dirname, '../../types/element-ui.d.ts');
|
||||
|
||||
let elementTsText = `${fs.readFileSync(elementTsPath)}
|
||||
/** ${ComponentName} Component */
|
||||
export class ${ComponentName} extends El${ComponentName} {}`;
|
||||
|
||||
const index = elementTsText.indexOf('export') - 1;
|
||||
const importString = `import { El${ComponentName} } from './${componentname}'`;
|
||||
|
||||
elementTsText = elementTsText.slice(0, index) + importString + '\n' + elementTsText.slice(index);
|
||||
|
||||
fileSave(elementTsPath)
|
||||
.write(elementTsText, 'utf8')
|
||||
.end('\n');
|
||||
|
||||
// 创建 package
|
||||
Files.forEach(file => {
|
||||
fileSave(path.join(PackagePath, file.filename))
|
||||
.write(file.content, 'utf8')
|
||||
.end('\n');
|
||||
});
|
||||
|
||||
// 添加到 nav.config.json
|
||||
const navConfigFile = require('../../examples/nav.config.json');
|
||||
|
||||
Object.keys(navConfigFile).forEach(lang => {
|
||||
let groups = navConfigFile[lang][4].groups;
|
||||
groups[groups.length - 1].list.push({
|
||||
path: `/${componentname}`,
|
||||
title: lang === 'zh-CN' && componentname !== chineseName
|
||||
? `${ComponentName} ${chineseName}`
|
||||
: ComponentName
|
||||
});
|
||||
});
|
||||
|
||||
fileSave(path.join(__dirname, '../../examples/nav.config.json'))
|
||||
.write(JSON.stringify(navConfigFile, null, ' '), 'utf8')
|
||||
.end('\n');
|
||||
|
||||
console.log('DONE!');
|
16
build/bin/template.js
Normal file
16
build/bin/template.js
Normal file
@ -0,0 +1,16 @@
|
||||
const path = require('path');
|
||||
const templates = path.resolve(process.cwd(), './examples/pages/template');
|
||||
|
||||
const chokidar = require('chokidar');
|
||||
let watcher = chokidar.watch([templates]);
|
||||
|
||||
watcher.on('ready', function() {
|
||||
watcher
|
||||
.on('change', function() {
|
||||
exec('npm run i18n');
|
||||
});
|
||||
});
|
||||
|
||||
function exec(cmd) {
|
||||
return require('child_process').execSync(cmd).toString().trim();
|
||||
}
|
6
build/bin/version.js
Normal file
6
build/bin/version.js
Normal file
@ -0,0 +1,6 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var version = process.env.VERSION || require('../../package.json').version;
|
||||
var content = { '1.4.13': '1.4', '2.0.11': '2.0', '2.1.0': '2.1', '2.2.2': '2.2', '2.3.9': '2.3', '2.4.11': '2.4', '2.5.4': '2.5', '2.6.3': '2.6', '2.7.2': '2.7', '2.8.2': '2.8', '2.9.2': '2.9', '2.10.1': '2.10', '2.11.1': '2.11', '2.12.0': '2.12', '2.13.2': '2.13', '2.14.1': '2.14' };
|
||||
if (!content[version]) content[version] = '2.15';
|
||||
fs.writeFileSync(path.resolve(__dirname, '../../examples/versions.json'), JSON.stringify(content));
|
Reference in New Issue
Block a user