@rws-framework/client 2.5.3 → 2.5.5
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/_tools.js +157 -140
- package/cfg/_default.cfg.js +2 -1
- package/package.json +2 -2
- package/rws.webpack.config.js +41 -46
- package/src/client.ts +4 -4
- package/src/services/ConfigService.ts +2 -3
package/_tools.js
CHANGED
|
@@ -7,8 +7,8 @@ const md5 = require('md5');
|
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
const { rwsPath } = require('@rws-framework/console');
|
|
9
9
|
|
|
10
|
-
function findRootWorkspacePath(currentPath) {
|
|
11
|
-
const parentPackageJsonPath = path.join(currentPath + '/..', 'package.json');
|
|
10
|
+
function findRootWorkspacePath(currentPath) {
|
|
11
|
+
const parentPackageJsonPath = path.join(currentPath + '/..', 'package.json');
|
|
12
12
|
const parentPackageDir = path.dirname(parentPackageJsonPath);
|
|
13
13
|
|
|
14
14
|
if (fs.existsSync(parentPackageJsonPath)) {
|
|
@@ -22,22 +22,21 @@ function findRootWorkspacePath(currentPath) {
|
|
|
22
22
|
return currentPath;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function findPackageDir()
|
|
26
|
-
{
|
|
25
|
+
function findPackageDir() {
|
|
27
26
|
return path.resolve(path.dirname(module.id));
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function getActiveWorkSpaces(currentPath, mode = 'all') {
|
|
31
|
-
if(!currentPath){
|
|
29
|
+
function getActiveWorkSpaces(currentPath, mode = 'all') {
|
|
30
|
+
if (!currentPath) {
|
|
32
31
|
throw new Error(`[_tools.js:getActiveWorkSpaces] "currentPath" argument is required.`);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
if(!(['all', 'frontend', 'backend'].includes(mode))){
|
|
34
|
+
if (!(['all', 'frontend', 'backend'].includes(mode))) {
|
|
36
35
|
throw new Error(`[_tools.js:getActiveWorkSpaces] "mode" argument can be only: "frontend", "backend" or "all".`);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const rootPkgDir = findRootWorkspacePath(currentPath)
|
|
40
|
-
const parentPackageJsonPath = path.join(rootPkgDir, 'package.json');
|
|
39
|
+
const parentPackageJsonPath = path.join(rootPkgDir, 'package.json');
|
|
41
40
|
const parentPackageDir = path.dirname(parentPackageJsonPath);
|
|
42
41
|
|
|
43
42
|
if (fs.existsSync(parentPackageJsonPath)) {
|
|
@@ -45,19 +44,19 @@ function getActiveWorkSpaces(currentPath, mode = 'all') {
|
|
|
45
44
|
|
|
46
45
|
if (packageJson.workspaces) {
|
|
47
46
|
return packageJson.workspaces.map((workspaceName) => path.join(rootPkgDir, workspaceName)).filter((workspaceDir) => {
|
|
48
|
-
if(mode === 'all'){
|
|
47
|
+
if (mode === 'all') {
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
let rwsPkgName = '@rws-framework/server';
|
|
53
52
|
|
|
54
|
-
if(mode === 'frontend'){
|
|
53
|
+
if (mode === 'frontend') {
|
|
55
54
|
rwsPkgName = '@rws-framework/client';
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
let hasDesiredPackage = false;
|
|
59
58
|
|
|
60
|
-
const workspaceWebpackFilePath = path.join(workspaceDir, 'package.json');
|
|
59
|
+
const workspaceWebpackFilePath = path.join(workspaceDir, 'package.json');
|
|
61
60
|
const workspacePackageJson = JSON.parse(fs.readFileSync(workspaceWebpackFilePath, 'utf-8'));
|
|
62
61
|
|
|
63
62
|
if (workspacePackageJson.dependencies && (!!workspacePackageJson.dependencies[rwsPkgName])) {
|
|
@@ -72,16 +71,16 @@ function getActiveWorkSpaces(currentPath, mode = 'all') {
|
|
|
72
71
|
return [currentPath];
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
async function runCommand(command, cwd = null, silent = false, extraArgs = { env: {}}) {
|
|
74
|
+
async function runCommand(command, cwd = null, silent = false, extraArgs = { env: {} }) {
|
|
76
75
|
return new Promise((resolve, reject) => {
|
|
77
76
|
const [cmd, ...args] = command.split(' ');
|
|
78
|
-
|
|
79
|
-
if(!cwd){
|
|
77
|
+
|
|
78
|
+
if (!cwd) {
|
|
80
79
|
console.log(`[RWS] Setting default CWD for "${command}"`);
|
|
81
80
|
cwd = process.cwd();
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
|
|
85
84
|
const env = { ...process.env, ...extraArgs.env };
|
|
86
85
|
|
|
87
86
|
console.log(`[RWS] Running command "${command}" from "${cwd}"`);
|
|
@@ -101,7 +100,7 @@ async function runCommand(command, cwd = null, silent = false, extraArgs = { env
|
|
|
101
100
|
});
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
function findSuperclassFilePath(entryFile){
|
|
103
|
+
function findSuperclassFilePath(entryFile) {
|
|
105
104
|
const program = ts.createProgram([entryFile], {
|
|
106
105
|
target: ts.ScriptTarget.ES5,
|
|
107
106
|
module: ts.ModuleKind.CommonJS
|
|
@@ -136,7 +135,7 @@ function findSuperclassFilePath(entryFile){
|
|
|
136
135
|
return null; // Return null if no superclass or file path is found
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
function findServiceFilesWithClassExtend(dir, classPath){
|
|
138
|
+
function findServiceFilesWithClassExtend(dir, classPath) {
|
|
140
139
|
const files = fs.readdirSync(dir);
|
|
141
140
|
let results = []
|
|
142
141
|
|
|
@@ -144,11 +143,11 @@ function findServiceFilesWithClassExtend(dir, classPath){
|
|
|
144
143
|
const filePath = path.join(dir, file);
|
|
145
144
|
const fileStat = fs.statSync(filePath);
|
|
146
145
|
|
|
147
|
-
if (fileStat.isDirectory()) {
|
|
146
|
+
if (fileStat.isDirectory()) {
|
|
148
147
|
results = [...results, ...findServiceFilesWithClassExtend(filePath, classPath)];
|
|
149
|
-
} else if (fileStat.isFile() && filePath.endsWith('.ts')) {
|
|
150
|
-
const foundPath = findSuperclassFilePath(filePath);
|
|
151
|
-
if(foundPath === classPath){
|
|
148
|
+
} else if (fileStat.isFile() && filePath.endsWith('.ts')) {
|
|
149
|
+
const foundPath = findSuperclassFilePath(filePath);
|
|
150
|
+
if (foundPath === classPath) {
|
|
152
151
|
results = [...results, filePath];
|
|
153
152
|
}
|
|
154
153
|
};
|
|
@@ -157,7 +156,7 @@ function findServiceFilesWithClassExtend(dir, classPath){
|
|
|
157
156
|
return results;
|
|
158
157
|
}
|
|
159
158
|
|
|
160
|
-
function findComponentFilesWithText(dir, text, ignored = [], fileList = []){
|
|
159
|
+
function findComponentFilesWithText(dir, text, ignored = [], fileList = []) {
|
|
161
160
|
const files = fs.readdirSync(dir);
|
|
162
161
|
|
|
163
162
|
files.forEach(file => {
|
|
@@ -167,15 +166,15 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []){
|
|
|
167
166
|
if (fileStat.isDirectory() && !ignored.includes(file)) {
|
|
168
167
|
// Recursively search this directory
|
|
169
168
|
findComponentFilesWithText(filePath, text, ignored, fileList);
|
|
170
|
-
} else if (fileStat.isFile() && filePath.endsWith('.ts')) {
|
|
169
|
+
} else if (fileStat.isFile() && filePath.endsWith('.ts')) {
|
|
171
170
|
// Read file content and check for text
|
|
172
171
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
173
|
-
if (content.includes(text)) {
|
|
172
|
+
if (content.includes(text)) {
|
|
174
173
|
const compInfo = extractComponentInfo(content);
|
|
175
|
-
if(compInfo){
|
|
176
|
-
const {tagName, className, options, isIgnored} = compInfo;
|
|
174
|
+
if (compInfo) {
|
|
175
|
+
const { tagName, className, options, isIgnored } = compInfo;
|
|
177
176
|
|
|
178
|
-
if(isIgnored){
|
|
177
|
+
if (isIgnored) {
|
|
179
178
|
return;
|
|
180
179
|
}
|
|
181
180
|
|
|
@@ -198,88 +197,88 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []){
|
|
|
198
197
|
return fileList;
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
function extractRWSViewArguments(sourceFile){
|
|
200
|
+
function extractRWSViewArguments(sourceFile) {
|
|
202
201
|
let argumentsExtracted = {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
className: null,
|
|
203
|
+
tagName: null,
|
|
204
|
+
options: null
|
|
206
205
|
};
|
|
207
206
|
|
|
208
207
|
let foundDecorator = false;
|
|
209
|
-
|
|
208
|
+
|
|
210
209
|
function visit(node) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
}
|
|
210
|
+
if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
|
|
211
|
+
const expression = node.expression;
|
|
212
|
+
const decoratorName = expression.expression.getText(sourceFile);
|
|
213
|
+
if (decoratorName === 'RWSView') {
|
|
214
|
+
foundDecorator = true;
|
|
215
|
+
const args = expression.arguments;
|
|
216
|
+
if (args.length > 0 && ts.isStringLiteral(args[0])) {
|
|
217
|
+
argumentsExtracted.tagName = args[0].text;
|
|
218
|
+
}
|
|
219
|
+
if (args.length > 1) {
|
|
220
|
+
if (ts.isObjectLiteralExpression(args[1])) {
|
|
221
|
+
const argVal = args[1].getText(sourceFile);
|
|
222
|
+
argumentsExtracted.options = JSON5.parse(argVal);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (node.parent && ts.isClassDeclaration(node.parent)) {
|
|
227
|
+
const classNode = node.parent;
|
|
228
|
+
if (classNode.name) { // ClassDeclaration.name is optional as classes can be unnamed/anonymous
|
|
229
|
+
argumentsExtracted.className = classNode.name.getText(sourceFile);
|
|
233
230
|
}
|
|
231
|
+
}
|
|
234
232
|
}
|
|
233
|
+
}
|
|
235
234
|
|
|
236
|
-
|
|
235
|
+
ts.forEachChild(node, visit);
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
visit(sourceFile);
|
|
240
239
|
|
|
241
|
-
if(!foundDecorator){
|
|
240
|
+
if (!foundDecorator) {
|
|
242
241
|
return null;
|
|
243
242
|
}
|
|
244
243
|
|
|
245
244
|
return argumentsExtracted;
|
|
246
245
|
}
|
|
247
246
|
|
|
248
|
-
function extractRWSIgnoreArguments(sourceFile){
|
|
247
|
+
function extractRWSIgnoreArguments(sourceFile) {
|
|
249
248
|
let argumentsExtracted = {
|
|
250
|
-
|
|
249
|
+
params: null,
|
|
251
250
|
};
|
|
252
251
|
let foundDecorator = false;
|
|
253
252
|
let ignored = false;
|
|
254
|
-
|
|
253
|
+
|
|
255
254
|
function visit(node) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
}
|
|
255
|
+
if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
|
|
256
|
+
const expression = node.expression;
|
|
257
|
+
const decoratorName = expression.expression.getText(sourceFile);
|
|
258
|
+
if (decoratorName === 'RWSView') {
|
|
259
|
+
foundDecorator = true;
|
|
260
|
+
const args = expression.arguments;
|
|
261
|
+
|
|
262
|
+
if (args.length) {
|
|
263
|
+
// Assuming the second argument is an object literal
|
|
264
|
+
if (ts.isObjectLiteralExpression(args[0])) {
|
|
265
|
+
const argVal = args[0].getText(sourceFile);
|
|
266
|
+
argumentsExtracted.options = argVal;
|
|
267
|
+
|
|
268
|
+
if (argVal.ignorePackaging === true) {
|
|
269
|
+
ignored = true;
|
|
270
|
+
}
|
|
274
271
|
}
|
|
272
|
+
}
|
|
275
273
|
}
|
|
274
|
+
}
|
|
276
275
|
|
|
277
|
-
|
|
276
|
+
ts.forEachChild(node, visit);
|
|
278
277
|
}
|
|
279
278
|
|
|
280
279
|
visit(sourceFile);
|
|
281
280
|
|
|
282
|
-
if(!foundDecorator){
|
|
281
|
+
if (!foundDecorator) {
|
|
283
282
|
return true;
|
|
284
283
|
}
|
|
285
284
|
|
|
@@ -288,8 +287,8 @@ function extractRWSIgnoreArguments(sourceFile){
|
|
|
288
287
|
|
|
289
288
|
function extractComponentInfo(componentCode) {
|
|
290
289
|
const componentNameRegex = /\@RWSView/g;
|
|
291
|
-
|
|
292
|
-
if(!componentNameRegex.test(componentCode)){
|
|
290
|
+
|
|
291
|
+
if (!componentNameRegex.test(componentCode)) {
|
|
293
292
|
return;
|
|
294
293
|
}
|
|
295
294
|
|
|
@@ -297,89 +296,89 @@ function extractComponentInfo(componentCode) {
|
|
|
297
296
|
|
|
298
297
|
let decoratorArgs = extractRWSViewArguments(tsSourceFile);
|
|
299
298
|
|
|
300
|
-
if(!decoratorArgs){
|
|
299
|
+
if (!decoratorArgs) {
|
|
301
300
|
decoratorArgs = {};
|
|
302
301
|
}
|
|
303
302
|
|
|
304
|
-
decoratorOpts = decoratorArgs.options;
|
|
303
|
+
decoratorOpts = decoratorArgs.options;
|
|
305
304
|
|
|
306
|
-
return {...decoratorArgs, options: decoratorOpts };
|
|
305
|
+
return { ...decoratorArgs, options: decoratorOpts };
|
|
307
306
|
}
|
|
308
307
|
|
|
309
308
|
function getAllFilesInFolder(folderPath, ignoreFilenames = [], recursive = false) {
|
|
310
309
|
const files = [];
|
|
311
310
|
function traverseDirectory(currentPath) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
if (pass) {
|
|
323
|
-
files.push(entryPath);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else if (entry.isDirectory() && recursive) {
|
|
327
|
-
traverseDirectory(entryPath);
|
|
311
|
+
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
|
|
312
|
+
entries.forEach(entry => {
|
|
313
|
+
const entryPath = path.join(currentPath, entry.name);
|
|
314
|
+
if (entry.isFile()) {
|
|
315
|
+
let pass = true;
|
|
316
|
+
ignoreFilenames.forEach((regEx) => {
|
|
317
|
+
if (regEx.test(entryPath)) {
|
|
318
|
+
pass = false;
|
|
328
319
|
}
|
|
329
|
-
|
|
320
|
+
});
|
|
321
|
+
if (pass) {
|
|
322
|
+
files.push(entryPath);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (entry.isDirectory() && recursive) {
|
|
326
|
+
traverseDirectory(entryPath);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
330
329
|
}
|
|
331
330
|
traverseDirectory(folderPath);
|
|
332
331
|
return files;
|
|
333
332
|
}
|
|
334
333
|
|
|
335
|
-
function setupTsConfig(tsConfigPath, executionDir)
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if(!fs.existsSync(tsConfigPath)){
|
|
334
|
+
function setupTsConfig(tsConfigPath, executionDir) {
|
|
335
|
+
|
|
336
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
339
337
|
throw new Error(`Typescript config file "${tsConfigPath}" does not exist`);
|
|
340
|
-
}
|
|
338
|
+
}
|
|
341
339
|
|
|
342
|
-
const tsConfigContents = fs.readFileSync(tsConfigPath, 'utf-8');
|
|
340
|
+
const tsConfigContents = fs.readFileSync(tsConfigPath, 'utf-8');
|
|
343
341
|
|
|
344
|
-
try{
|
|
345
|
-
|
|
342
|
+
try {
|
|
343
|
+
let tsConfig = JSON.parse(tsConfigContents);
|
|
346
344
|
|
|
347
345
|
const declarationsPath = path.resolve(__dirname, 'types') + '/declarations.d.ts';
|
|
348
346
|
const testsPath = path.resolve(__dirname, 'tests');
|
|
349
347
|
const declarationsPathMD5 = md5(fs.readFileSync(declarationsPath, 'utf-8'));
|
|
350
|
-
const testsPathMD5 = md5(fs.readFileSync(testsPath, 'utf-8'));
|
|
351
|
-
|
|
348
|
+
const testsPathMD5 = fs.existsSync(testsPath) ? md5(fs.readFileSync(testsPath, 'utf-8')) : null;
|
|
349
|
+
|
|
350
|
+
const includedMD5 = [];
|
|
351
|
+
|
|
352
|
+
let changed = false;
|
|
353
|
+
|
|
352
354
|
const included = [];
|
|
353
355
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if(!Object.keys(tsConfig).includes('include')){
|
|
356
|
+
if (!Object.keys(tsConfig).includes('include')) {
|
|
357
357
|
tsConfig['include'] = [];
|
|
358
|
-
}else{
|
|
358
|
+
} else {
|
|
359
359
|
tsConfig['include'] = tsConfig['include'].map((inc) => fs.existsSync(rwsPath.relativize(tsConfig['include'], executionDir)))
|
|
360
360
|
}
|
|
361
|
-
|
|
362
|
-
if(!Object.keys(tsConfig).includes('exclude')){
|
|
361
|
+
|
|
362
|
+
if (!Object.keys(tsConfig).includes('exclude')) {
|
|
363
363
|
tsConfig['exclude'] = [];
|
|
364
364
|
}
|
|
365
|
-
|
|
366
|
-
if(!
|
|
365
|
+
|
|
366
|
+
if (!included.includes(declarationsPath) && !includedMD5.includes(declarationsPathMD5)) {
|
|
367
367
|
console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript declarations to project tsconfig.json');
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
included.push(declarationsPath);
|
|
369
|
+
includedMD5.push(md5(fs.readFileSync(declarationsPath, 'utf-8')));
|
|
370
370
|
changed = true;
|
|
371
371
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
372
|
+
|
|
373
|
+
tsConfig['include'] = included;
|
|
374
|
+
|
|
375
|
+
if (testsPathMD5 && (!tsConfig['exclude'].includes(testsPath) && !included.includes(testsPathMD5))) {
|
|
375
376
|
console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript exclusions to project tsconfig.json');
|
|
376
377
|
tsConfig['exclude'].push(testsPath);
|
|
377
|
-
included.push();
|
|
378
|
-
|
|
379
378
|
changed = true;
|
|
380
379
|
}
|
|
381
|
-
|
|
382
|
-
if(changed){
|
|
380
|
+
|
|
381
|
+
if (changed) {
|
|
383
382
|
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
|
|
384
383
|
console.log(chalk.yellowBright('Typescript config file'), `"${chalk.blueBright(tsConfigPath)}"`, chalk.yellowBright('has been changed'));
|
|
385
384
|
}
|
|
@@ -393,17 +392,35 @@ function setupTsConfig(tsConfigPath, executionDir)
|
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
|
|
395
|
+
function getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix) {
|
|
396
|
+
return {
|
|
397
|
+
banner: `if(!window.RWS_PARTS_LOADED){
|
|
398
|
+
const script = document.createElement('script');
|
|
399
|
+
script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
|
|
400
|
+
script.type = 'text/javascript';
|
|
401
|
+
document.body.appendChild(script);
|
|
402
|
+
window.RWS_PARTS_LOADED = true;
|
|
403
|
+
console.log('[RWS INIT SCRIPT]', 'vendors injected...');
|
|
404
|
+
}`.replace('\n', ''),
|
|
405
|
+
raw: true,
|
|
406
|
+
entryOnly: true,
|
|
407
|
+
include: `${partedPrefix}.client.js`
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
|
|
396
412
|
module.exports = {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
413
|
+
findRootWorkspacePath,
|
|
414
|
+
findPackageDir,
|
|
415
|
+
getActiveWorkSpaces,
|
|
416
|
+
runCommand,
|
|
417
|
+
findComponentFilesWithText,
|
|
418
|
+
extractComponentInfo,
|
|
419
|
+
extractRWSViewArguments,
|
|
420
|
+
extractRWSIgnoreArguments,
|
|
421
|
+
findServiceFilesWithClassExtend,
|
|
422
|
+
findSuperclassFilePath,
|
|
423
|
+
getAllFilesInFolder,
|
|
424
|
+
setupTsConfig,
|
|
425
|
+
getPartedModeVendorsBannerParams
|
|
409
426
|
}
|
package/cfg/_default.cfg.js
CHANGED
|
@@ -5,8 +5,9 @@ const _DEFAULT_CONFIG_VARS = {
|
|
|
5
5
|
report: false,
|
|
6
6
|
publicDir: './public',
|
|
7
7
|
publicIndex: 'index.html',
|
|
8
|
-
outputFileName: 'client.
|
|
8
|
+
outputFileName: 'rws.client.js',
|
|
9
9
|
outputDir: './build',
|
|
10
|
+
tsConfigPath: './tsconfig.json',
|
|
10
11
|
//Frontend RWS client configs
|
|
11
12
|
backendUrl: null,
|
|
12
13
|
wsUrl: null,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rws-framework/client",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.5",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"docs": "typedoc --tsconfig ./tsconfig.json"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@microsoft/fast-element": "^1.12.0",
|
|
30
30
|
"@microsoft/fast-foundation": "^2.46.2",
|
|
31
|
-
"@rws-framework/console": "^0.3.
|
|
31
|
+
"@rws-framework/console": "^0.3.2",
|
|
32
32
|
"@types/moment": "^2.13.0",
|
|
33
33
|
"dragula": "^3.7.3",
|
|
34
34
|
"he": "^1.2.0",
|
package/rws.webpack.config.js
CHANGED
|
@@ -4,7 +4,7 @@ const webpack = require('webpack');
|
|
|
4
4
|
const uglify = require('uglify-js')
|
|
5
5
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
6
6
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
7
|
-
|
|
7
|
+
const chalk = require('chalk');
|
|
8
8
|
const RWSAfterPlugin = require('./webpack/rws_after_plugin');
|
|
9
9
|
const tools = require('./_tools');
|
|
10
10
|
const { _DEFAULT_CONFIG } = require('./cfg/_default.cfg');
|
|
@@ -16,6 +16,8 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
|
16
16
|
const JsMinimizerPlugin = require('terser-webpack-plugin');
|
|
17
17
|
|
|
18
18
|
const json5 = require('json5');
|
|
19
|
+
const { rwsPath } = require('@rws-framework/console');
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
const RWSWebpackWrapper = (config) => {
|
|
@@ -25,17 +27,17 @@ const RWSWebpackWrapper = (config) => {
|
|
|
25
27
|
|
|
26
28
|
const executionDir = RWSPath.relativize(BuildConfigurator.get('executionDir') || config.executionDir || process.cwd(), config.packageDir);
|
|
27
29
|
|
|
28
|
-
const isDev = BuildConfigurator.get('dev'
|
|
29
|
-
const isHotReload = BuildConfigurator.get('hot'
|
|
30
|
-
const isReport = BuildConfigurator.get('report'
|
|
30
|
+
const isDev = BuildConfigurator.get('dev', config.dev);
|
|
31
|
+
const isHotReload = BuildConfigurator.get('hot', config.hot) ;
|
|
32
|
+
const isReport = BuildConfigurator.get('report', config.report);
|
|
33
|
+
const isParted = BuildConfigurator.get('parted', config.parted || false);
|
|
31
34
|
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix') || config.partedDirUrlPrefix;
|
|
35
|
+
const partedPrefix = BuildConfigurator.get('partedPrefix', config.partedPrefix);
|
|
36
|
+
const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix', config.partedDirUrlPrefix);
|
|
35
37
|
|
|
36
|
-
const partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations'
|
|
37
|
-
const customServiceLocations = BuildConfigurator.get('customServiceLocations'
|
|
38
|
-
const outputDir = RWSPath.relativize(BuildConfigurator.get('outputDir'
|
|
38
|
+
const partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations', config.partedComponentsLocations);
|
|
39
|
+
const customServiceLocations = BuildConfigurator.get('customServiceLocations', config.customServiceLocations);
|
|
40
|
+
const outputDir = RWSPath.relativize(BuildConfigurator.get('outputDir', config.outputDir), config.packageDir);
|
|
39
41
|
|
|
40
42
|
const outputFileName = BuildConfigurator.get('outputFileName') || config.outputFileName;
|
|
41
43
|
const publicDir = BuildConfigurator.get('publicDir') || config.publicDir;
|
|
@@ -43,6 +45,26 @@ const RWSWebpackWrapper = (config) => {
|
|
|
43
45
|
|
|
44
46
|
const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
|
|
45
47
|
|
|
48
|
+
|
|
49
|
+
const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
RWSPath.removeDirectory(outputDir, true);
|
|
53
|
+
|
|
54
|
+
console.log(chalk.green('Build started with'))
|
|
55
|
+
console.log({
|
|
56
|
+
executionDir,
|
|
57
|
+
tsConfigPath,
|
|
58
|
+
outputDir,
|
|
59
|
+
dev: isDev,
|
|
60
|
+
publicDir,
|
|
61
|
+
parted: isParted,
|
|
62
|
+
partedPrefix,
|
|
63
|
+
partedDirUrlPrefix
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
//AFTER OPTION DEFINITIONS
|
|
46
68
|
|
|
47
69
|
let WEBPACK_PLUGINS = [
|
|
48
70
|
new webpack.DefinePlugin({
|
|
@@ -52,21 +74,6 @@ const RWSWebpackWrapper = (config) => {
|
|
|
52
74
|
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
|
|
53
75
|
];
|
|
54
76
|
|
|
55
|
-
// if(isParted){
|
|
56
|
-
// WEBPACK_PLUGINS.push(new webpack.BannerPlugin({
|
|
57
|
-
// banner: `if(!window.RWS_PARTS_LOADED){
|
|
58
|
-
// const script = document.createElement('script');
|
|
59
|
-
// script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
|
|
60
|
-
// script.type = 'text/javascript';
|
|
61
|
-
// document.body.appendChild(script);
|
|
62
|
-
// window.RWS_PARTS_LOADED = true;
|
|
63
|
-
// }`.replace('\n', ''),
|
|
64
|
-
// raw: true,
|
|
65
|
-
// entryOnly: true,
|
|
66
|
-
// // include: 'client'
|
|
67
|
-
// }));
|
|
68
|
-
// }
|
|
69
|
-
|
|
70
77
|
const WEBPACK_AFTER_ACTIONS = config.actions || [];
|
|
71
78
|
|
|
72
79
|
const aliases = config.aliases = {};
|
|
@@ -114,7 +121,7 @@ const RWSWebpackWrapper = (config) => {
|
|
|
114
121
|
WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS }));
|
|
115
122
|
}
|
|
116
123
|
|
|
117
|
-
const
|
|
124
|
+
const rwsInfoJson = outputDir + '/rws_info.json'
|
|
118
125
|
const automatedEntries = {};
|
|
119
126
|
|
|
120
127
|
const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', '@rws-framework/client']);
|
|
@@ -136,18 +143,7 @@ const RWSWebpackWrapper = (config) => {
|
|
|
136
143
|
|
|
137
144
|
const optimConfig = {
|
|
138
145
|
minimize: true,
|
|
139
|
-
minimizer:
|
|
140
|
-
new TerserPlugin({
|
|
141
|
-
terserOptions: {
|
|
142
|
-
mangle: false, //@error breaks FAST view stuff if enabled for all assets
|
|
143
|
-
output: {
|
|
144
|
-
comments: false
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
extractComments: false,
|
|
148
|
-
parallel: true,
|
|
149
|
-
})
|
|
150
|
-
] : [
|
|
146
|
+
minimizer: [
|
|
151
147
|
new TerserPlugin({
|
|
152
148
|
terserOptions: {
|
|
153
149
|
keep_classnames: true, // Prevent mangling of class names
|
|
@@ -168,6 +164,8 @@ const RWSWebpackWrapper = (config) => {
|
|
|
168
164
|
};
|
|
169
165
|
|
|
170
166
|
if (isParted) {
|
|
167
|
+
WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix)));
|
|
168
|
+
|
|
171
169
|
if (partedComponentsLocations) {
|
|
172
170
|
partedComponentsLocations.forEach((componentDir) => {
|
|
173
171
|
RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', '@rws-framework/client']))];
|
|
@@ -185,7 +183,8 @@ const RWSWebpackWrapper = (config) => {
|
|
|
185
183
|
automatedEntries[fileInfo.sanitName] = fileInfo.filePath;
|
|
186
184
|
});
|
|
187
185
|
|
|
188
|
-
fs.writeFileSync(
|
|
186
|
+
fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
|
|
187
|
+
|
|
189
188
|
optimConfig.splitChunks = {
|
|
190
189
|
cacheGroups: {
|
|
191
190
|
vendor: {
|
|
@@ -212,18 +211,14 @@ const RWSWebpackWrapper = (config) => {
|
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
};
|
|
215
|
-
} else {
|
|
216
|
-
if (fs.existsSync(splitInfoJson)) {
|
|
217
|
-
fs.unlinkSync(splitInfoJson);
|
|
218
|
-
}
|
|
219
214
|
}
|
|
220
215
|
|
|
221
|
-
const tsValidated = tools.setupTsConfig(
|
|
216
|
+
const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir);
|
|
222
217
|
|
|
223
218
|
if(!tsValidated){
|
|
224
219
|
throw new Error('RWS Webpack build failed.');
|
|
225
220
|
}
|
|
226
|
-
|
|
221
|
+
|
|
227
222
|
const cfgExport = {
|
|
228
223
|
entry: {
|
|
229
224
|
client: config.entry,
|
|
@@ -276,7 +271,7 @@ const RWSWebpackWrapper = (config) => {
|
|
|
276
271
|
loader: 'ts-loader',
|
|
277
272
|
options: {
|
|
278
273
|
allowTsInNodeModules: true,
|
|
279
|
-
configFile: path.resolve(
|
|
274
|
+
configFile: path.resolve(tsConfigPath)
|
|
280
275
|
}
|
|
281
276
|
},
|
|
282
277
|
{
|
package/src/client.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface IHotModule extends NodeModule {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
type RWSInfoType = { components: string[] };
|
|
36
36
|
type RWSEventListener = (event: CustomEvent) => void;
|
|
37
37
|
|
|
38
38
|
class RWSClient {
|
|
@@ -221,9 +221,9 @@ class RWSClient {
|
|
|
221
221
|
async loadPartedComponents(): Promise<void> {
|
|
222
222
|
this.assignClientToBrowser();
|
|
223
223
|
|
|
224
|
-
const componentParts:
|
|
224
|
+
const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
|
|
225
225
|
|
|
226
|
-
componentParts.forEach((componentName: string, key: number) => {
|
|
226
|
+
componentParts.components.forEach((componentName: string, key: number) => {
|
|
227
227
|
const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
|
|
228
228
|
|
|
229
229
|
const script: HTMLScriptElement = document.createElement('script');
|
|
@@ -232,7 +232,7 @@ class RWSClient {
|
|
|
232
232
|
script.type = 'text/javascript';
|
|
233
233
|
document.body.appendChild(script);
|
|
234
234
|
|
|
235
|
-
console.log(`Appended ${componentParts[key]} component (${partUrl})`);
|
|
235
|
+
console.log(`Appended ${componentParts.components[key]} component (${partUrl})`);
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -46,10 +46,9 @@ class ConfigService extends TheService {
|
|
|
46
46
|
if(defaultVal && defaultVal[0] === '@'){
|
|
47
47
|
defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
return defaultVal;
|
|
51
|
-
}
|
|
52
|
-
|
|
51
|
+
}
|
|
53
52
|
|
|
54
53
|
return this.data[key as keyof IRWSConfig];
|
|
55
54
|
}
|