@zohodesk/react-cli 1.1.0 → 1.1.2-9.exp.3

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.
Files changed (80) hide show
  1. package/.vscode/settings.json +25 -0
  2. package/README.md +453 -34
  3. package/bin/cli.js +25 -52
  4. package/docs/CustomChunks.md +12 -9
  5. package/docs/MarkdownParser.md +18 -0
  6. package/docs/ReactLive.md +8 -0
  7. package/docs/ValueReplacer.md +27 -0
  8. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  9. package/lib/babel/cmjs-plugins-presets.js +36 -7
  10. package/lib/babel/es-plugins-presets.js +45 -16
  11. package/lib/common/runPreProcess.js +71 -0
  12. package/lib/common/splitChunks.js +65 -45
  13. package/lib/common/testPattern.js +9 -9
  14. package/lib/configs/jest.config.js +4 -4
  15. package/lib/configs/libAlias.js +36 -2
  16. package/lib/configs/resolvers.js +7 -4
  17. package/lib/configs/webpack.css.umd.config.js +3 -2
  18. package/lib/configs/webpack.dev.config.js +28 -8
  19. package/lib/configs/webpack.docs.config.js +11 -5
  20. package/lib/configs/webpack.impact.config.js +9 -4
  21. package/lib/configs/webpack.prod.config.js +32 -10
  22. package/lib/constants.js +3 -3
  23. package/lib/deprecationLogger.js +40 -0
  24. package/lib/jest/preProcessors/jsPreprocessor.js +27 -2
  25. package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
  26. package/lib/loaderUtils/getCSSLoaders.js +32 -8
  27. package/lib/loaderUtils/getDevJsLoaders.js +8 -2
  28. package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
  29. package/lib/loaders/composeLoader.js +140 -14
  30. package/lib/loaders/docsLoader.js +5 -2
  31. package/lib/loaders/enhancedReactLiveConverter.js +151 -0
  32. package/lib/loaders/markdownLoader.js +71 -0
  33. package/lib/loaders/reactLiveConvertor.js +64 -66
  34. package/lib/loaders/workerLoader.js +37 -22
  35. package/lib/logger.js +7 -0
  36. package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
  37. package/lib/pluginUtils/getDevPlugins.js +24 -8
  38. package/lib/pluginUtils/getProdPlugins.js +34 -6
  39. package/lib/plugins/CssOrderControlPlugin.js +36 -0
  40. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
  41. package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
  42. package/lib/plugins/EventsHandlingPlugin.js +34 -0
  43. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
  44. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
  45. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
  46. package/lib/plugins/ReportGeneratePlugin.js +8 -6
  47. package/lib/plugins/ResourceHintsPlugin.js +13 -3
  48. package/lib/plugins/StatsPlugin.js +82 -0
  49. package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
  50. package/lib/plugins/utils/fileHandling.js +36 -51
  51. package/lib/plugins/variableConvertorUtils.js +4 -2
  52. package/lib/postcss-plugins/ValueReplacer.js +7 -17
  53. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
  54. package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
  55. package/lib/schemas/index.js +96 -27
  56. package/lib/servers/getCliPath.js +3 -5
  57. package/lib/servers/requireLocalOrGlobal.js +1 -1
  58. package/lib/utils/cssClassNameGenerate.js +43 -5
  59. package/lib/utils/deprecationSupport.js +134 -0
  60. package/lib/utils/getFileType.js +1 -1
  61. package/lib/utils/getOptions.js +34 -43
  62. package/lib/utils/getServerURL.js +7 -2
  63. package/lib/utils/index.js +27 -11
  64. package/lib/utils/initPreCommitHook.js +5 -5
  65. package/lib/utils/log.js +11 -0
  66. package/lib/utils/object-manipulation.js +88 -0
  67. package/lib/utils/pullOrigin.js +3 -3
  68. package/lib/utils/reinstallDependencies.js +3 -3
  69. package/lib/utils/selectorReplacer.js +47 -0
  70. package/lib/utils/switchBranch.js +4 -2
  71. package/lib/utils/typeCheck.js +10 -0
  72. package/lib/utils/variableConverter.js +26 -11
  73. package/npm-shrinkwrap.json +1001 -106
  74. package/package.json +12 -4
  75. package/templates/docs/all.html +1 -0
  76. package/templates/docs/component.html +1 -0
  77. package/templates/docs/components.html +1 -0
  78. package/templates/docs/css/markdown.css +202 -0
  79. package/templates/docs/css/style.css +136 -169
  80. package/templates/docs/index.html +796 -632
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ const {
4
+ markdownParser
5
+ } = require('../markdownLoader'); // Replace './your-file' with the correct file path
6
+
7
+
8
+ describe('markdownParser', () => {
9
+ test('For {}(braces) case', () => {
10
+ const source = `
11
+ /* MD:START
12
+ # {Hi, This is Test Case :)}
13
+ MD:END */
14
+ `;
15
+ const expectedOutput = `
16
+ <><div class="markDown"><h1>&#123;Hi, This is Test Case :)&#125;</h1>
17
+ </div></>
18
+ `;
19
+ expect(markdownParser(source)).toEqual(expectedOutput);
20
+ });
21
+ test('For $ (dollor) case', () => {
22
+ const source = `
23
+ /* MD:START
24
+ # $Hi, This is Test Case :)
25
+ MD:END */
26
+ `;
27
+ const expectedOutput = `
28
+ <><div class="markDown"><h1>&#36;Hi, This is Test Case :)</h1>
29
+ </div></>
30
+ `;
31
+ expect(markdownParser(source)).toEqual(expectedOutput);
32
+ });
33
+ test('For All kind of Tag Cases', () => {
34
+ const source = `
35
+ /* MD:START
36
+ # Markdown File with Variety of Data
37
+
38
+ ## Text
39
+
40
+ This is a paragraph of text.
41
+
42
+ ## Headings
43
+
44
+ ### Heading 1
45
+
46
+ ### Heading 2
47
+
48
+ #### Heading 2.1
49
+
50
+ #### Heading 2.2
51
+
52
+ ## Lists
53
+
54
+ ### Unordered List
55
+
56
+ - Item 1
57
+ - Item 2
58
+ - Item 3
59
+
60
+ ### Ordered List
61
+
62
+ 1. First item
63
+ 2. Second item
64
+ 3. Third item
65
+
66
+ ## Links
67
+
68
+ Here's a link to [OpenAI's website](https://openai.com).
69
+
70
+ ## Images
71
+
72
+ ![Markdown Logo](https://upload.wikimedia.org/wikipedia/commons/4/48/Markdown-mark.svg)
73
+
74
+ ## Tables
75
+
76
+ | Name | Age | Gender |
77
+ |-------|-----|--------|
78
+ | John | 25 | Male |
79
+ | Sarah | 30 | Female |
80
+ | Mark | 35 | Male |
81
+
82
+ MD:END */
83
+ `;
84
+ const expectedOutput = `
85
+ <><div class="markDown"><h1>Markdown File with Variety of Data</h1>
86
+ <h2>Text</h2>
87
+ <p>This is a paragraph of text.</p>
88
+ <h2>Headings</h2>
89
+ <h3>Heading 1</h3>
90
+ <h3>Heading 2</h3>
91
+ <h4>Heading 2.1</h4>
92
+ <h4>Heading 2.2</h4>
93
+ <h2>Lists</h2>
94
+ <h3>Unordered List</h3>
95
+ <ul>
96
+ <li>Item 1</li>
97
+ <li>Item 2</li>
98
+ <li>Item 3</li>
99
+ </ul>
100
+ <h3>Ordered List</h3>
101
+ <ol>
102
+ <li>First item</li>
103
+ <li>Second item</li>
104
+ <li>Third item</li>
105
+ </ol>
106
+ <h2>Links</h2>
107
+ <p>Here's a link to <a href="https://openai.com">OpenAI's website</a>.</p>
108
+ <h2>Images</h2>
109
+ <p><img src="https://upload.wikimedia.org/wikipedia/commons/4/48/Markdown-mark.svg" alt="Markdown Logo"/></p>
110
+ <h2>Tables</h2>
111
+ <table>
112
+ <thead>
113
+ <tr>
114
+ <th>Name</th>
115
+ <th>Age</th>
116
+ <th>Gender</th>
117
+ </tr>
118
+ </thead>
119
+ <tbody>
120
+ <tr>
121
+ <td>John</td>
122
+ <td>25</td>
123
+ <td>Male</td>
124
+ </tr>
125
+ <tr>
126
+ <td>Sarah</td>
127
+ <td>30</td>
128
+ <td>Female</td>
129
+ </tr>
130
+ <tr>
131
+ <td>Mark</td>
132
+ <td>35</td>
133
+ <td>Male</td>
134
+ </tr>
135
+ </tbody>
136
+ </table>
137
+ </div></>
138
+ `;
139
+ expect(markdownParser(source)).toEqual(expectedOutput);
140
+ });
141
+ test('For Source null case', () => {
142
+ expect(markdownParser(null)).toEqual('');
143
+ expect(markdownParser('')).toEqual('');
144
+ });
145
+ });
@@ -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
  });
@@ -6,7 +6,9 @@ var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));
6
6
 
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
 
9
- var _ReactLiveConvertor = require("./ReactLiveConvertor");
9
+ var _enhancedReactLiveConverter = require("./enhancedReactLiveConverter.js");
10
+
11
+ var _markdownLoader = require("./markdownLoader.js");
10
12
 
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
14
 
@@ -24,7 +26,8 @@ module.exports = function (source) {
24
26
 
25
27
  const src = _fs.default.readFileSync(originalFilePath).toString();
26
28
 
27
- options.docs.enableReactLive && (source = (0, _ReactLiveConvertor.reactLiveConvertor)(source, originalFilePath)); //to Enable the ReactLive Converter
29
+ options.docs.enableMDParser && (source = (0, _markdownLoader.markdownParser)(source));
30
+ options.docs.enableReactLive && (source = (0, _enhancedReactLiveConverter.enhancedReactLiveConverter)(source, originalFilePath)); //to Enable the ReactLive Converter
28
31
 
29
32
  return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
30
33
  };
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enhancedReactLiveConverter = enhancedReactLiveConverter;
7
+
8
+ const parser = require('@babel/parser');
9
+
10
+ const traverse = require('@babel/traverse').default;
11
+
12
+ const t = require("@babel/types");
13
+
14
+ const path = require('path');
15
+
16
+ function getFilename(originalFilePath) {
17
+ const [fileName] = path.basename(originalFilePath).split('.');
18
+ return fileName;
19
+ }
20
+
21
+ function convertKeyToValue(object = {}) {
22
+ let keys = Object.keys(object);
23
+ let values = Object.values(object);
24
+ return keys.reduce((value, item, i) => {
25
+ if (item.includes(',')) {
26
+ item = item.replace(/{|}/g, "");
27
+ item = '{ ' + item + ' }';
28
+ }
29
+
30
+ value = value + "'" + values[i] + "'" + ": " + item + ",";
31
+ return value;
32
+ }, '');
33
+ }
34
+
35
+ function mergeDuplicateValues(obj) {
36
+ let mergedObj = {};
37
+
38
+ for (let key in obj) {
39
+ if (obj.hasOwnProperty(key)) {
40
+ let value = obj[key];
41
+ let existingKey = Object.keys(mergedObj).find(k => mergedObj[k] === value);
42
+
43
+ if (existingKey) {
44
+ mergedObj[existingKey + ' , ' + key] = value;
45
+ delete mergedObj[existingKey];
46
+ } else {
47
+ mergedObj[key] = value;
48
+ }
49
+ }
50
+ }
51
+
52
+ return mergedObj;
53
+ }
54
+
55
+ function enhancedReactLiveConverter(source, originalFilePath) {
56
+ const fileName = getFilename(originalFilePath);
57
+
58
+ if (!source) {
59
+ return '';
60
+ }
61
+
62
+ let docCode = '';
63
+ const fileContent = source.replace(/[\s\r\n]*$/, '');
64
+ const ast = parser.parse(fileContent, {
65
+ sourceType: 'module',
66
+ plugins: ['jsx', 'classProperties']
67
+ });
68
+
69
+ function createImportStatements(input) {
70
+ let output = '';
71
+
72
+ for (const key in input) {
73
+ if (input.hasOwnProperty(key) && key !== 'React') {
74
+ output += `import ${key} from '${input[key]}';\n`;
75
+ }
76
+ }
77
+
78
+ return output;
79
+ }
80
+
81
+ const importBlock = {};
82
+ const printableCode = {};
83
+ let remainingBlock = ''; // Traverse the AST and find the import and export blocks
84
+
85
+ let remainingCode = ast.program.body.filter(node => node.type !== 'ImportDeclaration').filter(node => node.type !== 'ExpressionStatement').map(node => fileContent.substring(node.start, node.end)).join('').trim();
86
+ traverse(ast, {
87
+ ImportDeclaration(path) {
88
+ path.node.specifiers.map(specifier => {
89
+ if (t.isImportSpecifier(specifier)) {
90
+ importBlock[`{ ${specifier.local.name} }`] = path.node.source.value;
91
+ printableCode[`{ ${specifier.local.name} }`] = path.node.source.value;
92
+ return `{'${specifier.imported.name}': ${specifier.local.name}}`;
93
+ } else if (t.isImportDefaultSpecifier(specifier)) {
94
+ importBlock[`${specifier.local.name}`] = `${path.node.source.value}`;
95
+ printableCode[`${specifier.local.name}`] = `${path.node.source.value} `;
96
+ return specifier.local.name;
97
+ }
98
+ }).join(", ");
99
+ },
100
+
101
+ ExpressionStatement(path) {
102
+ const expression = path.get('expression');
103
+ const expressionLeft = expression.get('left');
104
+
105
+ if (path.isExpressionStatement() && expression.isAssignmentExpression() && expressionLeft.isMemberExpression()) {
106
+ const docCheck = expressionLeft.toString();
107
+
108
+ if (docCheck === `${fileName}.docs`) {
109
+ docCode = expression.toString();
110
+ } else if (docCheck.includes(fileName)) {
111
+ const startIndex = path.node.start;
112
+ const endIndex = path.node.end;
113
+ remainingBlock += fileContent.slice(startIndex, endIndex);
114
+ }
115
+ }
116
+ }
117
+
118
+ });
119
+ remainingCode = remainingCode.replace(/__DOCS__/, true);
120
+ remainingCode = remainingCode.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
121
+ remainingBlock = remainingBlock.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
122
+ const addBractick = `\`
123
+ ${createImportStatements(printableCode)}
124
+ ${remainingCode}
125
+
126
+ ${remainingBlock}\`
127
+ `;
128
+ const template = `
129
+
130
+ ${createImportStatements(importBlock)}
131
+
132
+ import { LiveProviderv3, LiveEditorv3, LiveErrorv3, LivePreviewv3, Wrapper, EditorWrapper , ErrorWrapper, PreviewWrapper } from '@zohodesk-private/react-live/es/index'
133
+
134
+ export default class ${fileName} extends React.Component{
135
+ render(){
136
+ return(
137
+ <LiveProviderv3 needToolBox scope={{import: {${convertKeyToValue(mergeDuplicateValues(printableCode))}}}} code={${addBractick}}>
138
+ <Wrapper>
139
+ <EditorWrapper><LiveEditorv3 /></EditorWrapper>
140
+ <PreviewWrapper><LivePreviewv3 /></PreviewWrapper>
141
+ <LiveErrorv3 needStyle />
142
+ </Wrapper>
143
+ </LiveProviderv3>
144
+ )
145
+ }
146
+ }
147
+
148
+ ${docCode}
149
+ `;
150
+ return template;
151
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.markdownParser = markdownParser;
7
+
8
+ const markdownIt = require('markdown-it'); // const md = new markdownIt({ linkify: true,breaks:true });
9
+
10
+
11
+ const md = new markdownIt({
12
+ html: false,
13
+ linkify: true,
14
+ typographer: true,
15
+ breaks: true,
16
+ xhtmlOut: true
17
+ }); //const md = new markdownIt();
18
+
19
+ function markdownParser(source) {
20
+ if (!source) {
21
+ return '';
22
+ }
23
+
24
+ const startTag = '/* MD:START';
25
+ const endTag = 'MD:END */'; // Iterate through all occurrences of the tags
26
+
27
+ let startIndex = source.indexOf(startTag);
28
+
29
+ while (startIndex !== -1) {
30
+ const endIndex = source.indexOf(endTag, startIndex);
31
+
32
+ if (endIndex !== -1) {
33
+ const extractedMarkdown = source.slice(startIndex + startTag.length, endIndex);
34
+ let lines = extractedMarkdown.split('\n');
35
+ lines = lines.filter(line => line.trim() !== '');
36
+ const firstLineIndentMatch = lines[0].match(/^\s+/);
37
+ const firstLineIndent = firstLineIndentMatch ? firstLineIndentMatch[0] : '';
38
+ const modifiedStr = lines.map(line => line.replace(new RegExp(`^${firstLineIndent}`), '')).join('\n').replace(/(:--)|(--:)/g, '---');
39
+ let html = md.render(modifiedStr); //html = html.replace(/"|<hr>|<img src=(".*?")>|<br>|:--|--:|{|}|\$/g, match => {
40
+
41
+ html = html.replace(/"|{|}|\$/g, match => {
42
+ // if (match === '<hr>') {
43
+ // return '<hr/>';
44
+ // } else if (match.startsWith('<img src=')) {
45
+ // return match.replace('>', '/>');
46
+ // } else if (match === '<br>') {
47
+ // return '<br/>';
48
+ if (match === '$') {
49
+ return '&#36;';
50
+ } else if (match === '{') {
51
+ return '&#123;';
52
+ } else if (match === '}') {
53
+ return '&#125;';
54
+ } // else if (match === ':--' || match === '--:' ) {
55
+ // return '---';
56
+ // }
57
+ else if (match === '}') {
58
+ return '&#125;';
59
+ }
60
+
61
+ return match;
62
+ }); // console.log(html,"html");
63
+
64
+ source = source.replace(source.slice(startIndex, endIndex + endTag.length), '<><div class="markDown">' + html + '</div></>');
65
+ }
66
+
67
+ startIndex = source.indexOf(startTag, startIndex + 1); // console.log(source)
68
+ }
69
+
70
+ return source;
71
+ }