@rws-framework/client 2.2.2 → 2.3.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.
@@ -0,0 +1,14 @@
1
+ declare const _DEFAULT_CONFIG: any;
2
+
3
+ declare function readConfigFile(filePath: string): any;
4
+ declare function get(key: string): any;
5
+ declare function exportDefaultConfig(): any;
6
+ declare function exportBuildConfig(): any;
7
+
8
+ export {
9
+ readConfigFile,
10
+ get,
11
+ exportDefaultConfig,
12
+ exportBuildConfig,
13
+ _DEFAULT_CONFIG
14
+ };
@@ -1,51 +1,48 @@
1
1
  const fs = require('fs');
2
2
  const json5 = require('json5');
3
3
 
4
+ const _DEFAULT_CONFIG = require('./cfg/_default.cfg')._DEFAULT_CONFIG;
5
+ const STORAGE = require('./cfg/_storage');
4
6
 
5
- const _STORAGE = { _loaded: false }
6
-
7
- const _DEFAULT_CONFIG = {
8
- dev: false,
9
- hot: false,
10
- report: false,
11
- backendUrl: null,
12
- wsUrl: null,
13
- transports: ['websocket'],
14
- parted: true,
15
- partedFileDir: './build',
16
- partedPrefix: 'rws',
17
- publicDir: './public',
18
- publicIndex: 'index.html',
19
- pubUrlPrefix: '/',
20
- outputFileName: 'client.rws.js'
21
- }
22
7
 
23
8
  function readConfigFile(filePath){
9
+ if(!fs.existsSync(filePath)){
10
+ return _DEFAULT_CONFIG;
11
+ }
12
+
24
13
  const fileConfig = json5.parse(fs.readFileSync(filePath, 'utf-8'));
25
14
 
26
- return {
27
- ..._DEFAULT_CONFIG,
15
+ return {
28
16
  ...fileConfig
29
17
  }
30
18
  }
31
19
 
32
20
  function get(key){
33
- if(!_STORAGE._loaded){
34
- Object.assign(_STORAGE, readConfigFile(process.cwd() + '/.rws.json'));
21
+ _init();
35
22
 
36
- console.log(_STORAGE);
37
- }
23
+ return STORAGE.get(key);
24
+ }
38
25
 
39
- if(Object.keys(_STORAGE).includes(key)){
40
- return _STORAGE[key];
41
- }
26
+ function exportDefaultConfig(){
27
+ return _DEFAULT_CONFIG;
28
+ }
29
+
30
+ function exportBuildConfig(){
31
+ _init();
42
32
 
43
- return null;
33
+ return STORAGE.getAll();
44
34
  }
45
35
 
36
+ function _init(){
37
+ if(!STORAGE.isLoaded()){
38
+ STORAGE.init(readConfigFile(process.cwd() + '/.rws.json'))
39
+ }
40
+ }
46
41
 
47
42
  module.exports = {
48
43
  readConfigFile,
44
+ exportDefaultConfig,
45
+ exportBuildConfig,
49
46
  get,
50
47
  _DEFAULT_CONFIG
51
48
  };
@@ -0,0 +1,23 @@
1
+ const _DEFAULT_CONFIG_VARS = {
2
+ //Build configs
3
+ dev: false,
4
+ hot: false,
5
+ report: false,
6
+ publicDir: './public',
7
+ publicIndex: 'index.html',
8
+ outputFileName: 'client.rws.js',
9
+ outputDir: process.cwd() + '/build',
10
+ //Frontend RWS client configs
11
+ backendUrl: null,
12
+ wsUrl: null,
13
+ partedDirUrlPrefix: '/lib/rws',
14
+ partedPrefix: 'rws',
15
+ pubUrlFilePrefix: '/',
16
+ //Universal configs
17
+ transports: ['websocket'],
18
+ parted: false,
19
+ }
20
+
21
+ const _DEFAULT_CONFIG = Object.freeze(_DEFAULT_CONFIG_VARS);
22
+
23
+ module.exports = {_DEFAULT_CONFIG};
@@ -0,0 +1,22 @@
1
+ interface Storage {
2
+ _loaded: boolean;
3
+ data: {
4
+ [key: string]: any;
5
+ };
6
+ }
7
+
8
+ declare const _STORAGE: Readonly<Storage>;
9
+
10
+ declare function get(key: string): any | null;
11
+ declare function getAll(): any;
12
+ declare function init(json: any): void;
13
+ declare function has(key: string): boolean;
14
+ declare function isLoaded(): boolean;
15
+
16
+ export {
17
+ get,
18
+ getAll,
19
+ has,
20
+ init,
21
+ isLoaded
22
+ };
@@ -0,0 +1,43 @@
1
+ class Storage {
2
+ static _instance;
3
+
4
+ _loaded = false;
5
+ data = {}
6
+
7
+ static create(){
8
+ if(!this._instance){
9
+ this._instance = new Storage();
10
+ }
11
+
12
+ return this._instance;
13
+ }
14
+ }
15
+
16
+ const _STORAGE = Storage.create();
17
+
18
+ function get(key){
19
+ if(!has(key)){
20
+ return null;
21
+ }
22
+
23
+ return _STORAGE.data[key];
24
+ }
25
+
26
+ function getAll(){
27
+ return _STORAGE.data;
28
+ }
29
+
30
+ function init(json){
31
+ _STORAGE.data = json;
32
+ _STORAGE._loaded = true;
33
+ }
34
+
35
+ function has(key){
36
+ return Object.keys(_STORAGE.data).includes(key);
37
+ }
38
+
39
+ function isLoaded(){
40
+ return _STORAGE._loaded;
41
+ }
42
+
43
+ module.exports = {get, getAll, has, init, isLoaded}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.2.2",
4
+ "version": "2.3.1",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -52,7 +52,7 @@
52
52
  "@open-wc/dev-server-hmr": "^0.1.2-next.0",
53
53
  "@types/dragula": "^3.7.4",
54
54
  "@types/express-fileupload": "^1.4.4",
55
- "@types/he": "^1.2.3",
55
+ "@types/he": "^1.2.3",
56
56
  "@types/json5": "^2.2.0",
57
57
  "@types/sanitize-html": "^2.11.0",
58
58
  "@types/socket.io-client": "^3.0.0",
@@ -67,7 +67,7 @@
67
67
  "eslint-plugin-unused-imports": "^3.1.0",
68
68
  "file-loader": "^6.2.0",
69
69
  "html-webpack-plugin": "^5.5.3",
70
- "loader-utils": "^3.2.1",
70
+ "loader-utils": "^3.2.1",
71
71
  "mini-css-extract-plugin": "^2.7.6",
72
72
  "node-sass": "^9.0.0",
73
73
  "sass-loader": "^13.3.2",
@@ -1,71 +1,73 @@
1
1
  const path = require('path');
2
- const webpack = require('webpack');
3
2
  const fs = require('fs');
4
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
5
- const JsMinimizerPlugin = require('terser-webpack-plugin');
6
- const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
3
+ const webpack = require('webpack');
4
+ const uglify = require('uglify-js')
7
5
  const HtmlWebpackPlugin = require('html-webpack-plugin');
8
6
  const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
7
+
9
8
  const RWSAfterPlugin = require('./webpack/rws_after_plugin');
10
- const { Console } = require('console');
11
- const { Interface } = require('readline');
12
- const ts = require('typescript');
13
9
  const tools = require('./_tools');
14
10
  const BuildConfigurator = require('./_rws_build_configurator');
11
+
15
12
  const TerserPlugin = require('terser-webpack-plugin');
16
13
  const HtmlMinifier = require('html-minifier').minify;
17
- const { CleanWebpackPlugin } = require("clean-webpack-plugin");
18
-
19
- let WEBPACK_PLUGINS = [];
20
-
21
- /**
22
- * The RWS webpack configurator.
23
- *
24
- * Example usage in importing file:
25
- *
26
- * RWSWebpackWrapper({
27
- dev: true,
28
- hot: false,
29
- tsConfigPath: executionDir + '/tsconfig.json',
30
- entry: `${executionDir}/src/index.ts`,
31
- executionDir: executionDir,
32
- publicDir: path.resolve(executionDir, 'public'),
33
- outputDir: path.resolve(executionDir, 'build'),
34
- outputFileName: 'jtrainer.client.js',
35
- copyToDir: {
36
- '../public/js/' : [
37
- './build/jtrainer.client.js',
38
- './build/jtrainer.client.js.map',
39
- './src/styles/compiled/main.css'
40
- ]
41
- },
42
- plugins: [
43
-
44
- ],
45
- });
46
- */
14
+ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
15
+ const JsMinimizerPlugin = require('terser-webpack-plugin');
16
+
17
+ const json5 = require('json5');
18
+
19
+
47
20
  const RWSWebpackWrapper = (config) => {
48
- const executionDir = config.executionDir || process.cwd();
21
+ const executionDir = config.executionDir || process.cwd();
49
22
 
50
- const isDev = config.dev || BuildConfigurator.get('dev');
51
- const isHotReload = config.hot || BuildConfigurator.get('hot');
52
- const isReport = config.report || BuildConfigurator.get('report');
53
- const outputDir = config.outputDir || BuildConfigurator.get('outputDir');
54
- const outputFileName = config.outputFileName || BuildConfigurator.get('outputFileName');
23
+ const isDev = BuildConfigurator.get('dev') || config.dev;
24
+ const isHotReload = BuildConfigurator.get('hot') || config.hot;
25
+ const isReport = BuildConfigurator.get('report') || config.report;
55
26
 
56
- const publicDir = config.publicDir || BuildConfigurator.get('publicDir');
57
- const serviceWorkerPath = config.serviceWorker || BuildConfigurator.get('serviceWorker');
27
+ const isParted = BuildConfigurator.get('parted') || config.parted;
28
+ const partedPrefix = BuildConfigurator.get('partedPrefix') || config.partedPrefix;
29
+ const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix') || config.partedDirUrlPrefix;
58
30
 
59
- const WEBPACK_AFTER_ACTIONS = config.actions || [];
31
+ const partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations') || config.partedComponentsLocations;
32
+ const customServiceLocations = BuildConfigurator.get('customServiceLocations') || config.customServiceLocations;
33
+ const outputDir = BuildConfigurator.get('outputDir') || config.outputDir;
34
+ const outputFileName = BuildConfigurator.get('outputFileName') || config.outputFileName;
35
+ const publicDir = BuildConfigurator.get('publicDir') || config.publicDir;
36
+ const serviceWorkerPath = BuildConfigurator.get('serviceWorker') || config.serviceWorker;
60
37
 
61
- const publicIndex = config.publicIndex || BuildConfigurator.get('publicIndex');
38
+ const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
62
39
 
63
- const aliases = config.aliases = {};
64
40
 
65
- aliases.fs = false;
41
+ let WEBPACK_PLUGINS = [
42
+ new webpack.DefinePlugin({
43
+ 'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportDefaultConfig()),
44
+ 'process.env._RWS_BUILD_OVERRIDE': JSON.stringify(BuildConfigurator.exportBuildConfig())
45
+ }),
46
+ new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/)
47
+ ];
66
48
 
67
- const modules_setup = [path.resolve(__dirname, 'node_modules'), 'node_modules'];
49
+ console.log('PARTED', isParted);
50
+
51
+ // if(isParted){
52
+ // WEBPACK_PLUGINS.push(new webpack.BannerPlugin({
53
+ // banner: `if(!window.RWS_PARTS_LOADED){
54
+ // const script = document.createElement('script');
55
+ // script.src = '${partedDirUrlPrefix}/${partedPrefix}.vendors.js';
56
+ // script.type = 'text/javascript';
57
+ // document.body.appendChild(script);
58
+ // window.RWS_PARTS_LOADED = true;
59
+ // }`.replace('\n', ''),
60
+ // raw: true,
61
+ // entryOnly: true,
62
+ // // include: 'client'
63
+ // }));
64
+ // }
65
+
66
+ const WEBPACK_AFTER_ACTIONS = config.actions || [];
68
67
 
68
+ const aliases = config.aliases = {};
69
+ aliases.fs = false;
70
+ const modules_setup = [path.resolve(__dirname, 'node_modules'), 'node_modules'];
69
71
  const overridePlugins = config.plugins || []
70
72
 
71
73
  if (isHotReload) {
@@ -81,7 +83,7 @@ const RWSWebpackWrapper = (config) => {
81
83
  WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, new webpack.optimize.ModuleConcatenationPlugin(), ...overridePlugins];
82
84
 
83
85
 
84
- if (isDev && isReport) {
86
+ if (isReport) {
85
87
  WEBPACK_PLUGINS.push(new BundleAnalyzerPlugin({
86
88
  analyzerMode: 'static',
87
89
  openAnalyzer: false,
@@ -95,10 +97,12 @@ const RWSWebpackWrapper = (config) => {
95
97
  });
96
98
  }
97
99
 
98
- if (!!config.copyToDir) {
100
+ const assetsToCopy = config.copyAssets || BuildConfigurator.get('copyAssets');
101
+
102
+ if (!!assetsToCopy) {
99
103
  WEBPACK_AFTER_ACTIONS.push({
100
104
  type: 'copy',
101
- actionHandler: config.copyToDir
105
+ actionHandler: assetsToCopy
102
106
  });
103
107
  }
104
108
 
@@ -120,14 +124,26 @@ const RWSWebpackWrapper = (config) => {
120
124
  path.resolve(executionDir, 'src', 'services')
121
125
  ];
122
126
 
123
- if (config.customServiceLocations) {
124
- config.customServiceLocations.forEach((serviceDir) => {
127
+ if (customServiceLocations) {
128
+ customServiceLocations.forEach((serviceDir) => {
125
129
  servicesLocations.push(serviceDir);
126
130
  });
127
131
  }
128
132
 
129
133
  const optimConfig = {
130
- minimizer: isDev ? [] : [
134
+ minimize: true,
135
+ minimizer: isDev ? [
136
+ new TerserPlugin({
137
+ terserOptions: {
138
+ mangle: false, //@error breaks FAST view stuff if enabled for all assets
139
+ output: {
140
+ comments: false
141
+ },
142
+ },
143
+ extractComments: false,
144
+ parallel: true,
145
+ })
146
+ ] : [
131
147
  new TerserPlugin({
132
148
  terserOptions: {
133
149
  keep_classnames: true, // Prevent mangling of class names
@@ -140,16 +156,16 @@ const RWSWebpackWrapper = (config) => {
140
156
  comments: false
141
157
  },
142
158
  },
143
- extractComments: false
159
+ extractComments: false,
160
+ parallel: true,
144
161
  }),
145
162
  new CssMinimizerPlugin(),
146
-
147
163
  ],
148
164
  };
149
165
 
150
- if (config.parted) {
151
- if (config.partedComponentsLocations) {
152
- config.partedComponentsLocations.forEach((componentDir) => {
166
+ if (isParted) {
167
+ if (partedComponentsLocations) {
168
+ partedComponentsLocations.forEach((componentDir) => {
153
169
  RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', '@rws-framework/client']))];
154
170
  });
155
171
  }
@@ -207,8 +223,8 @@ const RWSWebpackWrapper = (config) => {
207
223
  target: 'web',
208
224
  devtool: isDev ? (config.devtool || 'inline-source-map') : false,
209
225
  output: {
210
- path: config.outputDir,
211
- filename: config.parted ? (config.partedPrefix || 'rws') + '.[name].js' : config.outputFileName,
226
+ path: outputDir,
227
+ filename: isParted ? (partedPrefix || 'rws') + '.[name].js' : outputFileName,
212
228
  sourceMapFilename: '[file].map',
213
229
  },
214
230
  resolve: {
package/src/client.ts CHANGED
@@ -39,7 +39,7 @@ class RWSClient {
39
39
  private _container: Container;
40
40
  private user: IRWSUser = null;
41
41
 
42
- private config: IRWSConfig = { backendUrl: '', routes: {}, splitFileDir: '/', splitPrefix: 'rws' };
42
+ private config: IRWSConfig = {};
43
43
  protected initCallback: () => Promise<void> = async () => { };
44
44
 
45
45
  private isSetup = false;
@@ -106,17 +106,15 @@ class RWSClient {
106
106
 
107
107
  if (Object.keys(config).length) {
108
108
  this.appConfig.mergeConfig(this.config);
109
- }
110
-
111
- console.log(this.isSetup, this.config, this.appConfig);
109
+ }
112
110
 
113
111
  if (this.config.user && !this.config.dontPushToSW) {
114
112
  this.pushUserToServiceWorker(this.user);
115
113
  }
116
114
 
117
- await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
115
+ await startClient(this.appConfig, this.wsService, this.notifyService, this.routingService);
118
116
 
119
- await this.initCallback();
117
+ await this.initCallback();
120
118
 
121
119
  return this;
122
120
  }
@@ -223,35 +221,19 @@ class RWSClient {
223
221
  async loadPartedComponents(): Promise<void> {
224
222
  this.assignClientToBrowser();
225
223
 
226
- const componentParts: string[] = await this.apiService.get<string[]>(this.appConfig.get('splitFileDir') + '/rws_chunks_info.json');
227
-
228
- const _all: Promise<string>[] = [];
229
- componentParts.forEach((componentName: string) => {
230
-
231
- const scriptUrl: string = this.appConfig.get('splitFileDir') + `/${this.appConfig.get('splitPrefix')}.${componentName}.js`; // Replace with the path to your script file
232
-
224
+ const componentParts: string[] = await this.apiService.get<string[]>(this.appConfig.get('partedDirUrlPrefix') + '/rws_chunks_info.json');
233
225
 
226
+ componentParts.forEach((componentName: string, key: number) => {
227
+ const partUrl = `${this.appConfig.get('partedDirUrlPrefix')}/${this.appConfig.get('partedPrefix')}.${componentName}.js`;
234
228
 
235
- const headers: any = {};
236
-
237
- headers['Content-Type'] = 'application/javascript';
238
-
239
- _all.push(this.apiService.pureGet(scriptUrl, {
240
- headers
241
- }));
242
- });
243
-
244
- (await Promise.all(_all)).forEach((scriptCnt: string, key: number) => {
245
229
  const script: HTMLScriptElement = document.createElement('script');
246
- script.textContent = scriptCnt;
230
+ script.src = partUrl;
247
231
  script.async = true;
248
232
  script.type = 'text/javascript';
249
233
  document.body.appendChild(script);
250
234
 
251
- console.log(`Appended ${componentParts[key]} component`);
252
- });
253
-
254
- RWSClient.defineAllComponents();
235
+ console.log(`Appended ${componentParts[key]} component (${partUrl})`);
236
+ });
255
237
  }
256
238
 
257
239
  async onDOMLoad(): Promise<void> {
@@ -290,9 +272,18 @@ class RWSClient {
290
272
 
291
273
  static defineAllComponents() {
292
274
  const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
293
- // provideRWSDesignSystem().register(richWindowComponents[devStr].component);
275
+ console.log('defining', richWindowComponents)
276
+
277
+ Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
278
+ el.define(el as any, el.definition);
279
+ });
280
+ }
281
+
282
+
283
+ defineComponents(){
284
+ const richWindowComponents: RWSWindowComponentRegister = (window as Window & RWSWindow).RWS.components;
285
+ console.log('defining', richWindowComponents)
294
286
 
295
- console.log(richWindowComponents);
296
287
  Object.keys(richWindowComponents).map(key => richWindowComponents[key].component).forEach((el: IWithCompose<RWSViewComponent>) => {
297
288
  el.define(el as any, el.definition);
298
289
  });
@@ -63,7 +63,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
63
63
  @RWSInject(NotifyService) protected notifyService: NotifyServiceInstance
64
64
  ) {
65
65
  super();
66
- applyConstructor(this);
66
+ applyConstructor(this);
67
67
  }
68
68
 
69
69
  connectedCallback() {
@@ -71,7 +71,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
71
71
  applyConstructor(this);
72
72
 
73
73
  // console.trace(this.config);
74
-
74
+ // console.log(this.routingService);
75
75
  if (!(this.constructor as IWithCompose<this>).definition && (this.constructor as IWithCompose<this>).autoLoadFastElement) {
76
76
  throw new Error('RWS component is not named. Add `static definition = {name, template};`');
77
77
  }
@@ -81,7 +81,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
81
81
  if (this.fileAssets[file]) {
82
82
  return;
83
83
  }
84
- this.utilsService.getFileContents(this.config.get('pubUrlPrefix') + file).then((response: string) => {
84
+ this.utilsService.getFileContents(this.config.get('pubUrlFilePrefix') + file).then((response: string) => {
85
85
  this.fileAssets = { ...this.fileAssets, [file]: html`${response}` };
86
86
  });
87
87
  });
@@ -17,7 +17,7 @@ type InjectDecoratorReturnType = (target: any, key?: string | number | undefined
17
17
  function RWSInject<T extends RWSViewComponent>(dependencyClass: Key): InjectDecoratorReturnType {
18
18
  return (target: IWithCompose<T>, key?: keyof IWithCompose<T>, parameterIndex?: number) => {
19
19
  const loadedDependency = RWSContainer().get(dependencyClass);
20
- const paramNames = getFunctionParamNames(target.prototype.constructor);
20
+ const paramNames = getFunctionParamNames(target.prototype.constructor);
21
21
  target.prototype.constructor._toInject[paramNames[parameterIndex]] = loadedDependency;
22
22
  };
23
23
  }
@@ -63,8 +63,8 @@ const applyConstructor = (component: RWSViewComponent): void => {
63
63
  }
64
64
 
65
65
  const existingInjectedDependencies = (topConstructor as IWithCompose<RWSViewComponent>)._toInject;
66
-
67
66
  Object.keys(existingInjectedDependencies).forEach((depKey: string) => {
67
+
68
68
  const loadedDependency = existingInjectedDependencies[depKey];
69
69
  if(!(component as any)[depKey]){
70
70
  (component as any)[depKey] = loadedDependency;
@@ -0,0 +1,56 @@
1
+ import 'reflect-metadata';
2
+ import IRWSConfig from '../../interfaces/IRWSConfig.js';
3
+
4
+ function extractEnvVar(envVar: string){
5
+ const extractedVars = JSON.parse(JSON.stringify(envVar));
6
+
7
+ const {
8
+ backendUrl,
9
+ wsUrl,
10
+ partedDirUrlPrefix,
11
+ partedPrefix,
12
+ pubUrlFilePrefix,
13
+ transports,
14
+ parted
15
+ } = extractedVars;
16
+
17
+ const extractedFrontendVars = {
18
+ backendUrl,
19
+ wsUrl,
20
+ partedDirUrlPrefix,
21
+ partedPrefix,
22
+ pubUrlFilePrefix,
23
+ transports,
24
+ parted
25
+ };
26
+
27
+ return {
28
+ extractedVars,
29
+ extractedFrontendVars
30
+ }
31
+ }
32
+
33
+ function RWSFillBuild(config: Partial<IRWSConfig> = {}) {
34
+ return function <T extends { new(...args: any[]): {} }>(constructor: T) {
35
+ return class extends constructor {
36
+ _DEFAULTS: IRWSConfig;
37
+ _BUILD_OVERRIDE: IRWSConfig;
38
+ constructor(...args: any[]) {
39
+ super(...args);
40
+
41
+ const extractedFrontendDefaults = extractEnvVar(process.env._RWS_DEFAULTS).extractedFrontendVars;
42
+
43
+ this._DEFAULTS = {
44
+ ...config,
45
+ ...extractedFrontendDefaults
46
+ } as IRWSConfig;
47
+
48
+ const extractedFrontendBuildVars = extractEnvVar(process.env._RWS_BUILD_OVERRIDE).extractedFrontendVars;;
49
+
50
+ this._BUILD_OVERRIDE = extractedFrontendBuildVars as IRWSConfig;
51
+ }
52
+ };
53
+ };
54
+ }
55
+
56
+ export { RWSFillBuild }
@@ -3,12 +3,6 @@ import { RouterComponent } from './router/component';
3
3
  import { RWSProgress } from './progress/component';
4
4
  import { RWSLoader } from './loader/component';
5
5
 
6
- const RWSComponents = {
7
- RWSUploader,
8
- RouterComponent,
9
- RWSProgress,
10
- RWSLoader
11
- };
12
6
 
13
7
  function declareRWSComponents(parted: boolean = false): void
14
8
  {
@@ -20,4 +14,4 @@ function declareRWSComponents(parted: boolean = false): void
20
14
  }
21
15
  }
22
16
 
23
- export { RWSComponents, declareRWSComponents };
17
+ export { declareRWSComponents };
@@ -3,7 +3,7 @@ import { RWSRouter, _ROUTING_EVENT_NAME, RouteReturn } from '../../services/Rout
3
3
  import RWSViewComponent, { IRWSViewComponent } from '../_component';
4
4
  import {RWSView} from '../_decorator';
5
5
 
6
- @RWSView('rws-router', { ignorePackaging: true })
6
+ @RWSView('rws-router')
7
7
  export class RouterComponent extends RWSViewComponent {
8
8
  static autoLoadFastElement = false;
9
9
  private routing: RWSRouter;
@@ -15,19 +15,24 @@ export class RouterComponent extends RWSViewComponent {
15
15
 
16
16
  connectedCallback() {
17
17
  super.connectedCallback();
18
+
19
+
20
+
18
21
  this.routing = this.routingService.apply(this);
19
22
 
20
- if(this.currentUrl){
23
+ if(this.currentUrl){
21
24
  this.handleRoute(this.routing.handleRoute(this.currentUrl));
22
25
  }
23
26
  }
24
27
 
25
- currentUrlChanged(oldValue: string, newValue: string){
26
- if(!this.routing){
27
- this.routing = this.routingService.apply(this);
28
+ currentUrlChanged(oldValue: string, newValue: string){
29
+ if(newValue){
30
+ if(!this.routing){
31
+ this.routing = this.routingService.apply(this);
28
32
 
29
- }
30
- this.handleRoute(this.routing.handleRoute(newValue));
33
+ }
34
+ this.handleRoute(this.routing.handleRoute(newValue));
35
+ }
31
36
  }
32
37
 
33
38
  private handleRoute(route: RouteReturn){
@@ -0,0 +1 @@
1
+ <div class="router"></div>
package/src/index.ts CHANGED
@@ -29,7 +29,7 @@ import {
29
29
 
30
30
  import { RWSDecoratorOptions, RWSIgnore, RWSView, RWSInject } from './components/_decorator';
31
31
 
32
- import { RWSComponents, declareRWSComponents } from './components';
32
+ import { declareRWSComponents } from './components';
33
33
 
34
34
  export default RWSClient;
35
35
  export {
@@ -82,8 +82,6 @@ export {
82
82
  ngAttr,
83
83
 
84
84
  renderRouteComponent,
85
-
86
- RWSComponents,
87
85
 
88
86
  observable,
89
87
  attr,
@@ -12,7 +12,8 @@ export default interface IRWSConfig {
12
12
  user?: any
13
13
  ignoreRWSComponents?: boolean
14
14
  pubUrl?: string
15
- pubUrlPrefix?: string
15
+ pubUrlFilePrefix?: string
16
+ partedDirUrlPrefix?: string
16
17
  dontPushToSW?: boolean
17
18
  parted?: boolean
18
19
  partedFileDir?: string
@@ -28,13 +28,15 @@ class RWSRouter {
28
28
  }
29
29
 
30
30
  public fireHandler(route: IRWSRouteResult): RouteReturn
31
- { const handler = route.handler();
31
+ {
32
+ const handler = route.handler();
32
33
  return [handler[0], handler[1], this.utilsService.mergeDeep(route.params, handler[2])];
33
34
  }
34
35
 
35
36
  public handleRoute(url: string): RouteReturn
36
37
  {
37
38
  const currentRoute = this.find(url);
39
+ console.log('CR', currentRoute);
38
40
 
39
41
  if (history.pushState) {
40
42
  window.history.pushState({ path: url }, '', url);
@@ -1,42 +1,52 @@
1
1
  import TheService from './_service';
2
2
  import IRWSConfig from '../interfaces/IRWSConfig';
3
- import { RWSFillBuildConfig } from '../components/_decorators/RWSFillBuildConfig';
4
-
5
- @RWSFillBuildConfig()
6
- const _DEFAULTS: IRWSConfig = {
7
- pubUrlPrefix: '/',
8
- pubUrl : window.origin,
9
- partedFileDir: '/',
10
- partedPrefix: 'rws'
11
- }
3
+ import { RWSFillBuild } from '../components/_decorators/RWSFillBuild';
4
+
5
+
6
+
12
7
 
13
8
  const __SENT_TO_COMPONENTS: string[] = [];
14
9
 
10
+ @RWSFillBuild()
15
11
  class ConfigService extends TheService {
16
12
  static isLoaded: boolean = false;
13
+
14
+ _DEFAULTS: Partial<IRWSConfig> = {};
15
+ _BUILD_OVERRIDE: IRWSConfig = {};
17
16
 
18
17
  private data: IRWSConfig = {};
19
18
 
20
19
  constructor() {
21
- super();
20
+ super();
22
21
  }
23
22
 
24
23
  public get(key: keyof IRWSConfig): any
25
- {
24
+ {
25
+
26
+ if(!this._DEFAULTS){
27
+ throw new Error('No _DEFAULTS loaded!')
28
+ }
29
+
26
30
 
31
+ const isInDefaults: boolean = Object.keys(this._DEFAULTS).includes(key);
27
32
  const isInData: boolean = Object.keys(this.data).includes(key);
28
- const isInDefaults: boolean = Object.keys(_DEFAULTS).includes(key);
33
+ const isInBuildVars: boolean = Object.keys(this._BUILD_OVERRIDE).includes(key);
29
34
 
30
- if(!isInData && isInDefaults){
31
- let defaultVal = _DEFAULTS[key];
35
+ if(!isInData){
36
+ let defaultVal = null;
32
37
 
33
- if(defaultVal[0] === '@'){
38
+ if(isInDefaults){
39
+ defaultVal = this._DEFAULTS[key];
40
+ }
41
+
42
+ if(isInBuildVars && !!this._BUILD_OVERRIDE[key]){
43
+ defaultVal = this._BUILD_OVERRIDE[key];
44
+ }
45
+
46
+ if(defaultVal && defaultVal[0] === '@'){
34
47
  defaultVal = this.data[((defaultVal as string).slice(1)) as keyof IRWSConfig];
35
48
  }
36
-
37
49
  return defaultVal;
38
- } else if(!isInData && !isInDefaults) {
39
- return null;
40
50
  }
41
51
 
42
52
 
@@ -35,6 +35,28 @@ class RWSAfterPlugin {
35
35
  return await Promise.all(proms);
36
36
  });
37
37
  });
38
+
39
+ compiler.hooks.emit.tapAsync('RWSAfterPlugin', (compilation, callback) => {
40
+ Object.keys(compilation.assets).forEach((filename) => {
41
+
42
+ if (filename.endsWith('.js')) {
43
+ const asset = compilation.assets[filename];
44
+ let source = asset.source();
45
+ if(source.indexOf('css`') > -1 || source.indexOf('html`') > -1){
46
+ console.log('replacing', filename);
47
+ const updatedSource = source.replace(/\n/g, '');
48
+
49
+ // Update the asset with the new content
50
+ compilation.assets[filename] = {
51
+ source: () => updatedSource,
52
+ size: () => updatedSource.length
53
+ };
54
+ }
55
+ }
56
+ });
57
+
58
+ callback();
59
+ });
38
60
  }
39
61
 
40
62
  async _runActionType(actionType, action){
@@ -124,19 +124,6 @@ class RWSPlugin {
124
124
  const _self = this;
125
125
 
126
126
  return;
127
-
128
- compiler.hooks.thisCompilation.tap('RWSSassPlugin', (compilation) => {
129
- compilation.hooks.buildModule.tap('RWSSassPlugin', (module) => {
130
- if (module.resource && /\.scss$/.test(module.resource)) {
131
-
132
- let scssPath = module.resource;
133
-
134
- this.compileFile(scssPath, true).catch((e) => {
135
- throw e;
136
- })
137
- }
138
- });
139
- });
140
127
  }
141
128
 
142
129
  readSCSSFilesFromDirectory(dirPath) {
@@ -1,14 +0,0 @@
1
- import { Key } from '@microsoft/fast-foundation';
2
-
3
- import 'reflect-metadata';
4
- import IRWSConfig from '../../interfaces/IRWSConfig';
5
-
6
- type FillBuildDecoratorReturnType = (target: any, key?: string | number | undefined, parameterIndex?: number) => void;
7
-
8
- function RWSFillBuildConfig(dependencyClass: Key): FillBuildDecoratorReturnType {
9
- return (target: IRWSConfig, key?: string | number, parameterIndex?: number) => {
10
- console.log('ONBUILD', target, key, parameterIndex);
11
- };
12
- }
13
-
14
- export { RWSFillBuildConfig }