@rws-framework/client 2.10.8 → 2.10.10

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.
@@ -1,294 +1,162 @@
1
+ const { rwsPath } = require('@rws-framework/console');
1
2
  const path = require('path');
2
- const fs = require('fs');
3
- const webpack = require('webpack');
4
-
5
- const { rwsPath, RWSConfigBuilder } = require('@rws-framework/console');
6
-
7
- const HtmlWebpackPlugin = require('html-webpack-plugin');
8
-
9
- const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
10
-
11
-
12
- const RWSAfterPlugin = require('./webpack/rws_after_plugin');
13
-
14
3
  const chalk = require('chalk');
15
4
 
16
- const tools = require('./_tools');
5
+ const RWSWebpackPlugin = require('./webpack/rws_webpack_plugin');
17
6
 
18
7
  const buildInfo = require('./cfg/build_steps/webpack/_info');
19
8
  const { loadAliases } = require('./cfg/build_steps/webpack/_aliases');
20
- const { getRWSLoaders } = require('./cfg/build_steps/webpack/_loaders');
9
+ const { timingStart, timingStop, timeLog, toggleLogging } = require('./cfg/build_steps/webpack/_timing');
21
10
  const { getRWSProductionSetup } = require('./cfg/build_steps/webpack/_production');
22
11
  const { rwsExternals } = require('./cfg/build_steps/webpack/_rws_externals');
23
12
 
24
- const { _DEFAULT_CONFIG } = require('./cfg/_default.cfg');
25
- const { info } = require('console');
13
+ const tools = require('./_tools');
14
+ const { setComponentsChunks, scanComponents, generateRWSInfoFile, partedComponentsEvents } = require('./cfg/build_steps/webpack/_component_handling');
15
+ const { getBuildConfig } = require('./cfg/build_steps/webpack/_build_config');
16
+ const { createWebpackConfig } = require('./cfg/build_steps/webpack/_webpack_config');
17
+ const { executeRWSStartActions, timingActions, devActions } = require('./cfg/build_steps/webpack/_actions');
18
+ const { webpackDevServer } = require('./cfg/build_steps/webpack/_dev_servers');
19
+ const { RWS_WEBPACK_PLUGINS_BAG, addStartPlugins } = require('./cfg/build_steps/webpack/_plugins');
26
20
 
27
21
  const _MAIN_PACKAGE = rwsPath.findRootWorkspacePath(process.cwd());
28
- const RWSWebpackWrapper = async (config) => {
29
- const BuildConfigurator = new RWSConfigBuilder(rwsPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...config});
30
-
31
- config.packageDir = rwsPath.findPackageDir(process.cwd());
32
-
33
- const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || config.executionDir || process.cwd(), config.packageDir);
34
-
35
- const isWatcher = process.argv.includes('--watch') || false;
36
-
37
- const isDev = isWatcher ? true : (BuildConfigurator.get('dev', config.dev) || false);
38
- const isHotReload = BuildConfigurator.get('hot', config.hot);
39
- const isReport = BuildConfigurator.get('report', config.report);
40
- const isParted = BuildConfigurator.get('parted', config.parted || false);
41
-
42
- const partedPrefix = BuildConfigurator.get('partedPrefix', config.partedPrefix);
43
- const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix', config.partedDirUrlPrefix);
44
-
45
- let partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations', config.partedComponentsLocations);
46
- const customServiceLocations = BuildConfigurator.get('customServiceLocations', config.customServiceLocations); //@todo: check if needed
47
- const outputDir = rwsPath.relativize(BuildConfigurator.get('outputDir', config.outputDir), config.packageDir);
48
-
49
- const outputFileName = BuildConfigurator.get('outputFileName') || config.outputFileName;
50
- const publicDir = BuildConfigurator.get('publicDir') || config.publicDir;
51
- const serviceWorkerPath = BuildConfigurator.get('serviceWorker') || config.serviceWorker;
52
-
53
- const publicIndex = BuildConfigurator.get('publicIndex') || config.publicIndex;
54
-
55
- const devTools = isDev ? (BuildConfigurator.get('devtool') || 'source-map') : false;
56
- const devDebug = isDev ? (BuildConfigurator.get('devDebug') || config.devDebug || { build: false }) : null;
57
- const devRouteProxy = BuildConfigurator.get('devRouteProxy') || config.devRouteProxy;
58
22
 
59
- const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || config.tsConfigPath, executionDir);
60
- const rwsPlugins = {};
61
-
62
- if(config.rwsPlugins){
63
- for(const pluginEntry of config.rwsPlugins){
64
- const pluginBuilder = (await import(`${pluginEntry}/build.js`)).default;
65
- rwsPlugins[pluginEntry] = new pluginBuilder(BuildConfigurator, config);
66
- }
67
- }
23
+ // #SECTION INIT OPTIONS
24
+
25
+ const RWSWebpackWrapper = async (rwsFrontendConfig) => {
26
+ const {
27
+ executionDir,
28
+ isWatcher,
29
+ isDev,
30
+ isHotReload,
31
+ isReport,
32
+ isParted,
33
+ partedPrefix,
34
+ partedDirUrlPrefix,
35
+ partedComponentsLocations,
36
+ customServiceLocations,
37
+ outputDir,
38
+ outputFileName,
39
+ publicDir,
40
+ serviceWorkerPath,
41
+ publicIndex,
42
+ devTools,
43
+ devDebug,
44
+ devRouteProxy,
45
+ tsConfigPath,
46
+ rwsPlugins,
47
+ _packageDir,
48
+ BuildConfigurator
49
+ } = await getBuildConfig(rwsFrontendConfig);
50
+
51
+ timeLog({ devDebug });
52
+
53
+ if (devDebug?.timing) {
54
+ timingStart('build config');
55
+ }
68
56
 
69
57
  rwsPath.removeDirectory(outputDir, true);
58
+ buildInfo.start(executionDir, tsConfigPath, outputDir, isDev, publicDir, isParted, partedPrefix, partedDirUrlPrefix, devTools, rwsFrontendConfig.rwsPlugins);
70
59
 
71
- buildInfo.start(executionDir, tsConfigPath, outputDir, isDev, publicDir, isParted, partedPrefix, partedDirUrlPrefix, devTools, config.rwsPlugins);
72
-
73
- //AFTER OPTION DEFINITIONS
74
-
75
- let _rws_defines = {
76
- 'process.env._RWS_DEFAULTS': JSON.stringify(BuildConfigurator.exportDefaultConfig()),
77
- 'process.env._RWS_BUILD_OVERRIDE': JSON.stringify(BuildConfigurator.exportBuildConfig())
78
- }
79
-
80
- const rwsDefines = BuildConfigurator.get('rwsDefines') || config.rwsDefines || null;
60
+ // #SECTION INIT PLUGINS && ENV VARS DEFINES
61
+ addStartPlugins(rwsFrontendConfig, BuildConfigurator, devDebug, isHotReload, isReport, tsConfigPath);
81
62
 
82
- if(rwsDefines){
83
- _rws_defines = {..._rws_defines, ...rwsDefines}
84
- }
85
-
86
- let WEBPACK_PLUGINS = [
87
- new webpack.DefinePlugin(_rws_defines),
88
- new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/),
89
- new webpack.IgnorePlugin({
90
- resourceRegExp: /.*\.es6\.js$/,
91
- contextRegExp: /node_modules/
92
- }),
93
- ];
63
+ const WEBPACK_AFTER_ACTIONS = rwsFrontendConfig.actions || [];
64
+ const WEBPACK_AFTER_ERROR_ACTIONS = rwsFrontendConfig.error_actions || [];
94
65
 
95
- const WEBPACK_AFTER_ACTIONS = config.actions || [];
96
66
  const modules_setup = ['node_modules'];
97
67
 
98
68
  let optimConfig = null;
99
- let aliases = config.aliases = {};
100
-
101
- aliases = {...aliases, ...loadAliases(__dirname, path.resolve(_MAIN_PACKAGE, 'node_modules'))}
102
-
103
- const overridePlugins = config.plugins || []
104
-
105
- if (isHotReload) {
106
- if (!publicDir) {
107
- throw new Error('No public dir set')
108
- }
69
+ let aliases = rwsFrontendConfig.aliases || {};
109
70
 
110
- WEBPACK_PLUGINS.push(new HtmlWebpackPlugin({
111
- template: publicDir + '/' + publicIndex,
112
- }));
113
- }
71
+ aliases = { ...aliases, ...loadAliases(__dirname, path.resolve(_MAIN_PACKAGE, 'node_modules'), executionDir) }
114
72
 
115
- WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, ...overridePlugins];
73
+ // #SECTION PLUGIN STARTING HOOKS
116
74
 
75
+ executeRWSStartActions(WEBPACK_AFTER_ACTIONS, serviceWorkerPath, BuildConfigurator, rwsFrontendConfig);
117
76
 
118
- if (isReport) {
119
- WEBPACK_PLUGINS.push(new BundleAnalyzerPlugin({
120
- analyzerMode: 'static',
121
- openAnalyzer: false,
122
- }));
77
+ if (devDebug?.timing) {
78
+ timingStop('build config');
123
79
  }
124
80
 
125
- if (serviceWorkerPath) {
126
- WEBPACK_AFTER_ACTIONS.push({
127
- type: 'service_worker',
128
- actionHandler: serviceWorkerPath
129
- });
130
- }
131
-
132
- const assetsToCopy = BuildConfigurator.get('copyAssets') || config.copyAssets;
133
-
134
- if (!!assetsToCopy) {
135
- WEBPACK_AFTER_ACTIONS.push({
136
- type: 'copy',
137
- actionHandler: assetsToCopy
138
- });
139
- }
140
-
141
- const rwsInfoJson = outputDir + '/rws_info.json'
142
- const automatedEntries = {};
143
- let automatedChunks = {
144
- client: config.entry,
145
- };
146
-
147
- // if(isParted){
148
- // automatedChunks = {
149
- // index: config.entry,
150
- // client: __dirname + '/src/client.ts',
151
- // };
152
-
153
- // console.log({index: automatedChunks.client})
154
- // }
155
-
156
- const foundRWSUserClasses = tools.findComponentFilesWithText(executionDir, '@RWSView', ['dist', 'node_modules', '@rws-framework/client']);
157
- const foundRWSClientClasses = tools.findComponentFilesWithText(__dirname, '@RWSView', ['dist', 'node_modules']);
158
- let RWSComponents = [...foundRWSUserClasses, ...foundRWSClientClasses];
159
-
160
- if (partedComponentsLocations) {
161
- partedComponentsLocations.forEach((componentDir) => {
162
- RWSComponents = [...RWSComponents, ...(tools.findComponentFilesWithText(path.resolve(componentDir), '@RWSView', ['dist', 'node_modules', '@rws-framework/client']))];
163
- });
164
- }
165
-
166
- RWSComponents.forEach((fileInfo) => {
167
- const isIgnored = fileInfo.isIgnored;
168
-
169
- if (isIgnored === true) {
170
- // console.warn('Ignored: '+ fileInfo.filePath);
171
- return;
172
- }
173
-
174
- automatedEntries[fileInfo.tagName] = fileInfo.filePath;
175
-
176
- if(isParted){
177
- automatedChunks[fileInfo.tagName] = fileInfo.filePath;
178
- }
179
- });
180
81
 
181
- if (isParted) {
182
- // WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev)));
82
+ // #SECTION RWS COMPONENT SCAN && PARTED PROCESSING
83
+ const RWSComponents = scanComponents(await partedComponentsEvents(partedComponentsLocations, rwsPlugins, isParted), executionDir, __dirname);
84
+ console.log(`${chalk.cyanBright('RWS Scanned')} ${chalk.yellowBright(RWSComponents.length)} components`);
85
+ const { automatedChunks, automatedEntries } = setComponentsChunks(rwsFrontendConfig.entry, RWSComponents, isParted);
183
86
 
184
- for (const pluginKey of Object.keys(rwsPlugins)){
185
- const plugin = rwsPlugins[pluginKey];
186
- partedComponentsLocations = await plugin.onComponentsLocated(partedComponentsLocations);
187
- }
188
-
189
- }
87
+ // #SECTION RWS INFO FILE
88
+ generateRWSInfoFile(outputDir, automatedEntries);
89
+ console.log(chalk.greenBright(`RWSInfo file generated.`));
190
90
 
191
- fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
192
91
 
193
- const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir);
92
+ // #SECTION TSCONFIG VALIDATION/SETUP
93
+ const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir, rwsFrontendConfig.aliases);
194
94
 
195
95
  if (!tsValidated) {
196
96
  throw new Error('RWS Webpack build failed.');
197
- }
97
+ }
198
98
 
99
+ if (!isDev) {
100
+ // #SECTION RWS PROD SETUP
199
101
 
200
-
201
- if(!isDev){
202
- if(!optimConfig){
102
+ if (!optimConfig) {
203
103
  optimConfig = {};
204
104
  }
205
105
 
206
106
  optimConfig = getRWSProductionSetup(optimConfig, tsConfigPath);
207
-
208
- // WEBPACK_PLUGINS.push(new ESBuildPlugin());
209
- }
210
-
211
- const devExternalsVars = {
212
- packed: [],
213
- ignored: [],
214
- frontendRequestContextCache: []
215
107
  }
216
108
 
217
- if(devDebug?.build){
218
- const debugDir = path.join(executionDir, '.debug');
219
-
220
- if(!fs.existsSync(debugDir)){
221
- fs.mkdirSync(debugDir)
222
- }
223
-
224
- WEBPACK_AFTER_ACTIONS.push({
225
- type: 'custom',
226
- actionHandler: () => {
227
- fs.writeFileSync(path.join(debugDir, 'in_vendors.json'), JSON.stringify(devExternalsVars.ignored, null, 2));
228
- fs.writeFileSync(path.join(debugDir, 'rws_processed.json'), JSON.stringify(devExternalsVars.packed, null, 2));
229
- fs.writeFileSync(path.join(debugDir, 'requestcache.json'), JSON.stringify(devExternalsVars.frontendRequestContextCache, null, 2));
230
-
231
- console.log(chalk.yellow('[RWS BUILD] (after)'), `packaging debug saved in: ${debugDir}`);
232
- }
233
- });
234
- }
235
-
236
- if (WEBPACK_AFTER_ACTIONS.length) {
237
- WEBPACK_PLUGINS.push(new RWSAfterPlugin({ actions: WEBPACK_AFTER_ACTIONS, dev: isDev }));
238
- }
239
-
240
- let cfgExport = {
241
- context: executionDir,
242
- entry: {
243
- ...automatedChunks
244
- },
245
- mode: isDev ? 'development' : 'production',
246
- target: 'web',
247
- devtool: devTools,
248
- output: {
249
- path: outputDir,
250
- filename: isParted ? (partedPrefix || 'rws') + '.[name].js' : outputFileName,
251
- sourceMapFilename: '[file].map',
252
- },
253
- resolve: {
254
- extensions: ['.ts', '.js', '.scss', '.css'],
255
- modules: modules_setup,
256
- alias: {
257
- ...aliases
258
- }
259
- },
260
- module: {
261
- rules: getRWSLoaders(__dirname, path.resolve(config.packageDir, 'node_modules'), tsConfigPath),
262
- },
263
- plugins: WEBPACK_PLUGINS,
264
- externals: rwsExternals(executionDir, modules_setup, automatedChunks, {
265
- _vars: devExternalsVars
266
- })
109
+ // #SECTION RWS DEV ACTIONS
110
+ const devExternalsVars = devActions(WEBPACK_AFTER_ACTIONS, executionDir, devDebug);
111
+ timingActions(WEBPACK_AFTER_ACTIONS, WEBPACK_AFTER_ERROR_ACTIONS, devDebug);
112
+
113
+ // #SECTION RWS WEBPACK PLUGIN INIT
114
+ if (WEBPACK_AFTER_ACTIONS.length || WEBPACK_AFTER_ERROR_ACTIONS.length) {
115
+ RWS_WEBPACK_PLUGINS_BAG.add(new RWSWebpackPlugin({
116
+ actions: WEBPACK_AFTER_ACTIONS,
117
+ error_actions: WEBPACK_AFTER_ERROR_ACTIONS,
118
+ dev: isDev,
119
+ devDebug
120
+ }));
267
121
  }
268
122
 
269
- if(optimConfig){
123
+ // #SECTION RWS WEBPACK BUILD
124
+ const cfgExport = createWebpackConfig(
125
+ executionDir,
126
+ __dirname,
127
+ _packageDir,
128
+ isDev,
129
+ devTools,
130
+ devDebug,
131
+ isParted,
132
+ partedPrefix,
133
+ outputDir,
134
+ outputFileName,
135
+ automatedChunks,
136
+ modules_setup,
137
+ aliases,
138
+ tsConfigPath,
139
+ RWS_WEBPACK_PLUGINS_BAG.getPlugins(),
140
+ rwsExternals,
141
+ devExternalsVars
142
+ );
143
+
144
+ if (optimConfig) {
145
+ // setup production config if it got created above
270
146
  cfgExport.optimization = optimConfig;
271
147
  }
272
148
 
273
-
274
-
275
- for (const pluginKey of Object.keys(rwsPlugins)){
149
+ // #SECTION RWS PLUGINS onBuild EVENTS FIRE
150
+ for (const pluginKey of Object.keys(rwsPlugins)) {
276
151
  const plugin = rwsPlugins[pluginKey];
277
- cfgExport = await plugin.onBuild(cfgExport);
278
- }
279
-
280
- if(isDev){
281
- const backendUrl = BuildConfigurator.get('backendUrl') || config.backendUrl;
282
- const apiPort = BuildConfigurator.get('apiPort') || config.apiPort;
283
-
284
- if(backendUrl && apiPort){
285
- // cfgExport.devServer = {
286
- // hot: true, // Enable hot module replacement
287
- // open: true, // Automatically open the browser
288
- // }
289
- }
152
+ await plugin.onBuild(cfgExport);
290
153
  }
291
154
 
155
+ if (isDev) {
156
+ // #SECTION RWS DEV SERVERS
157
+ webpackDevServer(BuildConfigurator, rwsFrontendConfig, cfgExport);
158
+ }
159
+
292
160
  return cfgExport;
293
161
  }
294
162
 
@@ -52,37 +52,7 @@ class UtilsService extends TheService {
52
52
  }
53
53
 
54
54
  return 0;
55
-
56
- // const stack = error.stack || '';
57
- // const stackLines = stack.split('\n');
58
- // const relevantLine = stackLines[1];
59
-
60
- // // Extract file path from the stack line
61
- // const match = relevantLine.match(/\((.*?):\d+:\d+\)/);
62
- // if (!match) return -1;
63
- // const filePath = match[1];
64
-
65
- // // Assuming the source map is in the same directory with '.map' extension
66
- // const sourceMapPath = `${filePath}.map`;
67
-
68
- // if(sourceMap === null){
69
- // sourceMap = await this.fetchSourceMap(sourceMapPath);
70
- // }
71
-
72
- // let originalPosition: any = null;
73
-
74
- // await SourceMapConsumer.with(sourceMap, null, consumer => {
75
- // const lineMatch = relevantLine.match(/:(\d+):(\d+)/);
76
- // if (!lineMatch) return -1;
77
-
78
- // originalPosition = consumer.originalPositionFor({
79
- // line: parseInt(lineMatch[1]), // Example line and column
80
- // column: parseInt(lineMatch[2])
81
- // });
82
- // });
83
-
84
- // return originalPosition.line;
85
- }
55
+ }
86
56
  }
87
57
 
88
58
  export default UtilsService.getSingleton();
@@ -7,7 +7,11 @@ module.exports = function(content){
7
7
  const componentPath = path.resolve(componentDir, 'component.ts');
8
8
 
9
9
  if(fs.existsSync(componentPath)){
10
- fs.writeFileSync(componentPath, fs.readFileSync(componentPath, 'utf-8'))
10
+ const fileCnt = fs.readFileSync(componentPath, 'utf-8');
11
+
12
+ if(fileCnt){
13
+ fs.writeFile(componentPath, fileCnt, () => {})
14
+ }
11
15
  }
12
16
 
13
17
  return '';
@@ -12,8 +12,8 @@ module.exports = async function(content) {
12
12
  let fromTs = false;
13
13
 
14
14
  if(saveFile){
15
- try {
16
- const codeData = await plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
15
+ try {
16
+ const codeData = await plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
17
17
 
18
18
  const code = codeData.code;
19
19
  const deps = codeData.dependencies;
@@ -32,7 +32,11 @@ module.exports = async function(content) {
32
32
  }
33
33
 
34
34
  if(fs.existsSync(componentPath)){
35
- fs.writeFileSync(componentPath, fs.readFileSync(componentPath, 'utf-8'))
35
+ const fileCnt = fs.readFileSync(componentPath, 'utf-8');
36
+
37
+ if(fileCnt){
38
+ fs.writeFile(componentPath, fileCnt, () => {})
39
+ }
36
40
  }
37
41
 
38
42
  return '';
@@ -5,137 +5,78 @@ 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
+ const { rwsRuntimeHelper } = require('@rws-framework/console');
9
+ const { timingStart, timingStop } = require('../../cfg/build_steps/webpack/_timing');
10
+ const _scss_cache = require('../../cfg/build_steps/webpack/_cache');
11
+ const LoadersHelper = require('../../cfg/build_steps/webpack/_loaders');
12
+ const { sleep } = require('langchain/util/time');
13
+ const md5 = require('md5');
10
14
 
11
- const _defaultRWSLoaderOptions = {
12
- templatePath: 'template.html',
13
- stylesPath: 'styles.scss',
14
- fastOptions: { shadowOptions: { mode: 'open' } }
15
- }
16
15
 
17
16
  module.exports = async function(content) {
18
- let htmlFastImports = null;
17
+
19
18
  let processedContent = content;
20
19
  const filePath = this.resourcePath;
21
- const isDev = this._compiler.options.mode === 'development';
20
+ const isDev = this._compiler.options.mode === 'development';
21
+ let isIgnored = false;
22
+ let isDebugged = false;
22
23
 
23
- const htmlMinify = this._compiler.options.htmlMinify || true;
24
+ // timingStart('decorator_extraction');
25
+ const decoratorExtract = LoadersHelper.extractRWSViewArgs(processedContent);
26
+ const decoratorData = decoratorExtract ? decoratorExtract.viewDecoratorData : null;
27
+
28
+ const cachedCode = processedContent;
24
29
 
25
-
30
+ const compilationVariables = this._compilation;
31
+ const customCompilationOptions = compilationVariables?.customOptions || null;
26
32
 
27
- const RWSViewRegex = /(@RWSView\([^)]*)\)/;
28
- const tsSourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
33
+ const cachedTS = _scss_cache.cache(customCompilationOptions).getCachedItem(filePath, md5(cachedCode));
29
34
 
30
- let templatePath = 'template.html';
31
- let stylesPath = 'styles/layout.scss';
32
- let isIgnored = false;
33
- let isDebugged = false;
34
- let fastOptions = _defaultRWSLoaderOptions.fastOptions;
35
-
36
- const addedParamDefs = [];
37
- const addedParams = [];
38
-
39
- const decoratorData = tools.extractRWSViewArguments(tsSourceFile);
35
+ if(cachedTS){
36
+ return cachedTS;
37
+ }
40
38
 
41
-
42
39
  if(!decoratorData){
43
40
  return content;
44
41
  }
45
42
 
46
-
43
+ let templateName = null;
44
+ let stylesPath = null;
47
45
 
48
- if(decoratorData.options){
49
- if(decoratorData.options.template){
50
- templatePath = decoratorData.options.template;
46
+ if(decoratorData.decoratorArgs){
47
+ if(decoratorData.decoratorArgs.template){
48
+ templateName = decoratorData.decoratorArgs.template || null;
51
49
  }
52
50
 
53
- if(decoratorData.options.styles){
54
- stylesPath = decoratorData.options.styles;
51
+ if(decoratorData.decoratorArgs.styles){
52
+ stylesPath = decoratorData.decoratorArgs.styles || null;
55
53
  }
56
-
57
54
 
58
- if(decoratorData.options.ignorePackaging){
55
+ if(decoratorData.decoratorArgs.ignorePackaging){
59
56
  isIgnored = true;
60
57
  }
61
58
 
62
- if(decoratorData.options.debugPackaging){
59
+ if(decoratorData.decoratorArgs.debugPackaging){
63
60
  isDebugged = true;
64
- }
65
-
66
- if(decoratorData.options.fastElementOptions){
67
- fastOptions = decoratorData.options.fastElementOptions;
68
- }
69
-
70
- for (const key in fastOptions){
71
- addedParamDefs.push(`const ${key} = ${JSON.stringify(fastOptions[key])};`);
72
- addedParams.push(key);
73
- }
61
+ }
74
62
  }
75
63
 
76
64
  const tagName = decoratorData.tagName;
65
+ const className = decoratorData.className;
77
66
 
67
+ // timingStop('decorator_extraction');
68
+
78
69
  try {
79
- if(tagName){
80
- const templateName = 'template';
81
- const templatePath = path.dirname(filePath) + `/${templateName}.html`;
82
-
83
- const templateExists = fs.existsSync(templatePath);
84
-
85
- let template = 'const rwsTemplate: null = null;';
86
- let styles = 'const styles: null = null;'
87
-
88
- if(fs.existsSync(path.dirname(filePath) + '/styles')){
89
- const scsscontent = fs.readFileSync(path.dirname(filePath) + '/' + stylesPath, 'utf-8');
90
- const codeData = await plugin.compileScssCode(scsscontent, path.dirname(filePath) + '/styles', null, filePath, !isDev);
91
- const cssCode = codeData.code;
92
-
93
- styles = isDev ? `import './${stylesPath}';\n` : '';
94
- if(!templateExists){
95
- styles += `import { css } from '@microsoft/fast-element';\n`;
96
- }
97
- styles += `const styles = ${templateExists? 'T.': ''}css\`${cssCode}\`;\n`;
98
-
99
- this.addDependency(path.dirname(filePath) + '/' + stylesPath);
100
- }
101
-
102
- if(templateExists){
103
- const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
104
- htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
105
- template = `
106
- //@ts-ignore
107
- let rwsTemplate: any = T.html\`${templateContent}\`;
108
- `;
109
- this.addDependency(templatePath);
110
- }
111
-
112
- const viewReg = /@RWSView\(["']([^"']+)["'].*\)\s*(.*?\s+)?class\s+([a-zA-Z0-9_-]+)\s+extends\s+RWSViewComponent/gm
113
-
114
- let m;
115
- let className = null;
116
-
117
-
118
- while ((m = viewReg.exec(processedContent)) !== null) {
119
- // This is necessary to avoid infinite loops with zero-width matches
120
- if (m.index === viewReg.lastIndex) {
121
- viewReg.lastIndex++;
122
- }
123
-
124
- // The result can be accessed through the `m`-variable.
125
- m.forEach((match, groupIndex) => {
126
- if(groupIndex === 3){
127
- className = match;
128
- }
129
- });
130
- }
131
-
70
+ if(tagName){
71
+ const [template, htmlFastImports, templateExists] = await LoadersHelper.getTemplate(filePath, this.addDependency, templateName, isDev);
72
+ const styles = await LoadersHelper.getStyles(filePath, this.addDependency, templateExists, stylesPath, isDev);
132
73
 
133
74
  if(className){
134
- const replacedViewDecoratorContent = processedContent.replace(
135
- viewReg,
136
- `@RWSView('$1', null, { template: rwsTemplate, styles${addedParams.length? ', options: {' + (addedParams.join(', ')) + '}': ''} })\n$2class $3 extends RWSViewComponent `
137
- );
138
- processedContent = `${template}\n${styles}\n${addedParamDefs.join('\n')}\n` + replacedViewDecoratorContent;
75
+ const replacedViewDecoratorContent = decoratorExtract.replacedDecorator;
76
+
77
+ if(replacedViewDecoratorContent){
78
+ processedContent = `${template}\n${styles}\n${replacedViewDecoratorContent}`;
79
+ }
139
80
  }
140
81
 
141
82
  processedContent = `${htmlFastImports ? htmlFastImports + '\n' : ''}${processedContent}`;
@@ -149,9 +90,10 @@ let rwsTemplate: any = T.html\`${templateContent}\`;
149
90
 
150
91
  if(isDebugged){
151
92
  console.log(chalk.red('[RWS BUILD] Debugging into: ' + debugTsPath));
152
- fs.writeFileSync(debugTsPath, processedContent); //for final RWS TS preview.
93
+ fs.writeFile(debugTsPath, processedContent, () => {}); //for final RWS TS preview.
153
94
  }
154
95
 
96
+ _scss_cache.cache(customCompilationOptions).cacheItem(filePath, processedContent, cachedCode);
155
97
  return processedContent;
156
98
  }catch(e){
157
99
  console.log(chalk.red('RWS Typescript loader error:'));