@rws-framework/client 2.1.8 → 2.2.1

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
@@ -303,6 +303,32 @@ function extractComponentInfo(componentCode) {
303
303
  return {...decoratorArgs, options: decoratorOpts };
304
304
  }
305
305
 
306
+ function getAllFilesInFolder(folderPath, ignoreFilenames = [], recursive = false) {
307
+ const files = [];
308
+ function traverseDirectory(currentPath) {
309
+ const entries = fs.readdirSync(currentPath, { withFileTypes: true });
310
+ entries.forEach(entry => {
311
+ const entryPath = path.join(currentPath, entry.name);
312
+ if (entry.isFile()) {
313
+ let pass = true;
314
+ ignoreFilenames.forEach((regEx) => {
315
+ if (regEx.test(entryPath)) {
316
+ pass = false;
317
+ }
318
+ });
319
+ if (pass) {
320
+ files.push(entryPath);
321
+ }
322
+ }
323
+ else if (entry.isDirectory() && recursive) {
324
+ traverseDirectory(entryPath);
325
+ }
326
+ });
327
+ }
328
+ traverseDirectory(folderPath);
329
+ return files;
330
+ }
331
+
306
332
  module.exports = {
307
333
  findRootWorkspacePath,
308
334
  findPackageDir,
@@ -313,5 +339,6 @@ module.exports = {
313
339
  extractRWSViewArguments,
314
340
  extractRWSIgnoreArguments,
315
341
  findServiceFilesWithClassExtend,
316
- findSuperclassFilePath
342
+ findSuperclassFilePath,
343
+ getAllFilesInFolder
317
344
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.1.8",
4
+ "version": "2.2.1",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -11,6 +11,9 @@ const { Console } = require('console');
11
11
  const { Interface } = require('readline');
12
12
  const ts = require('typescript');
13
13
  const tools = require('./_tools');
14
+ const TerserPlugin = require('terser-webpack-plugin');
15
+ const HtmlMinifier = require('html-minifier').minify;
16
+ const { CleanWebpackPlugin } = require("clean-webpack-plugin");
14
17
 
15
18
  let WEBPACK_PLUGINS = [];
16
19
 
@@ -82,18 +85,18 @@ const RWSWebpackWrapper = (config) => {
82
85
  }));
83
86
  }
84
87
 
85
- if(serviceWorkerPath){
88
+ if (serviceWorkerPath) {
86
89
  WEBPACK_AFTER_ACTIONS.push({
87
90
  type: 'service_worker',
88
91
  actionHandler: serviceWorkerPath
89
- });
92
+ });
90
93
  }
91
94
 
92
- if(!!config.copyToDir){
95
+ if (!!config.copyToDir) {
93
96
  WEBPACK_AFTER_ACTIONS.push({
94
97
  type: 'copy',
95
98
  actionHandler: config.copyToDir
96
- });
99
+ });
97
100
  }
98
101
 
99
102
  if (WEBPACK_AFTER_ACTIONS.length) {
@@ -114,45 +117,59 @@ const RWSWebpackWrapper = (config) => {
114
117
  path.resolve(executionDir, 'src', 'services')
115
118
  ];
116
119
 
117
- if (config.customServiceLocations) {
118
- config.customServiceLocations.forEach((serviceDir) => {
120
+ if (config.customServiceLocations) {
121
+ config.customServiceLocations.forEach((serviceDir) => {
119
122
  servicesLocations.push(serviceDir);
120
- });
123
+ });
121
124
  }
122
125
 
123
126
  const optimConfig = {
124
- minimizer: [
125
- new JsMinimizerPlugin(),
126
- new CssMinimizerPlugin()
127
+ minimizer: isDev ? [] : [
128
+ new TerserPlugin({
129
+ terserOptions: {
130
+ keep_classnames: true, // Prevent mangling of class names
131
+ mangle: false, //@error breaks FAST view stuff if enabled for all assets
132
+ compress: {
133
+ dead_code: true,
134
+ pure_funcs: ['console.log', 'console.info', 'console.warn']
135
+ },
136
+ output: {
137
+ comments: false
138
+ },
139
+ },
140
+ extractComments: false
141
+ }),
142
+ new CssMinimizerPlugin(),
143
+
127
144
  ],
128
145
  };
129
146
 
130
147
  if (config.parted) {
131
- if (config.partedComponentsLocations) {
132
- config.partedComponentsLocations.forEach((componentDir) => {
148
+ if (config.partedComponentsLocations) {
149
+ config.partedComponentsLocations.forEach((componentDir) => {
133
150
  RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', '@rws-framework/client']))];
134
- });
151
+ });
135
152
  }
136
-
137
- RWSComponents.forEach((fileInfo) => {
138
- const isIgnored = fileInfo.isIgnored;
139
153
 
140
- if(isIgnored === true){
154
+ RWSComponents.forEach((fileInfo) => {
155
+ const isIgnored = fileInfo.isIgnored;
156
+
157
+ if (isIgnored === true) {
141
158
  // console.warn('Ignored: '+ fileInfo.filePath);
142
159
  return;
143
160
  }
144
161
 
145
- automatedEntries[fileInfo.sanitName] = fileInfo.filePath;
146
- });
162
+ automatedEntries[fileInfo.sanitName] = fileInfo.filePath;
163
+ });
147
164
 
148
- fs.writeFileSync(splitInfoJson, JSON.stringify(Object.keys(automatedEntries), null, 2));
165
+ fs.writeFileSync(splitInfoJson, JSON.stringify(Object.keys(automatedEntries), null, 2));
149
166
  optimConfig.splitChunks = {
150
167
  cacheGroups: {
151
168
  vendor: {
152
169
  test: (module) => {
153
170
  let importString = module.identifier();
154
171
 
155
- if(importString.split('!').length > 2){
172
+ if (importString.split('!').length > 2) {
156
173
  importString = importString.split('!')[2];
157
174
  }
158
175
 
@@ -162,30 +179,30 @@ const RWSWebpackWrapper = (config) => {
162
179
  const inExecDir = importString.indexOf(executionDir) > -1;
163
180
  const isNoPartedComponent = !Object.keys(automatedEntries).find(key => importString.indexOf(path.resolve(path.dirname(automatedEntries[key]))) > -1);
164
181
 
165
- let isAvailableForVendors = (inNodeModules || inVendorPackage) && isNoPartedComponent;
182
+ let isAvailableForVendors = (inNodeModules || inVendorPackage) && isNoPartedComponent;
166
183
 
167
184
 
168
185
  return isAvailableForVendors;
169
186
  },
170
187
  name: 'vendors',
171
188
  chunks: 'all',
172
- }
189
+ }
173
190
  }
174
- };
175
- }else{
176
- if(fs.existsSync(splitInfoJson)){
191
+ };
192
+ } else {
193
+ if (fs.existsSync(splitInfoJson)) {
177
194
  fs.unlinkSync(splitInfoJson);
178
195
  }
179
- }
180
-
196
+ }
197
+
181
198
  const cfgExport = {
182
- entry: {
183
- client: config.entry,
184
- ...automatedEntries
199
+ entry: {
200
+ client: config.entry,
201
+ ...automatedEntries
185
202
  },
186
203
  mode: isDev ? 'development' : 'production',
187
204
  target: 'web',
188
- devtool: config.devtool || 'inline-source-map',
205
+ devtool: isDev ? (config.devtool || 'inline-source-map') : false,
189
206
  output: {
190
207
  path: config.outputDir,
191
208
  filename: config.parted ? (config.partedPrefix || 'rws') + '.[name].js' : config.outputFileName,
@@ -200,7 +217,7 @@ const RWSWebpackWrapper = (config) => {
200
217
  plugins: [
201
218
  // new TsconfigPathsPlugin({configFile: config.tsConfigPath})
202
219
  ]
203
- },
220
+ },
204
221
  module: {
205
222
  rules: [
206
223
  {
@@ -18,7 +18,7 @@ type WSStatus = 'WS_OPEN' | 'WS_CLOSED' | 'WS_CONNECTING';
18
18
 
19
19
  const wsLog = async (fakeError: Error, text: any, socketId: string = null, isError: boolean = false): Promise<void> => {
20
20
  const logit = isError ? console.error : console.log;
21
- logit(`[webpack://junction_ai_trainer_ui/${module.id.replace('./', '')}:`, `<WS-CLIENT>${socketId ? `(${socketId})` : ''}`, text);
21
+ logit(`<WS-CLIENT>${socketId ? `(${socketId})` : ''}`, text);
22
22
  };
23
23
 
24
24
  class WSService extends TheService {
@@ -7,6 +7,10 @@ module.exports = function(content) {
7
7
  const plugin = new RWSPlugin();
8
8
  const filePath = this.resourcePath;
9
9
 
10
+ const options = this.getOptions() || { minify: false };
11
+
12
+ const isDev = this._compiler.options.dev;
13
+
10
14
  const saveFile = content.indexOf('@save') > -1;
11
15
  let fromTs = false;
12
16
 
@@ -15,16 +19,18 @@ module.exports = function(content) {
15
19
  }
16
20
 
17
21
  try {
18
- const code = plugin.compileScssCode(content, path.dirname(filePath), null, filePath);
22
+ const code = plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
19
23
 
20
24
  if (fromTs) {
21
25
  if (saveFile && code) {
22
- plugin.writeCssFile(filePath, code);
26
+ plugin.writeCssFile(filePath, code);
27
+
28
+ const newContext = this;
23
29
 
24
30
  // Properly setup the context for css-loader
25
31
  const loaderContext = {
26
- ...this,
27
- query: { sourceMap: true }, // Assuming you want source maps
32
+ ...newContext,
33
+ query: { sourceMap: isDev },
28
34
  async: () => (err, output) => {
29
35
  if (err) {
30
36
  callback(err);
@@ -28,14 +28,12 @@ function toJsonString(str) {
28
28
  }
29
29
  }
30
30
 
31
- module.exports = function(content) {
32
-
31
+ module.exports = async function(content) {
33
32
  let processedContent = content;
34
33
  const filePath = this.resourcePath;
35
- const options = this.getOptions() || {};
36
- const tsConfigPath = options.tsConfigPath || path.resolve(process.cwd(), 'tsconfig.json');
37
- const regex = /@RWSView/;
34
+ const isDev = this._compiler.options.dev;
38
35
 
36
+ const regex = /@RWSView/;
39
37
  const tsSourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
40
38
 
41
39
  let templatePath = 'template.html';
@@ -78,7 +76,7 @@ module.exports = function(content) {
78
76
  if(tagName){
79
77
 
80
78
  const lines = content.split('\n');
81
- const textToInsert = ` static definition = { name: '${tagName}', template, styles${addedParams.length? ', ' + (addedParams.join(', ')) : ''} };`;
79
+ const textToInsert = `static definition = { name: '${tagName}', template, styles${addedParams.length? ', ' + (addedParams.join(', ')) : ''} };`;
82
80
 
83
81
  let modifiedContent = '';
84
82
  let insertIndex = -1;
@@ -101,10 +99,7 @@ module.exports = function(content) {
101
99
  let styles = 'const styles: null = null;'
102
100
 
103
101
  if(fs.existsSync(path.dirname(filePath) + '/styles')){
104
- // const scssCode = fs.readFileSync(path.dirname(filePath) + '/styles/layout.scss', 'utf-8');
105
- // styles = 'const styles = T.css`' + plugin.compileScssCode(scssCode, path.dirname(filePath) + '/styles') + '`;'
106
-
107
- styles = `import styles from './${stylesPath}'`;
102
+ styles = `import styles from './${stylesPath}';`;
108
103
  }
109
104
 
110
105
  const templateName = 'template';
@@ -115,24 +110,32 @@ module.exports = function(content) {
115
110
  if(templateExists){
116
111
  this.addDependency(templatePath);
117
112
 
118
- template = `import './${templateName}.html';\nconst template: any = T.html\`${fs.readFileSync(templatePath, 'utf-8')}\`;`;
113
+ let htmlContent = fs.readFileSync(templatePath, 'utf-8');
114
+
115
+ // try {
116
+ // htmlContent = await htmlMinify(htmlContent, {
117
+ // collapseWhitespace: true,
118
+ // });
119
+ // } catch(e){
120
+ // console.error(e);
121
+ // }
122
+
123
+ template = `import './${templateName}.html';
124
+ //@ts-ignore
125
+ const template: any = T.html\`${htmlContent}\`;`;
119
126
  }
120
127
 
121
- processedContent = `
122
- import * as T from '@microsoft/fast-element';\n
123
- ${template}\n
124
- ${styles}\n
125
- ${addedParamDefs.join('\n')}
126
- \n
127
- ` + replaced;
128
+ processedContent = `import * as T from '@microsoft/fast-element';\n${template}\n${styles}\n${addedParamDefs.join('\n')}\n` + replaced;
128
129
  }
130
+
131
+ // fs.writeFileSync(__dirname + '/../node_modules/.compiledev/' + decoratorData.tagName.replace('-', '_') + '.ts', processedContent); //for final RWS TS preview.
129
132
 
130
133
  return processedContent;
131
134
 
132
135
  }catch(e){
133
136
  console.error(e);
134
137
  console.warn('IN:\n\n');
135
- console.log(processedContent);
138
+ // console.log(processedContent);
136
139
 
137
140
  return content;
138
141
  }
@@ -288,7 +288,7 @@ class RWSPlugin {
288
288
  return scssPath;
289
289
  }
290
290
 
291
- compileScssCode(scssCode, fileRootDir, createFile = false, filePath = null){
291
+ compileScssCode(scssCode, fileRootDir, createFile = false, filePath = null, minify = false){
292
292
  const _self = this;
293
293
  const [scssImports] = this.extractScssImports(scssCode);
294
294
 
@@ -310,7 +310,7 @@ class RWSPlugin {
310
310
 
311
311
  try {
312
312
 
313
- const result = sass.compileString(scssCode, { loadPaths: [fileRootDir] })
313
+ const result = sass.compileString(scssCode, { loadPaths: [fileRootDir], style: minify ? 'compressed' : 'expanded' });
314
314
  let finalCss = result.css;
315
315
 
316
316
  return finalCss;