@rws-framework/client 2.8.4 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/cfg/_default.cfg.js +1 -0
  2. package/cfg/build_steps/webpack/_aliases.js +10 -0
  3. package/cfg/build_steps/webpack/_info.js +19 -0
  4. package/cfg/build_steps/webpack/_loaders.js +40 -0
  5. package/cfg/build_steps/webpack/_rws_externals.js +66 -0
  6. package/cfg/tsconfigSetup.js +30 -10
  7. package/foundation/index.js +1 -0
  8. package/foundation/rws-foundation.d.ts +8 -0
  9. package/foundation/rws-foundation.js +8 -0
  10. package/package.json +6 -4
  11. package/rws.webpack.config.js +137 -131
  12. package/service_worker/src/_service_worker.ts +1 -1
  13. package/src/client/config.ts +10 -3
  14. package/src/client.ts +3 -2
  15. package/src/components/_attrs/external-observable.ts +72 -0
  16. package/src/components/_component.ts +4 -5
  17. package/src/components/_container.ts +4 -4
  18. package/src/components/_decorator.ts +39 -9
  19. package/src/components/_decorators/RWSFillBuild.ts +0 -1
  20. package/src/components/_decorators/RWSInject.ts +3 -3
  21. package/src/components/_decorators/_di.ts +2 -2
  22. package/src/components/loader/styles/layout.scss +5 -5
  23. package/src/index.d.ts +1 -0
  24. package/src/index.ts +5 -5
  25. package/src/plugins/_plugin.ts +1 -1
  26. package/src/services/ConfigService.ts +4 -4
  27. package/src/services/_service.ts +10 -7
  28. package/src/types/RWSWindow.ts +2 -1
  29. package/tsconfig.json +5 -1
  30. package/types/declarations.d.ts +1 -1
  31. package/webpack/loaders/rws_fast_scss_loader.js +39 -30
  32. package/webpack/loaders/rws_fast_ts_loader.js +5 -3
  33. package/webpack/rws_after_plugin.js +26 -23
  34. package/webpack/rws_scss_plugin.js +22 -11
  35. package/_rws_externals.js +0 -39
  36. package/src/components/_design_system.ts +0 -6
  37. package/webpack/loaders/rws_fast_html_loader.js +0 -8
  38. package/webpack/loaders/rws_uncomments_loader.js +0 -35
@@ -3,6 +3,7 @@ import { RWSClientInstance } from "../client";
3
3
 
4
4
  import { RWSPlugin, DefaultRWSPluginOptionsType } from "../plugins/_plugin";
5
5
  import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
6
+ import deepmerge from 'deepmerge';
6
7
 
7
8
  type RWSInfoType = { components: string[] };
8
9
 
@@ -89,12 +90,17 @@ function addPlugin<T extends DefaultRWSPluginOptionsType>(this: RWSClientInstan
89
90
  async function setup(this: RWSClientInstance, config: IRWSConfig = {}): Promise<IRWSConfig> {
90
91
  if (this.isSetup) {
91
92
  return this.config;
93
+ }
94
+
95
+ if(this.config){
96
+ this.config = deepmerge(this.config, config);
92
97
  }
93
98
 
94
- this.config = { ...this.config, ...config };
99
+ console.log(config, this.config.plugins)
100
+
95
101
  this.appConfig.mergeConfig(this.config);
96
102
 
97
- if(this.config.plugins){
103
+ if(this.config.plugins){
98
104
  for (const pluginEntry of this.config.plugins){
99
105
  addPlugin.bind(this)(pluginEntry);
100
106
  }
@@ -130,7 +136,8 @@ async function start(this: RWSClientInstance, config: IRWSConfig = {}): Promise<
130
136
  await this.initCallback();
131
137
 
132
138
  for (const plugin of RWSPlugin.getAllPlugins()){
133
- plugin.onClientStart();
139
+ console.log('plugin', plugin)
140
+ await plugin.onClientStart();
134
141
  }
135
142
 
136
143
  return this;
package/src/client.ts CHANGED
@@ -13,7 +13,7 @@ import { IBackendRoute } from './services/ApiService';
13
13
  import IRWSUser from './types/IRWSUser';
14
14
  import RWSWindow, { RWSWindowComponentRegister, loadRWSRichWindow } from './types/RWSWindow';
15
15
 
16
- import { DI, Container, Registration } from '@microsoft/fast-foundation';
16
+ import { DI, Container, Registration } from './components/_container';
17
17
 
18
18
  import RWSViewComponent, { IWithCompose } from './components/_component';
19
19
  import RWSContainer from './components/_container';
@@ -65,6 +65,7 @@ class RWSClient {
65
65
 
66
66
  this.loadServices();
67
67
 
68
+ this.config.plugins = [];
68
69
  this.pushDataToServiceWorker('SET_WS_URL', { url: this.appConfig.get('wsUrl') }, 'ws_url');
69
70
 
70
71
  if (this.user) {
@@ -73,7 +74,7 @@ class RWSClient {
73
74
  }
74
75
 
75
76
  addPlugin(pluginEntry: RWSPluginEntry<any>)
76
- {
77
+ {
77
78
  this.config.plugins.push(pluginEntry);
78
79
  }
79
80
 
@@ -0,0 +1,72 @@
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';
6
+
7
+ import * as he from 'he';
8
+
9
+ type SanitizeOptions = IOptions & { fullEncode?: boolean };
10
+
11
+ const heOpt: he.EncodeOptions = {
12
+ useNamedReferences: false,
13
+ encodeEverything: true,
14
+ };
15
+
16
+ function enc(html: string): string
17
+ {
18
+ return he.encode(html, heOpt);
19
+ }
20
+
21
+
22
+ const transformAnyTag = (tagName: string, attribs: { [key: string]: string }) => {
23
+ // Example: Wrap the original tag with `span` and indicate the original tag name in a data attribute
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
+ };
32
+
33
+ function applyDecorator(target: RWSViewComponent, prop: string, config: SanitizeOptions = null): void
34
+ {
35
+ modifyPropertyDescriptor(target, prop, config as IOptions);
36
+ }
37
+
38
+ function modifyPropertyDescriptor(target: any, propertyKey: string, config: IOptions = null): void {
39
+ const privatePropName = `_${String(propertyKey)}`;
40
+ Object.defineProperty(target, privatePropName, {
41
+ writable: true,
42
+ value: target[propertyKey],
43
+ });
44
+
45
+ Object.defineProperty(target, propertyKey, {
46
+ get() {
47
+ return this[privatePropName];
48
+ },
49
+ set(value: any) {
50
+ console.log('[DEBUG] external changed', propertyKey);
51
+ this[privatePropName] = value;
52
+ Observable.notify(this, propertyKey);
53
+ },
54
+ });
55
+ }
56
+
57
+ function externalAttr(configOrTarget?: SanitizeOptions | RWSViewComponent, prop?: string): void | any
58
+ {
59
+ if (arguments.length > 1) {
60
+ // Decorator used directly without factory invocation
61
+ // Apply the decorator immediately without returning anything
62
+ applyDecorator(configOrTarget as RWSViewComponent, prop!);
63
+ } else {
64
+ // Decorator factory invocation
65
+ const config = configOrTarget as SanitizeOptions;
66
+ // Return a function that applies the decorator, conforming to TypeScript's expectations for decorator factories
67
+ return (target: RWSViewComponent, property: string) => applyDecorator(target, property, config);
68
+ }
69
+ }
70
+
71
+
72
+ export { externalAttr };
@@ -1,5 +1,5 @@
1
1
  import { ViewTemplate, ElementStyles, observable, html, Constructable, PartialFASTElementDefinition, attr } from '@microsoft/fast-element';
2
- import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '@microsoft/fast-foundation';
2
+ import { FoundationElement, FoundationElementDefinition, FoundationElementRegistry, OverrideFoundationElementDefinition } from '../../foundation/rws-foundation';
3
3
  import ConfigService, { ConfigServiceInstance } from '../services/ConfigService';
4
4
  import UtilsService, { UtilsServiceInstance } from '../services/UtilsService';
5
5
  import DOMService, { DOMServiceInstance, DOMOutputType } from '../services/DOMService';
@@ -8,8 +8,7 @@ import NotifyService, { NotifyServiceInstance } from '../services/NotifyService'
8
8
  import { IRWSViewComponent, IAssetShowOptions } from '../types/IRWSViewComponent';
9
9
  import RWSWindow, { RWSWindowComponentInterface, loadRWSRichWindow } from '../types/RWSWindow';
10
10
  import { applyConstructor, RWSInject } from './_decorator';
11
-
12
- import 'reflect-metadata';
11
+ import TheRWSService from '../services/_service';
13
12
 
14
13
  interface IFastDefinition {
15
14
  name: string;
@@ -31,7 +30,7 @@ export interface IWithCompose<T extends RWSViewComponent> {
31
30
  compose: ComposeMethodType<FoundationElementDefinition, Constructable<T>>;
32
31
  define<TType extends (...params: any[]) => any>(type: TType, nameOrDef?: string | PartialFASTElementDefinition | undefined): TType;
33
32
  _verbose: boolean;
34
- _toInject: {[key: string]: any};
33
+ _toInject: {[key: string]: TheRWSService};
35
34
  _depKeys: {[key: string]: string[]};
36
35
  }
37
36
 
@@ -44,7 +43,7 @@ abstract class RWSViewComponent extends FoundationElement implements IRWSViewCom
44
43
 
45
44
  static autoLoadFastElement = true;
46
45
  static _defined: { [key: string]: boolean } = {};
47
- static _toInject: any[] = [];
46
+ static _toInject: {[key: string]: TheRWSService} = {};
48
47
  static _depKeys: {[key: string]: string[]} = {_all: []};
49
48
  static _verbose: boolean = false;
50
49
 
@@ -1,8 +1,6 @@
1
- import { DI } from '@microsoft/fast-foundation';
1
+ import {DI, Container, Key, Registration , InterfaceSymbol} from '@microsoft/fast-foundation';
2
2
  import {loadRWSRichWindow} from '../types/RWSWindow';
3
3
 
4
- import 'reflect-metadata';
5
-
6
4
  export default () => {
7
5
  const richWindow = loadRWSRichWindow();
8
6
 
@@ -13,4 +11,6 @@ export default () => {
13
11
  richWindow.RWS.container = DI.getOrCreateDOMContainer(richWindow.RWS.container_node);
14
12
 
15
13
  return richWindow.RWS.container;
16
- };
14
+ };
15
+
16
+ export { DI, Container, Key, Registration, InterfaceSymbol }
@@ -1,7 +1,11 @@
1
+ import RWSContainer from './_container';
2
+ import TheRWSService from '../services/_service';
3
+ import ConfigService from '../services/ConfigService';
4
+ import { loadRWSRichWindow } from '../types/RWSWindow';
1
5
  import RWSViewComponent, { IWithCompose } from './_component';
6
+ import { InterfaceSymbol } from './_container';
2
7
  import { RWSInject } from './_decorators/RWSInject';
3
8
  import { ElementStyles, ViewTemplate } from '@microsoft/fast-element';
4
- import 'reflect-metadata';
5
9
 
6
10
  interface RWSDecoratorOptions {
7
11
  template?: string,
@@ -50,26 +54,52 @@ function getParentConstructor(instance: any): any {
50
54
  return null;
51
55
  }
52
56
 
57
+
53
58
  const applyConstructor = (component: RWSViewComponent, x: boolean = false): void => {
54
59
  const mainConstructor: any = component.constructor;
55
60
  const parent = getParentConstructor(component);
61
+
56
62
 
57
63
  if (parent.name !== 'RWSViewComponent' ) {
58
64
  return;
59
65
  }
66
+
60
67
 
61
68
  const existingInjectedDependencies = (mainConstructor as IWithCompose<RWSViewComponent>)._toInject;
62
- const defaultDeps = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys['_all'] || [];
63
- const depsToInject = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys[mainConstructor.name] || [];
64
69
 
65
- Object.keys(existingInjectedDependencies).forEach((depKey: string) => {
66
- // console.log(`Checking "${mainConstructor.name}" for "${depKey}"`, [...defaultDeps, ...depsToInject]);
70
+ const regServices = loadRWSRichWindow().RWS._registered;
71
+
72
+
73
+ const depsToInject: string[] = (mainConstructor as IWithCompose<RWSViewComponent>)._depKeys[mainConstructor.name] || [];
74
+ const depsInInjector: string[] = Object.keys(existingInjectedDependencies);
75
+
76
+ const toInject: string[] = [...depsToInject]
67
77
 
68
- if ([...defaultDeps, ...depsToInject].includes(depKey)) {
69
- const loadedDependency = existingInjectedDependencies[depKey];
70
- (component as any)[depKey] = loadedDependency;
78
+ type KeyType = {[key: string]: TheRWSService | string };
79
+
80
+ function inject(services: KeyType){
81
+ for (const prop in services) {
82
+ const service = (typeof services[prop] === 'string' ? existingInjectedDependencies[prop] : services[prop]) as TheRWSService;
83
+ (component as any)[prop] = service;
71
84
  }
72
- });
85
+ }
86
+
87
+ inject(toInject.reduce((acc: KeyType, cur) => {
88
+ acc[cur] = cur;
89
+ return acc;
90
+ }, {}));
91
+
92
+ const defaultDeps: [string, TheRWSService][] = Object.keys(existingInjectedDependencies)
93
+ .filter((depKey: string) => existingInjectedDependencies[depKey].isDefault()).map((depKey => [depKey, existingInjectedDependencies[depKey]]));
94
+
95
+ inject(defaultDeps.reduce((acc: KeyType, cur: [string, TheRWSService]) => {
96
+ acc[cur[0]] = cur[1];
97
+ return acc;
98
+ }, {}));
99
+
100
+ inject({
101
+ config: RWSContainer().get(ConfigService)
102
+ })
73
103
  };
74
104
 
75
105
  export { RWSView, RWSDecoratorOptions, RWSIgnore, RWSInject, applyConstructor };
@@ -1,4 +1,3 @@
1
- import 'reflect-metadata';
2
1
  import IRWSConfig from '../../types/IRWSConfig.js';
3
2
 
4
3
  function extractEnvVar(envVar: string){
@@ -1,4 +1,4 @@
1
- import { Key } from '@microsoft/fast-foundation';
1
+ import { Key } from '../_container';
2
2
  import RWSViewComponent, { IWithCompose } from '../_component';
3
3
  import { loadDep, getFunctionParamNames } from './_di';
4
4
  import TheRWSService from '../../services/_service';
@@ -24,7 +24,7 @@ function addToComponentInjection(targetComponentName: string, constructor: any,
24
24
  if(!Object.keys(constructor._toInject).includes(depKey)){
25
25
  const loadedDependency = loadDep<TheRWSService>(dependencyClass);
26
26
  constructor._toInject[depKey] = loadedDependency;
27
- }
27
+ }
28
28
  }
29
29
 
30
30
  function RWSInject<T extends RWSViewComponent>(dependencyClass: Key, defaultService: boolean = false): InjectDecoratorReturnType {
@@ -40,7 +40,7 @@ function RWSInject<T extends RWSViewComponent>(dependencyClass: Key, defaultServ
40
40
  const depKey = paramNames[parameterIndex];
41
41
 
42
42
  addToComponentInjection(targetConstructor.name, targetConstructor, depKey, dependencyClass, defaultService);
43
- }
43
+ }
44
44
  };
45
45
  }
46
46
 
@@ -1,5 +1,5 @@
1
- import { Key } from '@microsoft/fast-foundation';
2
- import RWSContainer from '../_container';
1
+
2
+ import RWSContainer, { Key } from '../_container';
3
3
 
4
4
  function getFunctionParamNames(func: () => any): string[] {
5
5
  const constructorMatch = func.toString().match(/constructor\s*\(([^)]*)\)/);
@@ -1,5 +1,5 @@
1
1
  //loader
2
-
2
+ //save
3
3
  $loader-color: var(--primary-color, #eb7b13);
4
4
  $loader-size: 56px;
5
5
  $loader-height: 20px;
@@ -7,8 +7,8 @@ $loader-border-size: 8px;
7
7
  $loader-gap: 12px;
8
8
  $loader-animation-duration: 1s;
9
9
 
10
- @import "~/scss-loading-animations/src/loaders";
10
+ // @import "~/scss-loading-animations/src/loaders";
11
11
 
12
- .loader {
13
- @include loader01;
14
- }
12
+ // .loader {
13
+ // @include loader01;
14
+ // }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ import "../types/declarations"
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@ import { Transformer as HTMLTagTransformerType, Tag as HTMLTag, Attributes as HT
2
2
  import { observable, attr } from '@microsoft/fast-element';
3
3
  import IRWSConfig from './types/IRWSConfig';
4
4
  import RWSNotify, { NotifyUiType, NotifyLogType } from './types/RWSNotify';
5
- import { provideRWSDesignSystem } from './components/_design_system';
6
5
  import RWSService from './services/_service';
7
6
  import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
8
7
  import NotifyService, {NotifyServiceInstance} from './services/NotifyService';
@@ -12,6 +11,7 @@ import UtilsService, {UtilsServiceInstance} from './services/UtilsService';
12
11
  import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
13
12
  import { sanitizedAttr } from './components/_attrs/sanitize-html';
14
13
  import { ngAttr } from './components/_attrs/angular-attr';
14
+ import { externalAttr } from './components/_attrs/external-observable';
15
15
  import { RWSPlugin, DefaultRWSPluginOptionsType } from './plugins/_plugin';
16
16
  import RWSClient, { RWSClientInstance } from './client';
17
17
  import { RWSPluginEntry } from './types/IRWSConfig';
@@ -67,14 +67,14 @@ export {
67
67
  RWSView,
68
68
  sanitizedAttr,
69
69
  RWSIgnore,
70
- RWSInject,
71
- ngAttr,
70
+ RWSInject,
72
71
  observable,
72
+ externalAttr,
73
73
  attr,
74
+ ngAttr,
74
75
 
75
76
  RWSService,
76
- RWSViewComponent,
77
- provideRWSDesignSystem,
77
+ RWSViewComponent,
78
78
  declareRWSComponents,
79
79
 
80
80
  RWSContainer
@@ -1,5 +1,5 @@
1
1
  import RWSContainer from "../components/_container";
2
- import { Container } from "@microsoft/fast-foundation";
2
+ import { Container } from "../components/_container";
3
3
  import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
4
4
  import IRWSUser from "../types/IRWSUser";
5
5
  import { RWSInfoType } from "../client/components";
@@ -117,15 +117,15 @@ class ConfigService extends TheService {
117
117
  mergeConfig(config: IRWSConfig) {
118
118
  const unloaded = ConfigService.isLoaded;
119
119
 
120
- if(!Object.keys(this.data).includes('plugins')){
121
- this.data.plugins = [];
122
- }
120
+ this.data.plugins = [];
123
121
 
124
122
  this.data = Object.assign(this.data, config);
125
123
 
126
124
  if(unloaded){
127
125
  ConfigService.isLoaded = true;
128
126
  }
127
+
128
+ return this.data;
129
129
  }
130
130
 
131
131
  getData(): IRWSConfig
@@ -134,6 +134,6 @@ class ConfigService extends TheService {
134
134
  }
135
135
  }
136
136
 
137
- export default ConfigService.getSingleton();
137
+ export default ConfigService.getSingleton('ConfigService');
138
138
 
139
139
  export { ConfigService as ConfigServiceInstance };
@@ -1,5 +1,4 @@
1
- import { DI, InterfaceSymbol, Key, Registration } from '@microsoft/fast-foundation';
2
- import RWSContainer from '../components/_container';
1
+ import RWSContainer, { DI, InterfaceSymbol, Key, Registration } from '../components/_container';
3
2
  import { loadRWSRichWindow } from '../types/RWSWindow';
4
3
 
5
4
  export interface IWithDI<T> {
@@ -31,21 +30,25 @@ export default abstract class TheRWSService {
31
30
  this.getSingleton();
32
31
  }
33
32
 
34
- public static getSingleton<T extends Key>(this: IWithDI<T>): InterfaceSymbol<T>
33
+ public static getSingleton<T extends Key>(this: IWithDI<T>, serviceName: string = null): InterfaceSymbol<T>
35
34
  {
36
35
  const richWindow = loadRWSRichWindow();
37
36
 
38
- if(Object.keys(richWindow.RWS._registered).includes(this.name)){
39
- return richWindow.RWS._registered[this.name];
37
+ if(!serviceName){
38
+ serviceName = this.name;
40
39
  }
41
40
 
42
- const interf = DI.createInterface<T>(this.name);
41
+ if(Object.keys(richWindow.RWS._registered).includes(serviceName)){
42
+ return richWindow.RWS._registered[serviceName];
43
+ }
44
+
45
+ const interf = DI.createInterface<T>(serviceName);
43
46
 
44
47
  RWSContainer().register(
45
48
  Registration.singleton(interf, this)
46
49
  );
47
50
 
48
- richWindow.RWS._registered[this.name] = interf;
51
+ richWindow.RWS._registered[serviceName] = interf;
49
52
 
50
53
  return interf;
51
54
  }
@@ -1,5 +1,6 @@
1
1
  import { RWSClientInstance } from '../client';
2
- import { Container, InterfaceSymbol } from '@microsoft/fast-foundation';
2
+ import { Container, InterfaceSymbol } from '../components/_container';
3
+
3
4
  import { RWSPlugin, DefaultRWSPluginOptionsType } from '../plugins/_plugin';
4
5
  import { v1 as uuid} from 'uuid';
5
6
  export type RWSWindowComponentInterface = (params?: any) => void;
package/tsconfig.json CHANGED
@@ -18,10 +18,14 @@
18
18
  "lib": ["DOM", "ESNext"],
19
19
  },
20
20
  "paths": {
21
- "@rws-framework/client": ["src"]
21
+ "@rws-framework/client": ["src"],
22
+ "@rws-framework/foundation": ["foundation"]
22
23
  },
23
24
  "include": [
24
25
  "src",
25
26
  "types/docs-typings.d.ts"
27
+ ],
28
+ "exclude": [
29
+ "node_modules"
26
30
  ]
27
31
  }
@@ -1,5 +1,5 @@
1
1
  declare module '*.scss' {
2
- const content: import('@microsoft/fast-element').ElementStyles;
2
+ const content: string;
3
3
  export default content;
4
4
  }
5
5
 
@@ -1,9 +1,13 @@
1
1
  const RWSCssPlugin = require("../rws_scss_plugin");
2
2
  const path = require('path');
3
3
  const cssLoader = require('css-loader');
4
+ // const { css } = require('@microsoft/fast-element')
5
+
6
+ // function makeFastResource(context, code){
7
+ // return function(){ return css`${code}`; }.bind(context)();
8
+ // }
4
9
 
5
10
  module.exports = function(content) {
6
- const callback = this.async();
7
11
  const plugin = new RWSCssPlugin();
8
12
  const filePath = this.resourcePath;
9
13
 
@@ -19,36 +23,41 @@ module.exports = function(content) {
19
23
  }
20
24
 
21
25
  try {
22
- const code = plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
23
-
24
- if (fromTs) {
25
- if (saveFile && code) {
26
- plugin.writeCssFile(filePath, code);
27
-
28
- const newContext = this;
29
-
30
- // Properly setup the context for css-loader
31
- const loaderContext = {
32
- ...newContext,
33
- query: { sourceMap: isDev },
34
- async: () => (err, output) => {
35
- if (err) {
36
- callback(err);
37
- return;
38
- }
39
- callback(null, output);
40
- }
41
- };
42
-
43
- // Execute css-loader
44
- cssLoader.call(loaderContext, code);
45
- } else {
46
- const tsCode = `import { css } from '@microsoft/fast-element';\nexport default css\`${code}\`;`;
47
- callback(null, tsCode);
48
- }
49
- } else {
50
- callback(null, code);
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);
51
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
+
52
61
  } catch (e) {
53
62
  console.error(e);
54
63
  callback(e);
@@ -74,7 +74,8 @@ module.exports = async function(content) {
74
74
  let styles = 'const styles: null = null;'
75
75
 
76
76
  if(fs.existsSync(path.dirname(filePath) + '/styles')){
77
- styles = `import styles from './${stylesPath}';`;
77
+ styles = `import componentCSS from './${stylesPath}';\n`;
78
+ styles += `const styles = T.css\`\${componentCSS}\`;`;
78
79
  }
79
80
 
80
81
  const templateName = 'template';
@@ -83,10 +84,11 @@ module.exports = async function(content) {
83
84
  let template = 'const rwsTemplate: null = null;';
84
85
 
85
86
  if(templateExists){
87
+ const templateContent = fs.readFileSync(templatePath);
86
88
  htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport RWSTemplateHTML from './${templateName}.html';`;
87
89
  this.addDependency(templatePath);
88
- template = `
89
- let rwsTemplate: any = T.html\`\${RWSTemplateHTML}\`;
90
+ template = `
91
+ let rwsTemplate: any = T.html\`${templateContent}\`;
90
92
  `;
91
93
  }
92
94
 
@@ -1,8 +1,9 @@
1
1
  const rwsAfterCopy = require('./after/copy');
2
2
  const rwsAfterSW = require('./after/sw');
3
+ const deepmerge = require('deepmerge');
3
4
 
4
5
 
5
- const _DEFAULT_CONFIG = {actions: [], executionDir: process.cwd(), packageDir: process.cwd()}
6
+ const _DEFAULT_CONFIG = {actions: [], executionDir: process.cwd(), packageDir: process.cwd(), dev: false}
6
7
 
7
8
  const _DEFAULT_ACTION = {
8
9
  type: 'copy',
@@ -20,7 +21,7 @@ class RWSAfterPlugin {
20
21
  _allowedActionTypes = ['copy', 'custom', 'service_worker'];
21
22
 
22
23
  constructor(config = {}){
23
- this.config = Object.assign(this.config, config);
24
+ this.config = deepmerge(this.config, config);
24
25
  }
25
26
 
26
27
  apply(compiler) {
@@ -34,29 +35,31 @@ class RWSAfterPlugin {
34
35
 
35
36
  return await Promise.all(proms);
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, '');
38
+ });
48
39
 
49
- // Update the asset with the new content
50
- compilation.assets[filename] = {
51
- source: () => updatedSource,
52
- size: () => updatedSource.length
53
- };
54
- }
55
- }
40
+ if(!this.config.dev){
41
+ compiler.hooks.emit.tapAsync('RWSAfterPlugin', (compilation, callback) => {
42
+ Object.keys(compilation.assets).forEach((filename) => {
43
+
44
+ if (filename.endsWith('.js')) {
45
+ const asset = compilation.assets[filename];
46
+ let source = asset.source();
47
+
48
+ if((source.indexOf('css`') > -1 || source.indexOf('html`') > -1)){
49
+ const updatedSource = source.replace(/\n/g, '');
50
+
51
+ // Update the asset with the new content
52
+ compilation.assets[filename] = {
53
+ source: () => updatedSource,
54
+ size: () => updatedSource.length
55
+ };
56
+ }
57
+ }
58
+ });
59
+
60
+ callback();
56
61
  });
57
-
58
- callback();
59
- });
62
+ }
60
63
  }
61
64
 
62
65
  async _runActionType(actionType, action){