@zohodesk/react-cli 0.0.1-beta.176 → 0.0.1-beta.177
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 +108 -26
- package/docs/VariableConversion.md +22 -8
- package/lib/configs/webpack.prod.config.js +1 -1
- package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
- package/lib/plugins/VariableConversionCollector.js +154 -54
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +4 -2
- package/lib/postcss-plugins/variableModificationPlugin/index.js +2 -1
- package/lib/utils/cssURLReplacer.js +30 -43
- package/lib/utils/getFileType.js +49 -0
- package/package.json +2 -1
package/README.md
CHANGED
@@ -1,63 +1,143 @@
|
|
1
1
|
# React CLI
|
2
2
|
|
3
3
|
A CLI tool for build modern web application and libraries
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Below Steps:-
|
8
|
+
|
9
|
+
> `npm i -g @zohodesk/react-cli`
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
## Step 1
|
14
|
+
|
15
|
+
> `mkdir <your-project-folder> && cd mkdir <your-project-folder>`
|
16
|
+
|
17
|
+
## Step 2
|
18
|
+
|
19
|
+
- create `package.json` file
|
20
|
+
- add this to your `package.json`
|
21
|
+
|
22
|
+
```json
|
23
|
+
{
|
24
|
+
"scripts": {
|
25
|
+
"start": "react-cli start",
|
26
|
+
"build": "react-cli build"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
```
|
30
|
+
|
31
|
+
## Step 3
|
32
|
+
|
33
|
+
- create below files
|
34
|
+
- `src/index.js`
|
35
|
+
- `src/index.html`
|
36
|
+
|
37
|
+
## Step 4
|
38
|
+
|
39
|
+
Now to run app
|
40
|
+
|
41
|
+
> `npm run start`
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
# Change Logs
|
46
|
+
|
47
|
+
# 0.0.1-beta.177
|
48
|
+
|
49
|
+
**Changes:**
|
50
|
+
|
51
|
+
- We have added extra new Error option `MULTIPLE_OCCURANCES` support for **convert px to custom variables**.
|
52
|
+
- In case css --variables are not assigned an error will be thrown and logged in `.cli/logs/unassignedVariables.log`. The unassigned variables can be manually assigned in `variableMapping.json` through two keys :
|
53
|
+
- `changes` : for the variables that have to be converted, manual values can be added ( eg. "--wms_height": "height" )
|
54
|
+
- `ignore` : for the variables that do not have to be considered, they can be added as keys with some value in `ignore` key (eg. "--gc_widget_video_bg": "undefined"). These values will be ignored.
|
55
|
+
- strict mode can be enabled for checking --variables in `cssVariableReplacementOptions.strictMode`
|
56
|
+
For more information and reference, refer to `[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/VariableConversion.md)
|
57
|
+
|
58
|
+
- and this version has same as `0.0.1-exp.176.12`, `0.0.1-exp.176.11`
|
59
|
+
|
60
|
+
# 0.0.1-exp.176.12
|
61
|
+
|
62
|
+
**Changes:**
|
63
|
+
|
64
|
+
- Earlier versions of react-cli, we have been putting video files under images folder in build output, now, we have moved the video files under videos folder in build output.
|
65
|
+
|
66
|
+
# 0.0.1-exp.176.11
|
67
|
+
|
68
|
+
**Issue Fix:**
|
69
|
+
|
70
|
+
- When we use `react-cli.app.publicPaths.callback` this option and video files import, in place of publicPath url, **null** was there instead of file type `video` issue fixed.
|
71
|
+
|
4
72
|
# 0.0.1-beta.176
|
73
|
+
|
5
74
|
**Features:**
|
6
|
-
|
7
|
-
|
75
|
+
|
76
|
+
- we have added feature to **increase Selector weight** for all css classes in your project during build time.
|
77
|
+
To enable this feature you have to set `react-cli.app.plugins.selectorWeight` as `true` in **package.json**.
|
8
78
|
For more [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/SelectorWeight.md)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
79
|
+
- Updates to variable replacement are given :
|
80
|
+
- css variables with -- are now supported due to the webpack plugin `VariableConversionCollector` that is generated for the same.
|
81
|
+
- `DECIMAL_CHECK`, `DECIMAL_REJECT` are two new errors supported.
|
82
|
+
- support for text-indent, clip, flex, flex-basis, row-gap, column-gap, gap properties are now given.
|
83
|
+
For more information and reference, refer to `[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/VariableConversion.md)
|
14
84
|
|
15
85
|
# 0.0.1-beta.175
|
86
|
+
|
16
87
|
**Issue Fix:-**
|
17
|
-
* When we use "hoverActive" @import in css not working issue fixed
|
18
88
|
|
19
|
-
|
20
|
-
|
89
|
+
- When we use "hoverActive" @import in css not working issue fixed
|
90
|
+
|
91
|
+
**Features:**
|
92
|
+
|
93
|
+
- `minifiy` option supported for minimize index.html file in during build time. You can use this option as "react-cli.app.htmlTemplate.minify" the options are same as https://github.com/jantimon/html-webpack-plugin#minification
|
21
94
|
|
22
95
|
# 0.0.1-beta.174
|
23
96
|
|
24
97
|
cli has been updated to fix compose issue faced when classname:hover exists and classname does not before compose
|
25
98
|
|
26
99
|
**Issue Fix:-**
|
27
|
-
* In react-cli version `0.0.1-beta.173`, when we use `start` command throws error issue fixed
|
28
|
-
* while using `cssVariableReplacementOptions`, compose issue faced in css files, when classname:hover exists and classname does not exist issue fixed
|
29
100
|
|
30
|
-
|
31
|
-
|
32
|
-
|
101
|
+
- In react-cli version `0.0.1-beta.173`, when we use `start` command throws error issue fixed
|
102
|
+
- while using `cssVariableReplacementOptions`, compose issue faced in css files, when classname:hover exists and classname does not exist issue fixed
|
103
|
+
|
104
|
+
**Feature:-**
|
105
|
+
|
106
|
+
- `react-cli.test.classnameFormat` option added to change CssModules (Ex: import style from "./a.module.css" ) className transform template unittest case.
|
107
|
+
`classnameFormat` default value `[classname]` you can customize it. Example: `[classname]-[hash]`
|
33
108
|
|
34
109
|
**Changes:-**
|
35
|
-
|
110
|
+
|
111
|
+
- `jsonFile_test_*.json` files deleted after they used.
|
36
112
|
|
37
113
|
# 0.0.1-beta.173
|
38
114
|
|
39
|
-
**Features:**
|
40
|
-
|
115
|
+
**Features:**
|
116
|
+
|
117
|
+
- we have added feature to **convert px to custom variables** for all css files in your project during build time.
|
41
118
|
To enable this feature you have to set `react-cli.app.plugins.cssVariableReplacement` as `true` in **package.json**.
|
42
119
|
|
43
120
|
Conversion for css Variables from Variables to px in Supportapp completed (`variableIgnore.js` && `pxParserPostcss.js` to be referred to), and px to custom variables through the new `variableModificationPlugin`. Error Log generation can also be converted on enabling
|
44
121
|
|
45
|
-
For an more information and reference, refer to `[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/
|
122
|
+
For an more information and reference, refer to `[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/VariableConversion.md)
|
46
123
|
|
47
124
|
# 0.0.1-beta.172
|
125
|
+
|
48
126
|
We have renamed some options, For Our future features convenience.
|
49
127
|
We have given fallback support.
|
50
|
-
Deprecation Warnings:-
|
51
|
-
|
52
|
-
|
128
|
+
Deprecation Warnings:-
|
129
|
+
|
130
|
+
- `react-cli.app.hasRTL` ==> `react-cli.app.plugins.hasRTL`
|
131
|
+
- `react-cli.app.rtlExclude` ==> `react-cli.app.exclude.rtl`
|
53
132
|
|
54
|
-
|
55
|
-
|
56
|
-
these options have fallback support.
|
133
|
+
- `react-cli.docs.hasRTL` ==> `react-cli.docs.plugins.hasRTL`
|
134
|
+
- `react-cli.docs.rtlExclude` ==> `react-cli.docs.exclude.rtl`
|
135
|
+
these options have fallback support.
|
57
136
|
|
58
137
|
# 0.0.1-beta.171
|
59
138
|
|
60
139
|
Features added :
|
140
|
+
|
61
141
|
1. `react-cli.app.mediaQueryHoverActiveString` and `react-cli.docs.mediaQueryHoverActiveString` templates support added for @media(hover: hover) and @media(hover: none) queries. We can modify these to modify respective queries.
|
62
142
|
|
63
143
|
# 0.0.1-beta.170
|
@@ -112,10 +192,12 @@ Changes:-
|
|
112
192
|
1. `enableChunkHash` option enabled for dev mode, use it as `react-cli.app.enableChunkHash` in `package.json`
|
113
193
|
2. `--enable_efc=true` option added to enable efc by terminal
|
114
194
|
3. unwanted pem files removed
|
195
|
+
|
115
196
|
# 0.0.1-exp.167.1
|
197
|
+
|
116
198
|
Features:-
|
117
|
-
* In docs we have added `Description` for Component Props- check out it in `PropTypes` tab
|
118
199
|
|
200
|
+
- In docs we have added `Description` for Component Props- check out it in `PropTypes` tab
|
119
201
|
|
120
202
|
# 0.0.1-beta.167
|
121
203
|
|
@@ -5,18 +5,27 @@
|
|
5
5
|
Conversion for Variables from Variables to px in Supportapp completed (`variableIgnore.js` && `pxParserPostcss.js` to be referred to), and px to custom variables through the new `variableModificationPlugin`. Error Log generation can also be converted on enabling
|
6
6
|
|
7
7
|
**Features:**
|
8
|
-
|
8
|
+
# Features below are added form `0.0.1-beta.173`
|
9
9
|
1. variables are converted from px to custom variables ( options are consumed from `cssVariableReplacementOptions.json` present in source folder )
|
10
10
|
2. To enable the error log generation `errorLog` is to be made `true` in `cssVariableReplacementOptions.json` ( it will take a little longer than usual build time )
|
11
11
|
3. To enable the console display of errors that are generated, `errorInConsole` is to be made `true` in `cssVariableReplacementOptions.json`
|
12
12
|
4. To enable specific errors in the error log generation / error display on console, `DECLARATION_IGNORED`(for ignoring that particular line / declaration),`UNIT_ERROR` (when the Unit doesnt match the available units for the property),`RANGE_ERROR` (when the value does not fall within the range that is given for the property), `VARIABLE_PRESENT`(whether the value supposed to be in px for conversion sake is not converted from var() to px or if it's properly converted to px for conversion from px to var through our plugin) are to be individually made `true` in `cssVariableReplacementOptions.json`
|
13
13
|
|
14
|
-
|
14
|
+
# Features below are added form `0.0.1-beta.176`
|
15
15
|
|
16
16
|
* variables with -- are now supported due to the webpack plugin `VariableConversionCollector` that is generated for the same.
|
17
17
|
* `DECIMAL_CHECK`, `DECIMAL_REJECT` are two new errors supported.
|
18
18
|
* support for text-indent, clip, flex, flex-basis, row-gap, column-gap, gap properties are now given.
|
19
19
|
|
20
|
+
# Features below are added form `0.0.1-beta.177`
|
21
|
+
|
22
|
+
* new Error `MULTIPLE_OCCURANCES` supported.
|
23
|
+
* In case css --variables are not assigned an error will be thrown and logged in `.cli/logs/unassignedVariables.log`. The unassigned variables can be manually assigned in `variableMapping.json` through two keys :
|
24
|
+
* `changes` : for the variables that have to be converted, manual values can be added ( eg. "--wms_height": "height" )
|
25
|
+
* `ignore` : for the variables that do not have to be considered, they can be added as keys with some value in `ignore` key (eg. "--gc_widget_video_bg": "undefined"). These values will be ignored.
|
26
|
+
* strict mode can be enabled for checking --variables in `cssVariableReplacementOptions.strictMode`
|
27
|
+
|
28
|
+
For more information and reference, refer to `[details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/2.0.0/docs/VariableConversion.md)
|
20
29
|
|
21
30
|
<!-- file paths :
|
22
31
|
|
@@ -77,10 +86,13 @@ jsapps\supportapp\plugins\variableIgnore.js ( adding variable:ignore comment to
|
|
77
86
|
"errorLog": false,
|
78
87
|
"errorInConsole": false,
|
79
88
|
"errorsAllowed":{
|
80
|
-
"DECLARATION_IGNORED"
|
81
|
-
"UNIT_ERROR"
|
82
|
-
"
|
83
|
-
"
|
89
|
+
"DECLARATION_IGNORED": true,
|
90
|
+
"UNIT_ERROR": true,
|
91
|
+
"DECIMAL_CHECK": true,
|
92
|
+
"DECIMAL_REJECT": true,
|
93
|
+
"RANGE_ERROR": true,
|
94
|
+
"VARIABLE_PRESENT": true,
|
95
|
+
"MULTIPLE_OCCURANCES": false
|
84
96
|
},
|
85
97
|
"settings": {
|
86
98
|
"font-size": {
|
@@ -701,10 +713,12 @@ Consider the below mentioned :
|
|
701
713
|
=> `DECLARATION_IGNORED` : Lines that succeed the /*Variable:Ignore*/ comment.
|
702
714
|
=> `UNIT_ERROR` : the units that are not present in the corresponding property's `allowed` array are used.
|
703
715
|
=> `RANGE_ERROR` : numerical values that are not present within the range of the corresponding property's `range` is used.
|
704
|
-
=> `DECIMAL_CHECK` : Decimal values containing . will be shown
|
705
|
-
=> `DECIMAL_REJECT` : Decimal values such as .em which are to be rejected are shown
|
716
|
+
=> `DECIMAL_CHECK` : Decimal values containing . will be shown ( flex : 1.3 )
|
717
|
+
=> `DECIMAL_REJECT` : Decimal values such as .em which are to be rejected are shown ( font-size : 12.5px )
|
706
718
|
=> `VARIABLE_PRESENT` : conversion to px (Step 2) wasn't done properly and hence there are residues that contain `var` in it are found.
|
719
|
+
=> `MULTIPLE_OCCURANCES` : using --vars in multiple places ( using --zd_avatar_padding_left in left and right ), which results in confusion during conversion
|
707
720
|
|
721
|
+
. --variables can be checked and debugged when the `strictMode` flag is enabled in `cssVariableReplacementOptions.json` file. The variables unassigned will be logged in the `unassignedVariable.log`. The manual assigning of all keys present will be split into `ignore` and `changes` for ignoring the variable and changing the variable respectively.
|
708
722
|
|
709
723
|
* First two conversions are to be done manually by the use of the commands, `npm run variable:addignore` and `npm run variable:convert`
|
710
724
|
* Final conversion is done by react-cli on compilation of the source folder `npm run start --app:port=**** --app:domain=****`
|
@@ -183,7 +183,7 @@ module.exports = {
|
|
183
183
|
fallback: _path.default.join(__dirname, '..', 'loaders', 'fileLoader.js')
|
184
184
|
}
|
185
185
|
}]
|
186
|
-
}, (0, _configsAssetsLoaders.configVideoLoaderObj)(enableChunkHash ? './
|
186
|
+
}, (0, _configsAssetsLoaders.configVideoLoaderObj)(enableChunkHash ? './videos/[name].[hash:20].[ext]' : './videos/[name].[ext]'), {
|
187
187
|
test: /\.woff2|\.woff$|\.ttf$|\.eot$/,
|
188
188
|
use: [{
|
189
189
|
loader: 'url-loader',
|
@@ -57,7 +57,7 @@ function configAudioLoader(nameTemplate) {
|
|
57
57
|
function configVideoLoader(nameTemplate) {
|
58
58
|
return {
|
59
59
|
test: VidioExtRegex,
|
60
|
-
use: createLoaderOptionQueryString('url-loader', `./
|
60
|
+
use: createLoaderOptionQueryString('url-loader', `./videos/${nameTemplate}`, 1)
|
61
61
|
};
|
62
62
|
}
|
63
63
|
|
@@ -7,14 +7,24 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _postcss = _interopRequireDefault(require("postcss"));
|
9
9
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
11
|
-
|
12
10
|
var _ErrorHandler = require("../postcss-plugins/variableModificationPlugin/ErrorHandler");
|
13
11
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
13
|
|
16
14
|
// import { RawSource } from 'webpack-sources';
|
17
|
-
const
|
15
|
+
const fs = require('fs');
|
16
|
+
|
17
|
+
const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_'];
|
18
|
+
let variablesRead = {};
|
19
|
+
|
20
|
+
const {
|
21
|
+
errors,
|
22
|
+
errTable,
|
23
|
+
errHandler
|
24
|
+
} = require('../postcss-plugins/variableModificationPlugin/index');
|
25
|
+
|
26
|
+
const supportedProps = ['font-size', 'margin', 'margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', '^top', '^right', '^bottom', '^left', '^width', 'min-width', 'max-width', '^height', 'min-height', 'max-height', 'text-indent', 'clip', 'flex-basis', 'row-gap', 'gap', 'column-gap', 'flex']; // const avoidProps = [];
|
27
|
+
// -- is issue IO --
|
18
28
|
|
19
29
|
/*
|
20
30
|
issues eg :
|
@@ -35,7 +45,7 @@ function isIgnoreValuePresent(ignoreVals, prop) {
|
|
35
45
|
}
|
36
46
|
});
|
37
47
|
return present;
|
38
|
-
} // -- to convert the hyphen values to values --
|
48
|
+
} // -- to convert the hyphen values to values --
|
39
49
|
|
40
50
|
/*
|
41
51
|
input :
|
@@ -55,8 +65,8 @@ function extractVariableName(val) {
|
|
55
65
|
function rootConvertor(rootOriginal, variables, settingsObject) {
|
56
66
|
rootOriginal.walkRules(rule => {
|
57
67
|
rule.nodes.forEach((decl, index) => {
|
58
|
-
|
59
|
-
|
68
|
+
const prevNode = rule.nodes[index - 1];
|
69
|
+
const currentNode = rule.nodes[index];
|
60
70
|
|
61
71
|
if (decl.prop && decl.prop.includes('--')) {
|
62
72
|
if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'variable:ignore') {
|
@@ -69,16 +79,16 @@ function rootConvertor(rootOriginal, variables, settingsObject) {
|
|
69
79
|
|
70
80
|
if (settingsObject[variables[decl.prop]]) {
|
71
81
|
/* if there is no value for property, set it to default so that undefined doesn't get called as key */
|
72
|
-
if (!variables[decl.prop]
|
82
|
+
if (!variables[decl.prop]) {
|
73
83
|
variables[decl.prop] = 'default';
|
74
84
|
}
|
75
85
|
|
76
86
|
const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
|
77
|
-
|
87
|
+
const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
|
78
88
|
|
79
89
|
valArr.forEach((value, index) => {
|
80
90
|
if (value.includes('px')) {
|
81
|
-
|
91
|
+
const num = value.replace('px', '');
|
82
92
|
valArr[index] = pxReplacement.replace('$$', num);
|
83
93
|
}
|
84
94
|
});
|
@@ -90,22 +100,46 @@ function rootConvertor(rootOriginal, variables, settingsObject) {
|
|
90
100
|
return rootOriginal;
|
91
101
|
}
|
92
102
|
|
103
|
+
function createFolderIfNonExistant(path) {
|
104
|
+
if (!fs.existsSync(path)) {
|
105
|
+
fs.mkdirSync(path, {
|
106
|
+
recursive: true
|
107
|
+
});
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
function createFileIfNonExistant(path, content) {
|
112
|
+
if (fs.existsSync(path)) {
|
113
|
+
fs.writeFileSync(path, content, 'utf-8');
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
93
117
|
class VariableConversionCollector {
|
94
118
|
constructor(options = {}) {
|
95
119
|
this.optimize = options.optimize;
|
96
120
|
this.filename = options.cssVariableReplacementConfig;
|
121
|
+
this.fileHandler();
|
97
122
|
}
|
98
123
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
124
|
+
fileHandler() {
|
125
|
+
createFolderIfNonExistant('./.cli/logs/');
|
126
|
+
createFolderIfNonExistant('./.cli/config/variables/');
|
127
|
+
createFolderIfNonExistant('./.cli/config/selectorWeight/');
|
128
|
+
createFileIfNonExistant('./.cli/logs/unassignedVariables.log', '{}');
|
129
|
+
createFileIfNonExistant('./.cli/logs/css_error.log', '{}');
|
130
|
+
}
|
103
131
|
|
132
|
+
apply(compiler) {
|
133
|
+
const variables = {};
|
134
|
+
const unassigned = {};
|
135
|
+
const rawdata = fs.readFileSync(this.filename);
|
104
136
|
const data = JSON.parse(rawdata);
|
105
137
|
const {
|
106
138
|
settings: settingsObject,
|
107
139
|
errorLog: errorLogStatus,
|
108
|
-
errorInConsole: errorConsoleStatus
|
140
|
+
errorInConsole: errorConsoleStatus,
|
141
|
+
errorsAllowed,
|
142
|
+
strictMode
|
109
143
|
} = data; // If theres is no setting for default prop in settingsObject, set one.
|
110
144
|
|
111
145
|
if (!settingsObject.default) {
|
@@ -130,6 +164,13 @@ class VariableConversionCollector {
|
|
130
164
|
*/
|
131
165
|
|
132
166
|
|
167
|
+
if (fs.existsSync('./.cli/config/variables/variableMapping.json')) {
|
168
|
+
variablesRead = JSON.parse(fs.readFileSync('./.cli/config/variables/variableMapping.json', 'utf-8'));
|
169
|
+
Object.keys(variablesRead.changes).forEach(key => {
|
170
|
+
variables[key] = variablesRead.changes[key];
|
171
|
+
});
|
172
|
+
}
|
173
|
+
|
133
174
|
compiler.hooks.compilation.tap('VariableConversionCollector', compilation => {
|
134
175
|
compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
|
135
176
|
const mods = modules.filter(x => x.type.includes('css'));
|
@@ -137,37 +178,67 @@ class VariableConversionCollector {
|
|
137
178
|
const rootOriginal = _postcss.default.parse(module.content);
|
138
179
|
|
139
180
|
const filename = module.issuer.resource;
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
181
|
+
|
182
|
+
if (!filename.includes('node_modules')) {
|
183
|
+
rootOriginal.walkRules(rule => {
|
184
|
+
rule.walkDecls(decl => {
|
185
|
+
decl.value.split(' ').forEach(val => {
|
186
|
+
if (val && val.includes('--') && !new RegExp(ignoreVals.join('|'), 'gi').test(val) && decl.prop) {
|
187
|
+
const extractedValue = extractVariableName(val);
|
188
|
+
|
189
|
+
if (!variables[extractedValue]) {
|
190
|
+
variables[extractedValue] = decl.prop;
|
191
|
+
} else {
|
192
|
+
if (new RegExp(supportedProps.join('|'), 'gi').test(decl.prop)) {
|
193
|
+
// console.log(
|
194
|
+
// `${extractedValue} : ${variables[extractedValue]} already exists please check!`
|
195
|
+
// );
|
196
|
+
if (errorsAllowed.MULTIPLE_OCCURANCES) {
|
197
|
+
const errObj = {
|
198
|
+
decl,
|
199
|
+
type: 'MULTIPLE_OCCURANCES',
|
200
|
+
filename,
|
201
|
+
message: `${extractedValue} : ${variables[extractedValue]} already exists please check!`
|
202
|
+
};
|
203
|
+
errHandler.errorTable.push(errObj);
|
204
|
+
errHandler.errorFunction(errObj);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
} else {
|
209
|
+
// console.log(decl.prop);
|
210
|
+
if (/^--/gi.test(decl.prop) && val.trim() !== '' && !variables[decl.prop]) {
|
211
|
+
if (!Object.keys(variablesRead.ignore).includes(decl.prop)) {
|
212
|
+
unassigned[decl.prop] = variables[decl.prop];
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
});
|
146
217
|
});
|
147
218
|
});
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
}
|
168
|
-
}
|
219
|
+
/*
|
220
|
+
current value example:
|
221
|
+
{
|
222
|
+
--zdt_uploadlist_default_width : --zd_upload_width,
|
223
|
+
--zd_upload_width : width
|
224
|
+
}
|
225
|
+
expected value :
|
226
|
+
{
|
227
|
+
--zdt_uploadlist_default_width : width,
|
228
|
+
--zd_upload_width : width
|
229
|
+
}
|
230
|
+
|
231
|
+
conversion is done in the while loop below
|
232
|
+
*/
|
233
|
+
|
234
|
+
Object.keys(variables).forEach(key => {
|
235
|
+
while (variables[variables[key]]) {
|
236
|
+
variables[key] = variables[variables[key]];
|
237
|
+
}
|
238
|
+
});
|
239
|
+
}
|
169
240
|
});
|
170
|
-
}); // -- conversion for the root using rootConvertor --
|
241
|
+
}); // -- conversion for the root using rootConvertor --
|
171
242
|
|
172
243
|
/*
|
173
244
|
input :
|
@@ -200,30 +271,60 @@ class VariableConversionCollector {
|
|
200
271
|
*/
|
201
272
|
|
202
273
|
compiler.hooks.afterEmit.tap('error-display', () => {
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
274
|
+
if (Object.keys(unassigned).length > 0 && strictMode) {
|
275
|
+
console.log();
|
276
|
+
console.log(unassigned);
|
277
|
+
console.log();
|
278
|
+
let str = '{\n';
|
279
|
+
Object.keys(unassigned).forEach(key => {
|
280
|
+
str += `"${key}" : "${unassigned[key]}",\n`;
|
281
|
+
});
|
282
|
+
str += '}';
|
283
|
+
fs.writeFileSync('./.cli/logs/unassignedVariables.log', str, 'utf-8');
|
284
|
+
throw new Error('^^^ Variables above have not been assigned! ^^^');
|
285
|
+
}
|
207
286
|
|
208
|
-
|
209
|
-
|
287
|
+
const avlTypes = new Set([]);
|
288
|
+
const srtArr = errTable.sort((a, b) => {
|
210
289
|
avlTypes.add(a.type);
|
211
290
|
avlTypes.add(b.type);
|
212
291
|
|
213
292
|
if (a.type < b.type) {
|
214
293
|
return -1;
|
215
294
|
}
|
216
|
-
});
|
295
|
+
}); // variable constructed now to be written in a json file
|
296
|
+
// const newVars = Object.keys(variables)
|
297
|
+
// //Filter Object with key contanis "NAME"
|
298
|
+
// .filter(key => variables[key].includes('--'))
|
299
|
+
// .reduce(
|
300
|
+
// (obj, key) =>
|
301
|
+
// Object.assign(obj, {
|
302
|
+
// [key]: variables[key]
|
303
|
+
// }),
|
304
|
+
// {}
|
305
|
+
// );
|
306
|
+
// console.log('new variables: ', newVars);
|
307
|
+
// try {
|
308
|
+
// fs.writeFileSync('./variableMapping.json', JSON.stringify(variables));
|
309
|
+
// } catch (err) {
|
310
|
+
// console.log(err);
|
311
|
+
// }
|
312
|
+
// fs.writeFile('./variableMapping.json', JSON.stringify(variables), err => {
|
313
|
+
// if (err) {
|
314
|
+
// throw err;
|
315
|
+
// }
|
316
|
+
// console.log('variable mapping file generated.');
|
317
|
+
// });
|
217
318
|
|
218
319
|
if (errorConsoleStatus) {
|
219
|
-
const
|
320
|
+
const errorHandler = new _ErrorHandler.ErrorHandler();
|
220
321
|
avlTypes.forEach(type => {
|
221
322
|
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
222
323
|
console.log(`Error Type : ${type}`);
|
223
324
|
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
224
325
|
srtArr.forEach(err => {
|
225
326
|
if (err.decl.prop && err.decl.value && err.type === type) {
|
226
|
-
|
327
|
+
errorHandler.printError(err);
|
227
328
|
}
|
228
329
|
});
|
229
330
|
console.log('---------------------------------------------------------------------------------------------------------------------------');
|
@@ -231,14 +332,13 @@ class VariableConversionCollector {
|
|
231
332
|
}
|
232
333
|
|
233
334
|
if (errorLogStatus) {
|
234
|
-
|
235
|
-
|
335
|
+
fs.writeFileSync('./.cli/logs/css_error.log', '');
|
236
336
|
console.log('writing to logFile...');
|
237
337
|
|
238
338
|
if (errors.length > 0) {
|
239
339
|
errors.forEach((err, index) => {
|
240
340
|
if (errTable[index].decl.prop && errTable[index].decl.value) {
|
241
|
-
|
341
|
+
fs.appendFileSync('./.cli/logs/css_error.log', err);
|
242
342
|
}
|
243
343
|
});
|
244
344
|
}
|
@@ -16,13 +16,14 @@ class ErrorHandler {
|
|
16
16
|
DECIMAL_REJECT: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n unit : ${errObj.unitErrorVal} ,\n message : ${errObj.message}`),
|
17
17
|
UNIT_ERROR: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n unit : ${errObj.unitErrorVal} ,\n message : ${errObj.message}`),
|
18
18
|
RANGE_ERROR: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n message : ${errObj.message}\r`),
|
19
|
-
VARIABLE_PRESENT: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n message : ${errObj.message}`)
|
19
|
+
VARIABLE_PRESENT: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n message : ${errObj.message}`),
|
20
|
+
MULTIPLE_OCCURANCES: errObj => this.addError(` prop: ${errObj.decl.prop} ,\n value : ${errObj.decl.value} ,\n filename : ${errObj.filename} ,\n filepath : ${errObj.path} ,\n line : ${errObj.decl.source.start.line} ,\n message : ${errObj.message}`)
|
20
21
|
});
|
21
22
|
}
|
22
23
|
|
23
24
|
setAllowedErrs(allErrs) {
|
24
25
|
this.allowedErrs = allErrs;
|
25
|
-
['DECLARATION_IGNORED', 'DECIMAL_CHECK', 'DECIMAL_REJECT', 'UNIT_ERROR', 'RANGE_ERROR', 'VARIABLE_PRESENT'].forEach(err => {
|
26
|
+
['DECLARATION_IGNORED', 'DECIMAL_CHECK', 'DECIMAL_REJECT', 'UNIT_ERROR', 'RANGE_ERROR', 'VARIABLE_PRESENT', 'MULTIPLE_OCCURANCES'].forEach(err => {
|
26
27
|
if (!this.allowedErrs[err]) {
|
27
28
|
this[err] = () => null;
|
28
29
|
}
|
@@ -35,6 +36,7 @@ class ErrorHandler {
|
|
35
36
|
|
36
37
|
errorFunction(errObj) {
|
37
38
|
if (errObj.type && this.allowedErrs[errObj.type] && errObj.decl.prop && errObj.decl.value) {
|
39
|
+
console.log(this.allowedErrs[errObj.type]);
|
38
40
|
this[errObj.type](errObj);
|
39
41
|
}
|
40
42
|
}
|
@@ -3,19 +3,26 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.cssUrlReplacer = void 0;
|
7
|
+
Object.defineProperty(exports, "getFileType", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function () {
|
10
|
+
return _getFileType.getFileType;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
exports.getUrls = void 0;
|
7
14
|
|
8
15
|
var _fs = _interopRequireDefault(require("fs"));
|
9
16
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
11
|
-
|
12
17
|
var _crypto = _interopRequireDefault(require("crypto"));
|
13
18
|
|
19
|
+
var _getFileType = require("./getFileType");
|
20
|
+
|
14
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
22
|
|
16
|
-
|
23
|
+
const urlRegex = /url\(.*?\)/g;
|
17
24
|
|
18
|
-
|
25
|
+
const getHash = (file, isPath = false, needSubStr = true) => {
|
19
26
|
let hash = _crypto.default.createHash('md5');
|
20
27
|
|
21
28
|
if (isPath) {
|
@@ -28,45 +35,25 @@ let getHash = (file, isPath = false, needSubStr = true) => {
|
|
28
35
|
return hash ? needSubStr ? hash.substring(0, 20) : hash : null;
|
29
36
|
};
|
30
37
|
|
31
|
-
|
32
|
-
let {
|
33
|
-
ext
|
34
|
-
} = _path.default.parse(file);
|
35
|
-
|
36
|
-
if (ext === '.gif' || ext === '.png' || ext === '.jpg' || ext === '.jpeg' || ext === '.ico') {
|
37
|
-
return 'image';
|
38
|
-
} else if (ext === '.svg' || ext === '.woff' || ext === '.eot' || ext === '.ttf' || ext === '.woff2') {
|
39
|
-
return 'font';
|
40
|
-
} else if (ext === '.js') {
|
41
|
-
return 'js';
|
42
|
-
} else if (ext === '.css') {
|
43
|
-
return 'css';
|
44
|
-
}
|
45
|
-
|
46
|
-
return null;
|
47
|
-
};
|
48
|
-
|
49
|
-
exports.getFileType = getFileType;
|
50
|
-
|
51
|
-
let formatUrl = str => {
|
38
|
+
const formatUrl = str => {
|
52
39
|
let char = str.includes('"') ? '"' : str.includes('\'') ? '\'' : '(';
|
53
|
-
|
54
|
-
|
40
|
+
const statingIdx = str.indexOf(char) + 1;
|
41
|
+
const substr = str.substring(statingIdx, str.length);
|
55
42
|
char = char === '(' ? ')' : char;
|
56
43
|
return substr.substring(0, substr.indexOf(char));
|
57
44
|
};
|
58
45
|
|
59
|
-
|
60
|
-
|
46
|
+
const getUrls = css => {
|
47
|
+
const urlMatches = css.match(urlRegex);
|
61
48
|
let src = css;
|
62
49
|
|
63
50
|
if (urlMatches) {
|
64
|
-
|
51
|
+
const patterns = {};
|
65
52
|
urlMatches.forEach(pattern => {
|
66
|
-
|
67
|
-
|
53
|
+
const url = formatUrl(pattern);
|
54
|
+
const hash = getHash(url);
|
68
55
|
patterns[url] = hash;
|
69
|
-
|
56
|
+
const regex = new RegExp(pattern.replace(/([<>*()?${}|])/g, '\\$1'), 'g');
|
70
57
|
src = src.replace(regex, hash);
|
71
58
|
});
|
72
59
|
return {
|
@@ -78,12 +65,12 @@ let getUrls = css => {
|
|
78
65
|
|
79
66
|
exports.getUrls = getUrls;
|
80
67
|
|
81
|
-
|
82
|
-
|
68
|
+
const cssUrlReplacer = (css, domains, chunkHash = {}) => {
|
69
|
+
const obj = getUrls(css);
|
83
70
|
let src = css;
|
84
71
|
|
85
72
|
if (obj) {
|
86
|
-
|
73
|
+
const patterns = obj.urls;
|
87
74
|
src = obj.css;
|
88
75
|
Object.keys(patterns).forEach(pattern => {
|
89
76
|
let urlParts = pattern.split('/');
|
@@ -97,20 +84,20 @@ let cssUrlReplacer = (css, domains, chunkHash = {}) => {
|
|
97
84
|
fileName = fileName.replace(/\?.*$/g, '');
|
98
85
|
}
|
99
86
|
|
100
|
-
|
101
|
-
|
102
|
-
|
87
|
+
const hash = patterns[pattern];
|
88
|
+
const filename = fileName.replace(/(\?|#).*?$/g, '');
|
89
|
+
const regex = new RegExp(hash, 'g');
|
103
90
|
let {
|
104
91
|
hashedName
|
105
92
|
} = chunkHash[filename] || fileName;
|
106
93
|
|
107
94
|
if (domains && typeof urlParts[0] === 'string' && !urlParts[0].includes('http')) {
|
108
|
-
|
95
|
+
const {
|
109
96
|
font,
|
110
97
|
image
|
111
98
|
} = domains;
|
112
|
-
|
113
|
-
|
99
|
+
const type = (0, _getFileType.getFileType)(filename);
|
100
|
+
const customPath = type === 'image' ? `${image}/images` : type === 'font' ? `${font}/fonts` : urlParts.join('/');
|
114
101
|
urlParts = customPath.split('/');
|
115
102
|
}
|
116
103
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getFileType = getFileType;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
|
12
|
+
/* eslint-disable no-use-before-define */
|
13
|
+
function getFileType(file) {
|
14
|
+
const {
|
15
|
+
ext
|
16
|
+
} = _path.default.parse(file);
|
17
|
+
|
18
|
+
if (isImageFileExt(ext)) {
|
19
|
+
return 'image';
|
20
|
+
} else if (isFontFileExt(ext)) {
|
21
|
+
return 'font';
|
22
|
+
} else if (isVideoFileExt(ext)) {
|
23
|
+
return 'video';
|
24
|
+
} else if (isAudioFileExt(ext)) {
|
25
|
+
return 'audio';
|
26
|
+
} else if (ext === '.js') {
|
27
|
+
return 'js';
|
28
|
+
} else if (ext === '.css') {
|
29
|
+
return 'css';
|
30
|
+
}
|
31
|
+
|
32
|
+
return null;
|
33
|
+
}
|
34
|
+
|
35
|
+
function isImageFileExt(ext) {
|
36
|
+
return ext === '.gif' || ext === '.png' || ext === '.jpg' || ext === '.jpeg' || ext === '.ico';
|
37
|
+
}
|
38
|
+
|
39
|
+
function isFontFileExt(ext) {
|
40
|
+
return ext === '.svg' || ext === '.woff' || ext === '.eot' || ext === '.ttf' || ext === '.woff2';
|
41
|
+
}
|
42
|
+
|
43
|
+
function isVideoFileExt(ext) {
|
44
|
+
return ext === '.mp4';
|
45
|
+
}
|
46
|
+
|
47
|
+
function isAudioFileExt(ext) {
|
48
|
+
return ext === '.ogg';
|
49
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "0.0.1-beta.
|
3
|
+
"version": "0.0.1-beta.177",
|
4
4
|
"description": "A CLI tool for build modern web application and libraries",
|
5
5
|
"scripts": {
|
6
6
|
"init": "node ./lib/utils/init.js",
|
@@ -9,6 +9,7 @@
|
|
9
9
|
"start": "babel src -d lib -w --copy-files",
|
10
10
|
"build": "babel src -d lib --copy-files",
|
11
11
|
"prepare": "npm run clean && npm run build",
|
12
|
+
"prepublish": "npm prune now",
|
12
13
|
"lint": "eslint src ./bin/cli.js",
|
13
14
|
"postpublish": "node postpublish.js",
|
14
15
|
"expublish": "npm publish --tag experimental-version"
|