Skip to content

Commit e9d0845

Browse files
committed
build: fix miss antd.less file
1 parent 4cdb4d8 commit e9d0845

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"compile": "node antd-tools/cli/run.js compile",
3030
"pub": "node antd-tools/cli/run.js pub",
3131
"prepublish": "node antd-tools/cli/run.js guard",
32+
"pre-publish": "npm run test && node ./scripts/prepub",
3233
"dist": "node antd-tools/cli/run.js dist",
3334
"lint": "eslint -c ./.eslintrc --fix --ext .jsx,.js,.vue ./components",
3435
"lint:style": "stylelint \"./examples/**/*.less\" --fix --syntax less",

scripts/prepub.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint-disable */
4+
'use strict';
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
const packageInfo = require('../package.json');
9+
10+
if (fs.existsSync(path.join(__dirname, '../lib'))) {
11+
// Build package.json version to lib/version/index.js
12+
// prevent json-loader needing in user-side
13+
const versionFilePath = path.join(process.cwd(), 'lib', 'version', 'index.js');
14+
const versionFileContent = fs.readFileSync(versionFilePath).toString();
15+
fs.writeFileSync(
16+
versionFilePath,
17+
versionFileContent.replace(`require('../../package.json')`, `{ version: '${packageInfo.version}' }`)
18+
);
19+
console.log('Wrote version into lib/version/index.js');
20+
}
21+
22+
if (fs.existsSync(path.join(__dirname, '../dist'))) {
23+
// Build a entry less file to dist/antd.less
24+
const componentsPath = path.join(process.cwd(), 'components');
25+
let componentsLessContent = '';
26+
27+
// Build components in one file: lib/style/components.less
28+
fs.readdir(componentsPath, function (err, files) {
29+
files.forEach(function (file) {
30+
if (fs.existsSync(path.join(componentsPath, file, 'style', 'index.less'))) {
31+
componentsLessContent += `@import "../${path.join(file, 'style', 'index.less')}";\n`
32+
}
33+
});
34+
fs.writeFileSync(path.join(process.cwd(), 'lib', 'style', 'components.less'), componentsLessContent);
35+
36+
// Build less entry file: dist/antd.less
37+
fs.writeFileSync(
38+
path.join(process.cwd(), 'dist', 'antd.less'),
39+
'@import "../lib/style/index.less";\n@import "../lib/style/components.less";'
40+
);
41+
});
42+
console.log('Built a entry less file to dist/antd.less');
43+
}

0 commit comments

Comments
 (0)