mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
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:
@@ -50,5 +50,6 @@ Array [
|
||||
"Tooltip",
|
||||
"Mention",
|
||||
"Upload",
|
||||
"version",
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -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';
|
||||
|
||||
3
components/version/index.tsx
Normal file
3
components/version/index.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as pkg from '../../package.json';
|
||||
|
||||
export default (pkg as any).version;
|
||||
2
components/version/style/index.tsx
Normal file
2
components/version/style/index.tsx
Normal file
@@ -0,0 +1,2 @@
|
||||
// empty file prevent babel-plugin-import error
|
||||
import '../../style/index.less';
|
||||
@@ -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 = '';
|
||||
|
||||
@@ -50,5 +50,6 @@ Array [
|
||||
"Tooltip",
|
||||
"Mention",
|
||||
"Upload",
|
||||
"version",
|
||||
]
|
||||
`;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
5
typings/custom-typings.d.ts
vendored
5
typings/custom-typings.d.ts
vendored
@@ -83,3 +83,8 @@ declare var process: {
|
||||
NODE_ENV: string
|
||||
}
|
||||
};
|
||||
|
||||
declare module "*.json" {
|
||||
const value: any;
|
||||
export default value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user