diff --git a/scripts/prepub.js b/scripts/prepub.js index 42a8b1ff51..b8e316e10c 100644 --- a/scripts/prepub.js +++ b/scripts/prepub.js @@ -4,13 +4,43 @@ 'use strict'; // Build a entry less file to dist/antd.less -var fs = require('fs'); -var path = require('path'); +const fs = require('fs'); +const path = require('path'); +const packageInfo = require('../package.json'); + +if (fs.existsSync(path.join(__dirname, '../dist'))) { + fs.writeFileSync(path.join(process.cwd(), 'lib', 'version.js'), ` +module.exports = '${packageInfo.version}'; +`); + + const antdV = ` + (function(root) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports.version = '${packageInfo.version}'; + else + root["antd"].version = '${packageInfo.version}'; +})(this); +`; + + const antdPath = path.join(process.cwd(), 'dist', 'antd.js'); + const antdMinPath = path.join(process.cwd(), 'dist', 'antd.min.js'); + + if (fs.existsSync(antdPath)) { + const content = fs.readFileSync(antdPath, 'utf-8'); + const minContent = fs.readFileSync(antdMinPath, 'utf-8'); + fs.writeFileSync(antdPath, ` +${content} +${antdV} +`); + fs.writeFileSync(antdMinPath, ` +${minContent} +${antdV} +`); + } -if(fs.existsSync(path.join(__dirname,'../dist'))) { console.log('Building a entry less file to dist/antd.less'); - var componentsPath = path.join(process.cwd(), 'components'); - var componentsLessContent = ''; + const componentsPath = path.join(process.cwd(), 'components'); + let componentsLessContent = ''; // Build components in one file: lib/style/components.less fs.readdir(componentsPath, function (err, files) {