@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,46 +1,220 @@
1
1
  const path = require('path');
2
+ const fs = require('fs');
3
+ const RWSCssPlugin = require("../../../webpack/rws_scss_plugin");
4
+ const plugin = new RWSCssPlugin();
5
+ const JSON5 = require('json5');
6
+ const chalk = require('chalk');
7
+ const { timingCounterStart, timingCounterStop } = require('./_timing');
8
+ const { rwsRuntimeHelper } = require('@rws-framework/console');
2
9
 
3
- function getRWSLoaders(packageDir, nodeModulesPath, tsConfigPath){
10
+ function getRWSLoaders(packageDir, nodeModulesPath, tsConfigPath, devDebug) {
4
11
  const scssLoader = packageDir + '/webpack/loaders/rws_fast_scss_loader.js';
5
12
  const tsLoader = packageDir + '/webpack/loaders/rws_fast_ts_loader.js';
6
13
  const htmlLoader = packageDir + '/webpack/loaders/rws_fast_html_loader.js';
7
14
 
8
- return [
9
- {
10
- test: /\.html$/,
11
- use: [
12
- {
13
- loader: htmlLoader,
14
- },
15
- ],
16
- },
17
- {
18
- test: /\.(ts)$/,
19
- use: [
20
- {
21
- loader: 'ts-loader',
22
- options: {
23
- allowTsInNodeModules: true,
24
- configFile: path.resolve(tsConfigPath)
25
- }
26
- },
27
- {
28
- loader: tsLoader,
29
- }
30
- ],
31
- exclude: [
32
- /node_modules\/(?!\@rws-framework\/[A-Z0-9a-z])/,
33
- /\.debug\.ts$/,
34
- /\.d\.ts$/,
35
- ],
36
- },
37
- {
38
- test: /\.scss$/i,
39
- use: [
40
- scssLoader,
41
- ],
42
- },
15
+ return [
16
+ {
17
+ test: /\.html$/,
18
+ use: [
19
+ {
20
+ loader: htmlLoader,
21
+ },
22
+ ],
23
+ },
24
+ {
25
+ test: /\.(ts)$/,
26
+ use: [
27
+ {
28
+ loader: 'ts-loader',
29
+ options: {
30
+ allowTsInNodeModules: true,
31
+ configFile: path.resolve(tsConfigPath)
32
+ }
33
+ },
34
+ {
35
+ loader: tsLoader,
36
+ }
37
+ ],
38
+ exclude: [
39
+ /node_modules\/(?!\@rws-framework\/[A-Z0-9a-z])/,
40
+ /\.debug\.ts$/,
41
+ /\.d\.ts$/,
42
+ ],
43
+ },
44
+ {
45
+ test: /\.scss$/i,
46
+ use: [
47
+ scssLoader,
48
+ ],
49
+ },
43
50
  ]
44
51
  }
45
52
 
46
- module.exports = { getRWSLoaders }
53
+ function _extractRWSViewDefs(fastOptions = {}, decoratorArgs = {})
54
+ {
55
+ const addedParamDefs = [];
56
+ const addedParams = [];
57
+
58
+ for (const key in fastOptions){
59
+ addedParamDefs.push(`const ${key} = ${JSON.stringify(fastOptions[key])};`);
60
+ addedParams.push(key);
61
+ }
62
+
63
+ return [addedParamDefs, addedParams];
64
+ }
65
+
66
+ function extractRWSViewArgs(content, noReplace = false) {
67
+ const viewReg = /@RWSView\(\s*["']([^"']+)["'](?:\s*,\s*([\s\S]*?))?\s*\)\s*(.*?\s+)?class\s+([a-zA-Z0-9_-]+)\s+extends\s+RWSViewComponent/gm;
68
+
69
+ let m;
70
+ let tagName = null;
71
+ let className = null;
72
+ let classNamePrefix = null;
73
+ let decoratorArgs = null;
74
+
75
+ const _defaultRWSLoaderOptions = {
76
+ templatePath: 'template.html',
77
+ stylesPath: 'styles.scss',
78
+ fastOptions: { shadowOptions: { mode: 'open' } }
79
+ }
80
+
81
+
82
+ while ((m = viewReg.exec(content)) !== null) {
83
+ // This is necessary to avoid infinite loops with zero-width matches
84
+ if (m.index === viewReg.lastIndex) {
85
+ viewReg.lastIndex++;
86
+ }
87
+
88
+ // The result can be accessed through the `m`-variable.
89
+ m.forEach((match, groupIndex) => {
90
+ if (groupIndex === 1) {
91
+ tagName = match;
92
+ }
93
+
94
+ if (groupIndex === 2) {
95
+ if (match) {
96
+ try {
97
+ decoratorArgs = JSON5.parse(match);
98
+ } catch(e){
99
+ console.log(chalk.red('Decorator options parse error: ') + e.message + '\n Problematic line:');
100
+ console.log(`
101
+ @RWSView(${tagName}, ${match})
102
+ `);
103
+ console.log(chalk.yellowBright(`Decorator options failed to parse for "${tagName}" component.`) + ' { decoratorArgs } defaulting to null.');
104
+ console.log(match);
105
+
106
+ throw new Error('Failed parsing @RWSView')
107
+ }
108
+ }
109
+ }
110
+
111
+ if (groupIndex === 3) {
112
+ if(match){
113
+ classNamePrefix = match;
114
+ }
115
+ }
116
+
117
+ if (groupIndex === 4) {
118
+ className = match;
119
+ }
120
+ });
121
+ }
122
+
123
+ if(!tagName){
124
+ return null;
125
+ }
126
+
127
+ let processedContent = content;
128
+
129
+ let fastOptions = _defaultRWSLoaderOptions.fastOptions;
130
+
131
+ if (decoratorArgs && decoratorArgs.fastElementOptions) {
132
+ fastOptions = decoratorArgs.fastElementOptions;
133
+ }
134
+
135
+ let replacedDecorator = null;
136
+
137
+ if(!noReplace){
138
+ const [addedParamDefs, addedParams] = _extractRWSViewDefs(fastOptions, decoratorArgs);
139
+ const replacedViewDecoratorContent = processedContent.replace(
140
+ viewReg,
141
+ `@RWSView('$1', null, { template: rwsTemplate, styles${addedParams.length ? ', options: {' + (addedParams.join(', ')) + '}' : ''} })\n$3class $4 extends RWSViewComponent `
142
+ );
143
+
144
+ // console.log({replacedViewDecoratorContent});
145
+
146
+ replacedDecorator = `${addedParamDefs.join('\n')}\n${replacedViewDecoratorContent}`;
147
+ }
148
+
149
+ return {
150
+ viewDecoratorData: {
151
+ tagName,
152
+ className,
153
+ classNamePrefix,
154
+ decoratorArgs
155
+ },
156
+ replacedDecorator
157
+ }
158
+ }
159
+
160
+ async function getStyles(filePath, addDependency, templateExists, stylesPath = null, isDev = false) {
161
+ if(!stylesPath){
162
+ stylesPath = 'styles/layout.scss';
163
+ }
164
+
165
+ let styles = 'const styles: null = null;'
166
+ const stylesFilePath = path.dirname(filePath) + '/' + stylesPath;
167
+
168
+ if (fs.existsSync(stylesFilePath)) {
169
+ const scsscontent = fs.readFileSync(stylesFilePath, 'utf-8');
170
+ timingCounterStart();
171
+ const codeData = await plugin.compileScssCode(scsscontent, path.dirname(filePath) + '/styles', null, filePath, !isDev);
172
+ const elapsed = timingCounterStop();
173
+ let currentTimingList = rwsRuntimeHelper.getRWSVar('_timer_css');
174
+
175
+ if(currentTimingList){
176
+ currentTimingList += `\n${filePath}|${elapsed}`;
177
+ }else{
178
+ currentTimingList = `${filePath}|${elapsed}`;
179
+ }
180
+
181
+ rwsRuntimeHelper.setRWSVar('_timer_css', currentTimingList);
182
+
183
+ const cssCode = codeData.code;
184
+
185
+ styles = isDev ? `import './${stylesPath}';\n` : '';
186
+
187
+ if (!templateExists) {
188
+ styles += `import { css } from '@microsoft/fast-element';\n`;
189
+ }
190
+ styles += `const styles = ${templateExists ? 'T.' : ''}css\`${cssCode}\`;\n`;
191
+
192
+ addDependency(path.dirname(filePath) + '/' + stylesPath);
193
+ }
194
+
195
+ return styles;
196
+ }
197
+
198
+ async function getTemplate(filePath, addDependency, templateName = null, isDev = false) {
199
+ if(!templateName){
200
+ templateName = 'template';
201
+ }
202
+ const templatePath = path.dirname(filePath) + `/${templateName}.html`;
203
+ let htmlFastImports = null;
204
+ const templateExists = fs.existsSync(templatePath);
205
+
206
+ let template = 'const rwsTemplate: null = null;';
207
+
208
+ if (templateExists) {
209
+ const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
210
+ htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
211
+ template = `
212
+ //@ts-ignore
213
+ let rwsTemplate: any = T.html\`${templateContent}\`;
214
+ `; addDependency(templatePath);
215
+ }
216
+
217
+ return [template, htmlFastImports, templateExists];
218
+ }
219
+
220
+ module.exports = { getRWSLoaders, extractRWSViewArgs, getTemplate, getStyles }
@@ -0,0 +1,100 @@
1
+ const webpack = require('webpack')
2
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5
+ const { processEnvDefines } = require('./_env_defines');
6
+
7
+ const RWS_WEBPACK_PLUGINS_BAG = {
8
+ _plugins: [],
9
+ add(plugin) {
10
+ if (Array.isArray(plugin)) {
11
+ if (!plugin.length) {
12
+ return;
13
+ }
14
+
15
+ plugin.forEach((item) => {
16
+ RWS_WEBPACK_PLUGINS_BAG.add(item);
17
+ })
18
+ } else {
19
+ if (!plugin) {
20
+ return;
21
+ }
22
+
23
+ if (!this._plugins.includes(plugin)) {
24
+ this._plugins.push(plugin);
25
+ }
26
+ }
27
+ },
28
+ getPlugins() {
29
+ return this._plugins
30
+ }
31
+ }
32
+
33
+ function getPackageModPlugins() {
34
+ return [
35
+ new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb/),
36
+ new webpack.IgnorePlugin({
37
+ resourceRegExp: /.*\.es6\.js$/,
38
+ contextRegExp: /node_modules/
39
+ }),
40
+ ]
41
+ }
42
+
43
+ function getDefinesPlugins(BuildConfigurator, rwsFrontendConfig, devDebug) {
44
+ const _rws_defines = processEnvDefines(BuildConfigurator, rwsFrontendConfig, devDebug);
45
+
46
+ return [
47
+ new webpack.DefinePlugin(_rws_defines)
48
+ ]
49
+ }
50
+
51
+ function getBuilderOptimPlugins(BuildConfigurator, rwsFrontendConfig, tsConfigPath) {
52
+ const tsFork = new ForkTsCheckerWebpackPlugin({
53
+ async: false,
54
+ typescript: {
55
+ configFile: tsConfigPath,
56
+ diagnosticOptions: {
57
+ semantic: true,
58
+ syntactic: true,
59
+ },
60
+ },
61
+ });
62
+
63
+
64
+
65
+ return [
66
+
67
+ ]
68
+ }
69
+
70
+ function addStartPlugins(rwsFrontendConfig, BuildConfigurator, devDebug, isHotReload, isReport, tsConfigPath) {
71
+
72
+ RWS_WEBPACK_PLUGINS_BAG.add([
73
+ ...getDefinesPlugins(BuildConfigurator, rwsFrontendConfig, devDebug),
74
+ ...getBuilderOptimPlugins(BuildConfigurator, rwsFrontendConfig, tsConfigPath),
75
+ ...getPackageModPlugins()
76
+ ]);
77
+
78
+ if (isHotReload) {
79
+ if (!publicDir) {
80
+ throw new Error('No public dir set')
81
+ }
82
+
83
+ RWS_WEBPACK_PLUGINS_BAG.add(new HtmlWebpackPlugin({
84
+ template: publicDir + '/' + publicIndex,
85
+ }));
86
+ }
87
+
88
+ const overridePlugins = rwsFrontendConfig.plugins || []
89
+
90
+ RWS_WEBPACK_PLUGINS_BAG.add(overridePlugins);
91
+
92
+ if (isReport) {
93
+ RWS_WEBPACK_PLUGINS_BAG.add(new BundleAnalyzerPlugin({
94
+ analyzerMode: 'static',
95
+ openAnalyzer: false,
96
+ }));
97
+ }
98
+ }
99
+
100
+ module.exports = { RWS_WEBPACK_PLUGINS_BAG, addStartPlugins };
@@ -0,0 +1,53 @@
1
+ const TimingUtils = {
2
+ LOGGING: true,
3
+ TIMER_ON: true,
4
+
5
+ timeLog(...obj) {
6
+ if (!this.LOGGING || !this.TIMER_ON) {
7
+ return;
8
+ }
9
+ obj = [chalk.blueBright('[TIMING]'), ...obj];
10
+ console.log(...obj);
11
+ },
12
+
13
+ timingCounterStart() {
14
+ if (!this.TIMER_ON) {
15
+ return;
16
+ }
17
+ rwsRuntimeHelper.startExecTimeRecord();
18
+ },
19
+
20
+ timingCounterStop() {
21
+ if (!this.TIMER_ON) {
22
+ return 0;
23
+ }
24
+ return rwsRuntimeHelper.startExecTimeRecord() || 0;
25
+ },
26
+
27
+ timingStart(section) {
28
+ if (!this.TIMER_ON) {
29
+ return;
30
+ }
31
+ this.timingCounterStart();
32
+ this.timeLog(`Started timing "${chalk.yellow(section)}"`);
33
+ },
34
+
35
+ timingStop(section) {
36
+ if (!this.TIMER_ON) {
37
+ return 0;
38
+ }
39
+ const endTime = this.timingCounterStop();
40
+ this.timeLog(`Stopped timing "${chalk.yellow(section)}" @${endTime}ms`);
41
+ return endTime;
42
+ },
43
+
44
+ toggleLogging(val) {
45
+ this.LOGGING = val;
46
+ },
47
+
48
+ toggleTimer(val) {
49
+ this.TIMER_ON = val;
50
+ }
51
+ };
52
+
53
+ module.exports = TimingUtils;
@@ -0,0 +1,59 @@
1
+ const { getRWSLoaders } = require('./_loaders');
2
+ const path = require('path');
3
+
4
+ function createWebpackConfig(
5
+ executionDir,
6
+ clientPkgPath,
7
+ _packageDir,
8
+ isDev,
9
+ devTools,
10
+ devDebug,
11
+ isParted,
12
+ partedPrefix,
13
+ outputDir,
14
+ outputFileName,
15
+ automatedChunks,
16
+ modules_setup,
17
+ aliases,
18
+ tsConfigPath,
19
+ WEBPACK_PLUGINS,
20
+ rwsExternals,
21
+ devExternalsVars
22
+ ) {
23
+ return {
24
+ context: executionDir,
25
+ entry: {
26
+ ...automatedChunks
27
+ },
28
+ mode: isDev ? 'development' : 'production',
29
+ target: 'web',
30
+ devtool: devTools,
31
+ output: {
32
+ path: outputDir,
33
+ filename: isParted ? (partedPrefix || 'rws') + '.[name].js' : outputFileName,
34
+ sourceMapFilename: '[file].map',
35
+ },
36
+ resolve: {
37
+ extensions: ['.ts', '.js', '.scss', '.css'],
38
+ modules: modules_setup,
39
+ alias: {
40
+ ...aliases
41
+ }
42
+ },
43
+ module: {
44
+ rules: getRWSLoaders(clientPkgPath, path.resolve(_packageDir, 'node_modules'), tsConfigPath, devDebug),
45
+ },
46
+ plugins: WEBPACK_PLUGINS,
47
+ externals: rwsExternals(executionDir, modules_setup, automatedChunks, {
48
+ _vars: devExternalsVars
49
+ }),
50
+ cache: {
51
+ type: 'filesystem',
52
+ buildDependencies: {
53
+ config: [__filename],
54
+ },
55
+ }
56
+ }
57
+ }
58
+
59
+ module.exports = { createWebpackConfig }
@@ -19,8 +19,7 @@ function setupTsConfig(tsConfigPath, executionDir) {
19
19
  const declarationsPath = path.resolve(__dirname, '..', 'types') + '/declarations.d.ts';
20
20
  const foundationPath = path.resolve(__dirname, '..', 'foundation');
21
21
  const testsPath = path.resolve(__dirname, '..', 'tests');
22
- const declarationsPathMD5 = md5(fs.readFileSync(declarationsPath, 'utf-8'));
23
- const testsPathMD5 = fs.existsSync(testsPath) ? md5(fs.readFileSync(testsPath, 'utf-8')) : null;
22
+
24
23
 
25
24
  const relativeDeclarationsPath = path.relative(path.dirname(tsConfigPath), declarationsPath);
26
25
  const relativeTestsPath = path.relative(path.dirname(tsConfigPath), testsPath);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.10.8",
4
+ "version": "2.10.9",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@microsoft/fast-element": "^1.12.0",
30
30
  "@microsoft/fast-foundation": "^2.46.2",
31
- "@rws-framework/console": "*",
31
+ "@rws-framework/console": "^0.3.15",
32
32
  "@types/moment": "^2.13.0",
33
33
  "deepmerge": "^4.3.1",
34
34
  "dragula": "^3.7.3",
@@ -62,6 +62,7 @@
62
62
  "@types/sanitize-html": "^2.11.0",
63
63
  "@types/uuid": "^9.0.7",
64
64
  "@typescript-eslint/parser": "^5.0.0",
65
+ "fork-ts-checker-webpack-plugin": "^9.0.2",
65
66
  "browser-sync": "^2.29.3",
66
67
  "clean-webpack-plugin": "^4.0.0",
67
68
  "css-loader": "^6.8.1",