@zohodesk/react-cli 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/bin/cli.js +10 -4
- package/docs/ComposeMinification.md +13 -0
- package/docs/ReactLive.md +10 -0
- package/docs/patternFiltering.md +57 -0
- package/lib/common/buildEs.js +12 -0
- package/lib/configs/webpack.dev.config.js +3 -0
- package/lib/configs/webpack.docs.config.js +6 -0
- package/lib/configs/webpack.impact.config.js +2 -0
- package/lib/configs/webpack.prod.config.js +3 -0
- package/lib/loaderUtils/getCSSLoaders.js +77 -46
- package/lib/loaderUtils/tests/windowsModification.test.js +10 -0
- package/lib/loaderUtils/windowsModification.js +6 -1
- package/lib/loaders/composeLoader.js +172 -0
- package/lib/loaders/docsLoader.js +15 -7
- package/lib/loaders/reactLiveConvertor.js +107 -0
- package/lib/pluginUtils/getDevPlugins.js +10 -3
- package/lib/pluginUtils/getProdPlugins.js +8 -3
- package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
- package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
- package/lib/plugins/{UglifyCSSPlugin.js → MinifyPlugin.js} +3 -3
- package/lib/plugins/SelectorPlugin.js +63 -40
- package/lib/plugins/VariableConversionCollector.js +40 -97
- package/lib/plugins/index.js +7 -7
- package/lib/plugins/utils/classHandling.js +35 -0
- package/lib/plugins/utils/fileHandling.js +107 -0
- package/lib/plugins/utils/tests/fileHandling.test.js +30 -0
- package/lib/plugins/variableConvertorUtils.js +131 -0
- package/lib/postcss-plugins/EmptyPlugin.js +8 -0
- package/lib/postcss-plugins/ExcludePlugin.js +1 -1
- package/lib/postcss-plugins/ValueReplacer.js +5 -14
- package/lib/postcss-plugins/variableModificationPlugin/index.js +2 -19
- package/lib/schemas/index.js +33 -3
- package/lib/servers/server.js +2 -2
- package/lib/utils/cssClassNameGenerate.js +34 -9
- package/lib/utils/getOptions.js +16 -0
- package/lib/utils/variableConverter.js +89 -0
- package/{package-lock.json → npm-shrinkwrap.json} +1 -1
- package/package.json +3 -1
- package/lib/plugins/composeCommonPlugin.js +0 -30
- package/lib/postcss-plugins/variableModifier.js +0 -210
package/README.md
CHANGED
@@ -44,6 +44,22 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
+
# 1.1.0
|
48
|
+
|
49
|
+
**Feature Update**
|
50
|
+
- Support for desk-library to use variable convertion plugin using individual script.
|
51
|
+
- pattern filter changes, new filter system instead of exclude to include or exclude files for plugins.
|
52
|
+
For more info please refer to :
|
53
|
+
[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/patternFiltering.md)
|
54
|
+
- React Live feature implemented for Docs.
|
55
|
+
[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/ReactLive.md)
|
56
|
+
|
57
|
+
# 1.0.3-beta.1
|
58
|
+
|
59
|
+
**Issue Fix**
|
60
|
+
- nock api not working issue fixed. This error throwing in @zohodesk/react-cli@1.0.2 version. but working in older versions ( 0.0.1-beta.178 )
|
61
|
+
|
62
|
+
|
47
63
|
# 1.0.3
|
48
64
|
|
49
65
|
**Feature Update**
|
@@ -54,10 +70,11 @@ Now to run app
|
|
54
70
|
- @zohodesk/client_packages_group@**1.0.1** ==> @zohodesk/client_packages_group@**1.0.2**
|
55
71
|
|
56
72
|
|
73
|
+
|
57
74
|
# 1.0.2
|
58
75
|
|
59
76
|
**Feature Update**
|
60
|
-
- Selector replace plugin made custom postcss-plugin with update to code that was unpublished in package.
|
77
|
+
- Selector replace plugin made as a custom postcss-plugin with update to code that was unpublished in package.
|
61
78
|
|
62
79
|
# 1.0.1
|
63
80
|
|
package/bin/cli.js
CHANGED
@@ -50,7 +50,7 @@ if (preprocesserPath && existsSync(preprocesserPath)) {
|
|
50
50
|
case 'docs':
|
51
51
|
spawn(preprocessCli, [preprocesserPath], {
|
52
52
|
stdio: 'inherit',
|
53
|
-
cwd:
|
53
|
+
cwd: path.parse(preprocesserPath).dir
|
54
54
|
});
|
55
55
|
// NOTE: it's ok if we not close this here
|
56
56
|
// Because when node server stops this program willbe closed So this nodemon will be killed as well
|
@@ -116,6 +116,14 @@ switch (option) {
|
|
116
116
|
{ stdio: 'inherit' }
|
117
117
|
);
|
118
118
|
|
119
|
+
process.exit(result.status);
|
120
|
+
break;
|
121
|
+
case 'variableConverter':
|
122
|
+
result = spawnSync(
|
123
|
+
'node',
|
124
|
+
[require.resolve('../lib/utils/variableConverter')].concat(args),
|
125
|
+
{ stdio: 'inherit' }
|
126
|
+
);
|
119
127
|
process.exit(result.status);
|
120
128
|
break;
|
121
129
|
case 'valuereplacer':
|
@@ -215,9 +223,7 @@ switch (option) {
|
|
215
223
|
case 'devbuild':
|
216
224
|
result = spawnSync(
|
217
225
|
'node',
|
218
|
-
[
|
219
|
-
require.resolve('../lib/servers/devBuild')
|
220
|
-
].concat(args),
|
226
|
+
[require.resolve('../lib/servers/devBuild')].concat(args),
|
221
227
|
// [require.resolve('../lib/servers/staticServer'), '--expose-http2'].concat(args),
|
222
228
|
{ stdio: 'inherit' }
|
223
229
|
);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Compose Minification
|
2
|
+
|
3
|
+
We use this plugin to extract all the common attributes ( margin, padding... ) supported and write them in respective common files( margin.css, padding.css... ) These are further reference to the classname instead of a line of code by composing and adding classnames for the same.
|
4
|
+
|
5
|
+
|
6
|
+
# Feature :
|
7
|
+
|
8
|
+
* We can enable this plugin by representing the value of ` react-cli > app > plugins > composeMinification ` to `true`.
|
9
|
+
* The creation of `margin.css`, `padding.css`, `position.css` and so on will be done initially by a manual script for the application.
|
10
|
+
* Further the `composeMinification` plugin converts the `props` of common attributes under check into `compose` and `values` into `compose format` ( m10 from `../margin.css`)
|
11
|
+
* On runtime the conversion takes place and classnames for the properties (`margin`, `padding`, so on...) are added with references to respective files and styles are applied.
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
----> ReactLive <----
|
3
|
+
|
4
|
+
1. React Live is a live playground for reactjs (For now we have implemented in our docs)
|
5
|
+
2. So, for this we are using reactLiveConverter.js (src/loaders) to convert the file format.
|
6
|
+
3. We can enable/disable this feature by `npm run docs --enableReactLive=true/false` default value will be `true`.
|
7
|
+
4. Also we can enable/disable this feature by adding `enableReactLive` key inside the package.json under the `docs`.
|
8
|
+
|
9
|
+
# v1.1.0 update:
|
10
|
+
* ReactLive feature implemented.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Pattern filtering
|
2
|
+
|
3
|
+
As replacement for exclude we now have patterns in place of exclude to include or exclude a file based on its name in package.json.
|
4
|
+
|
5
|
+
|
6
|
+
# Example for patterns :
|
7
|
+
|
8
|
+
**Old System** :
|
9
|
+
To exclude `node_modules` folder from convertion for the `cssVariableReplacement` plugin, we used to have :
|
10
|
+
|
11
|
+
`react-cli > app > exclude > cssVariableReplacement` as ['node_modules'] in `package.json`
|
12
|
+
|
13
|
+
Example :
|
14
|
+
|
15
|
+
"exclude": {
|
16
|
+
"cssVariableReplacement": [
|
17
|
+
"node_modules"
|
18
|
+
]
|
19
|
+
},
|
20
|
+
|
21
|
+
**New System** :
|
22
|
+
|
23
|
+
To include all files for convertion for the `valueReplacer` plugin, we now have :
|
24
|
+
|
25
|
+
`react-cli > app > patterns > valueReplacer` as ['*'] in `package.json`
|
26
|
+
|
27
|
+
To include `src` files for convertion for the `cssVariableReplacement` plugin, we now have :
|
28
|
+
|
29
|
+
`react-cli > app > patterns > hoverActive` as ['src'] in `package.json`
|
30
|
+
|
31
|
+
To exclude `node_modules` files for convertion for the `hoverActive` plugin, we now have :
|
32
|
+
|
33
|
+
`react-cli > app > patterns > cssVariableReplacement` as ['!node_modules'] in `package.json`
|
34
|
+
Here the `!` denotes that the folder structure/file is not to be converted.
|
35
|
+
|
36
|
+
Example :
|
37
|
+
|
38
|
+
"patterns": {
|
39
|
+
"valueReplacer": [
|
40
|
+
"*"
|
41
|
+
],
|
42
|
+
"hoverActive": [
|
43
|
+
"src"
|
44
|
+
],
|
45
|
+
"cssVariableReplacement": [
|
46
|
+
"!node_modules"
|
47
|
+
],
|
48
|
+
},
|
49
|
+
|
50
|
+
Note :
|
51
|
+
`patterns` also added support for cssUniqueness to be applied to selective files.
|
52
|
+
|
53
|
+
"patterns" : {
|
54
|
+
"cssUniqueness": [
|
55
|
+
"*"
|
56
|
+
],
|
57
|
+
}
|
@@ -25,6 +25,7 @@ const {
|
|
25
25
|
outputFolder,
|
26
26
|
plugins,
|
27
27
|
exclude,
|
28
|
+
patterns,
|
28
29
|
mediaQueryHoverActiveString,
|
29
30
|
cssVariableReplacementConfig,
|
30
31
|
selectorWeightConfig,
|
@@ -102,6 +103,7 @@ module.exports = {
|
|
102
103
|
use: (0, _loaderUtils.getCSSLoaders)({
|
103
104
|
plugins,
|
104
105
|
exclude,
|
106
|
+
patterns,
|
105
107
|
mediaQueryHoverActiveString,
|
106
108
|
cssVariableReplacementConfig,
|
107
109
|
selectorWeightConfig,
|
@@ -114,6 +116,7 @@ module.exports = {
|
|
114
116
|
use: (0, _loaderUtils.getCSSLoaders)({
|
115
117
|
plugins,
|
116
118
|
exclude,
|
119
|
+
patterns,
|
117
120
|
mediaQueryHoverActiveString,
|
118
121
|
cssVariableReplacementConfig,
|
119
122
|
selectorWeightConfig,
|
@@ -22,6 +22,7 @@ const {
|
|
22
22
|
cssUniqueness,
|
23
23
|
plugins,
|
24
24
|
exclude,
|
25
|
+
patterns,
|
25
26
|
mediaQueryHoverActiveString,
|
26
27
|
cssVariableReplacementConfig,
|
27
28
|
selectorWeightConfig,
|
@@ -77,6 +78,7 @@ module.exports = isSSTest => ({
|
|
77
78
|
use: (0, _loaderUtils.getCSSLoaders)({
|
78
79
|
plugins,
|
79
80
|
exclude,
|
81
|
+
patterns,
|
80
82
|
mediaQueryHoverActiveString,
|
81
83
|
cssVariableReplacementConfig,
|
82
84
|
selectorWeightConfig,
|
@@ -95,6 +97,10 @@ module.exports = isSSTest => ({
|
|
95
97
|
interpolate: 'require'
|
96
98
|
}
|
97
99
|
}
|
100
|
+
}, {
|
101
|
+
test: /\.mjs$/,
|
102
|
+
include: /node_modules/,
|
103
|
+
type: 'javascript/auto'
|
98
104
|
}, {
|
99
105
|
test: /\.tmpl$/,
|
100
106
|
use: [{
|
@@ -21,6 +21,7 @@ const {
|
|
21
21
|
cssUniqueness,
|
22
22
|
plugins,
|
23
23
|
exclude,
|
24
|
+
patterns,
|
24
25
|
mediaQueryHoverActiveString,
|
25
26
|
cssVariableReplacementConfig,
|
26
27
|
selectorWeightConfig,
|
@@ -77,6 +78,7 @@ module.exports = {
|
|
77
78
|
use: (0, _loaderUtils.getCSSLoaders)({
|
78
79
|
plugins,
|
79
80
|
exclude,
|
81
|
+
patterns,
|
80
82
|
mediaQueryHoverActiveString,
|
81
83
|
cssVariableReplacementConfig,
|
82
84
|
selectorWeightConfig,
|
@@ -29,6 +29,7 @@ const {
|
|
29
29
|
server,
|
30
30
|
plugins,
|
31
31
|
exclude,
|
32
|
+
patterns,
|
32
33
|
mediaQueryHoverActiveString,
|
33
34
|
cssVariableReplacementConfig,
|
34
35
|
selectorWeightConfig,
|
@@ -153,6 +154,7 @@ module.exports = {
|
|
153
154
|
use: (0, _loaderUtils.getCSSLoaders)({
|
154
155
|
plugins,
|
155
156
|
exclude,
|
157
|
+
patterns,
|
156
158
|
cssVariableReplacementConfig,
|
157
159
|
selectorWeightConfig,
|
158
160
|
mediaQueryHoverActiveString,
|
@@ -165,6 +167,7 @@ module.exports = {
|
|
165
167
|
use: (0, _loaderUtils.getCSSLoaders)({
|
166
168
|
plugins,
|
167
169
|
exclude,
|
170
|
+
patterns,
|
168
171
|
mediaQueryHoverActiveString,
|
169
172
|
cssVariableReplacementConfig,
|
170
173
|
selectorWeightConfig,
|
@@ -11,7 +11,7 @@ var _cssClassNameGenerate = _interopRequireDefault(require("../utils/cssClassNam
|
|
11
11
|
|
12
12
|
var _utils = require("../utils");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _fileHandling = require("../plugins/utils/fileHandling");
|
15
15
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
@@ -19,21 +19,10 @@ const fs = require('fs');
|
|
19
19
|
|
20
20
|
const options = (0, _utils.getOptions)();
|
21
21
|
|
22
|
-
function excludeEmptyCheckPlugin({
|
23
|
-
enable,
|
24
|
-
ignore,
|
25
|
-
plugins
|
26
|
-
}) {
|
27
|
-
return enable ? ignore.length === 0 ? plugins : [require('../postcss-plugins/ExcludePlugin')({
|
28
|
-
ignore,
|
29
|
-
plugins
|
30
|
-
})] : [];
|
31
|
-
}
|
32
|
-
|
33
22
|
const getCSSLoaders = optionsObj => {
|
34
23
|
const {
|
35
24
|
plugins,
|
36
|
-
|
25
|
+
patterns,
|
37
26
|
mediaQueryHoverActiveString,
|
38
27
|
cssVariableReplacementConfig,
|
39
28
|
classNameBlob,
|
@@ -51,10 +40,6 @@ const getCSSLoaders = optionsObj => {
|
|
51
40
|
const {
|
52
41
|
cssSelectorZipPath
|
53
42
|
} = options.impactService;
|
54
|
-
const rtlExcludeLocal = (0, _windowsModification.windowsModification)(exclude.rtl);
|
55
|
-
const hoverActiveExcludeLocal = (0, _windowsModification.windowsModification)(exclude.hoverActive);
|
56
|
-
const combinerMediaQueryExcludeLocal = (0, _windowsModification.windowsModification)(exclude.combinerMediaQuery);
|
57
|
-
const cssVariableReplacementExcludeLocal = (0, _windowsModification.windowsModification)(exclude.cssVariableReplacement);
|
58
43
|
const cssLoaderOptions = {
|
59
44
|
// importLoaders: hasRTL||hoverActive ? 1 : 0,
|
60
45
|
importLoaders: 1,
|
@@ -65,34 +50,19 @@ const getCSSLoaders = optionsObj => {
|
|
65
50
|
if (classNameBlob) {
|
66
51
|
cssLoaderOptions.modules.localIdentName = classNameBlob;
|
67
52
|
} else {
|
68
|
-
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix);
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if (prefix === '[dir]') {
|
77
|
-
return selector;
|
78
|
-
}
|
79
|
-
|
80
|
-
return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
|
53
|
+
cssLoaderOptions.modules.getLocalIdent = (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix, patterns);
|
54
|
+
} // console.log('selector weight config : ', selectorWeightConfig);
|
55
|
+
|
56
|
+
|
57
|
+
let postcssPlugins = [plugins.valueReplacer && require('../postcss-plugins/ValueReplacer')(valueReplacer), plugins.selectorReplace && require('../postcss-plugins/SelectorReplace')(selectorReplace), plugins.hasRTL && require('@zohodesk/postcss-rtl')({
|
58
|
+
addPrefixToSelector: function addPrefixToSelector(selector, prefix) {
|
59
|
+
if (prefix === '[dir]') {
|
60
|
+
return selector;
|
81
61
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
plugins: [require('postcss-combine-media-query')]
|
87
|
-
}), ...excludeEmptyCheckPlugin({
|
88
|
-
enable: plugins.hoverActive,
|
89
|
-
ignore: hoverActiveExcludeLocal,
|
90
|
-
plugins: [require('../postcss-plugins/hoverActivePlugin')(mediaQueryHoverActiveString)]
|
91
|
-
}), ...excludeEmptyCheckPlugin({
|
92
|
-
enable: plugins.cssVariableReplacement,
|
93
|
-
ignore: cssVariableReplacementExcludeLocal,
|
94
|
-
plugins: [fs.existsSync(cssVariableReplacementConfig) && require('../postcss-plugins/variableModificationPlugin/index').plugin(cssVariableReplacementConfig)]
|
95
|
-
})].filter(Boolean);
|
62
|
+
|
63
|
+
return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
|
64
|
+
}
|
65
|
+
}), plugins.combinerMediaQuery && require('postcss-combine-media-query')(), plugins.hoverActive && require('../postcss-plugins/hoverActivePlugin')(mediaQueryHoverActiveString), plugins.cssVariableReplacement && fs.existsSync(cssVariableReplacementConfig) && require('../postcss-plugins/variableModificationPlugin/index').plugin(cssVariableReplacementConfig)].filter(Boolean);
|
96
66
|
return [cssSelectorZipPath && {
|
97
67
|
loader: require.resolve('../loaders/selectorMappingLoader')
|
98
68
|
}, {
|
@@ -112,10 +82,71 @@ const getCSSLoaders = optionsObj => {
|
|
112
82
|
loader: 'postcss-loader',
|
113
83
|
options: {
|
114
84
|
ident: 'postcss',
|
115
|
-
plugins: function () {
|
116
|
-
|
85
|
+
plugins: function (params) {
|
86
|
+
// console.log('check here : ', params.resourcePath);
|
87
|
+
// getCSSLoaders for all postcss filtering
|
88
|
+
|
89
|
+
/*
|
90
|
+
input :
|
91
|
+
params.resourcePath : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
92
|
+
patterns : [
|
93
|
+
// include all files
|
94
|
+
"valueReplacer": [
|
95
|
+
"*"
|
96
|
+
],
|
97
|
+
// include all files
|
98
|
+
"selectorReplace": [
|
99
|
+
"*"
|
100
|
+
],
|
101
|
+
// include src folder, include deskapp folder, exclude node modules
|
102
|
+
"hoverActive": [
|
103
|
+
"src",
|
104
|
+
"deskapp",
|
105
|
+
"!node_modules"
|
106
|
+
],
|
107
|
+
// include src folder, include deskapp folder, exclude node modules
|
108
|
+
"combinerMediaQuery": [
|
109
|
+
"src",
|
110
|
+
"deskapp",
|
111
|
+
"!node_modules"
|
112
|
+
],
|
113
|
+
// include src folder, include deskapp folder, exclude node modules
|
114
|
+
"hasRTL": [
|
115
|
+
"src",
|
116
|
+
"deskapp",
|
117
|
+
"!node_modules"
|
118
|
+
],
|
119
|
+
// include src folder, include deskapp folder, exclude node modules
|
120
|
+
"cssVariableReplacement": [
|
121
|
+
"src",
|
122
|
+
"deskapp",
|
123
|
+
"!node_modules"
|
124
|
+
],
|
125
|
+
// include src folder, include deskapp folder, exclude node modules
|
126
|
+
"selectorWeight": [
|
127
|
+
"src",
|
128
|
+
"deskapp",
|
129
|
+
"!node_modules"
|
130
|
+
],
|
131
|
+
// include all files
|
132
|
+
"cssUniqueness": [
|
133
|
+
"*"
|
134
|
+
]
|
135
|
+
],
|
136
|
+
|
137
|
+
[ postcssPlugins that are implemented ]
|
138
|
+
*/
|
139
|
+
postcssPlugins = (0, _fileHandling.isFileNameMatchingPattern)({
|
140
|
+
filename: params.resourcePath,
|
141
|
+
filterObject: patterns,
|
142
|
+
plugins: postcssPlugins
|
143
|
+
}); // postcssPlugins that are allowed
|
144
|
+
|
145
|
+
return postcssPlugins.length > 0 ? postcssPlugins : [require('../postcss-plugins/EmptyPlugin')()];
|
117
146
|
}
|
118
147
|
}
|
148
|
+
} : null, plugins.composeMinification ? {
|
149
|
+
loader: require.resolve('../loaders/composeLoader')
|
119
150
|
} : null].filter(Boolean);
|
120
151
|
};
|
121
152
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const {
|
4
|
+
windowsModificationFile
|
5
|
+
} = require('../windowsModification');
|
6
|
+
|
7
|
+
const tests = ['D:\\MyWork\\React Build\\desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'D:/MyWork/React Build/desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'desk_client_app\\jsapps\\supportapp\\src\\components\\Accessibility\\Accessibility.module.css', 'desk_client_app/jsapps/supportapp/src/components/Accessibility/Accessibility.module.css', 'src\\components\\Accessibility\\Accessibility.module.css', 'src/components/Accessibility/Accessibility.module.css', 'Accessibility.module.css', ''];
|
8
|
+
tests.forEach(test => {
|
9
|
+
console.log(windowsModificationFile(test));
|
10
|
+
});
|
@@ -4,8 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.windowsModification = windowsModification;
|
7
|
+
exports.windowsModificationFile = windowsModificationFile;
|
7
8
|
const isWin = process.platform === 'win32';
|
8
9
|
|
9
10
|
function windowsModification(array) {
|
10
11
|
return isWin ? array && Array.isArray(array) && array.map(r => r.replace(/\//g, '\\')) : array;
|
11
|
-
}
|
12
|
+
}
|
13
|
+
|
14
|
+
function windowsModificationFile(filename) {
|
15
|
+
return isWin ? filename.replace(/\//g, '\\') : filename;
|
16
|
+
} // module.exports = { windowsModification, windowsModificationFile };
|
@@ -0,0 +1,172 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
4
|
+
|
5
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
6
|
+
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
|
9
|
+
const supportedProps = ['margin-top', 'margin-bottom', 'margin-left', 'margin-right', // 'margin',
|
10
|
+
'padding-top', 'padding-bottom', 'padding-left', 'padding-right', // 'padding',
|
11
|
+
'top', 'bottom', 'left', 'right', 'height', 'width', 'min-height', 'min-width', 'max-height', 'max-width'];
|
12
|
+
const renameProps = {
|
13
|
+
'margin-top': {
|
14
|
+
pos: 'mt',
|
15
|
+
neg: 'mt_'
|
16
|
+
},
|
17
|
+
'margin-bottom': {
|
18
|
+
pos: 'mb',
|
19
|
+
neg: 'mb_'
|
20
|
+
},
|
21
|
+
'margin-left': {
|
22
|
+
pos: 'ml',
|
23
|
+
neg: 'ml_'
|
24
|
+
},
|
25
|
+
'margin-right': {
|
26
|
+
pos: 'mr',
|
27
|
+
neg: 'mr_'
|
28
|
+
},
|
29
|
+
margin: {
|
30
|
+
pos: 'm',
|
31
|
+
neg: 'm_'
|
32
|
+
},
|
33
|
+
'padding-top': {
|
34
|
+
pos: 'pt',
|
35
|
+
neg: 'pt_'
|
36
|
+
},
|
37
|
+
'padding-bottom': {
|
38
|
+
pos: 'pb',
|
39
|
+
neg: 'pb_'
|
40
|
+
},
|
41
|
+
'padding-left': {
|
42
|
+
pos: 'pl',
|
43
|
+
neg: 'pl_'
|
44
|
+
},
|
45
|
+
'padding-right': {
|
46
|
+
pos: 'pr',
|
47
|
+
neg: 'pr_'
|
48
|
+
},
|
49
|
+
padding: {
|
50
|
+
pos: 'p',
|
51
|
+
neg: 'p_'
|
52
|
+
},
|
53
|
+
top: {
|
54
|
+
pos: 'post',
|
55
|
+
neg: 'post_'
|
56
|
+
},
|
57
|
+
bottom: {
|
58
|
+
pos: 'posb',
|
59
|
+
neg: 'posb_'
|
60
|
+
},
|
61
|
+
left: {
|
62
|
+
pos: 'posl',
|
63
|
+
neg: 'posl_'
|
64
|
+
},
|
65
|
+
right: {
|
66
|
+
pos: 'posr',
|
67
|
+
neg: 'posr_'
|
68
|
+
},
|
69
|
+
height: {
|
70
|
+
pos: 'h',
|
71
|
+
neg: 'h_'
|
72
|
+
},
|
73
|
+
width: {
|
74
|
+
pos: 'w',
|
75
|
+
neg: 'w_'
|
76
|
+
},
|
77
|
+
'min-height': {
|
78
|
+
pos: 'minh',
|
79
|
+
neg: 'minh_'
|
80
|
+
},
|
81
|
+
'min-width': {
|
82
|
+
pos: 'minw',
|
83
|
+
neg: 'minw_'
|
84
|
+
},
|
85
|
+
'max-height': {
|
86
|
+
pos: 'maxh',
|
87
|
+
neg: 'maxh_'
|
88
|
+
},
|
89
|
+
'max-width': {
|
90
|
+
pos: 'maxw',
|
91
|
+
neg: 'maxw_'
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
function objToClassName(prop, data) {
|
96
|
+
return renameProps[prop] ? data < 0 ? renameProps[prop].neg ? `${renameProps[prop].neg}${data * -1}` : `undef${data * -1}` : renameProps[prop].pos ? `${renameProps[prop].pos}${data}` : `undef${data}` : `undef${data}`;
|
97
|
+
}
|
98
|
+
|
99
|
+
const commonFilePath = {
|
100
|
+
'margin-left': 'src/common/css/margin.css',
|
101
|
+
'margin-right': 'src/common/css/margin.css',
|
102
|
+
'margin-top': 'src/common/css/margin.css',
|
103
|
+
'margin-bottom': 'src/common/css/margin.css',
|
104
|
+
'padding-left': 'src/common/css/padding.css',
|
105
|
+
'padding-right': 'src/common/css/padding.css',
|
106
|
+
'padding-top': 'src/common/css/padding.css',
|
107
|
+
'padding-bottom': 'src/common/css/padding.css',
|
108
|
+
top: 'src/common/css/position.css',
|
109
|
+
bottom: 'src/common/css/position.css',
|
110
|
+
left: 'src/common/css/position.css',
|
111
|
+
right: 'src/common/css/position.css',
|
112
|
+
height: 'src/common/css/height.css',
|
113
|
+
width: 'src/common/css/width.css',
|
114
|
+
'min-height': 'src/common/css/height.css',
|
115
|
+
'min-width': 'src/common/css/width.css',
|
116
|
+
'max-height': 'src/common/css/height.css',
|
117
|
+
'max-width': 'src/common/css/width.css'
|
118
|
+
}; // const preNames = {
|
119
|
+
// height: 'zd-height-',
|
120
|
+
// 'max-height': 'zd-height-',
|
121
|
+
// 'min-height': 'zd-height-',
|
122
|
+
// width: 'zd-width-',
|
123
|
+
// 'max-width': 'zd-width-',
|
124
|
+
// 'min-width': 'zd-width-',
|
125
|
+
// top: 'zd-position-',
|
126
|
+
// bottom: 'zd-position-',
|
127
|
+
// left: 'zd-position-',
|
128
|
+
// right: 'zd-position-',
|
129
|
+
// 'padding-top': 'zd-padding-',
|
130
|
+
// 'padding-bottom': 'zd-padding-',
|
131
|
+
// 'padding-left': 'zd-padding-',
|
132
|
+
// 'padding-right': 'zd-padding-',
|
133
|
+
// 'margin-top': 'zd-margin-',
|
134
|
+
// 'margin-bottom': 'zd-margin-',
|
135
|
+
// 'margin-left': 'zd-margin-',
|
136
|
+
// 'margin-right': 'zd-margin-'
|
137
|
+
// };
|
138
|
+
|
139
|
+
function allowParent(rule) {
|
140
|
+
return rule.parent.type === 'root' || rule.parent.type === 'atrule' && rule.parent.name === 'media';
|
141
|
+
}
|
142
|
+
|
143
|
+
module.exports = function (source) {
|
144
|
+
const {
|
145
|
+
resourcePath
|
146
|
+
} = this;
|
147
|
+
|
148
|
+
let root = _postcss.default.parse(source);
|
149
|
+
|
150
|
+
root.walkRules(rule => {
|
151
|
+
rule.walkDecls(decl => {
|
152
|
+
if (!allowParent(rule)) {
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (supportedProps.includes(decl.prop) && /px$/gi.test(decl.value) && !/^--/gi.test(decl.prop) && commonFilePath[decl.prop] && !decl.value.includes('calc') && !/[,\s+]+|(\w+)\.|:|(\d+)%/gi.test(rule.selector)) {
|
157
|
+
let composeString = `from "${_path.default.relative(_path.default.parse(resourcePath).dir, // resourcePath
|
158
|
+
commonFilePath[decl.prop]).replace(/\\/gi, '/')}"`; // n++ < 10 && console.log(composeString);
|
159
|
+
|
160
|
+
if (!composeString.includes('src')) {
|
161
|
+
const cls = objToClassName(decl.prop, parseInt(decl.value));
|
162
|
+
composeString = `${cls} ${composeString}`;
|
163
|
+
decl.value = composeString;
|
164
|
+
decl.prop = 'composes'; // n < 10 && console.log(rule.selector, decl.prop, decl.value);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
});
|
168
|
+
});
|
169
|
+
const output = root.toString(); // console.log(output);
|
170
|
+
|
171
|
+
return output;
|
172
|
+
};
|
@@ -2,21 +2,29 @@
|
|
2
2
|
|
3
3
|
var _fs = _interopRequireDefault(require("fs"));
|
4
4
|
|
5
|
+
var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));
|
6
|
+
|
5
7
|
var _path = _interopRequireDefault(require("path"));
|
6
8
|
|
9
|
+
var _ReactLiveConvertor = require("./ReactLiveConvertor");
|
10
|
+
|
7
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
12
|
|
9
13
|
module.exports = function (source) {
|
10
|
-
|
11
|
-
|
14
|
+
const comNameAry = this.resourcePath.split(_path.default.sep);
|
15
|
+
const filePath = this.resourcePath;
|
16
|
+
|
17
|
+
const appPath = _fs.default.realpathSync(process.cwd());
|
12
18
|
|
13
|
-
|
19
|
+
const changePath = filePath.replace('/lib/', '/src/');
|
20
|
+
const comName = comNameAry[comNameAry.length - 1];
|
21
|
+
const name = comName.substring(0, comName.lastIndexOf('.'));
|
22
|
+
const options = (0, _getOptions.default)();
|
23
|
+
const originalFilePath = filePath.startsWith(appPath) ? filePath : changePath;
|
14
24
|
|
15
|
-
|
16
|
-
let comName = comNameAry[comNameAry.length - 1];
|
17
|
-
let name = comName.substring(0, comName.lastIndexOf('.'));
|
25
|
+
const src = _fs.default.readFileSync(originalFilePath).toString();
|
18
26
|
|
19
|
-
|
27
|
+
options.docs.enableReactLive && (source = (0, _ReactLiveConvertor.reactLiveConvertor)(source, originalFilePath)); //to Enable the ReactLive Converter
|
20
28
|
|
21
29
|
return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
|
22
30
|
};
|