forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-variables.js
More file actions
48 lines (44 loc) · 1.58 KB
/
export-variables.js
File metadata and controls
48 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const path = require('path');
const fs = require('fs-extra');
const cwd = process.cwd();
module.exports = function*(options) {
const exportNextCorVars = [
'lib/core/util/_mixin.scss',
'lib/core/util/_function.scss',
'lib/core/style/_global.scss',
'lib/core/style/_size.scss',
'lib/core/style/_color.scss',
'lib/core/style/_corner.scss',
'lib/core/style/_font.scss',
'lib/core/style/_line.scss',
'lib/core/style/_shadow.scss',
'lib/core/style/_icon.scss',
'lib/core/style/_motion.scss',
'lib/core/utility/_form-element.scss',
'lib/core/utility/_mask.scss',
'lib/core/utility/_popup.scss',
];
const exportVars = [].concat(exportNextCorVars);
const possibleNames = ['variable.scss', 'variables.scss', '_variable.scss'];
const entries = options.entries;
for (let i = 0; i < entries.length; i++) {
const entryName = entries[i].name;
for (let j = 0; j < possibleNames.length; j++) {
const possibleName = possibleNames[j];
const possiblePath = path.join(
cwd,
'lib',
entryName,
'scss',
possibleName
);
if (yield fs.exists(possiblePath)) {
exportVars.push(path.relative(cwd, possiblePath));
break;
}
}
}
const varScss = exportVars.map(p => `@import "${p}";`).join('\n');
const varScssPath = path.join(cwd, 'variables.scss');
yield fs.writeFile(varScssPath, varScss);
};