From a7c30b5148024352b978d0c11cb375237b940c03 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 9 Sep 2016 11:51:28 +0800 Subject: [PATCH] package: add lint script & lock vue version --- bin/build-all.js | 2 +- bin/build-entry.js | 45 ++++++++++++------------ bin/iconInit.js | 2 +- bin/new.js | 18 +++++----- package.json | 11 +++--- packages/message-box/cooking.conf.js | 2 +- packages/notification/cooking.conf.js | 2 +- packages/pagination/cooking.conf.js | 2 +- packages/popover/cooking.conf.js | 2 +- packages/progress/cooking.conf.js | 2 +- packages/radio/cooking.conf.js | 2 +- packages/rate/cooking.conf.js | 2 +- packages/row/cooking.conf.js | 2 +- packages/select-dropdown/cooking.conf.js | 2 +- packages/select/cooking.conf.js | 2 +- packages/slider/cooking.conf.js | 2 +- packages/spinner/cooking.conf.js | 2 +- packages/steps/cooking.conf.js | 2 +- packages/switch/cooking.conf.js | 2 +- packages/table/cooking.conf.js | 2 +- packages/tabs/cooking.conf.js | 2 +- packages/tag/cooking.conf.js | 2 +- packages/theme-default/gulpfile.js | 4 +-- packages/tooltip/cooking.conf.js | 2 +- packages/tree/cooking.conf.js | 2 +- packages/upload/cooking.conf.js | 2 +- scripts/cooking.component.js | 2 +- scripts/cooking.demo.js | 22 ++++++------ src/utils/strip-tags.js | 2 +- 29 files changed, 75 insertions(+), 73 deletions(-) diff --git a/bin/build-all.js b/bin/build-all.js index 8c52544ef..f1f4e7b99 100644 --- a/bin/build-all.js +++ b/bin/build-all.js @@ -14,7 +14,7 @@ Object.keys(components).forEach(key => { const filePath = path.join(__dirname, `../packages/${key}/cooking.conf.js`); if (existsSync(filePath)) { - componentPaths.push(`packages/${key}/cooking.conf.js`) + componentPaths.push(`packages/${key}/cooking.conf.js`); } }); diff --git a/bin/build-entry.js b/bin/build-entry.js index 77e0b5ee2..b60f3c692 100644 --- a/bin/build-entry.js +++ b/bin/build-entry.js @@ -1,12 +1,12 @@ -var Components = require('../components.json') -var fs = require('fs') -var render = require('json-templater/string') -var uppercamelcase = require('uppercamelcase') -var path = require('path') +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 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) { @@ -33,41 +33,40 @@ module.exports = { install, {{list}} }; -` +`; -delete Components.font +delete Components.font; -var ComponentNames = Object.keys(Components) +var ComponentNames = Object.keys(Components); -var includeComponentTemplate = [] -var installTemplate = [] -var listTemplate = [] +var includeComponentTemplate = []; +var installTemplate = []; +var listTemplate = []; ComponentNames.forEach(name => { - var componentName = uppercamelcase(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}`) -}) + 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) +fs.writeFileSync(OUTPUT_PATH, template); +console.log('[build entry] DONE:', OUTPUT_PATH); diff --git a/bin/iconInit.js b/bin/iconInit.js index 5f5df7db3..bdbd75554 100644 --- a/bin/iconInit.js +++ b/bin/iconInit.js @@ -15,6 +15,6 @@ nodes.forEach((node) => { if (arr && arr[1]) { classList.push(arr[1]); } -}) +}); fs.writeFile(path.resolve(__dirname, '../examples/icon.json'), JSON.stringify(classList)); diff --git a/bin/new.js b/bin/new.js index a79c0286f..4a8832b3c 100644 --- a/bin/new.js +++ b/bin/new.js @@ -92,9 +92,9 @@ export default { }, { filename: path.join('../../examples/docs/', `${componentname}.md`), - content:`## ${chineseName}` + content: `## ${chineseName}` } -] +]; // 添加到 components.json const componentsFile = require('../components.json'); @@ -105,27 +105,27 @@ if (componentsFile[componentname]) { componentsFile[componentname] = [`./packages/${componentname}/index.js`]; fileSave(path.join(__dirname, '../components.json')) .write(JSON.stringify(componentsFile, null, ' '), 'utf8') - .end('\n') + .end('\n'); // 创建 package Files.forEach(file => { fileSave(path.join(PackagePath, file.filename)) .write(file.content, 'utf8') - .end('\n') -}) + .end('\n'); +}); // 添加到 nav.config.json const navConfigFile = require('../examples/nav.config.json'); navConfigFile[navConfigFile.length - 1].list.push({ path: `/${componentname}`, name: `${chineseName} (${componentname})`, - title: componentname === chineseName ? - componentname : - `${componentname} ${chineseName}` + title: componentname === chineseName + ? componentname + : `${componentname} ${chineseName}` }); fileSave(path.join(__dirname, '../examples/nav.config.json')) .write(JSON.stringify(navConfigFile, null, ' '), 'utf8') - .end('\n') + .end('\n'); console.log('DONE!'); diff --git a/package.json b/package.json index ae866bedb..3a15695f0 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,15 @@ ], "scripts": { "dev": "npm i && (node bin/iconInit.js & node bin/build-entry.js) && cooking watch -c scripts/cooking.demo.js", - "dist": "del -f lib && cooking build -c scripts/cooking.conf.js,scripts/cooking.common.js -p && cooking build -c scripts/cooking.component.js -p && npm run build:theme", + "dist": "npm run lint && del -f lib && cooking build -c scripts/cooking.conf.js,scripts/cooking.common.js -p && cooking build -c scripts/cooking.component.js -p && npm run build:theme", "dist:all": "node bin/build-all.js && npm run build:theme", "build:theme": "gulp build --gulpfile packages/theme-default/gulpfile.js && cp-cli packages/theme-default/lib lib/theme-default", "deploy": "cooking build -c scripts/cooking.demo.js -p", "gh-docs": "cooking build -c scripts/cooking.demo.js -p && gh-pages -d examples/element-ui --remote origin", "postinstall": "lerna bootstrap", "pub": "npm run dist && kp", - "pub:all": "npm run dist:all && lerna publish" + "pub:all": "npm run dist:all && lerna publish", + "lint": "eslint src/** packages/** scripts/** bin/** --ext .js,.vue --ignore-pattern node_modules" }, "repository": { "type": "git", @@ -67,12 +68,14 @@ "theaterjs": "^3.0.0", "uppercamelcase": "^1.1.0", "url-loader": "^0.5.7", - "vue": "^2.0.0-rc.3", + "vue": "2.0.0-rc.3", + "vue-loader": "9.3.2", "vue-markdown-loader": "^0.4.0", "vue-popup": "^0.2.3", "vue-router": "^2.0.0-beta.2", + "vue-template-compiler": "2.0.0-rc.3", "webpack": "^1.13.2", "webpack-dev-server": "^1.15.1", "wind-dom": "0.0.3" } -} \ No newline at end of file +} diff --git a/packages/message-box/cooking.conf.js b/packages/message-box/cooking.conf.js index f5f99f542..91b00a0ad 100644 --- a/packages/message-box/cooking.conf.js +++ b/packages/message-box/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElMessageBox', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/notification/cooking.conf.js b/packages/notification/cooking.conf.js index 2b2024aec..84de84b7c 100644 --- a/packages/notification/cooking.conf.js +++ b/packages/notification/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElNotification', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/pagination/cooking.conf.js b/packages/pagination/cooking.conf.js index da8c4f2cb..bd5f7c8b8 100644 --- a/packages/pagination/cooking.conf.js +++ b/packages/pagination/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElPagination', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/popover/cooking.conf.js b/packages/popover/cooking.conf.js index e725401ae..e22023c98 100644 --- a/packages/popover/cooking.conf.js +++ b/packages/popover/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElPopover', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/progress/cooking.conf.js b/packages/progress/cooking.conf.js index 6c2b99b32..50c7cd22f 100644 --- a/packages/progress/cooking.conf.js +++ b/packages/progress/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElProgress', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/radio/cooking.conf.js b/packages/radio/cooking.conf.js index 962c73067..b0d8c6848 100644 --- a/packages/radio/cooking.conf.js +++ b/packages/radio/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElCascader', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/rate/cooking.conf.js b/packages/rate/cooking.conf.js index 21f681bf3..bcaa8e678 100644 --- a/packages/rate/cooking.conf.js +++ b/packages/rate/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElRate', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/row/cooking.conf.js b/packages/row/cooking.conf.js index c028807b0..5862fb85f 100644 --- a/packages/row/cooking.conf.js +++ b/packages/row/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElRow', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/select-dropdown/cooking.conf.js b/packages/select-dropdown/cooking.conf.js index 84984f713..e9ae74d0e 100644 --- a/packages/select-dropdown/cooking.conf.js +++ b/packages/select-dropdown/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElSelectMenu', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/select/cooking.conf.js b/packages/select/cooking.conf.js index f27b627f2..3e95331eb 100644 --- a/packages/select/cooking.conf.js +++ b/packages/select/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElSelect', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/slider/cooking.conf.js b/packages/slider/cooking.conf.js index e78a54ba0..0dd4a8501 100644 --- a/packages/slider/cooking.conf.js +++ b/packages/slider/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElSlider', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/spinner/cooking.conf.js b/packages/spinner/cooking.conf.js index ae4b4b00f..caaa525db 100644 --- a/packages/spinner/cooking.conf.js +++ b/packages/spinner/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElSpinner', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/steps/cooking.conf.js b/packages/steps/cooking.conf.js index 2b63e86b2..18c834295 100644 --- a/packages/steps/cooking.conf.js +++ b/packages/steps/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElSteps', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/switch/cooking.conf.js b/packages/switch/cooking.conf.js index 962c73067..b0d8c6848 100644 --- a/packages/switch/cooking.conf.js +++ b/packages/switch/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElCascader', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/table/cooking.conf.js b/packages/table/cooking.conf.js index 82e6489f4..5989266ba 100644 --- a/packages/table/cooking.conf.js +++ b/packages/table/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElTable', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/tabs/cooking.conf.js b/packages/tabs/cooking.conf.js index 1e38b2773..50d11c47b 100644 --- a/packages/tabs/cooking.conf.js +++ b/packages/tabs/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElTabs', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/tag/cooking.conf.js b/packages/tag/cooking.conf.js index 7d8d98599..ea9f0d477 100644 --- a/packages/tag/cooking.conf.js +++ b/packages/tag/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElTag', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/theme-default/gulpfile.js b/packages/theme-default/gulpfile.js index 91b1984da..5856951b2 100644 --- a/packages/theme-default/gulpfile.js +++ b/packages/theme-default/gulpfile.js @@ -21,14 +21,14 @@ const salad = require('postcss-salad')({ } }); -gulp.task('compile', function () { +gulp.task('compile', function() { return gulp.src('./src/*.css') .pipe(postcss([salad])) .pipe(cssmin()) .pipe(gulp.dest('./lib')); }); -gulp.task('copyfont', function () { +gulp.task('copyfont', function() { return gulp.src('./src/fonts/**') .pipe(cssmin()) .pipe(gulp.dest('./lib/fonts')); diff --git a/packages/tooltip/cooking.conf.js b/packages/tooltip/cooking.conf.js index bba55d7d4..7ccb2ff4e 100644 --- a/packages/tooltip/cooking.conf.js +++ b/packages/tooltip/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElTooltip', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/tree/cooking.conf.js b/packages/tree/cooking.conf.js index 630745b31..1e2c5be4c 100644 --- a/packages/tree/cooking.conf.js +++ b/packages/tree/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElTree', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/packages/upload/cooking.conf.js b/packages/upload/cooking.conf.js index 7af8e7361..5273fb1bf 100644 --- a/packages/upload/cooking.conf.js +++ b/packages/upload/cooking.conf.js @@ -9,7 +9,7 @@ cooking.set({ template: false, format: 'umd', moduleName: 'ElUpload', - extends: ['vue2'] + extends: ['vue2'] }); cooking.add('resolve.alias', { diff --git a/scripts/cooking.component.js b/scripts/cooking.component.js index 7a6cef89d..56cfbeba4 100644 --- a/scripts/cooking.component.js +++ b/scripts/cooking.component.js @@ -3,7 +3,7 @@ var path = require('path'); var Components = require('../components.json'); var entries = {}; -Object.keys(Components).forEach(function (key) { +Object.keys(Components).forEach(function(key) { const compo = Components[key]; compo[0] = path.join(process.cwd(), compo[0]); diff --git a/scripts/cooking.demo.js b/scripts/cooking.demo.js index 1ae6fe75d..41bfb2baa 100644 --- a/scripts/cooking.demo.js +++ b/scripts/cooking.demo.js @@ -4,9 +4,9 @@ var md = require('markdown-it')(); var Components = require('../components.json'); var striptags = require('../src/utils/strip-tags'); -function convert(str){ - str = str.replace(/(&#x)(\w{4});/gi,function($0){ - return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16)); +function convert(str) { + str = str.replace(/(&#x)(\w{4});/gi, function($0) { + return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g, '$2'), 16)); }); return str; } @@ -50,7 +50,7 @@ cooking.set({ } } }) - ] + ]; } }); @@ -70,7 +70,7 @@ cooking.add('vueMarkdown', { return params.trim().match(/^demo\s*(.*)$/); }, - render: function (tokens, idx) { + render: function(tokens, idx) { var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/); if (tokens[idx].nesting === 1) { var description = (m && m.length > 1) ? m[1] : ''; @@ -88,8 +88,8 @@ cooking.add('vueMarkdown', { } }] ], - preprocess: function (MarkdownIt, source) { - MarkdownIt.renderer.rules.table_open = function () { + preprocess: function(MarkdownIt, source) { + MarkdownIt.renderer.rules.table_open = function() { return ''; }; MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence); @@ -97,11 +97,11 @@ cooking.add('vueMarkdown', { } }); -var wrap = function (render) { - return function () { +var wrap = function(render) { + return function() { return render.apply(this, arguments) .replace('', '') + .replace('', ''); }; }; @@ -112,7 +112,7 @@ cooking.add('resolve.alias', { }); var externals = {}; -Object.keys(Components).forEach(function (key) { +Object.keys(Components).forEach(function(key) { externals[`packages/${key}/style.css`] = 'null'; }); diff --git a/src/utils/strip-tags.js b/src/utils/strip-tags.js index ca7caf03b..19583f063 100644 --- a/src/utils/strip-tags.js +++ b/src/utils/strip-tags.js @@ -9,7 +9,7 @@ var cheerio = require('cheerio'); -module.exports = function (str, tags) { +module.exports = function(str, tags) { var $ = cheerio.load(str, {decodeEntities: false}); if (!tags || tags.length === 0) {