@zohodesk/react-cli 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -44,6 +44,12 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.5
48
+
49
+ **Issue Fix**
50
+
51
+ - include pattern fix for variable converter plugin fixed
52
+
47
53
  # 1.1.4
48
54
 
49
55
  **Issue Fix**
@@ -62,7 +62,10 @@ const getCSSLoaders = optionsObj => {
62
62
 
63
63
  return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
64
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);
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) // ,
66
+ // plugins.composeMinification &&
67
+ // require('../postcss-plugins/composePlugin')()
68
+ ].filter(Boolean);
66
69
  return [cssSelectorZipPath && {
67
70
  loader: require.resolve('../loaders/selectorMappingLoader')
68
71
  }, {
@@ -4,12 +4,43 @@ var _path = _interopRequireDefault(require("path"));
4
4
 
5
5
  var _postcss = _interopRequireDefault(require("postcss"));
6
6
 
7
+ var _classHandling = require("../../lib/plugins/utils/classHandling");
8
+
9
+ var _fileHandling = require("../plugins/utils/fileHandling");
10
+
11
+ var _utils = require("../utils");
12
+
13
+ var _ignore = _interopRequireDefault(require("ignore"));
14
+
7
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
16
 
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'];
17
+ const supportedProps = ['margin-top', 'margin-bottom', 'margin-left', 'margin-right', 'margin', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', 'padding', 'top', 'bottom', 'left', 'right', 'height', 'width', 'min-height', 'min-width', 'max-height', 'max-width', 'float', 'overflow', 'position', 'display', 'text-align', 'white-space', 'visibility'];
12
18
  const renameProps = {
19
+ position: {
20
+ cls: 'posn'
21
+ },
22
+ display: {
23
+ cls: 'disp'
24
+ },
25
+ float: {
26
+ cls: 'flo'
27
+ },
28
+ overflow: {
29
+ cls: 'over'
30
+ },
31
+ 'text-align': {
32
+ cls: 'txtAlgn'
33
+ },
34
+ 'white-space': {
35
+ cls: 'whSpc'
36
+ },
37
+ visibility: {
38
+ cls: 'vis'
39
+ },
40
+ 'font-size': {
41
+ pos: 'fs',
42
+ neg: 'fs_'
43
+ },
13
44
  'margin-top': {
14
45
  pos: 'mt',
15
46
  neg: 'mt_'
@@ -96,11 +127,48 @@ function objToClassName(prop, data) {
96
127
  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
128
  }
98
129
 
130
+ function objtoClassNameString(prop, data) {
131
+ let temp = data.toString().replace(/-/gi, '');
132
+ return `${renameProps[prop].cls}_${temp.replace(/\s*/gi, '')}`;
133
+ }
134
+
135
+ const multipleClassName = {
136
+ margin: ['margin-top', 'margin-right', 'margin-bottom', 'margin-left'],
137
+ padding: ['padding-top', 'padding-right', 'padding-bottom', 'padding-left']
138
+ };
139
+
140
+ function objToClassNameMultiple(prop, data) {
141
+ data = data.trim().replace(/\s+/gi, ' ');
142
+ let dataArr = data.split(' ');
143
+
144
+ if (dataArr.length === 3) {
145
+ dataArr[3] = dataArr[1];
146
+ }
147
+
148
+ if (dataArr.length === 2) {
149
+ dataArr[3] = dataArr[1];
150
+ dataArr[2] = dataArr[0];
151
+ }
152
+
153
+ if (dataArr.length === 1) {
154
+ dataArr[3] = dataArr[0];
155
+ dataArr[2] = dataArr[0];
156
+ dataArr[1] = dataArr[0];
157
+ }
158
+
159
+ let composeClasses = '';
160
+ dataArr.forEach((data, index) => composeClasses += `${objToClassName(multipleClassName[prop][index], parseInt(data, 10))} `);
161
+ composeClasses = composeClasses.substring(0, composeClasses.length - 1);
162
+ return composeClasses;
163
+ }
164
+
99
165
  const commonFilePath = {
166
+ margin: 'src/common/css/margin.css',
100
167
  'margin-left': 'src/common/css/margin.css',
101
168
  'margin-right': 'src/common/css/margin.css',
102
169
  'margin-top': 'src/common/css/margin.css',
103
170
  'margin-bottom': 'src/common/css/margin.css',
171
+ padding: 'src/common/css/padding.css',
104
172
  'padding-left': 'src/common/css/padding.css',
105
173
  'padding-right': 'src/common/css/padding.css',
106
174
  'padding-top': 'src/common/css/padding.css',
@@ -114,8 +182,37 @@ const commonFilePath = {
114
182
  'min-height': 'src/common/css/height.css',
115
183
  'min-width': 'src/common/css/width.css',
116
184
  'max-height': 'src/common/css/height.css',
117
- 'max-width': 'src/common/css/width.css'
118
- }; // const preNames = {
185
+ 'max-width': 'src/common/css/width.css',
186
+ fontSize: 'src/common/css/fontSize.css',
187
+ textProps: 'src/common/css/textProps.css',
188
+ display: 'src/common/css/textProps.css',
189
+ float: 'src/common/css/textProps.css',
190
+ overflow: 'src/common/css/textProps.css',
191
+ position: 'src/common/css/position.css',
192
+ 'text-align': 'src/common/css/textProps.css',
193
+ 'white-space': 'src/common/css/textProps.css',
194
+ visibility: 'src/common/css/textProps.css'
195
+ };
196
+
197
+ function generateComposeString(resourcePath, prop, value) {
198
+ let composeString = `from "${_path.default.relative(_path.default.parse(resourcePath).dir, // resourcePath
199
+ commonFilePath[prop]).replace(/\\/gi, '/')}"`;
200
+ let cls = '';
201
+
202
+ if (/^position|^overflow|^display|^float|^text-align|^white-space|^visibility/gi.test(prop)) {
203
+ console.log(prop, value, 'textvals');
204
+ cls = objtoClassNameString(prop, value);
205
+ } else if (/^margin$|^padding$/gi.test(prop)) {
206
+ // console.log(prop, value, 'margin');
207
+ cls = objToClassNameMultiple(prop, value);
208
+ } else {
209
+ // console.log(prop, value, 'common');
210
+ cls = objToClassName(prop, parseInt(value));
211
+ }
212
+
213
+ composeString = `${cls} ${composeString}`;
214
+ return composeString;
215
+ } // const preNames = {
119
216
  // height: 'zd-height-',
120
217
  // 'max-height': 'zd-height-',
121
218
  // 'min-height': 'zd-height-',
@@ -136,6 +233,7 @@ const commonFilePath = {
136
233
  // 'margin-right': 'zd-margin-'
137
234
  // };
138
235
 
236
+
139
237
  function allowParent(rule) {
140
238
  return rule.parent.type === 'root' || rule.parent.type === 'atrule' && rule.parent.name === 'media';
141
239
  }
@@ -144,25 +242,53 @@ module.exports = function (source) {
144
242
  const {
145
243
  resourcePath
146
244
  } = this;
245
+ const options = (0, _utils.getOptions)(); // console.log(options.app.patterns.composeMinification);
246
+ // const ig = ignore({ allowRelativePaths: true }).add(options.app.patterns.composeMinification);
247
+ // const newFilename = path.relative(path.parse(process.cwd()).base, resourcePath);
248
+ // console.log(newFilename, ig.ignores(newFilename));
147
249
 
148
250
  let root = _postcss.default.parse(source);
149
251
 
252
+ if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
253
+ filename: resourcePath,
254
+ filterArr: options.app.patterns.composeMinification
255
+ })) {
256
+ return root.toString();
257
+ }
258
+
150
259
  root.walkRules(rule => {
151
260
  rule.walkDecls(decl => {
261
+ if (/^-ms|^-webkit|^moz/gi.test(decl.prop)) {
262
+ return;
263
+ }
264
+
152
265
  if (!allowParent(rule)) {
153
266
  return;
154
267
  }
155
268
 
269
+ if ((0, _classHandling.isInsideMediaQuery)(rule)) {
270
+ console.log('inside media query', rule.selector);
271
+ return;
272
+ }
273
+
274
+ if (supportedProps.includes(decl.prop) && /^position$|^overflow|^float|^display|^text-align|^white-space|^visibility/gi.test(decl.prop) && !/[,\s+]+|(\w+)\.|:|::|body|(\d+)%|>/gi.test(rule.selector) && commonFilePath[decl.prop] && !decl.value.includes('var(--')) {
275
+ decl.value = generateComposeString(resourcePath, decl.prop, decl.value);
276
+ decl.prop = 'composes';
277
+ return;
278
+ }
279
+
156
280
  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
- }
281
+ // n++ < 10 && console.log(composeString);
282
+ // if (!composeString.includes('src')) {
283
+ // if (/px$/gi.test(decl.value)) {
284
+ decl.value = generateComposeString(resourcePath, decl.prop, decl.value); // }
285
+ // if (/^position$|^display$|^overflow$|^float$/gi.test(decl.prop)) {
286
+ // console.log(decl.prop);
287
+ // }
288
+
289
+ decl.prop = 'composes'; // console.log(decl.prop, decl.value);
290
+ // n < 10 && console.log(rule.selector, decl.prop, decl.value);
291
+ // }
166
292
  }
167
293
  });
168
294
  });
@@ -16,6 +16,8 @@ const path = require('path');
16
16
 
17
17
  const fs = require('fs');
18
18
 
19
+ const ignore = require('ignore');
20
+
19
21
  const postcssVariableConvertor = require('../postcss-plugins/variableModificationPlugin/index').plugin;
20
22
 
21
23
  const cwd = process.cwd();
@@ -45,7 +47,8 @@ function watchHandler(fromPath, toPath) {
45
47
  // errorsAllowed,
46
48
  // strictMode
47
49
 
48
- } = cssVariableOptions;
50
+ } = cssVariableOptions; //Variable Webpack Object Generation
51
+
49
52
  rootOriginal.walkRules(rule => {
50
53
  rule.walkDecls(decl => {
51
54
  decl.value.split(' ').forEach(val => {
@@ -58,23 +61,35 @@ function watchHandler(fromPath, toPath) {
58
61
  }
59
62
  });
60
63
  });
61
- });
64
+ }); // if (
65
+ // !isFileNameMatchingPluginPattern({
66
+ // filename: fromPath,
67
+ // filterArr
68
+ // })
69
+ // ) {
70
+ // return;
71
+ // }
62
72
 
63
- if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
64
- filename: fromPath,
65
- filterArr
66
- })) {
73
+ const ig = ignore({
74
+ allowRelativePaths: true
75
+ }).add(filterArr);
76
+
77
+ if (ig.ignores(fromPath)) {
78
+ // console.log(fromPath);
79
+ // console.log(ig.ignores(fromPath));
80
+ // console.log(
81
+ // '----------------------------------------------------------------'
82
+ // );
67
83
  return;
68
- }
84
+ } // Convert code
69
85
 
70
- const convertedCode = (0, _variableConvertorUtils.variableConverter)(rootOriginal, variables, settingsObject).toString(); // if (convertedCode.trim() !== '') {
71
- // fs.writeFileSync(fromPath, convertedCode);
72
- // }
73
- // console.log(convertedCode);
86
+
87
+ const convertedCode = (0, _variableConvertorUtils.variableConverter)(rootOriginal, variables, settingsObject).toString(); // run postcss plugin for css code input
74
88
 
75
89
  postcss([postcssVariableConvertor(cssVariableConfigFilePath)]).process(convertedCode, {
76
90
  from: undefined
77
91
  }).then(result => {
92
+ //write new css file data in file
78
93
  fs.writeFileSync(toPath, result.css);
79
94
  }); // console.log(variableOptions);
80
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "A CLI tool for build modern web application and libraries",
5
5
  "scripts": {
6
6
  "init": "node ./lib/utils/init.js",