From 288205c953bf3c8d55fb2ee41c01bcab03f2ed9b Mon Sep 17 00:00:00 2001 From: tjz <415800467@qq.com> Date: Sun, 18 Mar 2018 19:59:38 +0800 Subject: [PATCH] add publish sh --- .gitignore | 3 +- LICENSE | 213 +- README-zh_CN.md | 46 + README.md | 48 +- antd-tools/cli/index.js | 27 + antd-tools/cli/run.js | 26 + antd-tools/getBabelCommonConfig.js | 15 + antd-tools/getWebpackConfig.js | 210 + antd-tools/gulpfile.js | 70 + antd-tools/postcssConfig.js | 18 + antd-tools/runCmd.js | 20 + antd-tools/transformLess.js | 33 + antd-tools/utils/get-npm-args.js | 18 + antd-tools/utils/getChangelog.js | 23 + antd-tools/utils/getRunCmdEnv.js | 14 + components/card/Card.vue | 2 +- components/index.js | 1 + examples/index.js | 1 - index-with-locales.js | 11 + package-lock.json | 5840 +++++++++++++++++++++++++++- package.json | 53 +- postcss.config.js | 5 + webpack.build.config.js | 40 + webpack.prod.config.js | 6 + 24 files changed, 6476 insertions(+), 267 deletions(-) create mode 100644 README-zh_CN.md create mode 100644 antd-tools/cli/index.js create mode 100644 antd-tools/cli/run.js create mode 100644 antd-tools/getBabelCommonConfig.js create mode 100644 antd-tools/getWebpackConfig.js create mode 100644 antd-tools/gulpfile.js create mode 100644 antd-tools/postcssConfig.js create mode 100644 antd-tools/runCmd.js create mode 100644 antd-tools/transformLess.js create mode 100644 antd-tools/utils/get-npm-args.js create mode 100644 antd-tools/utils/getChangelog.js create mode 100644 antd-tools/utils/getRunCmdEnv.js create mode 100644 index-with-locales.js create mode 100644 postcss.config.js create mode 100644 webpack.build.config.js diff --git a/.gitignore b/.gitignore index 51b07a34e..8141d49fb 100644 --- a/.gitignore +++ b/.gitignore @@ -58,7 +58,8 @@ typings/ .env .idea .DS_Store -dist/ +dist +lib # 备份文件 /components/test/* diff --git a/LICENSE b/LICENSE index 8dada3eda..5d5bd95ea 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,22 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +MIT License - 1. Definitions. +Copyright (c) 2017-present tangjinzhou - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README-zh_CN.md b/README-zh_CN.md new file mode 100644 index 000000000..a59b63e90 --- /dev/null +++ b/README-zh_CN.md @@ -0,0 +1,46 @@ +
+ + + +
+ +# Ant Design Vue +[![Travis branch](https://img.shields.io/travis/vueComponent/ant-design/master.svg?style=flat-square)](https://travis-ci.org/vueComponent/ant-design) +[![Dependency Status](https://beta.gemnasium.com/badges/github.com/vueComponent/ant-design.svg)](https://beta.gemnasium.com/projects/github.com/vueComponent/ant-design) +[![npm package](https://img.shields.io/npm/v/vue-ant-design/next.svg?style=flat-square)](https://www.npmjs.org/package/vue-ant-design) +[![NPM downloads](http://img.shields.io/npm/dm/vue-ant-design.svg?style=flat-square)](https://npmjs.org/package/ant-design) +[![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://www.npmjs.com/package/vue-ant-design) + + +Ant Design 的 Angular 实现,开发和服务于企业级后台产品。 + + +[README in English](README.md) + +## 特性 + +- 提炼自企业级中后台产品的交互语言和视觉风格。 +- 开箱即用的高质量 React 组件。 +- 全链路开发和设计工具体系。 + +## 安装 + +### 使用 npm 或 yarn 安装 + +```bash +$ npm install vue-ant-design --save +``` + +```bash +$ yarn add vue-ant-design +``` + +如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。 + + +## 链接 + +- [首页](https://vuecomponent.github.io/ant-design/) +- [Vue官方文档](https://cn.vuejs.org/) +- [Antd React](http://ant.design/) + diff --git a/README.md b/README.md index ae9e78db5..a5dc4cb7e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,46 @@ -# ant-design -ant-design ++ + + +
+ +# Ant Design Vue +[![Travis branch](https://img.shields.io/travis/vueComponent/ant-design/master.svg?style=flat-square)](https://travis-ci.org/vueComponent/ant-design) +[![Dependency Status](https://beta.gemnasium.com/badges/github.com/vueComponent/ant-design.svg)](https://beta.gemnasium.com/projects/github.com/vueComponent/ant-design) +[![npm package](https://img.shields.io/npm/v/vue-ant-design/next.svg?style=flat-square)](https://www.npmjs.org/package/vue-ant-design) +[![NPM downloads](http://img.shields.io/npm/dm/vue-ant-design.svg?style=flat-square)](https://npmjs.org/package/ant-design) +[![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://www.npmjs.com/package/vue-ant-design) + + +An enterprise-class UI components based on Ant Design and Vue. + +[README in English](README.md) + +## 特性 + +- An enterprise-class UI design system for desktop applications. +- A set of high-quality React components out of the box. +- The whole package of development and design resources and tools. + + +## 安装 + +### 使用 npm 或 yarn 安装 + +```bash +$ npm install vue-ant-design --save +``` + +```bash +$ yarn add vue-ant-design +``` + +如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。 + + +## 链接 + +- [首页](https://vuecomponent.github.io/ant-design/) +- [Vue官方文档](https://cn.vuejs.org/) +- [Ant Design React](http://ant.design/) -[Vue Ant Design](https://vuecomponent.github.io/ant-design) diff --git a/antd-tools/cli/index.js b/antd-tools/cli/index.js new file mode 100644 index 000000000..61d130361 --- /dev/null +++ b/antd-tools/cli/index.js @@ -0,0 +1,27 @@ +#!/usr/bin/env node + +'use strict' + +require('colorful').colorful() + +const program = require('commander') +const packageInfo = require('../../package.json') + +program + .version(packageInfo.version) + .command('run [name]', 'run specified task') + .parse(process.argv) + +// https://github.com/tj/commander.js/pull/260 +const proc = program.runningCommand +if (proc) { + proc.on('close', process.exit.bind(process)) + proc.on('error', () => { + process.exit(1) + }) +} + +const subCmd = program.args[0] +if (!subCmd || subCmd !== 'run') { + program.help() +} diff --git a/antd-tools/cli/run.js b/antd-tools/cli/run.js new file mode 100644 index 000000000..9842290fe --- /dev/null +++ b/antd-tools/cli/run.js @@ -0,0 +1,26 @@ +#!/usr/bin/env node + +'use strict' + +require('colorful').colorful() +const gulp = require('gulp') +const program = require('commander') + +program.on('--help', () => { + console.log(' Usage:'.to.bold.blue.color) + console.log() +}) + +program.parse(process.argv) + +const task = program.args[0] + +if (!task) { + program.help() +} else { + console.log('antd-tools run', task) + + require('../gulpfile') + + gulp.start(task) +} diff --git a/antd-tools/getBabelCommonConfig.js b/antd-tools/getBabelCommonConfig.js new file mode 100644 index 000000000..2ff5c2222 --- /dev/null +++ b/antd-tools/getBabelCommonConfig.js @@ -0,0 +1,15 @@ +'use strict' + +module.exports = function (modules) { + const plugins = [ + 'babel-plugin-transform-vue-jsx', + 'babel-plugin-transform-object-rest-spread', + 'babel-plugin-syntax-dynamic-import', + 'babel-plugin-transform-decorators-legacy', + ] + + return { + presets: ['babel-preset-env'], + plugins, + } +} diff --git a/antd-tools/getWebpackConfig.js b/antd-tools/getWebpackConfig.js new file mode 100644 index 000000000..28d9ee8b9 --- /dev/null +++ b/antd-tools/getWebpackConfig.js @@ -0,0 +1,210 @@ +const path = require('path') +const webpack = require('webpack') +const ExtractTextPlugin = require('extract-text-webpack-plugin') +const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin') +const deepAssign = require('deep-assign') +const chalk = require('chalk') +const postcssConfig = require('./postcssConfig') +const distFileBaseName = 'antd' +module.exports = function (modules) { + const pkg = require(path.join(process.cwd(), 'package.json')) + const babelConfig = require('./getBabelCommonConfig')(modules || false) + + const pluginImportOptions = [ + { + style: true, + libraryName: 'antd', + libraryDirectory: 'components', + }, + ] + + // if (distFileBaseName !== 'antd') { + // pluginImportOptions.push({ + // style: 'css', + // libraryDirectory: 'components', + // libraryName: 'antd', + // }) + // } + + babelConfig.plugins.push([ + require.resolve('babel-plugin-import'), + pluginImportOptions, + ]) + + const config = { + devtool: 'source-map', + + output: { + path: path.join(process.cwd(), './dist/'), + filename: '[name].js', + }, + + resolve: { + modules: ['node_modules', path.join(__dirname, '../node_modules')], + extensions: ['.js', '.vue', '.md', '.json'], + alias: { + 'vue$': 'vue/dist/vue.esm.js', + '@': process.cwd(), + }, + }, + + node: [ + 'child_process', + 'cluster', + 'dgram', + 'dns', + 'fs', + 'module', + 'net', + 'readline', + 'repl', + 'tls', + ].reduce((acc, name) => Object.assign({}, acc, { [name]: 'empty' }), {}), + + module: { + noParse: [/moment.js/], + rules: [ + { + test: /\.vue$/, + exclude: /node_modules/, + use: [ + { + loader: 'babel-loader', + options: babelConfig, + }, + { + loader: 'vue-loader', + }, + ], + }, + { + test: /\.js$/, + loader: 'babel-loader', exclude: /node_modules/, + }, + { + test: /\.css$/, + use: ExtractTextPlugin.extract({ + use: [ + { + loader: 'css-loader', + options: { + sourceMap: true, + }, + }, + { + loader: 'postcss-loader', + options: Object.assign( + {}, + postcssConfig, + { sourceMap: true } + ), + }, + ], + }), + }, + { + test: /\.less$/, + use: ExtractTextPlugin.extract({ + use: [ + { + loader: 'css-loader', + options: { + sourceMap: true, + }, + }, + { + loader: 'postcss-loader', + options: Object.assign( + {}, + postcssConfig, + { sourceMap: true } + ), + }, + { + loader: 'less-loader', + options: { + sourceMap: true, + }, + }, + ], + }), + }, + ], + }, + + plugins: [ + new ExtractTextPlugin({ + filename: '[name].css', + disable: false, + allChunks: true, + }), + new CaseSensitivePathsPlugin(), + new webpack.BannerPlugin(` +${distFileBaseName} v${pkg.version} + +Copyright 2017-present, tangjinzhou, Inc. +All rights reserved. + `), + new webpack.ProgressPlugin((percentage, msg, addInfo) => { + const stream = process.stderr + if (stream.isTTY && percentage < 0.71) { + stream.cursorTo(0) + stream.write(`📦 ${chalk.magenta(msg)} (${chalk.magenta(addInfo)})`) + stream.clearLine(1) + } else if (percentage === 1) { + console.log(chalk.green('\nwebpack: bundle build is now finished.')) + } + }), + ], + } + + if (process.env.RUN_ENV === 'PRODUCTION') { + const entry = ['./components/index'] + config.entry = { + [`${distFileBaseName}.min`]: entry, + } + config.externals = { + vue: { + root: 'Vue', + commonjs2: 'vue', + commonjs: 'vue', + amd: 'vue', + }, + } + config.output.library = distFileBaseName + config.output.libraryTarget = 'umd' + + const uncompressedConfig = deepAssign({}, config) + + config.plugins = config.plugins.concat([ + new webpack.optimize.UglifyJsPlugin({ + sourceMap: true, + output: { + ascii_only: true, + }, + compress: { + warnings: false, + }, + }), + new webpack.optimize.ModuleConcatenationPlugin(), + new webpack.LoaderOptionsPlugin({ + minimize: true, + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'), + }), + ]) + + uncompressedConfig.entry = { + [distFileBaseName]: entry, + } + + uncompressedConfig.plugins.push(new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify('development'), + })) + + return [config, uncompressedConfig] + } + + return config +} diff --git a/antd-tools/gulpfile.js b/antd-tools/gulpfile.js new file mode 100644 index 000000000..a9269938c --- /dev/null +++ b/antd-tools/gulpfile.js @@ -0,0 +1,70 @@ +'use strict' + +// const install = require('./install') +// const runCmd = require('./runCmd') +// const getBabelCommonConfig = require('./getBabelCommonConfig') +// const merge2 = require('merge2') +// const { execSync } = require('child_process') +// const through2 = require('through2') +// const transformLess = require('./transformLess') +const webpack = require('webpack') +// const babel = require('gulp-babel') +// const argv = require('minimist')(process.argv.slice(2)) +// const GitHub = require('github') + +// const packageJson = require(`${process.cwd()}/package.json`) +// const getNpm = require('./getNpm') +// const selfPackage = require('../package.json') +// const chalk = require('chalk') +// const getNpmArgs = require('./utils/get-npm-args') +// const getChangelog = require('./utils/getChangelog') +const path = require('path') +// const watch = require('gulp-watch') +const gulp = require('gulp') +// const fs = require('fs') +const rimraf = require('rimraf') + +const cwd = process.cwd() +// const libDir = path.join(cwd, 'lib') + +function dist (done) { + rimraf.sync(path.join(cwd, 'dist')) + process.env.RUN_ENV = 'PRODUCTION' + const webpackConfig = require(path.join(cwd, 'webpack.build.config.js')) + webpack(webpackConfig, (err, stats) => { + if (err) { + console.error(err.stack || err) + if (err.details) { + console.error(err.details) + } + return + } + + const info = stats.toJson() + + if (stats.hasErrors()) { + console.error(info.errors) + } + + if (stats.hasWarnings()) { + console.warn(info.warnings) + } + + const buildInfo = stats.toString({ + colors: true, + children: true, + chunks: false, + modules: false, + chunkModules: false, + hash: false, + version: false, + }) + console.log(buildInfo) + done(0) + }) +} + +gulp.task('dist', (done) => { + dist(done) +}) + diff --git a/antd-tools/postcssConfig.js b/antd-tools/postcssConfig.js new file mode 100644 index 000000000..47ea4a3ba --- /dev/null +++ b/antd-tools/postcssConfig.js @@ -0,0 +1,18 @@ +const rucksack = require('rucksack-css') +const autoprefixer = require('autoprefixer') + +module.exports = { + plugins: [ + rucksack(), + autoprefixer({ + browsers: [ + 'last 2 versions', + 'Firefox ESR', + '> 1%', + 'ie >= 9', + 'iOS >= 8', + 'Android >= 4', + ], + }), + ], +} diff --git a/antd-tools/runCmd.js b/antd-tools/runCmd.js new file mode 100644 index 000000000..d3c0bd64f --- /dev/null +++ b/antd-tools/runCmd.js @@ -0,0 +1,20 @@ +'use strict' + +const getRunCmdEnv = require('./utils/getRunCmdEnv') + +function runCmd (cmd, _args, fn) { + const args = _args || [] + const runner = require('child_process').spawn(cmd, args, { + // keep color + stdio: 'inherit', + env: getRunCmdEnv(), + }) + + runner.on('close', (code) => { + if (fn) { + fn(code) + } + }) +} + +module.exports = runCmd diff --git a/antd-tools/transformLess.js b/antd-tools/transformLess.js new file mode 100644 index 000000000..2cbf8adeb --- /dev/null +++ b/antd-tools/transformLess.js @@ -0,0 +1,33 @@ +const less = require('less') +const { readFileSync } = require('fs') +const path = require('path') +const postcss = require('postcss') +const NpmImportPlugin = require('less-plugin-npm-import') +const postcssConfig = require('./postcssConfig') + +function transformLess (lessFile, config = {}) { + const { cwd = process.cwd() } = config + const resolvedLessFile = path.resolve(cwd, lessFile) + + let data = readFileSync(resolvedLessFile, 'utf-8') + data = data.replace(/^\uFEFF/, '') + + // Do less compile + const lessOpts = { + paths: [path.dirname(resolvedLessFile)], + filename: resolvedLessFile, + plugins: [ + new NpmImportPlugin({ prefix: '~' }), + ], + } + return less.render(data, lessOpts) + .then((result) => { + const source = result.css + return postcss(postcssConfig.plugins).process(source) + }) + .then((r) => { + return r.css + }) +} + +module.exports = transformLess diff --git a/antd-tools/utils/get-npm-args.js b/antd-tools/utils/get-npm-args.js new file mode 100644 index 000000000..3006156ee --- /dev/null +++ b/antd-tools/utils/get-npm-args.js @@ -0,0 +1,18 @@ +'use strict' + +// NOTE: the following code was partially adopted from https://github.com/iarna/in-publish +module.exports = function getNpmArgs () { + let npmArgv = null + + try { + npmArgv = JSON.parse(process.env.npm_config_argv) + } catch (err) { + return null + } + + if (typeof npmArgv !== 'object' || !npmArgv.cooked || !Array.isArray(npmArgv.cooked)) { + return null + } + + return npmArgv.cooked +} diff --git a/antd-tools/utils/getChangelog.js b/antd-tools/utils/getChangelog.js new file mode 100644 index 000000000..d05718fd8 --- /dev/null +++ b/antd-tools/utils/getChangelog.js @@ -0,0 +1,23 @@ +const fs = require('fs') + +module.exports = function getChangelog (file, version) { + const lines = fs.readFileSync(file).toString().split('\n') + const changeLog = [] + const startPattern = new RegExp(`^## ${version}`) + const stopPattern = /^## / // 前一个版本 + const skipPattern = /^`/ // 日期 + let begin = false + for (let i = 0; i < lines.length; i += 1) { + const line = lines[i] + if (begin && stopPattern.test(line)) { + break + } + if (begin && line && !skipPattern.test(line)) { + changeLog.push(line) + } + if (!begin) { + begin = startPattern.test(line) + } + } + return changeLog.join('\n') +} diff --git a/antd-tools/utils/getRunCmdEnv.js b/antd-tools/utils/getRunCmdEnv.js new file mode 100644 index 000000000..48033b93c --- /dev/null +++ b/antd-tools/utils/getRunCmdEnv.js @@ -0,0 +1,14 @@ +'use strict' + +const path = require('path') + +module.exports = function getRunCmdEnv () { + const env = {} + Object.keys(process.env).forEach((key) => { + env[key] = process.env[key] + }) + // make sure `antd-tools/node_modules/.bin` in the PATH env + const nodeModulesBinDir = path.join(__dirname, '../../node_modules/.bin') + env.PATH = env.PATH ? `${nodeModulesBinDir}:${env.PATH}` : nodeModulesBinDir + return env +} diff --git a/components/card/Card.vue b/components/card/Card.vue index c1081d7ac..ea7f86775 100644 --- a/components/card/Card.vue +++ b/components/card/Card.vue @@ -1,5 +1,5 @@