fix: change way to add package.version (#4842)

* Change way to add package.version

* replace content than create new content
This commit is contained in:
偏右
2017-02-13 14:27:12 +08:00
committed by Benjy Cui
parent 1f223d8e4c
commit dd589a4366
8 changed files with 32 additions and 30 deletions

View File

@@ -50,5 +50,6 @@ Array [
"Tooltip",
"Mention",
"Upload",
"version",
]
`;

View File

@@ -106,3 +106,5 @@ export { default as Tooltip } from './tooltip';
export { default as Mention } from './mention';
export { default as Upload } from './upload';
export { default as version } from './version';

View File

@@ -0,0 +1,3 @@
import * as pkg from '../../package.json';
export default (pkg as any).version;

View File

@@ -0,0 +1,2 @@
// empty file prevent babel-plugin-import error
import '../../style/index.less';

View File

@@ -3,41 +3,23 @@
/* eslint-disable */
'use strict';
// Build a entry less file to dist/antd.less
const fs = require('fs');
const path = require('path');
const packageInfo = require('../package.json');
if (fs.existsSync(path.join(__dirname, '../lib'))) {
// Build package.json version to lib/version/index.js
// prevent json-loader needing in user-side
const versionFilePath = path.join(process.cwd(), 'lib', 'version', 'index.js');
const versionFileContent = fs.readFileSync(versionFilePath).toString();
fs.writeFileSync(
versionFilePath,
versionFileContent.replace(`require('../../package.json')`, `{ version: '${packageInfo.version}' }`)
);
}
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}
`);
}
// Build a entry less file to dist/antd.less
console.log('Building a entry less file to dist/antd.less');
const componentsPath = path.join(process.cwd(), 'components');
let componentsLessContent = '';

View File

@@ -50,5 +50,6 @@ Array [
"Tooltip",
"Mention",
"Upload",
"version",
]
`;

View File

@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import pkg from '../package.json';
describe('antd dist files', () => {
// https://github.com/ant-design/ant-design/issues/1638
@@ -19,5 +20,10 @@ describe('antd dist files', () => {
.indexOf('function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }')
).toBe(-1);
});
it('should have antd.version', () => {
const antd = require('../dist/antd'); // eslint-disable-line global-require
expect(antd.version).toBe(pkg.version);
});
}
});

View File

@@ -83,3 +83,8 @@ declare var process: {
NODE_ENV: string
}
};
declare module "*.json" {
const value: any;
export default value;
}