@rws-framework/client 2.10.8 → 2.10.9

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,292 +1,161 @@
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
22
 
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
-
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
- }
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');
67
55
  }
68
56
 
69
- rwsPath.removeDirectory(outputDir, true);
70
-
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
- }
57
+ //rwsPath.removeDirectory(outputDir, true);
79
58
 
80
- const rwsDefines = BuildConfigurator.get('rwsDefines') || config.rwsDefines || null;
59
+ buildInfo.start(executionDir, tsConfigPath, outputDir, isDev, publicDir, isParted, partedPrefix, partedDirUrlPrefix, devTools, rwsFrontendConfig.rwsPlugins);
81
60
 
82
- if(rwsDefines){
83
- _rws_defines = {..._rws_defines, ...rwsDefines}
84
- }
61
+ // #SECTION INIT PLUGINS && ENV VARS DEFINES
62
+ addStartPlugins(rwsFrontendConfig, BuildConfigurator, devDebug, isHotReload, isReport, tsConfigPath);
85
63
 
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
- ];
64
+ const WEBPACK_AFTER_ACTIONS = rwsFrontendConfig.actions || [];
65
+ const WEBPACK_AFTER_ERROR_ACTIONS = rwsFrontendConfig.error_actions || [];
94
66
 
95
- const WEBPACK_AFTER_ACTIONS = config.actions || [];
96
67
  const modules_setup = ['node_modules'];
97
68
 
98
69
  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
- }
109
-
110
- WEBPACK_PLUGINS.push(new HtmlWebpackPlugin({
111
- template: publicDir + '/' + publicIndex,
112
- }));
113
- }
114
-
115
- WEBPACK_PLUGINS = [...WEBPACK_PLUGINS, ...overridePlugins];
70
+ let aliases = rwsFrontendConfig.aliases = {};
116
71
 
72
+ aliases = { ...aliases, ...loadAliases(__dirname, path.resolve(_MAIN_PACKAGE, 'node_modules')) }
117
73
 
118
- if (isReport) {
119
- WEBPACK_PLUGINS.push(new BundleAnalyzerPlugin({
120
- analyzerMode: 'static',
121
- openAnalyzer: false,
122
- }));
123
- }
74
+ // #SECTION PLUGIN STARTING HOOKS
124
75
 
125
- if (serviceWorkerPath) {
126
- WEBPACK_AFTER_ACTIONS.push({
127
- type: 'service_worker',
128
- actionHandler: serviceWorkerPath
129
- });
130
- }
76
+ executeRWSStartActions(WEBPACK_AFTER_ACTIONS, serviceWorkerPath, BuildConfigurator, rwsFrontendConfig);
131
77
 
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
- });
78
+ if (devDebug?.timing) {
79
+ timingStop('build config');
164
80
  }
165
81
 
166
- RWSComponents.forEach((fileInfo) => {
167
- const isIgnored = fileInfo.isIgnored;
168
-
169
- if (isIgnored === true) {
170
- // console.warn('Ignored: '+ fileInfo.filePath);
171
- return;
172
- }
173
82
 
174
- automatedEntries[fileInfo.tagName] = fileInfo.filePath;
83
+ // #SECTION RWS COMPONENT SCAN && PARTED PROCESSING
84
+ const RWSComponents = scanComponents(await partedComponentsEvents(partedComponentsLocations, rwsPlugins, isParted), executionDir, __dirname);
85
+ console.log(`${chalk.cyanBright('RWS Scanned')} ${chalk.yellowBright(RWSComponents.length)} components`);
86
+ const { automatedChunks, automatedEntries } = setComponentsChunks(rwsFrontendConfig.entry, RWSComponents, isParted);
175
87
 
176
- if(isParted){
177
- automatedChunks[fileInfo.tagName] = fileInfo.filePath;
178
- }
179
- });
88
+ // #SECTION RWS INFO FILE
89
+ generateRWSInfoFile(outputDir, automatedEntries);
90
+ console.log(chalk.greenBright(`RWSInfo file generated.`));
180
91
 
181
- if (isParted) {
182
- // WEBPACK_PLUGINS.push(new webpack.BannerPlugin(tools.getPartedModeVendorsBannerParams(partedDirUrlPrefix, partedPrefix, isDev)));
183
-
184
- for (const pluginKey of Object.keys(rwsPlugins)){
185
- const plugin = rwsPlugins[pluginKey];
186
- partedComponentsLocations = await plugin.onComponentsLocated(partedComponentsLocations);
187
- }
188
-
189
- }
190
-
191
- fs.writeFileSync(rwsInfoJson, JSON.stringify({ components: Object.keys(automatedEntries) }, null, 2));
192
92
 
93
+ // #SECTION TSCONFIG VALIDATION/SETUP
193
94
  const tsValidated = tools.setupTsConfig(tsConfigPath, executionDir);
194
95
 
195
96
  if (!tsValidated) {
196
97
  throw new Error('RWS Webpack build failed.');
197
- }
98
+ }
198
99
 
100
+ if (!isDev) {
101
+ // #SECTION RWS PROD SETUP
199
102
 
200
-
201
- if(!isDev){
202
- if(!optimConfig){
103
+ if (!optimConfig) {
203
104
  optimConfig = {};
204
105
  }
205
106
 
206
107
  optimConfig = getRWSProductionSetup(optimConfig, tsConfigPath);
207
-
208
- // WEBPACK_PLUGINS.push(new ESBuildPlugin());
209
108
  }
210
109
 
211
- const devExternalsVars = {
212
- packed: [],
213
- ignored: [],
214
- frontendRequestContextCache: []
215
- }
216
-
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
- })
110
+ // #SECTION RWS DEV ACTIONS
111
+ const devExternalsVars = devActions(WEBPACK_AFTER_ACTIONS, executionDir, devDebug);
112
+ timingActions(WEBPACK_AFTER_ACTIONS, WEBPACK_AFTER_ERROR_ACTIONS, devDebug);
113
+
114
+ // #SECTION RWS WEBPACK PLUGIN INIT
115
+ if (WEBPACK_AFTER_ACTIONS.length || WEBPACK_AFTER_ERROR_ACTIONS.length) {
116
+ RWS_WEBPACK_PLUGINS_BAG.add(new RWSWebpackPlugin({
117
+ actions: WEBPACK_AFTER_ACTIONS,
118
+ error_actions: WEBPACK_AFTER_ERROR_ACTIONS,
119
+ dev: isDev,
120
+ devDebug
121
+ }));
267
122
  }
268
123
 
269
- if(optimConfig){
124
+ // #SECTION RWS WEBPACK BUILD
125
+ const cfgExport = createWebpackConfig(
126
+ executionDir,
127
+ __dirname,
128
+ _packageDir,
129
+ isDev,
130
+ devTools,
131
+ devDebug,
132
+ isParted,
133
+ partedPrefix,
134
+ outputDir,
135
+ outputFileName,
136
+ automatedChunks,
137
+ modules_setup,
138
+ aliases,
139
+ tsConfigPath,
140
+ RWS_WEBPACK_PLUGINS_BAG.getPlugins(),
141
+ rwsExternals,
142
+ devExternalsVars
143
+ );
144
+
145
+ if (optimConfig) {
146
+ // setup production config if it got created above
270
147
  cfgExport.optimization = optimConfig;
271
148
  }
272
149
 
273
-
274
-
275
- for (const pluginKey of Object.keys(rwsPlugins)){
150
+ // #SECTION RWS PLUGINS onBuild EVENTS FIRE
151
+ for (const pluginKey of Object.keys(rwsPlugins)) {
276
152
  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
- }
153
+ await plugin.onBuild(cfgExport);
154
+ }
155
+
156
+ if (isDev) {
157
+ // #SECTION RWS DEV SERVERS
158
+ webpackDevServer(BuildConfigurator, rwsFrontendConfig, cfgExport);
290
159
  }
291
160
 
292
161
  return cfgExport;
@@ -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();
@@ -1,6 +1,7 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs');
3
3
  const RWSScssPlugin = require('../rws_scss_plugin');
4
+ const { timingStart, timingStop } = require('../../cfg/build_steps/webpack/_timing');
4
5
 
5
6
  module.exports = async function(content) {
6
7
  const filePath = this.resourcePath;
@@ -13,7 +14,9 @@ module.exports = async function(content) {
13
14
 
14
15
  if(saveFile){
15
16
  try {
17
+ timingStart('CSS Compilation of ' + filePath);
16
18
  const codeData = await plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
19
+ const endTime = timingStop('CSS Compilation of ' + filePath);
17
20
 
18
21
  const code = codeData.code;
19
22
  const deps = codeData.dependencies;
@@ -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}`;
@@ -152,6 +93,7 @@ let rwsTemplate: any = T.html\`${templateContent}\`;
152
93
  fs.writeFileSync(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:'));
@@ -4,8 +4,10 @@ const _tools = require('../_tools');
4
4
  const _scss_compiler_builder = require('./scss/_compiler');
5
5
  let _scss_compiler = null;
6
6
  const _scss_import_builder = require('./scss/_import');
7
+
7
8
  let _scss_import = null;
8
9
  const _scss_fs_builder = require('./scss/_fs');
10
+ const { timingStart, timingStop } = require('../cfg/build_steps/webpack/_timing');
9
11
  let _scss_fs = null;
10
12
 
11
13
 
@@ -40,15 +42,16 @@ class RWSScssPlugin {
40
42
  }
41
43
 
42
44
  async compileFile(scssPath) {
43
- scssPath = _scss_import.processImportPath(scssPath, path.dirname(scssPath))
45
+ scssPath = _scss_import.processImportPath(scssPath, path.dirname(scssPath))
46
+
44
47
 
45
48
  let scssCode = _scss_fs.getCodeFromFile(scssPath);
46
49
 
47
- return await _scss_compiler.compileScssCode(scssCode, path.dirname(scssPath));
50
+ return await _scss_compiler.compileScssCode(scssCode, path.dirname(scssPath), null, scssPath);
48
51
  }
49
52
 
50
53
  async compileScssCode(scssCode, scssPath){
51
- return await _scss_compiler.compileScssCode(scssCode, scssPath);
54
+ return await _scss_compiler.compileScssCode(scssCode, scssPath, null, scssPath);
52
55
  }
53
56
 
54
57
  writeCssFile(scssFilePath, cssContent){