@rws-framework/client 2.5.4 → 2.6.0

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 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, isOreo } = compInfo;
177
176
 
178
- if(isIgnored){
177
+ if (isIgnored) {
179
178
  return;
180
179
  }
181
180
 
@@ -188,7 +187,8 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []){
188
187
  className,
189
188
  sanitName: className.toLowerCase(),
190
189
  content,
191
- isIgnored: options?.ignorePackaging
190
+ isIgnored: options?.ignorePackaging,
191
+ isOreo: options?.oreoMode
192
192
  });
193
193
  }
194
194
  }
@@ -198,88 +198,88 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []){
198
198
  return fileList;
199
199
  }
200
200
 
201
- function extractRWSViewArguments(sourceFile){
201
+ function extractRWSViewArguments(sourceFile) {
202
202
  let argumentsExtracted = {
203
- className: null,
204
- tagName: null,
205
- options: null
203
+ className: null,
204
+ tagName: null,
205
+ options: null
206
206
  };
207
207
 
208
208
  let foundDecorator = false;
209
-
209
+
210
210
  function visit(node) {
211
- if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
212
- const expression = node.expression;
213
- const decoratorName = expression.expression.getText(sourceFile);
214
- if (decoratorName === 'RWSView') {
215
- foundDecorator = true;
216
- const args = expression.arguments;
217
- if (args.length > 0 && ts.isStringLiteral(args[0])) {
218
- argumentsExtracted.tagName = args[0].text;
219
- }
220
- if (args.length > 1) {
221
- if (ts.isObjectLiteralExpression(args[1])) {
222
- const argVal = args[1].getText(sourceFile);
223
- argumentsExtracted.options = JSON5.parse(argVal);
224
- }
225
- }
226
-
227
- if (node.parent && ts.isClassDeclaration(node.parent)) {
228
- const classNode = node.parent;
229
- if (classNode.name) { // ClassDeclaration.name is optional as classes can be unnamed/anonymous
230
- argumentsExtracted.className = classNode.name.getText(sourceFile);
231
- }
232
- }
211
+ if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
212
+ const expression = node.expression;
213
+ const decoratorName = expression.expression.getText(sourceFile);
214
+ if (decoratorName === 'RWSView') {
215
+ foundDecorator = true;
216
+ const args = expression.arguments;
217
+ if (args.length > 0 && ts.isStringLiteral(args[0])) {
218
+ argumentsExtracted.tagName = args[0].text;
219
+ }
220
+ if (args.length > 1) {
221
+ if (ts.isObjectLiteralExpression(args[1])) {
222
+ const argVal = args[1].getText(sourceFile);
223
+ argumentsExtracted.options = JSON5.parse(argVal);
233
224
  }
225
+ }
226
+
227
+ if (node.parent && ts.isClassDeclaration(node.parent)) {
228
+ const classNode = node.parent;
229
+ if (classNode.name) { // ClassDeclaration.name is optional as classes can be unnamed/anonymous
230
+ argumentsExtracted.className = classNode.name.getText(sourceFile);
231
+ }
232
+ }
234
233
  }
234
+ }
235
235
 
236
- ts.forEachChild(node, visit);
236
+ ts.forEachChild(node, visit);
237
237
  }
238
238
 
239
239
  visit(sourceFile);
240
240
 
241
- if(!foundDecorator){
241
+ if (!foundDecorator) {
242
242
  return null;
243
243
  }
244
244
 
245
245
  return argumentsExtracted;
246
246
  }
247
247
 
248
- function extractRWSIgnoreArguments(sourceFile){
248
+ function extractRWSIgnoreArguments(sourceFile) {
249
249
  let argumentsExtracted = {
250
- params: null,
250
+ params: null,
251
251
  };
252
252
  let foundDecorator = false;
253
253
  let ignored = false;
254
-
254
+
255
255
  function visit(node) {
256
- if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
257
- const expression = node.expression;
258
- const decoratorName = expression.expression.getText(sourceFile);
259
- if (decoratorName === 'RWSView') {
260
- foundDecorator = true;
261
- const args = expression.arguments;
262
-
263
- if (args.length) {
264
- // Assuming the second argument is an object literal
265
- if (ts.isObjectLiteralExpression(args[0])) {
266
- const argVal = args[0].getText(sourceFile);
267
- argumentsExtracted.options = argVal;
268
-
269
- if(argVal.ignorePackaging === true){
270
- ignored = true;
271
- }
272
- }
273
- }
256
+ if (ts.isDecorator(node) && ts.isCallExpression(node.expression)) {
257
+ const expression = node.expression;
258
+ const decoratorName = expression.expression.getText(sourceFile);
259
+ if (decoratorName === 'RWSView') {
260
+ foundDecorator = true;
261
+ const args = expression.arguments;
262
+
263
+ if (args.length) {
264
+ // Assuming the second argument is an object literal
265
+ if (ts.isObjectLiteralExpression(args[0])) {
266
+ const argVal = args[0].getText(sourceFile);
267
+ argumentsExtracted.options = argVal;
268
+
269
+ if (argVal.ignorePackaging === true) {
270
+ ignored = true;
271
+ }
274
272
  }
273
+ }
275
274
  }
275
+ }
276
276
 
277
- ts.forEachChild(node, visit);
277
+ ts.forEachChild(node, visit);
278
278
  }
279
279
 
280
280
  visit(sourceFile);
281
281
 
282
- if(!foundDecorator){
282
+ if (!foundDecorator) {
283
283
  return true;
284
284
  }
285
285
 
@@ -288,8 +288,8 @@ function extractRWSIgnoreArguments(sourceFile){
288
288
 
289
289
  function extractComponentInfo(componentCode) {
290
290
  const componentNameRegex = /\@RWSView/g;
291
-
292
- if(!componentNameRegex.test(componentCode)){
291
+
292
+ if (!componentNameRegex.test(componentCode)) {
293
293
  return;
294
294
  }
295
295
 
@@ -297,92 +297,90 @@ function extractComponentInfo(componentCode) {
297
297
 
298
298
  let decoratorArgs = extractRWSViewArguments(tsSourceFile);
299
299
 
300
- if(!decoratorArgs){
300
+ if (!decoratorArgs) {
301
301
  decoratorArgs = {};
302
302
  }
303
303
 
304
- decoratorOpts = decoratorArgs.options;
304
+ decoratorOpts = decoratorArgs.options;
305
305
 
306
- return {...decoratorArgs, options: decoratorOpts };
306
+ return { ...decoratorArgs, options: decoratorOpts };
307
307
  }
308
308
 
309
309
  function getAllFilesInFolder(folderPath, ignoreFilenames = [], recursive = false) {
310
310
  const files = [];
311
311
  function traverseDirectory(currentPath) {
312
- const entries = fs.readdirSync(currentPath, { withFileTypes: true });
313
- entries.forEach(entry => {
314
- const entryPath = path.join(currentPath, entry.name);
315
- if (entry.isFile()) {
316
- let pass = true;
317
- ignoreFilenames.forEach((regEx) => {
318
- if (regEx.test(entryPath)) {
319
- pass = false;
320
- }
321
- });
322
- if (pass) {
323
- files.push(entryPath);
324
- }
325
- }
326
- else if (entry.isDirectory() && recursive) {
327
- traverseDirectory(entryPath);
312
+ const entries = fs.readdirSync(currentPath, { withFileTypes: true });
313
+ entries.forEach(entry => {
314
+ const entryPath = path.join(currentPath, entry.name);
315
+ if (entry.isFile()) {
316
+ let pass = true;
317
+ ignoreFilenames.forEach((regEx) => {
318
+ if (regEx.test(entryPath)) {
319
+ pass = false;
328
320
  }
329
- });
321
+ });
322
+ if (pass) {
323
+ files.push(entryPath);
324
+ }
325
+ }
326
+ else if (entry.isDirectory() && recursive) {
327
+ traverseDirectory(entryPath);
328
+ }
329
+ });
330
330
  }
331
331
  traverseDirectory(folderPath);
332
332
  return files;
333
333
  }
334
334
 
335
- function setupTsConfig(tsConfigPath, executionDir)
336
- {
337
-
338
- if(!fs.existsSync(tsConfigPath)){
339
- throw new Error(`Typescript config file "${tsConfigPath}" does not exist`);
340
- }
341
-
342
- console.log('tspath', tsConfigPath);
335
+ function setupTsConfig(tsConfigPath, executionDir) {
343
336
 
344
- const tsConfigContents = fs.readFileSync(tsConfigPath, 'utf-8');
337
+ if (!fs.existsSync(tsConfigPath)) {
338
+ throw new Error(`Typescript config file "${tsConfigPath}" does not exist`);
339
+ }
345
340
 
346
- try{
347
- let tsConfig = JSON.parse(tsConfigContents);
341
+ const tsConfigContents = fs.readFileSync(tsConfigPath, 'utf-8');
348
342
 
343
+ try {
344
+ let tsConfig = JSON.parse(tsConfigContents);
345
+
349
346
  const declarationsPath = path.resolve(__dirname, 'types') + '/declarations.d.ts';
350
347
  const testsPath = path.resolve(__dirname, 'tests');
351
348
  const declarationsPathMD5 = md5(fs.readFileSync(declarationsPath, 'utf-8'));
352
- const testsPathMD5 = fs.existsSync(testsPath) ? md5(fs.readFileSync(testsPath, 'utf-8')) : null;
353
-
349
+ const testsPathMD5 = fs.existsSync(testsPath) ? md5(fs.readFileSync(testsPath, 'utf-8')) : null;
350
+
351
+ const relativeDeclarationsPath = path.relative(path.dirname(tsConfigPath), declarationsPath);
352
+ const relativeTestsPath = path.relative(path.dirname(tsConfigPath), testsPath);
353
+
354
354
  const includedMD5 = [];
355
355
 
356
- let changed = false;
356
+ let changed = false;
357
357
 
358
- const included = [];
359
-
360
- if(!Object.keys(tsConfig).includes('include')){
358
+
359
+ if (!Object.keys(tsConfig).includes('include')) {
361
360
  tsConfig['include'] = [];
362
- }else{
363
- tsConfig['include'] = tsConfig['include'].map((inc) => fs.existsSync(rwsPath.relativize(tsConfig['include'], executionDir)))
364
- }
365
-
366
- if(!Object.keys(tsConfig).includes('exclude')){
361
+ } else {
362
+ tsConfig['include'] = tsConfig['include'].filter((inc) => fs.existsSync(rwsPath.relativize(inc, executionDir)))
363
+ }
364
+
365
+ if (!Object.keys(tsConfig).includes('exclude')) {
367
366
  tsConfig['exclude'] = [];
368
- }
369
-
370
- if(!included.includes(declarationsPath) && !includedMD5.includes(declarationsPathMD5)){
367
+ }
368
+
369
+
370
+ if (!tsConfig['include'].includes(relativeDeclarationsPath)) {
371
371
  console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript declarations to project tsconfig.json');
372
- included.push(declarationsPath);
373
- includedMD5.push(md5(fs.readFileSync(declarationsPath, 'utf-8')));
372
+ tsConfig['include'].push(relativeDeclarationsPath);
373
+ includedMD5.push(md5(fs.readFileSync(declarationsPath, 'utf-8')));
374
374
  changed = true;
375
- }
376
-
377
- tsConfig['include'] = included;
378
-
379
- if(testsPathMD5 && (!tsConfig['exclude'].includes(testsPath) && !included.includes(testsPathMD5))){
375
+ }
376
+
377
+ if ((!tsConfig['exclude'].includes(relativeTestsPath))) {
380
378
  console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript exclusions to project tsconfig.json');
381
- tsConfig['exclude'].push(testsPath);
379
+ tsConfig['exclude'].push(relativeTestsPath);
382
380
  changed = true;
383
381
  }
384
-
385
- if(changed){
382
+
383
+ if (changed) {
386
384
  fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
387
385
  console.log(chalk.yellowBright('Typescript config file'), `"${chalk.blueBright(tsConfigPath)}"`, chalk.yellowBright('has been changed'));
388
386
  }
@@ -396,17 +394,35 @@ function setupTsConfig(tsConfigPath, executionDir)
396
394
  }
397
395
  }
398
396
 
397
+ function getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix) {
398
+ return {
399
+ banner: `if(!window.RWS_PARTS_LOADED){
400
+ const script = document.createElement('script');
401
+ script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
402
+ script.type = 'text/javascript';
403
+ document.body.appendChild(script);
404
+ window.RWS_PARTS_LOADED = true;
405
+ console.log('[RWS INIT SCRIPT]', 'vendors injected...');
406
+ }`.replace('\n', ''),
407
+ raw: true,
408
+ entryOnly: true,
409
+ include: `${partedPrefix}.client.js`
410
+ };
411
+ }
412
+
413
+
399
414
  module.exports = {
400
- findRootWorkspacePath,
401
- findPackageDir,
402
- getActiveWorkSpaces,
403
- runCommand,
404
- findComponentFilesWithText,
405
- extractComponentInfo,
406
- extractRWSViewArguments,
407
- extractRWSIgnoreArguments,
408
- findServiceFilesWithClassExtend,
409
- findSuperclassFilePath,
410
- getAllFilesInFolder,
411
- setupTsConfig
415
+ findRootWorkspacePath,
416
+ findPackageDir,
417
+ getActiveWorkSpaces,
418
+ runCommand,
419
+ findComponentFilesWithText,
420
+ extractComponentInfo,
421
+ extractRWSViewArguments,
422
+ extractRWSIgnoreArguments,
423
+ findServiceFilesWithClassExtend,
424
+ findSuperclassFilePath,
425
+ getAllFilesInFolder,
426
+ setupTsConfig,
427
+ getPartedModeVendorsBannerParams
412
428
  }
@@ -5,7 +5,7 @@ const _DEFAULT_CONFIG_VARS = {
5
5
  report: false,
6
6
  publicDir: './public',
7
7
  publicIndex: 'index.html',
8
- outputFileName: 'client.rws.js',
8
+ outputFileName: 'rws.client.js',
9
9
  outputDir: './build',
10
10
  tsConfigPath: './tsconfig.json',
11
11
  //Frontend RWS client configs