@rws-framework/client 2.9.2 → 2.9.4
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/README.md +2 -0
- package/cfg/_default.cfg.js +2 -0
- package/cfg/build_steps/webpack/_aliases.js +0 -0
- package/cfg/build_steps/webpack/_info.js +0 -0
- package/cfg/build_steps/webpack/_loaders.js +14 -6
- package/foundation/index.js +0 -0
- package/foundation/rws-foundation.d.ts +0 -0
- package/foundation/rws-foundation.js +0 -0
- package/package.json +20 -10
- package/rws.webpack.config.js +18 -8
- package/src/components/_attrs/_default_observable_accessor.ts +9 -0
- package/src/components/_attrs/_extended_accessor.ts +35 -0
- package/src/components/_attrs/_external_observable_accessor.ts +9 -0
- package/src/components/_attrs/angular-attr.ts +7 -4
- package/src/components/_attrs/external-attr.ts +3 -0
- package/src/components/_attrs/external-observable.ts +35 -58
- package/src/components/_decorator.ts +1 -1
- package/src/index.ts +3 -1
- package/webpack/loaders/rws_fast_html_loader.js +14 -0
- package/webpack/loaders/rws_fast_scss_loader.js +8 -59
- package/webpack/loaders/rws_fast_ts_loader.js +29 -17
package/README.md
CHANGED
|
@@ -379,8 +379,10 @@ const options?: RWSDecoratorOptions;
|
|
|
379
379
|
class WebChat extends RWSViewComponent {
|
|
380
380
|
@attr tagAttr: string; //HTML tag attr
|
|
381
381
|
@ngAttr fromNgAttr: string; //HTML attr from angular template
|
|
382
|
+
@externalAttr fromExAttr: string; //HTML attr with change observation
|
|
382
383
|
@sanitizedAttr htmlAttr: string; //HTML attr that's sanitized with every val change
|
|
383
384
|
@observable someVar: any; //Var for templates/value change observation
|
|
385
|
+
@externalObservable someExVar: string; //Var for templates/value change observation with external watch
|
|
384
386
|
}
|
|
385
387
|
```
|
|
386
388
|
|
package/cfg/_default.cfg.js
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -9,11 +9,13 @@ function getRWSLoaders(packageDir, nodeModulesPath, tsConfigPath){
|
|
|
9
9
|
|
|
10
10
|
return [
|
|
11
11
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
test: /\.html$/,
|
|
13
|
+
use: [
|
|
14
|
+
{
|
|
15
|
+
loader: htmlLoader,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
17
19
|
{
|
|
18
20
|
test: /\.(ts)$/,
|
|
19
21
|
use: [
|
|
@@ -33,7 +35,13 @@ function getRWSLoaders(packageDir, nodeModulesPath, tsConfigPath){
|
|
|
33
35
|
/\.debug\.ts$/,
|
|
34
36
|
/\.d\.ts$/,
|
|
35
37
|
],
|
|
36
|
-
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
test: /\.scss$/i,
|
|
41
|
+
use: [
|
|
42
|
+
scssLoader,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
37
45
|
]
|
|
38
46
|
}
|
|
39
47
|
|
package/foundation/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rws-framework/client",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.9.
|
|
5
|
-
"main": "src/index.ts",
|
|
4
|
+
"version": "2.9.4",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"docs": "typedoc --tsconfig ./tsconfig.json"
|
|
8
8
|
},
|
|
@@ -30,27 +30,36 @@
|
|
|
30
30
|
"@microsoft/fast-foundation": "^2.46.2",
|
|
31
31
|
"@rws-framework/console": "*",
|
|
32
32
|
"@types/moment": "^2.13.0",
|
|
33
|
-
"dragula": "^3.7.3",
|
|
34
33
|
"deepmerge": "^4.3.1",
|
|
34
|
+
"dragula": "^3.7.3",
|
|
35
35
|
"he": "^1.2.0",
|
|
36
36
|
"json5": "^2.2.3",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
38
|
"moment": "^2.29.4",
|
|
39
|
+
"node-sass": "^7.0.3",
|
|
39
40
|
"partial-json-parser": "^1.0.0",
|
|
40
41
|
"reflect-metadata": "^0.1.13",
|
|
41
42
|
"resolve-url-loader": "^5.0.0",
|
|
42
43
|
"sanitize-html": "^2.12.1",
|
|
43
|
-
"sass": "
|
|
44
|
+
"sass": "1.69.7",
|
|
45
|
+
"sass-loader": "^13.3.2",
|
|
44
46
|
"scss-loading-animations": "^1.0.1",
|
|
45
47
|
"socket.io-client": "^4.7.2",
|
|
48
|
+
"source-map": "^0.7.4",
|
|
49
|
+
"source-map-support": "^0.5.21",
|
|
50
|
+
"stacktrace-gps": "^3.1.2",
|
|
51
|
+
"style-loader": "^3.3.3",
|
|
52
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
46
53
|
"ts-loader": "^9.4.4",
|
|
54
|
+
"ts-transformer-keys": "^0.4.4",
|
|
47
55
|
"tsc-watch": "^6.0.4",
|
|
48
56
|
"tslib": "^2.6.2",
|
|
57
|
+
"uglify-js": "^3.17.4",
|
|
49
58
|
"upload": "^1.3.2",
|
|
50
59
|
"url-router": "^13.0.0",
|
|
51
60
|
"uuid": "^9.0.1",
|
|
52
|
-
"v4": "^0.0.1"
|
|
53
|
-
|
|
61
|
+
"v4": "^0.0.1",
|
|
62
|
+
"webpack": "^5.89.0"
|
|
54
63
|
},
|
|
55
64
|
"devDependencies": {
|
|
56
65
|
"@types/dragula": "^3.7.4",
|
|
@@ -60,7 +69,8 @@
|
|
|
60
69
|
"@types/he": "^1.2.3",
|
|
61
70
|
"@types/sanitize-html": "^2.11.0",
|
|
62
71
|
"@types/uuid": "^9.0.7",
|
|
63
|
-
"@typescript-eslint/parser": "^5.0.0",
|
|
72
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
73
|
+
"browser-sync": "^2.29.3",
|
|
64
74
|
"clean-webpack-plugin": "^4.0.0",
|
|
65
75
|
"css-loader": "^6.8.1",
|
|
66
76
|
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
@@ -71,12 +81,12 @@
|
|
|
71
81
|
"mini-css-extract-plugin": "^2.7.6",
|
|
72
82
|
"minimatch": "^9.0.4",
|
|
73
83
|
"node-sass": "^9.0.0",
|
|
84
|
+
"raw-loader": "^4.0.2",
|
|
74
85
|
"sass-loader": "^13.3.2",
|
|
75
86
|
"source-map": "^0.7.4",
|
|
76
87
|
"style-loader": "^3.3.3",
|
|
77
88
|
"terser-webpack-plugin": "^5.3.9",
|
|
78
|
-
"ts-loader": "^9.4.4",
|
|
79
|
-
"raw-loader": "^4.0.2",
|
|
89
|
+
"ts-loader": "^9.4.4",
|
|
80
90
|
"ts-node": "^10.9.1",
|
|
81
91
|
"tsconfig-paths": "^4.2.0",
|
|
82
92
|
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
|
@@ -86,7 +96,7 @@
|
|
|
86
96
|
"typedoc-plugin-rename-defaults": "^0.7.0",
|
|
87
97
|
"typedoc-theme-hierarchy": "^4.1.2",
|
|
88
98
|
"typescript": "^5.1.6",
|
|
89
|
-
"url-loader": "^4.1.1",
|
|
99
|
+
"url-loader": "^4.1.1",
|
|
90
100
|
"webpack": "^5.75.0",
|
|
91
101
|
"webpack-bundle-analyzer": "^4.10.1",
|
|
92
102
|
"webpack-cli": "^5.1.4",
|
package/rws.webpack.config.js
CHANGED
|
@@ -5,6 +5,8 @@ const webpack = require('webpack');
|
|
|
5
5
|
const { rwsPath, RWSConfigBuilder } = require('@rws-framework/console');
|
|
6
6
|
|
|
7
7
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
8
|
+
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
|
|
9
|
+
|
|
8
10
|
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
9
11
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
10
12
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
@@ -24,7 +26,7 @@ const { _DEFAULT_CONFIG } = require('./cfg/_default.cfg');
|
|
|
24
26
|
const { info } = require('console');
|
|
25
27
|
|
|
26
28
|
const _MAIN_PACKAGE = rwsPath.findRootWorkspacePath(process.cwd());
|
|
27
|
-
|
|
29
|
+
console.log(process.argv);
|
|
28
30
|
const RWSWebpackWrapper = async (config) => {
|
|
29
31
|
const BuildConfigurator = new RWSConfigBuilder(rwsPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...config});
|
|
30
32
|
|
|
@@ -52,6 +54,7 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
52
54
|
|
|
53
55
|
const devTools = isDev ? (BuildConfigurator.get('devtool') || 'source-map') : false;
|
|
54
56
|
const devDebug = isDev ? (BuildConfigurator.get('devDebug') || config.devDebug || { build: false }) : null;
|
|
57
|
+
const devRouteProxy = BuildConfigurator.get('devRouteProxy') || config.devRouteProxy;
|
|
55
58
|
|
|
56
59
|
const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
|
|
57
60
|
const rwsPlugins = {};
|
|
@@ -283,7 +286,7 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
283
286
|
sourceMapFilename: '[file].map',
|
|
284
287
|
},
|
|
285
288
|
resolve: {
|
|
286
|
-
extensions: ['.ts', '.js'],
|
|
289
|
+
extensions: ['.ts', '.js', '.scss', '.css'],
|
|
287
290
|
modules: modules_setup,
|
|
288
291
|
alias: {
|
|
289
292
|
...aliases
|
|
@@ -302,18 +305,25 @@ const RWSWebpackWrapper = async (config) => {
|
|
|
302
305
|
cfgExport.optimization = optimConfig;
|
|
303
306
|
}
|
|
304
307
|
|
|
305
|
-
|
|
306
|
-
cfgExport.devServer = {
|
|
307
|
-
hot: true,
|
|
308
|
-
static: publicDir
|
|
309
|
-
}
|
|
310
|
-
}
|
|
308
|
+
|
|
311
309
|
|
|
312
310
|
for (const pluginKey of Object.keys(rwsPlugins)){
|
|
313
311
|
const plugin = rwsPlugins[pluginKey];
|
|
314
312
|
cfgExport = await plugin.onBuild(cfgExport);
|
|
315
313
|
}
|
|
316
314
|
|
|
315
|
+
if(isDev){
|
|
316
|
+
const backendUrl = BuildConfigurator.get('backendUrl') || config.backendUrl;
|
|
317
|
+
const apiPort = BuildConfigurator.get('apiPort') || config.apiPort;
|
|
318
|
+
|
|
319
|
+
if(backendUrl && apiPort){
|
|
320
|
+
// cfgExport.devServer = {
|
|
321
|
+
// hot: true, // Enable hot module replacement
|
|
322
|
+
// open: true, // Automatically open the browser
|
|
323
|
+
// }
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
317
327
|
return cfgExport;
|
|
318
328
|
}
|
|
319
329
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Accessor, Observable } from "@microsoft/fast-element";
|
|
2
|
+
import { ExtendedObservableAccessor } from "./_extended_accessor";
|
|
3
|
+
|
|
4
|
+
export class DefaultObservableAccessor extends ExtendedObservableAccessor {
|
|
5
|
+
|
|
6
|
+
constructor(public name: string, protected watcher: any = void 0) {
|
|
7
|
+
super(name, watcher);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Observable, Accessor } from "@microsoft/fast-element";
|
|
2
|
+
|
|
3
|
+
export abstract class ExtendedObservableAccessor implements Accessor {
|
|
4
|
+
protected field: string;
|
|
5
|
+
protected callback: string;
|
|
6
|
+
|
|
7
|
+
constructor(public name: string, protected watcher: any = void 0, suffix: string = 'Changed') {
|
|
8
|
+
this.field = `_${name}`;
|
|
9
|
+
this.callback = `${name}${suffix}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getValue(source: any): any {
|
|
13
|
+
Observable.track(source, this.name);
|
|
14
|
+
|
|
15
|
+
return source[this.field];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setValue(source: any, newValue: any): void {
|
|
19
|
+
const field = this.field;
|
|
20
|
+
const oldValue = source[field];
|
|
21
|
+
|
|
22
|
+
if (oldValue !== newValue) {
|
|
23
|
+
source[field] = newValue;
|
|
24
|
+
|
|
25
|
+
const callback = source[this.callback];
|
|
26
|
+
|
|
27
|
+
if (typeof callback === 'function') {
|
|
28
|
+
callback.call(source, oldValue, newValue);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Observable.getNotifier(source).notify(this.name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Accessor, Observable } from "@microsoft/fast-element";
|
|
2
|
+
import { ExtendedObservableAccessor } from "./_extended_accessor";
|
|
3
|
+
|
|
4
|
+
export class ExternalObservableAccessor extends ExtendedObservableAccessor {
|
|
5
|
+
|
|
6
|
+
constructor(public name: string, protected watcher: any = void 0) {
|
|
7
|
+
super(name, watcher , '');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -31,6 +31,9 @@ function applyDecorator(target: TargetType, prop: string, config: AttributeConfi
|
|
|
31
31
|
|
|
32
32
|
function modifyPropertyDescriptor(target: any, propertyKey: string): void {
|
|
33
33
|
const privatePropName = `_${String(propertyKey)}`;
|
|
34
|
+
|
|
35
|
+
Observable.track(target, propertyKey);
|
|
36
|
+
|
|
34
37
|
Object.defineProperty(target, privatePropName, {
|
|
35
38
|
writable: true,
|
|
36
39
|
value: target[propertyKey],
|
|
@@ -39,15 +42,15 @@ function modifyPropertyDescriptor(target: any, propertyKey: string): void {
|
|
|
39
42
|
Object.defineProperty(target, propertyKey, {
|
|
40
43
|
get() {
|
|
41
44
|
const value: string = this[privatePropName];
|
|
45
|
+
|
|
42
46
|
return isNgValue(value) ? null : value;
|
|
43
47
|
},
|
|
44
48
|
set(value: any) {
|
|
45
|
-
if (typeof value === 'string' && isNgValue(value)) {
|
|
49
|
+
if (typeof value === 'string' && isNgValue(value)) {
|
|
46
50
|
this[privatePropName] = null; // Set to null if condition is met
|
|
47
51
|
} else {
|
|
48
|
-
this[privatePropName] = value;
|
|
49
|
-
}
|
|
50
|
-
Observable.notify(this, propertyKey);
|
|
52
|
+
this[privatePropName] = value;
|
|
53
|
+
}
|
|
51
54
|
},
|
|
52
55
|
});
|
|
53
56
|
}
|
|
@@ -1,72 +1,49 @@
|
|
|
1
|
-
import { Observable } from '@microsoft/fast-element';
|
|
2
|
-
import RWSViewComponent from '../_component';
|
|
3
|
-
import DOMService from '../../services/DOMService';
|
|
4
|
-
import RWSContainer from '../_container';
|
|
5
|
-
import { IOptions } from 'sanitize-html';
|
|
1
|
+
import { Observable, Accessor, observable as parentObservable} from '@microsoft/fast-element';
|
|
6
2
|
|
|
7
|
-
import
|
|
3
|
+
import RWSViewComponent from '../_component';
|
|
4
|
+
import { DefaultObservableAccessor } from './_default_observable_accessor';
|
|
5
|
+
import { ExternalObservableAccessor } from './_external_observable_accessor';
|
|
8
6
|
|
|
9
|
-
type SanitizeOptions = IOptions & { fullEncode?: boolean };
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
useNamedReferences: false,
|
|
13
|
-
encodeEverything: true,
|
|
14
|
-
};
|
|
8
|
+
type ExternalObservableOptions = {} | unknown;
|
|
15
9
|
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
return he.encode(html, heOpt);
|
|
10
|
+
function isString(test: unknown){
|
|
11
|
+
return typeof test === 'string';
|
|
19
12
|
}
|
|
20
13
|
|
|
14
|
+
function externalObservable(targetComponent: RWSViewComponent | unknown, nameOrAccessor: string | Accessor, opts: ExternalObservableOptions = null): void | any
|
|
15
|
+
{
|
|
21
16
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
tagName: 'span', // Change this to any tag you want to transform to
|
|
26
|
-
attribs: {
|
|
27
|
-
...attribs,
|
|
28
|
-
'data-original-tag': tagName
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
};
|
|
17
|
+
const target = targetComponent as any;
|
|
18
|
+
const propName = typeof nameOrAccessor === 'string' ? nameOrAccessor : nameOrAccessor.name;
|
|
32
19
|
|
|
33
|
-
function applyDecorator(target: RWSViewComponent, prop: string, config: SanitizeOptions = null): void
|
|
34
|
-
{
|
|
35
|
-
modifyPropertyDescriptor(target, prop, config as IOptions);
|
|
36
|
-
}
|
|
37
20
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
writable: true,
|
|
42
|
-
value: target[propertyKey],
|
|
43
|
-
});
|
|
21
|
+
if (isString(nameOrAccessor)) {
|
|
22
|
+
nameOrAccessor = new DefaultObservableAccessor(propName);
|
|
23
|
+
}
|
|
44
24
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
25
|
+
const defaultAccessor: Accessor = nameOrAccessor as Accessor;
|
|
26
|
+
const extendedAccessor = new ExternalObservableAccessor(propName);
|
|
27
|
+
|
|
28
|
+
const accessors: Accessor[] = [
|
|
29
|
+
defaultAccessor,
|
|
30
|
+
extendedAccessor
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
for (const accessor of accessors){
|
|
34
|
+
Observable.getAccessors(target).push(accessor);
|
|
56
35
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return (target: RWSViewComponent, property: string) => applyDecorator(target, property, config);
|
|
68
|
-
}
|
|
36
|
+
Reflect.defineProperty(target, accessor.name, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get(this: any) {
|
|
39
|
+
return accessor.getValue(this);
|
|
40
|
+
},
|
|
41
|
+
set(this: any, newValue: any) {
|
|
42
|
+
accessor.setValue(this, newValue);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
69
46
|
}
|
|
70
47
|
|
|
71
48
|
|
|
72
|
-
export {
|
|
49
|
+
export { externalObservable };
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,8 @@ import UtilsService, {UtilsServiceInstance} from './services/UtilsService';
|
|
|
11
11
|
import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
|
|
12
12
|
import { sanitizedAttr } from './components/_attrs/sanitize-html';
|
|
13
13
|
import { ngAttr } from './components/_attrs/angular-attr';
|
|
14
|
-
import {
|
|
14
|
+
import { externalObservable } from './components/_attrs/external-observable';
|
|
15
|
+
import { externalAttr } from './components/_attrs/external-attr';
|
|
15
16
|
import { RWSPlugin, DefaultRWSPluginOptionsType } from './plugins/_plugin';
|
|
16
17
|
import RWSClient, { RWSClientInstance } from './client';
|
|
17
18
|
import { RWSPluginEntry } from './types/IRWSConfig';
|
|
@@ -69,6 +70,7 @@ export {
|
|
|
69
70
|
RWSIgnore,
|
|
70
71
|
RWSInject,
|
|
71
72
|
observable,
|
|
73
|
+
externalObservable,
|
|
72
74
|
externalAttr,
|
|
73
75
|
attr,
|
|
74
76
|
ngAttr,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
module.exports = function(content){
|
|
5
|
+
const filePath = this.resourcePath;
|
|
6
|
+
const componentDir = path.dirname(filePath);
|
|
7
|
+
const componentPath = path.resolve(componentDir, 'component.ts');
|
|
8
|
+
|
|
9
|
+
if(fs.existsSync(componentPath)){
|
|
10
|
+
fs.writeFileSync(componentPath, fs.readFileSync(componentPath, 'utf-8'))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
@@ -1,65 +1,14 @@
|
|
|
1
|
-
const RWSCssPlugin = require("../rws_scss_plugin");
|
|
2
1
|
const path = require('path');
|
|
3
|
-
const
|
|
4
|
-
// const { css } = require('@microsoft/fast-element')
|
|
2
|
+
const fs = require('fs');
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
// return function(){ return css`${code}`; }.bind(context)();
|
|
8
|
-
// }
|
|
9
|
-
|
|
10
|
-
module.exports = function(content) {
|
|
11
|
-
const plugin = new RWSCssPlugin();
|
|
4
|
+
module.exports = function(content) {
|
|
12
5
|
const filePath = this.resourcePath;
|
|
6
|
+
const componentDir = path.resolve(path.dirname(filePath), '..');
|
|
7
|
+
const componentPath = path.resolve(componentDir, 'component.ts');
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const isDev = this._compiler.options.mode === 'development';
|
|
17
|
-
|
|
18
|
-
const saveFile = content.indexOf('@save') > -1;
|
|
19
|
-
let fromTs = false;
|
|
20
|
-
|
|
21
|
-
if (plugin.checkForImporterType(this._module, 'ts')) {
|
|
22
|
-
fromTs = true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const codeData = plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
|
|
27
|
-
|
|
28
|
-
const code = codeData.code;
|
|
29
|
-
const deps = codeData.dependencies;
|
|
30
|
-
|
|
31
|
-
for (const dependency of deps){
|
|
32
|
-
this.addDependency(dependency);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (fromTs && saveFile && code) {
|
|
36
|
-
plugin.writeCssFile(filePath, code);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// if(!fromTs){
|
|
40
|
-
// return (context) => makeFastResource(context, code);
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// Properly setup the context for css-loader
|
|
44
|
-
|
|
45
|
-
const callback = this.async();
|
|
46
|
-
const loaderContext = {
|
|
47
|
-
...this,
|
|
48
|
-
query: { sourceMap: isDev },
|
|
49
|
-
async: () => (err, output) => {
|
|
50
|
-
if (err) {
|
|
51
|
-
callback(err);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
callback(null, output);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Execute css-loader with the generated CSS code
|
|
59
|
-
cssLoader.call(loaderContext, code);
|
|
60
|
-
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.error(e);
|
|
63
|
-
callback(e);
|
|
9
|
+
if(fs.existsSync(componentPath)){
|
|
10
|
+
fs.writeFileSync(componentPath, fs.readFileSync(componentPath, 'utf-8'))
|
|
64
11
|
}
|
|
12
|
+
|
|
13
|
+
return '';
|
|
65
14
|
};
|
|
@@ -5,6 +5,8 @@ const ts = require('typescript');
|
|
|
5
5
|
const tools = require('../../_tools');
|
|
6
6
|
const chalk = require('chalk');
|
|
7
7
|
const {html_error_proof} = require('./ts/html_error');
|
|
8
|
+
const RWSCssPlugin = require("../rws_scss_plugin");
|
|
9
|
+
const plugin = new RWSCssPlugin();
|
|
8
10
|
|
|
9
11
|
const _defaultRWSLoaderOptions = {
|
|
10
12
|
templatePath: 'template.html',
|
|
@@ -12,9 +14,8 @@ const _defaultRWSLoaderOptions = {
|
|
|
12
14
|
fastOptions: { shadowOptions: { mode: 'open' } }
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
module.exports = async function(content) {
|
|
17
|
+
module.exports = async function(content) {
|
|
18
|
+
let htmlFastImports = null;
|
|
18
19
|
let processedContent = content;
|
|
19
20
|
const filePath = this.resourcePath;
|
|
20
21
|
const isDev = this._compiler.options.mode === 'development';
|
|
@@ -70,28 +71,39 @@ module.exports = async function(content) {
|
|
|
70
71
|
const tagName = decoratorData.tagName;
|
|
71
72
|
|
|
72
73
|
try {
|
|
73
|
-
if(tagName){
|
|
74
|
+
if(tagName){
|
|
75
|
+
const templateName = 'template';
|
|
76
|
+
const templatePath = path.dirname(filePath) + `/${templateName}.html`;
|
|
77
|
+
|
|
78
|
+
const templateExists = fs.existsSync(templatePath);
|
|
79
|
+
|
|
80
|
+
let template = 'const rwsTemplate: null = null;';
|
|
74
81
|
let styles = 'const styles: null = null;'
|
|
75
82
|
|
|
76
83
|
if(fs.existsSync(path.dirname(filePath) + '/styles')){
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
const scsscontent = fs.readFileSync(path.dirname(filePath) + '/' + stylesPath, 'utf-8');
|
|
85
|
+
const codeData = plugin.compileScssCode(scsscontent, path.dirname(filePath) + '/styles', null, filePath, !isDev);
|
|
86
|
+
const cssCode = codeData.code;
|
|
87
|
+
|
|
88
|
+
styles = `import './${stylesPath}';\n`;
|
|
89
|
+
if(!templateExists){
|
|
90
|
+
styles += `import { css } from '@microsoft/fast-element';\n`;
|
|
91
|
+
}
|
|
92
|
+
styles += `const styles = ${templateExists? 'T.': ''}css\`${cssCode}\`;\n`;
|
|
93
|
+
|
|
94
|
+
this.addDependency(path.dirname(filePath) + '/' + stylesPath);
|
|
95
|
+
}
|
|
80
96
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let template = 'const rwsTemplate: null = null;';
|
|
85
|
-
|
|
86
|
-
if(templateExists){
|
|
87
|
-
const templateContent = fs.readFileSync(templatePath);
|
|
88
|
-
htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport RWSTemplateHTML from './${templateName}.html';`;
|
|
89
|
-
this.addDependency(templatePath);
|
|
97
|
+
if(templateExists){
|
|
98
|
+
const templateContent = fs.readFileSync(templatePath, 'utf-8');
|
|
99
|
+
htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
|
|
90
100
|
template = `
|
|
101
|
+
//@ts-ignore
|
|
91
102
|
let rwsTemplate: any = T.html\`${templateContent}\`;
|
|
92
103
|
`;
|
|
104
|
+
this.addDependency(templatePath);
|
|
93
105
|
}
|
|
94
|
-
|
|
106
|
+
|
|
95
107
|
const viewReg = /@RWSView\(['"]([a-zA-Z0-9_-]+)['"],?.*\)\sclass\s([a-zA-Z0-9_-]+) extends RWSViewComponent/gs
|
|
96
108
|
|
|
97
109
|
let m;
|