@zohodesk/react-cli 1.1.20-exp.2 → 1.1.20-exp.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -6
- package/bin/cli.js +4 -0
- package/docs/ReactLive.md +1 -5
- package/lib/babel/cmjs-plugins-presets.js +28 -8
- package/lib/babel/es-plugins-presets.js +37 -17
- package/lib/common/getEntries.js +3 -12
- package/lib/configs/jest.config.js +3 -3
- package/lib/configs/webpack.dev.config.js +6 -1
- package/lib/configs/webpack.prod.config.js +8 -3
- package/lib/jest/preProcessors/jsPreprocessor.js +2 -2
- package/lib/loaderUtils/getDevJsLoaders.js +3 -2
- package/lib/loaders/docsLoader.js +2 -2
- package/lib/pluginUtils/getProdPlugins.js +1 -1
- package/lib/schemas/index.js +7 -0
- package/npm-shrinkwrap.json +662 -14486
- package/package.json +6 -1
- package/lib/loaders/enhancedReactLiveConverter.js +0 -151
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zohodesk/react-cli",
|
3
|
-
"version": "1.1.20-exp.
|
3
|
+
"version": "1.1.20-exp.4",
|
4
4
|
"description": "A CLI tool for build modern web application and libraries",
|
5
5
|
"scripts": {
|
6
6
|
"init": "node ./lib/utils/init.js",
|
@@ -98,6 +98,8 @@
|
|
98
98
|
"redux-mock-store": "1.5.4",
|
99
99
|
"rimraf": "3.0.2",
|
100
100
|
"script-loader": "0.7.2",
|
101
|
+
"ts-loader": "8.2.0",
|
102
|
+
"typescript": "5.2.2",
|
101
103
|
"uglifycss": "0.0.29",
|
102
104
|
"url-loader": "4.1.0",
|
103
105
|
"webpack": "4.44.1",
|
@@ -121,5 +123,8 @@
|
|
121
123
|
],
|
122
124
|
"@babel/react"
|
123
125
|
]
|
126
|
+
},
|
127
|
+
"devDependencies": {
|
128
|
+
"@babel/preset-typescript": "7.23.2"
|
124
129
|
}
|
125
130
|
}
|
@@ -1,151 +0,0 @@
|
|
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
|
-
}
|