@zohodesk/react-cli 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ {
2
+ "workbench.iconTheme": "vscode-icons",
3
+ "window.zoomLevel": 1,
4
+ "window.autoDetectColorScheme": true,
5
+ "gitlens.views.stashes.files.layout": "list",
6
+ "git.openRepositoryInParentFolders": "never",
7
+ "diffEditor.ignoreTrimWhitespace": false,
8
+ "workbench.colorTheme": "Default Light+",
9
+ "editor.indentSize": "tabSize",
10
+ "eslint.enable": true
11
+ }
package/README.md CHANGED
@@ -44,6 +44,14 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.0.1
48
+
49
+ **Issue Fix**
50
+ - variable conversion for px and var(--) values in same declaration was not supported, now it is supported.
51
+ - package-lock.json removed from `.npmignore`
52
+
53
+ **Feature Update**
54
+ - exclude added to Selector Plugin
47
55
  # 1.0.0
48
56
  ## Major Release
49
57
  **Changes:**
@@ -4,3 +4,6 @@
4
4
  * all classes in all files will be added with the `defaultSelector` provided in package.json to increase selector weight
5
5
  * in case a specific chunk file is supposed to have a different selector, it can be mentioned in the `customFileSelectorWeight.json`. This will add the new selector to that particular chunk file.
6
6
  * `excludeStrings` is an array used to exclude selectors that should not be converted. Default selectors such as body, html are excluded through this way.
7
+
8
+ # v1.0.1 update:
9
+ * exclude support added, file paths to be added in `react-cli > app > exclude > selectorWeight` to be excluded from conversion.
@@ -4,8 +4,13 @@
4
4
 
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
+
8
+ **Issue Fix**
9
+ # Issue fix done in `1.0.1`
10
+ - variable conversion for px and var(--) values in same declaration was not supported, now it is supported.
11
+
7
12
  **Features:**
8
- # Features below are added form `0.0.1-beta.173`
13
+ # Features below are added from `0.0.1-beta.173`
9
14
  1. variables are converted from px to custom variables ( options are consumed from `cssVariableReplacementOptions.json` present in source folder )
10
15
  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
16
  3. To enable the console display of errors that are generated, `errorInConsole` is to be made `true` in `cssVariableReplacementOptions.json`
@@ -48,7 +48,7 @@ const getDevPlugins = (options, publicPath) => {
48
48
  hasShadowDOM,
49
49
  cssVariableReplacementConfig,
50
50
  plugins: pluginObject,
51
- // exclude,
51
+ exclude,
52
52
  selectorWeightConfig,
53
53
  server: {
54
54
  mode
@@ -200,7 +200,8 @@ const getDevPlugins = (options, publicPath) => {
200
200
 
201
201
  if (pluginObject.selectorWeight) {
202
202
  pluginsArr.push(new _SelectorPlugin.default({
203
- selectorWeightConfig
203
+ selectorWeightConfig,
204
+ exclude: exclude.selectorWeight
204
205
  }));
205
206
  }
206
207
 
@@ -9,15 +9,21 @@ var _postcss = _interopRequireDefault(require("postcss"));
9
9
 
10
10
  var _fs = _interopRequireDefault(require("fs"));
11
11
 
12
- var _webpackSources = require("webpack-sources");
12
+ var _windowsModification = require("../loaderUtils/windowsModification");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- const path = require('path');
17
-
18
- const isCss = filename => path.extname(filename) === '.css';
16
+ function checkFilename(filename, data) {
17
+ let keyMatch = undefined;
18
+ Object.keys(data).forEach(key => {
19
+ if (filename.includes(key)) {
20
+ keyMatch = key;
21
+ }
22
+ });
23
+ return keyMatch;
24
+ }
19
25
 
20
- function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings) {
26
+ function rootConvertor(rootOriginal, defaultSelector, data, filename, excludeStrings) {
21
27
  rootOriginal.walkRules((rule, index) => {
22
28
  const prevNode = rootOriginal.nodes[index - 1];
23
29
 
@@ -31,14 +37,14 @@ function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, exclu
31
37
  }
32
38
  }
33
39
 
34
- if (excludeStrings.includes(rule.selector)) {
35
- return;
36
- }
40
+ const selectorArr = rule.selector.split(',');
41
+ selectorArr.forEach((singleSelectorStr, index) => {
42
+ if (excludeStrings.includes(singleSelectorStr.trim())) {
43
+ return;
44
+ }
37
45
 
38
- let ruleArr = rule.selector.split(',');
39
- ruleArr.forEach((rule, index) => {
40
- if (rule.includes(']')) {
41
- if (rule.slice(rule.lastIndexOf(']') + 2).trim() === '') {
46
+ if (singleSelectorStr.includes(']')) {
47
+ if (singleSelectorStr.slice(singleSelectorStr.lastIndexOf(']') + 2).trim() === '') {
42
48
  return;
43
49
  } // console.log(
44
50
  // rule.slice(rule.lastIndexOf(']') + 2).trim(),
@@ -46,22 +52,34 @@ function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, exclu
46
52
  // );
47
53
 
48
54
 
49
- ruleArr[index] = `${rule.slice(0, rule.lastIndexOf(']') + 1).trim()} ${defaultSelector}${rule.slice(rule.lastIndexOf(']') + 2).trim()}`; // console.log(ruleArr[index]);
55
+ selectorArr[index] = `${singleSelectorStr.slice(0, singleSelectorStr.lastIndexOf(']') + 1).trim()} ${defaultSelector}${singleSelectorStr.slice(singleSelectorStr.lastIndexOf(']') + 2).trim()}`; // console.log(ruleArr[index]);
50
56
 
51
57
  return;
52
58
  }
53
59
 
54
- ruleArr[index] = data[chunkFilename] ? `${data[chunkFilename].defaultSelector}${rule}` : `${defaultSelector}${rule}`;
60
+ const keyMatch = checkFilename(filename, data);
61
+ selectorArr[index] = data[keyMatch] ? `${data[keyMatch].defaultSelector}${singleSelectorStr}` : `${defaultSelector}${singleSelectorStr}`;
55
62
  });
56
- rule.selector = ruleArr.join(',\n'); // console.log(`${rule.selector} converted`);
63
+ rule.selector = selectorArr.join(',\n'); // console.log(`${rule.selector} converted`);
57
64
  });
58
65
  return rootOriginal;
59
66
  }
60
67
 
68
+ function ignoreFile(excludeArr, filename) {
69
+ let ignore = false;
70
+ excludeArr.forEach(exclStr => {
71
+ if (filename.includes(exclStr)) {
72
+ ignore = true;
73
+ }
74
+ });
75
+ return ignore;
76
+ }
77
+
61
78
  class SelectorPlugin {
62
79
  constructor(options = {}) {
63
80
  this.optimize = options.optimize;
64
81
  this.selectorWeightConfig = options.selectorWeightConfig;
82
+ this.exclude = options.exclude;
65
83
  }
66
84
 
67
85
  apply(compiler) {
@@ -74,19 +92,24 @@ class SelectorPlugin {
74
92
  const rawdata = _fs.default.readFileSync(customFileDetails);
75
93
 
76
94
  const data = JSON.parse(rawdata);
95
+ this.exclude = (0, _windowsModification.windowsModification)(this.exclude);
77
96
  compiler.hooks.compilation.tap('selector-weight-rewrite', compilation => {
78
- compilation.hooks.optimizeChunkAssets.tapAsync('selector-weight-rewrite', (chunks, callback) => {
79
- chunks.forEach(chunk => {
80
- chunk.files.filter(isCss).forEach(chunkFilename => {
81
- const asset = compilation.assets[chunkFilename];
82
- const sourceStr = asset.source();
97
+ compilation.hooks.optimizeModules.tap('selector-weight-rewrite', modules => {
98
+ const mods = modules.filter(x => x.type.includes('css'));
99
+ mods.forEach(module => {
100
+ const rootOriginal = _postcss.default.parse(module.content);
101
+
102
+ const filename = module.issuer.resource; // if (!filename.includes('node_modules')) {
103
+
104
+ if (ignoreFile(this.exclude, filename)) {
105
+ return;
106
+ } // console.log(filename);
83
107
 
84
- const rootOriginal = _postcss.default.parse(sourceStr);
85
108
 
86
- compilation.assets[chunkFilename] = new _webpackSources.RawSource(rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings).toString());
87
- });
109
+ module.content = //new RawSource(
110
+ rootConvertor(rootOriginal, defaultSelector, data, filename, excludeStrings).toString(); // );
111
+ // }
88
112
  });
89
- callback();
90
113
  });
91
114
  });
92
115
  }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _postcss = _interopRequireDefault(require("postcss"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ module.exports = _postcss.default.plugin('postcss-include-files', opts => {
8
+ const {
9
+ plugins
10
+ } = opts;
11
+ return (root, result) => {
12
+ const inputFile = root.source.input.file;
13
+ const includeFile = opts.include.some(file => inputFile.indexOf(file) !== -1);
14
+
15
+ if (includeFile) {
16
+ // console.log(inputFile);
17
+ const handler = response => response.messages.forEach(msg => result.messages.push(msg));
18
+
19
+ return (0, _postcss.default)(plugins).process(root, {
20
+ from: undefined
21
+ }).then(handler);
22
+ }
23
+ };
24
+ });
@@ -36,7 +36,6 @@ class ErrorHandler {
36
36
 
37
37
  errorFunction(errObj) {
38
38
  if (errObj.type && this.allowedErrs[errObj.type] && errObj.decl.prop && errObj.decl.value) {
39
- console.log(this.allowedErrs[errObj.type]);
40
39
  this[errObj.type](errObj);
41
40
  }
42
41
  }
@@ -10,8 +10,6 @@ const {
10
10
  ErrorHandler
11
11
  } = require('./ErrorHandler');
12
12
 
13
- const errors = [];
14
- const errorTable = [];
15
13
  const errHandler = new ErrorHandler();
16
14
  const convertableProps = {
17
15
  'font-size': true,
@@ -121,7 +119,7 @@ const singleConvertor = (value, changeVal, details, range) => {
121
119
  // console.log(value, 'not within range')
122
120
 
123
121
 
124
- let errObj = {
122
+ const errObj = {
125
123
  decl,
126
124
  type: 'RANGE_ERROR',
127
125
  filename,
@@ -147,6 +145,8 @@ const singleConvertor = (value, changeVal, details, range) => {
147
145
  // } else {
148
146
  // console.log('++++++++++++++++++++++rect val!', value);
149
147
  // }
148
+
149
+ return;
150
150
  };
151
151
 
152
152
  module.exports = {
@@ -189,10 +189,11 @@ module.exports = {
189
189
  const fromPath = rootOriginal.source.input.from; // this will be problem for linux and mac use require('path').sep
190
190
  // split not need use slice and lastIndexOf less memory
191
191
 
192
- const filename = fromPath.split(path.sep).pop();
192
+ const filename = fromPath.split(path.sep).pop(); // if(filename.includes('AddFormResponsive.module.css'){
193
+ // }
193
194
 
194
195
  if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase().includes(commentStr)) {
195
- let errObj = {
196
+ const errObj = {
196
197
  decl,
197
198
  type: 'DECLARATION_IGNORED',
198
199
  filename,
@@ -255,7 +256,7 @@ module.exports = {
255
256
  } else {
256
257
  if (!decl.value.includes('calc')) {
257
258
  // addError(` prop: ${decl.prop} ,\n value : ${decl.value} ,\n filename : ${filename} ,\n filepath : ${path} ,\n line : ${decl.source.start.line} ,\n unit : ${unitErrorVal} ,\n message : ${unitErrorVal} (Unit) Not Allowed \r`);
258
- let errObj = {
259
+ const errObj = {
259
260
  decl,
260
261
  filename,
261
262
  unitErrorVal: unitErrorVal,
@@ -285,8 +286,29 @@ module.exports = {
285
286
  }
286
287
  }
287
288
  } else {
289
+ if (settingsObject[decl.prop] && decl.value && decl.value.includes('px') && decl.value.includes('var(--')) {
290
+ const valArr = decl.value.split(' ');
291
+ const settings = settingsObject[decl.prop];
292
+ const {
293
+ range
294
+ } = settings;
295
+ const convertedVals = valArr.map(val => {
296
+ if (val.includes('px')) {
297
+ const convertedVal = singleConvertor(val, settings.replacements.px, {
298
+ decl,
299
+ filename,
300
+ path: fromPath
301
+ }, range);
302
+ return convertedVal ? convertedVal : val;
303
+ }
304
+
305
+ return val;
306
+ });
307
+ decl.value = convertedVals.join(' ');
308
+ }
309
+
288
310
  if (decl.prop && decl.value && !decl.prop.includes('--') && valRegex.test(decl.value) && (settingsObject[decl.prop] || convertableProps[decl.prop]) && decl.value.includes('var') && !decl.value.includes('calc')) {
289
- let errObj = {
311
+ const errObj = {
290
312
  decl,
291
313
  type: 'VARIABLE_PRESENT',
292
314
  filename,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A CLI tool for build modern web application and libraries",
5
5
  "scripts": {
6
6
  "init": "node ./lib/utils/init.js",