@rws-framework/client 2.5.5 → 2.6.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 +19 -17
- package/package.json +98 -97
- package/rws.webpack.config.js +39 -34
- package/src/client/components.ts +46 -0
- package/src/client/config.ts +120 -0
- package/src/client/services.ts +28 -0
- package/src/client.ts +41 -129
- package/src/components/_component.ts +1 -1
- package/src/components/_decorator.ts +2 -1
- package/src/interfaces/IRWSConfig.ts +1 -0
- package/src/services/ApiService.ts +4 -3
- package/src/services/ConfigService.ts +16 -5
- package/src/services/DOMService.ts +14 -4
- package/src/services/NotifyService.ts +4 -5
- package/src/services/RoutingService.ts +1 -0
- package/src/services/ServiceWorkerService.ts +1 -0
- package/src/services/UtilsService.ts +2 -13
- package/src/services/WSService.ts +1 -0
- package/src/services/_service.ts +12 -0
- package/webpack/index.js +4 -6
- package/webpack/{rws_fast_scss_loader.js → loaders/rws_fast_scss_loader.js} +2 -2
- package/webpack/{rws_fast_ts_loader.js → loaders/rws_fast_ts_loader.js} +6 -27
- package/webpack/loaders/rws_uncomments_loader.js +35 -0
- package/webpack/{rws_plugin.js → rws_scss_plugin.js} +2 -2
- package/webpack/rws_fast_css_loader.js +0 -16
- /package/webpack/{rws_fast_html_loader.js → loaders/rws_fast_html_loader.js} +0 -0
package/_tools.js
CHANGED
|
@@ -172,7 +172,7 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []) {
|
|
|
172
172
|
if (content.includes(text)) {
|
|
173
173
|
const compInfo = extractComponentInfo(content);
|
|
174
174
|
if (compInfo) {
|
|
175
|
-
const { tagName, className, options, isIgnored } = compInfo;
|
|
175
|
+
const { tagName, className, options, isIgnored, isOreo } = compInfo;
|
|
176
176
|
|
|
177
177
|
if (isIgnored) {
|
|
178
178
|
return;
|
|
@@ -187,7 +187,8 @@ function findComponentFilesWithText(dir, text, ignored = [], fileList = []) {
|
|
|
187
187
|
className,
|
|
188
188
|
sanitName: className.toLowerCase(),
|
|
189
189
|
content,
|
|
190
|
-
isIgnored: options?.ignorePackaging
|
|
190
|
+
isIgnored: options?.ignorePackaging,
|
|
191
|
+
isOreo: options?.oreoMode
|
|
191
192
|
});
|
|
192
193
|
}
|
|
193
194
|
}
|
|
@@ -341,44 +342,45 @@ function setupTsConfig(tsConfigPath, executionDir) {
|
|
|
341
342
|
|
|
342
343
|
try {
|
|
343
344
|
let tsConfig = JSON.parse(tsConfigContents);
|
|
344
|
-
|
|
345
|
+
|
|
345
346
|
const declarationsPath = path.resolve(__dirname, 'types') + '/declarations.d.ts';
|
|
346
347
|
const testsPath = path.resolve(__dirname, 'tests');
|
|
347
348
|
const declarationsPathMD5 = md5(fs.readFileSync(declarationsPath, 'utf-8'));
|
|
348
349
|
const testsPathMD5 = fs.existsSync(testsPath) ? md5(fs.readFileSync(testsPath, 'utf-8')) : null;
|
|
349
350
|
|
|
351
|
+
const relativeDeclarationsPath = path.relative(path.dirname(tsConfigPath), declarationsPath);
|
|
352
|
+
const relativeTestsPath = path.relative(path.dirname(tsConfigPath), testsPath);
|
|
353
|
+
|
|
350
354
|
const includedMD5 = [];
|
|
351
355
|
|
|
352
|
-
let changed = false;
|
|
356
|
+
let changed = false;
|
|
353
357
|
|
|
354
|
-
const included = [];
|
|
355
358
|
|
|
356
359
|
if (!Object.keys(tsConfig).includes('include')) {
|
|
357
360
|
tsConfig['include'] = [];
|
|
358
361
|
} else {
|
|
359
|
-
tsConfig['include'] = tsConfig['include'].
|
|
360
|
-
}
|
|
362
|
+
tsConfig['include'] = tsConfig['include'].filter((inc) => fs.existsSync(rwsPath.relativize(inc, executionDir)))
|
|
363
|
+
}
|
|
361
364
|
|
|
362
365
|
if (!Object.keys(tsConfig).includes('exclude')) {
|
|
363
366
|
tsConfig['exclude'] = [];
|
|
364
|
-
}
|
|
367
|
+
}
|
|
365
368
|
|
|
366
|
-
|
|
369
|
+
|
|
370
|
+
if (!tsConfig['include'].includes(relativeDeclarationsPath)) {
|
|
367
371
|
console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript declarations to project tsconfig.json');
|
|
368
|
-
|
|
369
|
-
includedMD5.push(md5(fs.readFileSync(declarationsPath, 'utf-8')));
|
|
372
|
+
tsConfig['include'].push(relativeDeclarationsPath);
|
|
373
|
+
includedMD5.push(md5(fs.readFileSync(declarationsPath, 'utf-8')));
|
|
370
374
|
changed = true;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
tsConfig['include'] = included;
|
|
375
|
+
}
|
|
374
376
|
|
|
375
|
-
if (
|
|
377
|
+
if ((!tsConfig['exclude'].includes(relativeTestsPath))) {
|
|
376
378
|
console.log(chalk.blueBright('[RWS TS CONFIG]'), 'adding RWS typescript exclusions to project tsconfig.json');
|
|
377
|
-
tsConfig['exclude'].push(
|
|
379
|
+
tsConfig['exclude'].push(relativeTestsPath);
|
|
378
380
|
changed = true;
|
|
379
381
|
}
|
|
380
382
|
|
|
381
|
-
if (changed) {
|
|
383
|
+
if (changed) {
|
|
382
384
|
fs.writeFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
|
|
383
385
|
console.log(chalk.yellowBright('Typescript config file'), `"${chalk.blueBright(tsConfigPath)}"`, chalk.yellowBright('has been changed'));
|
|
384
386
|
}
|
package/package.json
CHANGED
|
@@ -1,99 +1,100 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
2
|
+
"name": "@rws-framework/client",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "2.6.1",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"docs": "typedoc --tsconfig ./tsconfig.json"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"rws-client": "./console.js"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/papablack/rws-client.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"frontend",
|
|
18
|
+
"rws",
|
|
19
|
+
"client",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "papablack",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/papablack/rws-client/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/papablack/rws-client#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@microsoft/fast-element": "^1.12.0",
|
|
30
|
+
"@microsoft/fast-foundation": "^2.46.2",
|
|
31
|
+
"@rws-framework/console": "^0.3.5",
|
|
32
|
+
"@types/moment": "^2.13.0",
|
|
33
|
+
"dragula": "^3.7.3",
|
|
34
|
+
"he": "^1.2.0",
|
|
35
|
+
"json5": "^2.2.3",
|
|
36
|
+
"lodash": "^4.17.21",
|
|
37
|
+
"moment": "^2.29.4",
|
|
38
|
+
"partial-json-parser": "^1.0.0",
|
|
39
|
+
"reflect-metadata": "^0.1.13",
|
|
40
|
+
"resolve-url-loader": "^5.0.0",
|
|
41
|
+
"sanitize-html": "^2.12.1",
|
|
42
|
+
"sass": "^1.69.7",
|
|
43
|
+
"scss-loading-animations": "^1.0.1",
|
|
44
|
+
"socket.io-client": "^4.7.2",
|
|
45
|
+
"ts-loader": "^9.4.4",
|
|
46
|
+
"tsc-watch": "^6.0.4",
|
|
47
|
+
"tslib": "^2.6.2",
|
|
48
|
+
"upload": "^1.3.2",
|
|
49
|
+
"url-router": "^13.0.0",
|
|
50
|
+
"uuid": "^9.0.1",
|
|
51
|
+
"v4": "^0.0.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/dragula": "^3.7.4",
|
|
55
|
+
"@types/eslint": "^6.0.0",
|
|
56
|
+
"@types/express-fileupload": "^1.4.4",
|
|
57
|
+
"@types/glob": "^8.1.0",
|
|
58
|
+
"@types/he": "^1.2.3",
|
|
59
|
+
"@types/sanitize-html": "^2.11.0",
|
|
60
|
+
"@types/uuid": "^9.0.7",
|
|
61
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
62
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
63
|
+
"css-loader": "^6.8.1",
|
|
64
|
+
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
65
|
+
"eslint": "^6.0.0",
|
|
66
|
+
"file-loader": "^6.2.0",
|
|
67
|
+
"html-webpack-plugin": "^5.5.3",
|
|
68
|
+
"loader-utils": "^3.2.1",
|
|
69
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
70
|
+
"minimatch": "^9.0.4",
|
|
71
|
+
"node-sass": "^9.0.0",
|
|
72
|
+
"sass-loader": "^13.3.2",
|
|
73
|
+
"source-map": "^0.7.4",
|
|
74
|
+
"style-loader": "^3.3.3",
|
|
75
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
76
|
+
"ts-loader": "^9.4.4",
|
|
77
|
+
"ts-node": "^10.9.1",
|
|
78
|
+
"tsconfig-paths": "^4.2.0",
|
|
79
|
+
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
|
80
|
+
"typedoc": "^0.25.4",
|
|
81
|
+
"typedoc-plugin-mermaid": "^1.10.0",
|
|
82
|
+
"typedoc-plugin-not-exported": "^0.1.6",
|
|
83
|
+
"typedoc-plugin-rename-defaults": "^0.7.0",
|
|
84
|
+
"typedoc-theme-hierarchy": "^4.1.2",
|
|
85
|
+
"typescript": "^5.1.6",
|
|
86
|
+
"url-loader": "^4.1.1",
|
|
87
|
+
"webpack": "^5.75.0",
|
|
88
|
+
"webpack-bundle-analyzer": "^4.10.1",
|
|
89
|
+
"webpack-cli": "^5.1.4",
|
|
90
|
+
"webpack-dev-server": "^4.15.1",
|
|
91
|
+
"webpack-node-externals": "^3.0.0"
|
|
92
|
+
},
|
|
93
|
+
"resolutions": {
|
|
94
|
+
"lodash": "^4.17.21"
|
|
95
|
+
},
|
|
96
|
+
"overrides": {
|
|
97
|
+
"lodash": "^4.17.21"
|
|
98
|
+
}
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
|
package/rws.webpack.config.js
CHANGED
|
@@ -18,17 +18,15 @@ const JsMinimizerPlugin = require('terser-webpack-plugin');
|
|
|
18
18
|
const json5 = require('json5');
|
|
19
19
|
const { rwsPath } = require('@rws-framework/console');
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const RWSWebpackWrapper = (config) => {
|
|
24
|
-
const BuildConfigurator = new RWSConfigBuilder(RWSPath.findPackageDir(process.cwd()) + '/.rws.json', _DEFAULT_CONFIG);
|
|
21
|
+
const RWSWebpackWrapper = (config) => {
|
|
22
|
+
const BuildConfigurator = new RWSConfigBuilder(RWSPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...config});
|
|
25
23
|
|
|
26
24
|
config.packageDir = RWSPath.findPackageDir(process.cwd());
|
|
27
25
|
|
|
28
26
|
const executionDir = RWSPath.relativize(BuildConfigurator.get('executionDir') || config.executionDir || process.cwd(), config.packageDir);
|
|
29
27
|
|
|
30
28
|
const isDev = BuildConfigurator.get('dev', config.dev);
|
|
31
|
-
const isHotReload = BuildConfigurator.get('hot', config.hot)
|
|
29
|
+
const isHotReload = BuildConfigurator.get('hot', config.hot);
|
|
32
30
|
const isReport = BuildConfigurator.get('report', config.report);
|
|
33
31
|
const isParted = BuildConfigurator.get('parted', config.parted || false);
|
|
34
32
|
|
|
@@ -45,14 +43,14 @@ const RWSWebpackWrapper = (config) => {
|
|
|
45
43
|
|
|
46
44
|
const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
|
|
50
|
-
|
|
46
|
+
|
|
47
|
+
const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
|
|
48
|
+
|
|
51
49
|
|
|
52
50
|
RWSPath.removeDirectory(outputDir, true);
|
|
53
51
|
|
|
54
52
|
console.log(chalk.green('Build started with'))
|
|
55
|
-
console.log({
|
|
53
|
+
console.log({
|
|
56
54
|
executionDir,
|
|
57
55
|
tsConfigPath,
|
|
58
56
|
outputDir,
|
|
@@ -60,9 +58,9 @@ const RWSWebpackWrapper = (config) => {
|
|
|
60
58
|
publicDir,
|
|
61
59
|
parted: isParted,
|
|
62
60
|
partedPrefix,
|
|
63
|
-
partedDirUrlPrefix
|
|
61
|
+
partedDirUrlPrefix
|
|
64
62
|
});
|
|
65
|
-
|
|
63
|
+
|
|
66
64
|
|
|
67
65
|
//AFTER OPTION DEFINITIONS
|
|
68
66
|
|
|
@@ -91,7 +89,7 @@ const RWSWebpackWrapper = (config) => {
|
|
|
91
89
|
}));
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
WEBPACK_PLUGINS = [...WEBPACK_PLUGINS,
|
|
92
|
+
WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, ...overridePlugins];
|
|
95
93
|
|
|
96
94
|
|
|
97
95
|
if (isReport) {
|
|
@@ -110,14 +108,14 @@ const RWSWebpackWrapper = (config) => {
|
|
|
110
108
|
|
|
111
109
|
const assetsToCopy = BuildConfigurator.get('copyAssets') || config.copyAssets;
|
|
112
110
|
|
|
113
|
-
if (!!assetsToCopy) {
|
|
111
|
+
if (!!assetsToCopy) {
|
|
114
112
|
WEBPACK_AFTER_ACTIONS.push({
|
|
115
113
|
type: 'copy',
|
|
116
114
|
actionHandler: assetsToCopy
|
|
117
115
|
});
|
|
118
116
|
}
|
|
119
117
|
|
|
120
|
-
if (WEBPACK_AFTER_ACTIONS.length) {
|
|
118
|
+
if (WEBPACK_AFTER_ACTIONS.length) {
|
|
121
119
|
WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS }));
|
|
122
120
|
}
|
|
123
121
|
|
|
@@ -141,9 +139,11 @@ const RWSWebpackWrapper = (config) => {
|
|
|
141
139
|
});
|
|
142
140
|
}
|
|
143
141
|
|
|
144
|
-
const optimConfig = {
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
const optimConfig = {};
|
|
143
|
+
|
|
144
|
+
if(!isDev){
|
|
145
|
+
optimConfig.minimize = true;
|
|
146
|
+
optimConfig.minimizer = [
|
|
147
147
|
new TerserPlugin({
|
|
148
148
|
terserOptions: {
|
|
149
149
|
keep_classnames: true, // Prevent mangling of class names
|
|
@@ -160,8 +160,9 @@ const RWSWebpackWrapper = (config) => {
|
|
|
160
160
|
parallel: true,
|
|
161
161
|
}),
|
|
162
162
|
new CssMinimizerPlugin(),
|
|
163
|
-
]
|
|
164
|
-
}
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
|
|
165
166
|
|
|
166
167
|
if (isParted) {
|
|
167
168
|
WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix)));
|
|
@@ -215,7 +216,7 @@ const RWSWebpackWrapper = (config) => {
|
|
|
215
216
|
|
|
216
217
|
const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir);
|
|
217
218
|
|
|
218
|
-
if(!tsValidated){
|
|
219
|
+
if (!tsValidated) {
|
|
219
220
|
throw new Error('RWS Webpack build failed.');
|
|
220
221
|
}
|
|
221
222
|
|
|
@@ -237,31 +238,26 @@ const RWSWebpackWrapper = (config) => {
|
|
|
237
238
|
modules: modules_setup,
|
|
238
239
|
alias: {
|
|
239
240
|
...aliases
|
|
240
|
-
}
|
|
241
|
-
plugins: [
|
|
242
|
-
// new TsconfigPathsPlugin({configFile: config.tsConfigPath})
|
|
243
|
-
]
|
|
241
|
+
}
|
|
244
242
|
},
|
|
245
243
|
module: {
|
|
246
|
-
rules: [
|
|
244
|
+
rules: [
|
|
247
245
|
{
|
|
248
246
|
test: /\.html$/,
|
|
249
247
|
use: [
|
|
250
|
-
path.resolve(__dirname, './webpack/rws_fast_html_loader.js')
|
|
248
|
+
path.resolve(__dirname, './webpack/loaders/rws_fast_html_loader.js')
|
|
251
249
|
],
|
|
252
250
|
},
|
|
253
251
|
{
|
|
254
252
|
test: /\.css$/,
|
|
255
253
|
use: [
|
|
256
|
-
'css-loader',
|
|
257
|
-
// path.resolve(__dirname, './webpack/rws_fast_css_loader.js')
|
|
254
|
+
'css-loader',
|
|
258
255
|
],
|
|
259
256
|
},
|
|
260
257
|
{
|
|
261
258
|
test: /\.scss$/,
|
|
262
|
-
use: [
|
|
263
|
-
|
|
264
|
-
path.resolve(__dirname, './webpack/rws_fast_scss_loader.js'),
|
|
259
|
+
use: [
|
|
260
|
+
path.resolve(__dirname, './webpack/loaders/rws_fast_scss_loader.js'),
|
|
265
261
|
],
|
|
266
262
|
},
|
|
267
263
|
{
|
|
@@ -271,12 +267,12 @@ const RWSWebpackWrapper = (config) => {
|
|
|
271
267
|
loader: 'ts-loader',
|
|
272
268
|
options: {
|
|
273
269
|
allowTsInNodeModules: true,
|
|
274
|
-
configFile: path.resolve(tsConfigPath)
|
|
270
|
+
configFile: path.resolve(tsConfigPath)
|
|
275
271
|
}
|
|
276
272
|
},
|
|
277
273
|
{
|
|
278
|
-
loader: path.resolve(__dirname, './webpack/rws_fast_ts_loader.js'),
|
|
279
|
-
}
|
|
274
|
+
loader: path.resolve(__dirname, './webpack/loaders/rws_fast_ts_loader.js'),
|
|
275
|
+
}
|
|
280
276
|
],
|
|
281
277
|
exclude: /node_modules\/(?!\@rws-framework\/client)/,
|
|
282
278
|
}
|
|
@@ -286,6 +282,15 @@ const RWSWebpackWrapper = (config) => {
|
|
|
286
282
|
optimization: optimConfig,
|
|
287
283
|
}
|
|
288
284
|
|
|
285
|
+
// if(isDev){
|
|
286
|
+
cfgExport.module.rules.push({
|
|
287
|
+
test: /\.js$/,
|
|
288
|
+
use: [
|
|
289
|
+
path.resolve(__dirname, './webpack/loaders/rws_uncomments_loader.js'),
|
|
290
|
+
],
|
|
291
|
+
})
|
|
292
|
+
// }
|
|
293
|
+
|
|
289
294
|
if (isHotReload) {
|
|
290
295
|
cfgExport.devServer = {
|
|
291
296
|
hot: true,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import RWSWindow, { RWSWindowComponentRegister } from "../interfaces/RWSWindow";
|
|
2
|
+
import { RWSClientInstance } from "../client";
|
|
3
|
+
import RWSViewComponent, { IWithCompose } from "../components/_component";
|
|
4
|
+
type RWSInfoType = { components: string[] };
|
|
5
|
+
|
|
6
|
+
async function loadPartedComponents(this: RWSClientInstance): Promise<void> {
|
|
7
|
+
this.assignClientToBrowser();
|
|
8
|
+
|
|
9
|
+
const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
|
|
10
|
+
|
|
11
|
+
componentParts.components.forEach((componentName: string, key: number) => {
|
|
12
|
+
const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
|
|
13
|
+
|
|
14
|
+
const script: HTMLScriptElement = document.createElement('script');
|
|
15
|
+
script.src = partUrl;
|
|
16
|
+
script.async = true;
|
|
17
|
+
script.type = 'text/javascript';
|
|
18
|
+
document.body.appendChild(script);
|
|
19
|
+
|
|
20
|
+
console.log(`Appended ${componentParts.components[key]} component (${partUrl})`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function defineAllComponents() {
|
|
25
|
+
const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
|
|
26
|
+
|
|
27
|
+
Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
|
|
28
|
+
el.define(el as any, el.definition);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getBinds(this: RWSClientInstance){
|
|
33
|
+
return {
|
|
34
|
+
loadPartedComponents: loadPartedComponents.bind(this)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getBinds;
|
|
39
|
+
|
|
40
|
+
const ComponentHelperStatic = {
|
|
41
|
+
defineAllComponents: defineAllComponents
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
ComponentHelperStatic
|
|
46
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IRWSConfig, IRWSUser } from "../index";
|
|
2
|
+
import { RWSClientInstance } from "../client";
|
|
3
|
+
import startClient from '../run';
|
|
4
|
+
|
|
5
|
+
type RWSInfoType = { components: string[] };
|
|
6
|
+
|
|
7
|
+
function getUser(this: RWSClientInstance): IRWSUser {
|
|
8
|
+
|
|
9
|
+
const localSaved = localStorage.getItem('the_rws_user');
|
|
10
|
+
|
|
11
|
+
if (localSaved) {
|
|
12
|
+
this.setUser(JSON.parse(localSaved) as IRWSUser);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return this.user;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function setUser(this: RWSClientInstance, user: IRWSUser): RWSClientInstance {
|
|
19
|
+
if (!user || !user?.jwt_token) {
|
|
20
|
+
console.warn('[RWS Client Warning]', 'Passed user is not valid', user);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.user = user;
|
|
25
|
+
|
|
26
|
+
this.apiService.setToken(this.user.jwt_token);
|
|
27
|
+
this.wsService.setUser(this.user);
|
|
28
|
+
|
|
29
|
+
localStorage.setItem('the_rws_user', JSON.stringify(this.user));
|
|
30
|
+
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function pushDataToServiceWorker(this: RWSClientInstance, type: string, data: any, asset_type: string = 'data_push'): void {
|
|
35
|
+
let tries = 0;
|
|
36
|
+
|
|
37
|
+
const doIt: () => void = () => {
|
|
38
|
+
try {
|
|
39
|
+
this.swService.sendDataToServiceWorker(type, data, asset_type);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (tries < 3) {
|
|
42
|
+
setTimeout(() => { doIt(); }, 300);
|
|
43
|
+
tries++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
doIt();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function pushUserToServiceWorker(this: RWSClientInstance, userData: any) {
|
|
52
|
+
this.setUser(userData);
|
|
53
|
+
this.pushDataToServiceWorker('SET_USER', userData, 'logged_user');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function get(this: RWSClientInstance, key: string): any | null
|
|
57
|
+
{
|
|
58
|
+
if(Object.keys(this.customServices).includes(key)){
|
|
59
|
+
return this.customServices[key];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if(Object.keys(this.defaultServices).includes(key)){
|
|
63
|
+
return this.defaultServices[key];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<IRWSConfig> {
|
|
70
|
+
if (this.isSetup) {
|
|
71
|
+
return this.config;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.config = { ...this.config, ...config };
|
|
75
|
+
this.appConfig.mergeConfig(this.config);
|
|
76
|
+
|
|
77
|
+
if (this.appConfig.get('parted')) {
|
|
78
|
+
await this.loadPartedComponents();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
this.isSetup = true;
|
|
83
|
+
return this.config;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function start(this: RWSClientInstance, config: IRWSConfig = {}): Promise<RWSClientInstance> {
|
|
87
|
+
this.config = { ...this.config, ...config };
|
|
88
|
+
|
|
89
|
+
if (!this.isSetup) {
|
|
90
|
+
this.config = await this.setup(this.config);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (Object.keys(config).length) {
|
|
94
|
+
this.appConfig.mergeConfig(this.config);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (this.config.user && !this.config.dontPushToSW) {
|
|
98
|
+
this.pushUserToServiceWorker(this.user);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
|
|
102
|
+
|
|
103
|
+
await this.initCallback();
|
|
104
|
+
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getBinds(this: RWSClientInstance) {
|
|
109
|
+
return {
|
|
110
|
+
start: start.bind(this),
|
|
111
|
+
setup: setup.bind(this),
|
|
112
|
+
get: get.bind(this),
|
|
113
|
+
setUser: setUser.bind(this),
|
|
114
|
+
getUser: getUser.bind(this),
|
|
115
|
+
pushDataToServiceWorker: pushDataToServiceWorker.bind(this),
|
|
116
|
+
pushUserToServiceWorker: pushUserToServiceWorker.bind(this)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default getBinds;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { loadRWSRichWindow } from "../interfaces/RWSWindow";
|
|
2
|
+
import { RWSClientInstance } from "../client";
|
|
3
|
+
type RWSInfoType = { components: string[] };
|
|
4
|
+
|
|
5
|
+
async function loadServices(this: RWSClientInstance){
|
|
6
|
+
const richWindow = loadRWSRichWindow();
|
|
7
|
+
|
|
8
|
+
for (const serviceKey of Object.keys(richWindow.RWS._registered)){
|
|
9
|
+
const currentService = this._container.get(richWindow.RWS._registered[serviceKey]);
|
|
10
|
+
|
|
11
|
+
if(currentService.isInClient() && !Object.keys(this.customServices).includes(serviceKey)){
|
|
12
|
+
this.customServices[serviceKey] = currentService;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if(currentService.isDefault() && !Object.keys(this.defaultServices).includes(serviceKey)){
|
|
16
|
+
this.defaultServices[serviceKey] = currentService;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function getBinds(this: RWSClientInstance){
|
|
23
|
+
return {
|
|
24
|
+
loadServices: loadServices.bind(this),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default getBinds;
|
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import IRWSConfig from './interfaces/IRWSConfig';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import RWSNotify from './types/RWSNotify';
|
|
4
4
|
|
|
5
5
|
import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
|
|
@@ -14,7 +14,7 @@ import { IBackendRoute } from './services/ApiService';
|
|
|
14
14
|
import IRWSUser from './interfaces/IRWSUser';
|
|
15
15
|
import RWSWindow, { RWSWindowComponentRegister, loadRWSRichWindow } from './interfaces/RWSWindow';
|
|
16
16
|
|
|
17
|
-
import { DI, Container } from '@microsoft/fast-foundation';
|
|
17
|
+
import { DI, Container, Registration } from '@microsoft/fast-foundation';
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
IFrontRoutes
|
|
@@ -22,6 +22,11 @@ import {
|
|
|
22
22
|
|
|
23
23
|
import RWSViewComponent, { IWithCompose } from './components/_component';
|
|
24
24
|
import RWSContainer from './components/_container';
|
|
25
|
+
import TheRWSService from './services/_service';
|
|
26
|
+
|
|
27
|
+
import ComponentHelper, { ComponentHelperStatic } from './client/components';
|
|
28
|
+
import ServicesHelper from './client/services';
|
|
29
|
+
import ConfigHelper from './client/config';
|
|
25
30
|
|
|
26
31
|
interface IHotModule extends NodeModule {
|
|
27
32
|
hot?: {
|
|
@@ -36,19 +41,20 @@ type RWSInfoType = { components: string[] };
|
|
|
36
41
|
type RWSEventListener = (event: CustomEvent) => void;
|
|
37
42
|
|
|
38
43
|
class RWSClient {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
protected
|
|
44
|
+
protected _container: Container;
|
|
45
|
+
protected user: IRWSUser = null;
|
|
46
|
+
|
|
47
|
+
protected config: IRWSConfig = {};
|
|
48
|
+
protected isSetup = false;
|
|
49
|
+
protected devStorage: { [key: string]: any } = {};
|
|
50
|
+
protected customServices: { [serviceName: string]: TheRWSService} = {};
|
|
51
|
+
protected defaultServices: { [serviceName: string]: TheRWSService} = {};
|
|
44
52
|
|
|
45
|
-
private
|
|
46
|
-
|
|
53
|
+
private componentHelper = ComponentHelper.bind(this)();
|
|
54
|
+
private servicesHelper = ServicesHelper.bind(this)();
|
|
55
|
+
private configHelper = ConfigHelper.bind(this)();
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
console.log('Received custom event from web component:', event.detail);
|
|
50
|
-
// this.broadcastConfigForViewComponents();
|
|
51
|
-
};
|
|
57
|
+
protected initCallback: () => Promise<void> = async () => { };
|
|
52
58
|
|
|
53
59
|
constructor(
|
|
54
60
|
@ConfigService public appConfig: ConfigServiceInstance,
|
|
@@ -61,62 +67,32 @@ class RWSClient {
|
|
|
61
67
|
@NotifyService public notifyService: NotifyServiceInstance
|
|
62
68
|
) {
|
|
63
69
|
this._container = RWSContainer();
|
|
64
|
-
this.user = this.getUser();
|
|
70
|
+
this.user = this.getUser();
|
|
71
|
+
|
|
72
|
+
this.loadServices();
|
|
65
73
|
|
|
66
74
|
this.pushDataToServiceWorker('SET_WS_URL', { url: this.appConfig.get('wsUrl') }, 'ws_url');
|
|
67
75
|
|
|
68
76
|
if (this.user) {
|
|
69
77
|
this.pushUserToServiceWorker({ ...this.user, instructor: false });
|
|
70
|
-
}
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
async setup(config: IRWSConfig = {}): Promise<IRWSConfig> {
|
|
74
|
-
|
|
75
|
-
return this.config;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.config = { ...this.config, ...config };
|
|
79
|
-
this.appConfig.mergeConfig(this.config);
|
|
80
|
-
|
|
81
|
-
// this.on<IRWSConfig>('rws_cfg_call', this.cfgSetupListener);
|
|
82
|
-
|
|
83
|
-
const hotModule: IHotModule = (module as IHotModule);
|
|
84
|
-
|
|
85
|
-
if (hotModule.hot) {
|
|
86
|
-
hotModule.hot.accept('./print.js', function () {
|
|
87
|
-
console.log('Accepting the updated module!');
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (this.appConfig.get('parted')) {
|
|
92
|
-
await this.loadPartedComponents();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.isSetup = true;
|
|
97
|
-
return this.config;
|
|
82
|
+
return this.configHelper.setup(config);
|
|
98
83
|
}
|
|
99
84
|
|
|
100
85
|
async start(config: IRWSConfig = {}): Promise<RWSClient> {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!this.isSetup) {
|
|
104
|
-
this.config = await this.setup(this.config);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Object.keys(config).length) {
|
|
108
|
-
this.appConfig.mergeConfig(this.config);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (this.config.user && !this.config.dontPushToSW) {
|
|
112
|
-
this.pushUserToServiceWorker(this.user);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
|
|
86
|
+
return this.configHelper.start(config);
|
|
87
|
+
}
|
|
116
88
|
|
|
117
|
-
|
|
89
|
+
private loadServices(){
|
|
90
|
+
return this.servicesHelper.loadServices();
|
|
91
|
+
}
|
|
118
92
|
|
|
119
|
-
|
|
93
|
+
get(key: string): any | null
|
|
94
|
+
{
|
|
95
|
+
return this.configHelper.get(key);
|
|
120
96
|
}
|
|
121
97
|
|
|
122
98
|
addRoutes(routes: IFrontRoutes) {
|
|
@@ -146,53 +122,20 @@ class RWSClient {
|
|
|
146
122
|
}
|
|
147
123
|
|
|
148
124
|
pushDataToServiceWorker(type: string, data: any, asset_type: string = 'data_push'): void {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const doIt: () => void = () => {
|
|
152
|
-
try {
|
|
153
|
-
this.swService.sendDataToServiceWorker(type, data, asset_type);
|
|
154
|
-
} catch (e) {
|
|
155
|
-
if (tries < 3) {
|
|
156
|
-
setTimeout(() => { doIt(); }, 300);
|
|
157
|
-
tries++;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
doIt();
|
|
125
|
+
this.configHelper.pushDataToServiceWorker(type, data, asset_type);
|
|
126
|
+
|
|
163
127
|
}
|
|
164
128
|
|
|
165
129
|
pushUserToServiceWorker(userData: any) {
|
|
166
|
-
this.
|
|
167
|
-
this.pushDataToServiceWorker('SET_USER', userData, 'logged_user');
|
|
130
|
+
this.configHelper.pushUserToServiceWorker(userData);
|
|
168
131
|
}
|
|
169
132
|
|
|
170
133
|
getUser(): IRWSUser {
|
|
171
|
-
|
|
172
|
-
const localSaved = localStorage.getItem('the_rws_user');
|
|
173
|
-
|
|
174
|
-
if (localSaved) {
|
|
175
|
-
this.setUser(JSON.parse(localSaved) as IRWSUser);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return this.user;
|
|
134
|
+
return this.configHelper.getUser();
|
|
179
135
|
}
|
|
180
136
|
|
|
181
137
|
setUser(user: IRWSUser): RWSClient {
|
|
182
|
-
|
|
183
|
-
console.warn('[RWS Client Warning]', 'Passed user is not valid', user);
|
|
184
|
-
return this;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
this.user = user;
|
|
188
|
-
|
|
189
|
-
this.apiService.setToken(this.user.jwt_token);
|
|
190
|
-
this.wsService.setUser(this.user);
|
|
191
|
-
|
|
192
|
-
localStorage.setItem('the_rws_user', JSON.stringify(this.user));
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return this;
|
|
138
|
+
return this.configHelper.setUser(user);
|
|
196
139
|
}
|
|
197
140
|
|
|
198
141
|
getConfig(): ConfigServiceInstance {
|
|
@@ -219,29 +162,11 @@ class RWSClient {
|
|
|
219
162
|
}
|
|
220
163
|
|
|
221
164
|
async loadPartedComponents(): Promise<void> {
|
|
222
|
-
this.
|
|
223
|
-
|
|
224
|
-
const componentParts: RWSInfoType = await this.apiService.get<RWSInfoType>(this.appConfig.get('partedDirUrlPrefix') + '/rws_info.json');
|
|
225
|
-
|
|
226
|
-
componentParts.components.forEach((componentName: string, key: number) => {
|
|
227
|
-
const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
|
|
228
|
-
|
|
229
|
-
const script: HTMLScriptElement = document.createElement('script');
|
|
230
|
-
script.src = partUrl;
|
|
231
|
-
script.async = true;
|
|
232
|
-
script.type = 'text/javascript';
|
|
233
|
-
document.body.appendChild(script);
|
|
234
|
-
|
|
235
|
-
console.log(`Appended ${componentParts.components[key]} component (${partUrl})`);
|
|
236
|
-
});
|
|
165
|
+
return this.componentHelper.loadPartedComponents();
|
|
237
166
|
}
|
|
238
167
|
|
|
239
168
|
async onDOMLoad(): Promise<void> {
|
|
240
|
-
return
|
|
241
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
242
|
-
resolve();
|
|
243
|
-
});
|
|
244
|
-
});
|
|
169
|
+
return this.domService.onDOMLoad()
|
|
245
170
|
}
|
|
246
171
|
|
|
247
172
|
assignClientToBrowser(): void {
|
|
@@ -261,30 +186,17 @@ class RWSClient {
|
|
|
261
186
|
return window;
|
|
262
187
|
}
|
|
263
188
|
|
|
264
|
-
|
|
265
|
-
private broadcastConfigForViewComponents(): void {
|
|
266
|
-
document.dispatchEvent(new CustomEvent<{ config: IRWSConfig }>('rws_cfg_broadcast', { detail: { config: this.appConfig.getData() } }));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
189
|
static getDI(): typeof DI {
|
|
270
190
|
return DI;
|
|
271
191
|
}
|
|
272
192
|
|
|
273
193
|
static defineAllComponents() {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
|
|
277
|
-
el.define(el as any, el.definition);
|
|
278
|
-
});
|
|
194
|
+
ComponentHelperStatic.defineAllComponents();
|
|
279
195
|
}
|
|
280
196
|
|
|
281
197
|
|
|
282
198
|
defineComponents(){
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
|
|
286
|
-
el.define(el as any, el.definition);
|
|
287
|
-
});
|
|
199
|
+
ComponentHelperStatic.defineAllComponents();
|
|
288
200
|
}
|
|
289
201
|
}
|
|
290
202
|
|
|
@@ -82,7 +82,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
|
|
|
82
82
|
if (this.fileAssets[file]) {
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
this.
|
|
85
|
+
this.apiService.pureGet(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
|
|
86
86
|
this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
|
|
87
87
|
});
|
|
88
88
|
});
|
|
@@ -35,7 +35,8 @@ type IBackendRoute = IHTTProute | IPrefixedHTTProutes;
|
|
|
35
35
|
|
|
36
36
|
const _DEFAULT_CONTENT_TYPE = 'application/json';
|
|
37
37
|
|
|
38
|
-
class
|
|
38
|
+
class ApiService extends TheService {
|
|
39
|
+
static _DEFAULT: boolean = true;
|
|
39
40
|
private token?: string;
|
|
40
41
|
|
|
41
42
|
constructor(@ConfigService private config: ConfigServiceInstance) {
|
|
@@ -238,5 +239,5 @@ class ApiServiceInstance extends TheService {
|
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
241
|
|
|
241
|
-
export default
|
|
242
|
-
export { IBackendRoute, RequestOptions, ApiServiceInstance, IHTTProute, IPrefixedHTTProutes };
|
|
242
|
+
export default ApiService.getSingleton();
|
|
243
|
+
export { IBackendRoute, RequestOptions, ApiService as ApiServiceInstance, IHTTProute, IPrefixedHTTProutes };
|
|
@@ -9,6 +9,7 @@ const __SENT_TO_COMPONENTS: string[] = [];
|
|
|
9
9
|
|
|
10
10
|
@RWSFillBuild()
|
|
11
11
|
class ConfigService extends TheService {
|
|
12
|
+
static _DEFAULT: boolean = false;
|
|
12
13
|
static isLoaded: boolean = false;
|
|
13
14
|
|
|
14
15
|
_DEFAULTS: Partial<IRWSConfig> = {};
|
|
@@ -32,21 +33,31 @@ class ConfigService extends TheService {
|
|
|
32
33
|
const isInData: boolean = Object.keys(this.data).includes(key);
|
|
33
34
|
const isInBuildVars: boolean = Object.keys(this._BUILD_OVERRIDE).includes(key);
|
|
34
35
|
|
|
36
|
+
let isDev = false;
|
|
37
|
+
|
|
38
|
+
if((Object.keys(this._BUILD_OVERRIDE).includes('dev'))){
|
|
39
|
+
isDev = Object.keys(this._BUILD_OVERRIDE).includes('dev') && this._BUILD_OVERRIDE.dev;
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
if(!isInData){
|
|
36
43
|
let defaultVal = null;
|
|
37
44
|
|
|
38
45
|
if(isInDefaults){
|
|
39
46
|
defaultVal = this._DEFAULTS[key];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if(isInBuildVars && !!this._BUILD_OVERRIDE[key]){
|
|
43
|
-
defaultVal = this._BUILD_OVERRIDE[key];
|
|
44
|
-
}
|
|
47
|
+
}
|
|
45
48
|
|
|
46
49
|
if(defaultVal && defaultVal[0] === '@'){
|
|
47
50
|
defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
if(isInBuildVars && Object.keys(this._BUILD_OVERRIDE).includes(key)){
|
|
54
|
+
if(isDev){
|
|
55
|
+
console.warn(`.rws.json override [${key}]:`), this._BUILD_OVERRIDE[key];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
defaultVal = this._BUILD_OVERRIDE[key];
|
|
59
|
+
}
|
|
60
|
+
|
|
50
61
|
return defaultVal;
|
|
51
62
|
}
|
|
52
63
|
|
|
@@ -9,7 +9,8 @@ type DOMOutputType<T extends Element> = NodeListOf<T> | T | null;
|
|
|
9
9
|
declare let trustedTypes: TrustedTypePolicyFactory;
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
class
|
|
12
|
+
class DOMService extends RWSService {
|
|
13
|
+
static _DEFAULT: boolean = true;
|
|
13
14
|
parse$<T extends Element>(input: NodeListOf<T>, directReturn: boolean = false): DOMOutputType<T> {
|
|
14
15
|
if(input.length > 1 || directReturn) {
|
|
15
16
|
return input;
|
|
@@ -83,9 +84,18 @@ class DOMServiceInstance extends RWSService {
|
|
|
83
84
|
|
|
84
85
|
return sanitized;
|
|
85
86
|
}
|
|
87
|
+
|
|
88
|
+
async onDOMLoad(): Promise<void>
|
|
89
|
+
{
|
|
90
|
+
return new Promise<void>((resolve) => {
|
|
91
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
92
|
+
resolve();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
const DOMService = DOMServiceInstance.getSingleton();
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
export
|
|
99
|
+
|
|
100
|
+
export default DOMService.getSingleton();
|
|
101
|
+
export { DOMOutputType, DOMService, TagsProcessorType, DOMService as DOMServiceInstance };
|
|
@@ -4,7 +4,8 @@ import TheService from './_service';
|
|
|
4
4
|
* @class
|
|
5
5
|
* @extends TheService
|
|
6
6
|
*/
|
|
7
|
-
class
|
|
7
|
+
class NotifyService extends TheService {
|
|
8
|
+
static _DEFAULT: boolean = true;
|
|
8
9
|
private notifier: RWSNotify;
|
|
9
10
|
|
|
10
11
|
public setNotifier(notifier: RWSNotify)
|
|
@@ -43,7 +44,5 @@ class NotifyServiceInstance extends TheService {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export default NotifyService;
|
|
49
|
-
export { NotifyServiceInstance };
|
|
47
|
+
export default NotifyService.getSingleton();
|
|
48
|
+
export { NotifyService as NotifyServiceInstance };
|
|
@@ -9,6 +9,7 @@ import ConfigService, { ConfigServiceInstance } from './ConfigService';
|
|
|
9
9
|
type IFrontRoutes = Record<string, unknown>;
|
|
10
10
|
|
|
11
11
|
class RoutingService extends TheService {
|
|
12
|
+
static _DEFAULT: boolean = true;
|
|
12
13
|
private router: Router<any>;
|
|
13
14
|
private routes: IFrontRoutes;
|
|
14
15
|
|
|
@@ -3,19 +3,8 @@ import ApiService, {ApiServiceInstance} from './ApiService';
|
|
|
3
3
|
|
|
4
4
|
import { RawSourceMap } from 'source-map';
|
|
5
5
|
|
|
6
|
-
class UtilsService extends TheService {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(@ApiService apiService: ApiServiceInstance){
|
|
10
|
-
super();
|
|
11
|
-
this.apiService = apiService;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async getFileContents(filePath: string): Promise<string>
|
|
15
|
-
{
|
|
16
|
-
return this.apiService.pureGet(filePath);
|
|
17
|
-
}
|
|
18
|
-
|
|
6
|
+
class UtilsService extends TheService {
|
|
7
|
+
static _DEFAULT: boolean = true;
|
|
19
8
|
mergeDeep<T>(target: T | any, source: T | any): T
|
|
20
9
|
{
|
|
21
10
|
const isObject = (obj: any) => obj && typeof obj === 'object';
|
package/src/services/_service.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface IWithDI<T> {
|
|
|
10
10
|
|
|
11
11
|
export default abstract class TheRWSService {
|
|
12
12
|
_RELOADABLE: boolean = false;
|
|
13
|
+
static _IN_CLIENT: boolean = false;
|
|
14
|
+
static _DEFAULT: boolean = false;
|
|
13
15
|
|
|
14
16
|
constructor() {
|
|
15
17
|
}
|
|
@@ -47,4 +49,14 @@ export default abstract class TheRWSService {
|
|
|
47
49
|
|
|
48
50
|
return interf;
|
|
49
51
|
}
|
|
52
|
+
|
|
53
|
+
isDefault(): boolean
|
|
54
|
+
{
|
|
55
|
+
return (this as any).constructor._DEFAULT;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
isInClient(): boolean
|
|
59
|
+
{
|
|
60
|
+
return (this as any).constructor._IN_CLIENT;
|
|
61
|
+
}
|
|
50
62
|
}
|
package/webpack/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const tsLoader = require('./rws_fast_ts_loader');
|
|
1
|
+
const scssLoader = require('./loaders/rws_fast_scss_loader');
|
|
2
|
+
const htmlLoader = require('./loaders/rws_fast_html_loader');
|
|
3
|
+
const tsLoader = require('./loaders/rws_fast_ts_loader');
|
|
5
4
|
|
|
6
|
-
module.exports = {
|
|
7
|
-
cssLoader,
|
|
5
|
+
module.exports = {
|
|
8
6
|
scssLoader,
|
|
9
7
|
htmlLoader,
|
|
10
8
|
tsLoader
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const RWSCssPlugin = require("../rws_scss_plugin");
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const cssLoader = require('css-loader');
|
|
4
4
|
|
|
5
5
|
module.exports = function(content) {
|
|
6
6
|
const callback = this.async();
|
|
7
|
-
const plugin = new
|
|
7
|
+
const plugin = new RWSCssPlugin();
|
|
8
8
|
const filePath = this.resourcePath;
|
|
9
9
|
|
|
10
10
|
const options = this.getOptions() || { minify: false };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const ts = require('typescript');
|
|
5
|
-
const tools = require('
|
|
6
|
-
|
|
5
|
+
const tools = require('../../_tools');
|
|
6
|
+
|
|
7
7
|
|
|
8
8
|
const _defaultRWSLoaderOptions = {
|
|
9
9
|
templatePath: 'template.html',
|
|
@@ -11,23 +11,6 @@ const _defaultRWSLoaderOptions = {
|
|
|
11
11
|
fastOptions: { shadowOptions: { mode: 'open' } }
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function toJsonString(str) {
|
|
15
|
-
// Replace single quotes with double quotes
|
|
16
|
-
str = str.replace(/'/g, '"');
|
|
17
|
-
|
|
18
|
-
// Add double quotes around keys
|
|
19
|
-
str = str.replace(/([a-zA-Z0-9_]+)(?=\s*:)/g, '"$1"');
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Parse the string as JSON and then stringify it to get a JSON string
|
|
23
|
-
const jsonObj = JSON.parse(str);
|
|
24
|
-
return JSON.stringify(jsonObj);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error("Error in parsing:", error);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
14
|
module.exports = async function(content) {
|
|
32
15
|
let processedContent = content;
|
|
33
16
|
const filePath = this.resourcePath;
|
|
@@ -95,7 +78,7 @@ module.exports = async function(content) {
|
|
|
95
78
|
|
|
96
79
|
replaced = modifiedContent;
|
|
97
80
|
replaced = replaced.replace(`@RWSView('${tagName}')`, '');
|
|
98
|
-
|
|
81
|
+
|
|
99
82
|
let styles = 'const styles: null = null;'
|
|
100
83
|
|
|
101
84
|
if(fs.existsSync(path.dirname(filePath) + '/styles')){
|
|
@@ -112,13 +95,9 @@ module.exports = async function(content) {
|
|
|
112
95
|
|
|
113
96
|
let htmlContent = fs.readFileSync(templatePath, 'utf-8');
|
|
114
97
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// });
|
|
119
|
-
// } catch(e){
|
|
120
|
-
// console.error(e);
|
|
121
|
-
// }
|
|
98
|
+
if(!isDev){
|
|
99
|
+
htmlContent = htmlContent.replace(/\n/g, '');
|
|
100
|
+
}
|
|
122
101
|
|
|
123
102
|
template = `import './${templateName}.html';
|
|
124
103
|
//@ts-ignore
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const Terser = require('terser');
|
|
5
|
+
|
|
6
|
+
async function removeCommentsFromFile(code, inputSourceMap) {
|
|
7
|
+
const callback = this.async();
|
|
8
|
+
const sourceMap = this.sourceMap;
|
|
9
|
+
// Configure Terser to remove comments
|
|
10
|
+
try {
|
|
11
|
+
const minifyOptions = {
|
|
12
|
+
format: {
|
|
13
|
+
comments: false // Remove all comments
|
|
14
|
+
},
|
|
15
|
+
sourceMap: sourceMap
|
|
16
|
+
? {
|
|
17
|
+
content: inputSourceMap || false,
|
|
18
|
+
url: 'out.js.map'
|
|
19
|
+
}
|
|
20
|
+
: false
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Minify source code
|
|
24
|
+
const result = await Terser.minify(code, minifyOptions);
|
|
25
|
+
|
|
26
|
+
// Pass along the source map if enabled
|
|
27
|
+
callback(null, result.code, result.map || inputSourceMap);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
callback(err);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = async function (source, inputSourceMap) {
|
|
34
|
+
return await removeCommentsFromFile.bind(this)(source, inputSourceMap);
|
|
35
|
+
};
|
|
@@ -15,7 +15,7 @@ const log = (args) => {
|
|
|
15
15
|
console.log(args);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
class
|
|
18
|
+
class RWSScssPlugin {
|
|
19
19
|
autoCompile = [];
|
|
20
20
|
|
|
21
21
|
constructor(params){
|
|
@@ -326,4 +326,4 @@ class RWSPlugin {
|
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
module.exports =
|
|
329
|
+
module.exports = RWSScssPlugin;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// custom-css-loader.js
|
|
2
|
-
const RWSPlugin = require("./rws_plugin");
|
|
3
|
-
const plugin = new RWSPlugin();
|
|
4
|
-
|
|
5
|
-
module.exports = function(content) {
|
|
6
|
-
|
|
7
|
-
if(this.resourcePath == '/app/frontend/src/styles/main.scss'){
|
|
8
|
-
console.log('zzzzz',content, plugin.checkForImporterType(this._module, 'ts'));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if(!plugin.checkForImporterType(this._module, 'ts')){
|
|
12
|
-
return content;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return `import { css } from '@microsoft/fast-element';\nexport default css\`${content}\`;`;
|
|
16
|
-
};
|
|
File without changes
|