@rws-framework/client 2.1.8 → 2.2.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 +28 -1
- package/package.json +1 -1
- package/rws.webpack.config.js +50 -33
- package/src/services/WSService.ts +1 -1
- package/webpack/rws_fast_scss_loader.js +10 -4
- package/webpack/rws_fast_ts_loader.js +23 -19
- package/webpack/rws_plugin.js +2 -2
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
package/rws.webpack.config.js
CHANGED
|
@@ -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
|
|
126
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
...
|
|
27
|
-
query: { sourceMap:
|
|
32
|
+
...newContext,
|
|
33
|
+
query: { sourceMap: isDev },
|
|
28
34
|
async: () => (err, output) => {
|
|
29
35
|
if (err) {
|
|
30
36
|
callback(err);
|
|
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const ts = require('typescript');
|
|
5
5
|
const tools = require('../_tools');
|
|
6
6
|
const RWSPlugin = require("./rws_plugin");
|
|
7
|
+
const htmlMinify = require('html-minifier').minify;
|
|
7
8
|
|
|
8
9
|
const _defaultRWSLoaderOptions = {
|
|
9
10
|
templatePath: 'template.html',
|
|
@@ -28,14 +29,12 @@ function toJsonString(str) {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
module.exports = function(content) {
|
|
32
|
-
|
|
32
|
+
module.exports = async function(content) {
|
|
33
33
|
let processedContent = content;
|
|
34
34
|
const filePath = this.resourcePath;
|
|
35
|
-
const
|
|
36
|
-
const tsConfigPath = options.tsConfigPath || path.resolve(process.cwd(), 'tsconfig.json');
|
|
37
|
-
const regex = /@RWSView/;
|
|
35
|
+
const isDev = this._compiler.options.dev;
|
|
38
36
|
|
|
37
|
+
const regex = /@RWSView/;
|
|
39
38
|
const tsSourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
40
39
|
|
|
41
40
|
let templatePath = 'template.html';
|
|
@@ -78,7 +77,7 @@ module.exports = function(content) {
|
|
|
78
77
|
if(tagName){
|
|
79
78
|
|
|
80
79
|
const lines = content.split('\n');
|
|
81
|
-
const textToInsert = `
|
|
80
|
+
const textToInsert = `static definition = { name: '${tagName}', template, styles${addedParams.length? ', ' + (addedParams.join(', ')) : ''} };`;
|
|
82
81
|
|
|
83
82
|
let modifiedContent = '';
|
|
84
83
|
let insertIndex = -1;
|
|
@@ -101,10 +100,7 @@ module.exports = function(content) {
|
|
|
101
100
|
let styles = 'const styles: null = null;'
|
|
102
101
|
|
|
103
102
|
if(fs.existsSync(path.dirname(filePath) + '/styles')){
|
|
104
|
-
|
|
105
|
-
// styles = 'const styles = T.css`' + plugin.compileScssCode(scssCode, path.dirname(filePath) + '/styles') + '`;'
|
|
106
|
-
|
|
107
|
-
styles = `import styles from './${stylesPath}'`;
|
|
103
|
+
styles = `import styles from './${stylesPath}';`;
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
const templateName = 'template';
|
|
@@ -115,24 +111,32 @@ module.exports = function(content) {
|
|
|
115
111
|
if(templateExists){
|
|
116
112
|
this.addDependency(templatePath);
|
|
117
113
|
|
|
118
|
-
|
|
114
|
+
let htmlContent = fs.readFileSync(templatePath, 'utf-8');
|
|
115
|
+
|
|
116
|
+
// try {
|
|
117
|
+
// htmlContent = await htmlMinify(htmlContent, {
|
|
118
|
+
// collapseWhitespace: true,
|
|
119
|
+
// });
|
|
120
|
+
// } catch(e){
|
|
121
|
+
// console.error(e);
|
|
122
|
+
// }
|
|
123
|
+
|
|
124
|
+
template = `import './${templateName}.html';
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
const template: any = T.html\`${htmlContent}\`;`;
|
|
119
127
|
}
|
|
120
128
|
|
|
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;
|
|
129
|
+
processedContent = `import * as T from '@microsoft/fast-element';\n${template}\n${styles}\n${addedParamDefs.join('\n')}\n` + replaced;
|
|
128
130
|
}
|
|
131
|
+
|
|
132
|
+
// fs.writeFileSync(__dirname + '/../node_modules/.compiledev/' + decoratorData.tagName.replace('-', '_') + '.ts', processedContent); //for final RWS TS preview.
|
|
129
133
|
|
|
130
134
|
return processedContent;
|
|
131
135
|
|
|
132
136
|
}catch(e){
|
|
133
137
|
console.error(e);
|
|
134
138
|
console.warn('IN:\n\n');
|
|
135
|
-
console.log(processedContent);
|
|
139
|
+
// console.log(processedContent);
|
|
136
140
|
|
|
137
141
|
return content;
|
|
138
142
|
}
|
package/webpack/rws_plugin.js
CHANGED
|
@@ -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;
|