mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
refactor: 📦 Generate version.js from package.json (#23957)
* 📦 generate version.js from package.json
* components/version/version.ts
* remove version.js
* fix scripts
* Add pretest and predist
* clean up finalizeCompile
* fix lint
This commit is contained in:
parent
612bcdf4a6
commit
d221458939
@ -1,7 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
const packageInfo = require('./package.json');
|
|
||||||
const defaultVars = require('./scripts/default-vars');
|
const defaultVars = require('./scripts/default-vars');
|
||||||
const darkVars = require('./scripts/dark-vars');
|
const darkVars = require('./scripts/dark-vars');
|
||||||
const compactVars = require('./scripts/compact-vars');
|
const compactVars = require('./scripts/compact-vars');
|
||||||
@ -17,30 +15,6 @@ module.exports = {
|
|||||||
// We need compile additional content for antd user
|
// We need compile additional content for antd user
|
||||||
function finalizeCompile() {
|
function finalizeCompile() {
|
||||||
if (fs.existsSync(path.join(__dirname, './lib'))) {
|
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}' }`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Wrote version into lib/version/index.js');
|
|
||||||
|
|
||||||
// Build package.json version to lib/version/index.d.ts
|
|
||||||
// prevent https://github.com/ant-design/ant-design/issues/4935
|
|
||||||
const versionDefPath = path.join(process.cwd(), 'lib', 'version', 'index.d.ts');
|
|
||||||
fs.writeFileSync(
|
|
||||||
versionDefPath,
|
|
||||||
`declare var _default: "${packageInfo.version}";\nexport default _default;\n`,
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Wrote version into lib/version/index.d.ts');
|
|
||||||
|
|
||||||
// Build a entry less file to dist/antd.less
|
// Build a entry less file to dist/antd.less
|
||||||
const componentsPath = path.join(process.cwd(), 'components');
|
const componentsPath = path.join(process.cwd(), 'components');
|
||||||
let componentsLessContent = '';
|
let componentsLessContent = '';
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -57,3 +57,4 @@ site/theme/template/Resources/*.jsx
|
|||||||
site/theme/template/Resources/**/*.jsx
|
site/theme/template/Resources/**/*.jsx
|
||||||
site/theme/template/NotFound.jsx
|
site/theme/template/NotFound.jsx
|
||||||
scripts/previewEditor/index.html
|
scripts/previewEditor/index.html
|
||||||
|
components/version/version.tsx
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
import packageInfo from '../../package.json';
|
/* eslint import/no-unresolved: 0 */
|
||||||
|
// @ts-ignore
|
||||||
|
import version from './version';
|
||||||
|
|
||||||
export default packageInfo.version;
|
export default version;
|
||||||
|
11
package.json
11
package.json
@ -50,6 +50,9 @@
|
|||||||
"build": "npm run compile && npm run dist",
|
"build": "npm run compile && npm run dist",
|
||||||
"bundlesize": "bundlesize",
|
"bundlesize": "bundlesize",
|
||||||
"check-commit": "node ./scripts/check-commit",
|
"check-commit": "node ./scripts/check-commit",
|
||||||
|
"precompile": "npm run version",
|
||||||
|
"pretest": "npm run version",
|
||||||
|
"predist": "npm run version",
|
||||||
"compile": "antd-tools run compile",
|
"compile": "antd-tools run compile",
|
||||||
"changelog": "node ./scripts/print-changelog",
|
"changelog": "node ./scripts/print-changelog",
|
||||||
"predeploy": "antd-tools run clean && npm run site && cp netlify.toml CNAME _site && cp -r .circleci/ .github/ _site && npm run site:test",
|
"predeploy": "antd-tools run clean && npm run site && cp netlify.toml CNAME _site && cp -r .circleci/ .github/ _site && npm run site:test",
|
||||||
@ -71,7 +74,8 @@
|
|||||||
"prettier": "prettier -c --write '**/*'",
|
"prettier": "prettier -c --write '**/*'",
|
||||||
"pretty-quick": "pretty-quick",
|
"pretty-quick": "pretty-quick",
|
||||||
"pub": "antd-tools run pub",
|
"pub": "antd-tools run pub",
|
||||||
"prepublish": "antd-tools run guard",
|
"postinstall": "npm run version",
|
||||||
|
"prepublishOnly": "antd-tools run guard",
|
||||||
"site": "cross-env NODE_ICU_DATA=node_modules/full-icu concurrently \"bisheng build --ssr -c ./site/bisheng.config.js\" \"node ./scripts/generateColorLess.js\"",
|
"site": "cross-env NODE_ICU_DATA=node_modules/full-icu concurrently \"bisheng build --ssr -c ./site/bisheng.config.js\" \"node ./scripts/generateColorLess.js\"",
|
||||||
"sort": "npx sort-package-json",
|
"sort": "npx sort-package-json",
|
||||||
"sort-api": "antd-tools run sort-api-table",
|
"sort-api": "antd-tools run sort-api-table",
|
||||||
@ -82,7 +86,8 @@
|
|||||||
"test-all": "./scripts/test-all.sh",
|
"test-all": "./scripts/test-all.sh",
|
||||||
"test-node": "jest --config .jest.node.js --no-cache",
|
"test-node": "jest --config .jest.node.js --no-cache",
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"site:test": "jest --config .jest.site.js --cache=false"
|
"site:test": "jest --config .jest.site.js --cache=false",
|
||||||
|
"version": "node ./scripts/generate-version"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
@ -273,7 +278,7 @@
|
|||||||
"bundlesize": [
|
"bundlesize": [
|
||||||
{
|
{
|
||||||
"path": "./dist/antd.min.js",
|
"path": "./dist/antd.min.js",
|
||||||
"maxSize": "305 kB"
|
"maxSize": "300 kB"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "./dist/antd.min.css",
|
"path": "./dist/antd.min.css",
|
||||||
|
10
scripts/generate-version.js
Normal file
10
scripts/generate-version.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const { version } = require('../package.json');
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(__dirname, '..', 'components', 'version', 'version.tsx'),
|
||||||
|
`export default '${version}'`,
|
||||||
|
'utf8',
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user