@rws-framework/client 2.12.0 → 2.13.1

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 (56) hide show
  1. package/builder/vite/index.ts +5 -0
  2. package/builder/vite/rws.vite.config.ts +50 -0
  3. package/{webpack → builder/webpack}/index.js +3 -1
  4. package/{webpack → builder/webpack}/loaders/rws_fast_html_loader.js +8 -0
  5. package/{webpack → builder/webpack}/loaders/rws_fast_scss_loader.js +8 -1
  6. package/{webpack → builder/webpack}/loaders/rws_fast_ts_loader.js +1 -1
  7. package/{rws.webpack.config.js → builder/webpack/rws.webpack.config.js} +18 -13
  8. package/bun.lockb +0 -0
  9. package/cfg/build_steps/vite/_build_config.ts +106 -0
  10. package/cfg/build_steps/vite/_env_defines.ts +17 -0
  11. package/cfg/build_steps/vite/_loaders.ts +185 -0
  12. package/cfg/build_steps/vite/index.ts +3 -0
  13. package/cfg/build_steps/vite/loaders/html.ts +12 -0
  14. package/cfg/build_steps/vite/loaders/index.ts +9 -0
  15. package/cfg/build_steps/vite/loaders/loader.type.ts +28 -0
  16. package/cfg/build_steps/vite/loaders/scss.ts +33 -0
  17. package/cfg/build_steps/vite/loaders/ts.ts +313 -0
  18. package/cfg/build_steps/vite/rws_scss_plugin.ts +60 -0
  19. package/cfg/build_steps/vite/scss/_compiler.ts +95 -0
  20. package/cfg/build_steps/vite/scss/_fonts.ts +81 -0
  21. package/cfg/build_steps/vite/scss/_fs.ts +82 -0
  22. package/cfg/build_steps/vite/scss/_import.ts +185 -0
  23. package/cfg/build_steps/vite/types.ts +8 -0
  24. package/cfg/build_steps/webpack/_actions.js +0 -0
  25. package/cfg/build_steps/webpack/_build_config.js +0 -0
  26. package/cfg/build_steps/webpack/_component_handling.js +0 -0
  27. package/cfg/build_steps/webpack/_dev_servers.js +0 -0
  28. package/cfg/build_steps/webpack/_env_defines.js +2 -7
  29. package/cfg/build_steps/webpack/_loaders.js +0 -6
  30. package/cfg/build_steps/webpack/_plugins.js +0 -0
  31. package/cfg/build_steps/webpack/_webpack_config.js +6 -1
  32. package/package.json +11 -9
  33. package/src/client/config.ts +2 -2
  34. package/src/client.ts +1 -1
  35. package/src/components/_component.ts +4 -2
  36. package/src/components/_container.ts +2 -6
  37. package/src/components/_decorator.ts +1 -1
  38. package/src/components/_definitions.ts +0 -1
  39. package/src/components/_event_handling.ts +1 -1
  40. package/src/index.ts +60 -70
  41. package/src/services/ApiService.ts +1 -8
  42. package/src/services/_service.ts +2 -2
  43. package/src/styles/_grid.scss +16 -8
  44. package/src/styles/_scrollbars.scss +1 -0
  45. package/src/styles/includes.scss +0 -1
  46. package/src/types/IRWSConfig.ts +2 -2
  47. package/src/types/IRWSPlugin.ts +3 -5
  48. /package/{webpack → builder/webpack}/after/copy.js +0 -0
  49. /package/{webpack → builder/webpack}/after/sw.js +0 -0
  50. /package/{webpack → builder/webpack}/loaders/ts/html_error.js +0 -0
  51. /package/{webpack → builder/webpack}/rws_scss_plugin.js +0 -0
  52. /package/{webpack → builder/webpack}/rws_webpack_plugin.js +0 -0
  53. /package/{webpack → builder/webpack}/scss/_compiler.js +0 -0
  54. /package/{webpack → builder/webpack}/scss/_fonts.js +0 -0
  55. /package/{webpack → builder/webpack}/scss/_fs.js +0 -0
  56. /package/{webpack → builder/webpack}/scss/_import.js +0 -0
@@ -0,0 +1,5 @@
1
+ import { rwsViteBuilder } from './rws.vite.config';
2
+
3
+ export {
4
+ rwsViteBuilder
5
+ };
@@ -0,0 +1,50 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import { processEnvDefines } from '../../cfg/build_steps/vite/_env_defines';
4
+ import { getRWSVitePlugins } from '../../cfg/build_steps/vite/_loaders';
5
+ import { rwsPath } from '@rws-framework/console';
6
+ import type { RWSViteConfig } from '../../cfg/build_steps/vite/types';
7
+ import type { UserConfig } from 'vite'; // Add this import
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ export const _DEFAULT_CFG: RWSViteConfig = {
13
+ dev: true,
14
+ tsConfigPath: path.resolve(rwsPath.findPackageDir(process.cwd()), 'tsconfig.json'),
15
+ cssOutputPath: path.resolve(rwsPath.findPackageDir(process.cwd()), 'public', 'css'),
16
+ };
17
+
18
+ export function rwsViteBuilder(config: Partial<RWSViteConfig> = _DEFAULT_CFG, devDebug = false): UserConfig {
19
+ if(!config.tsConfigPath){
20
+ config.tsConfigPath = _DEFAULT_CFG.tsConfigPath;
21
+ }
22
+
23
+ if(!config.cssOutputPath){
24
+ config.cssOutputPath = _DEFAULT_CFG.cssOutputPath;
25
+ }
26
+
27
+ const theConfig: RWSViteConfig = {..._DEFAULT_CFG, ...config};
28
+
29
+ // Return a plain configuration object
30
+ return {
31
+ define: processEnvDefines(theConfig, _DEFAULT_CFG, devDebug),
32
+ plugins: getRWSVitePlugins({
33
+ packageDir: rwsPath.findPackageDir(process.cwd()),
34
+ nodeModulesPath: `${rwsPath.findRootWorkspacePath(process.cwd())}/node_modules`,
35
+ tsConfigPath: theConfig.tsConfigPath,
36
+ cssOutputPath: theConfig.cssOutputPath as string,
37
+ dev: config.dev as boolean
38
+ }),
39
+ build: {
40
+ minify: !config.dev,
41
+ sourcemap: config.dev,
42
+ outDir: 'dist',
43
+ rollupOptions: {
44
+ input: {
45
+ main: path.resolve(process.cwd(), 'index.html')
46
+ }
47
+ }
48
+ }
49
+ };
50
+ }
@@ -1,8 +1,10 @@
1
1
  const scssLoader = require('./loaders/rws_fast_scss_loader');
2
2
  const htmlLoader = require('./loaders/rws_fast_html_loader');
3
3
  const tsLoader = require('./loaders/rws_fast_ts_loader');
4
+ const { RWSWebpackWrapper } = require('./rws.webpack.config');
4
5
 
5
- module.exports = {
6
+ module.exports = {
7
+ RWSWebpackWrapper,
6
8
  scssLoader,
7
9
  htmlLoader,
8
10
  tsLoader
@@ -5,6 +5,14 @@ module.exports = function(content){
5
5
  const filePath = this.resourcePath;
6
6
  const componentDir = path.dirname(filePath);
7
7
  const componentPath = path.resolve(componentDir, 'component.ts');
8
+
9
+ if(fs.existsSync(componentPath)){
10
+ const fileCnt = fs.readFileSync(componentPath, 'utf-8');
11
+
12
+ if(fileCnt){
13
+ fs.writeFile(componentPath, fileCnt, () => {})
14
+ }
15
+ }
8
16
 
9
17
  return '';
10
18
  }
@@ -31,6 +31,13 @@ module.exports = async function(content) {
31
31
  }
32
32
  }
33
33
 
34
-
34
+ if(fs.existsSync(componentPath)){
35
+ const fileCnt = fs.readFileSync(componentPath, 'utf-8');
36
+
37
+ if(fileCnt){
38
+ fs.writeFile(componentPath, fileCnt, () => {})
39
+ }
40
+ }
41
+
35
42
  return '';
36
43
  };
@@ -24,7 +24,7 @@ module.exports = async function(content) {
24
24
  const customCompilationOptions = compilationVariables?.customOptions || null;
25
25
 
26
26
  const cachedTS = _scss_cache.cache(customCompilationOptions).getCachedItem(filePath, md5(cachedCode));
27
-
27
+
28
28
  if(cachedTS){
29
29
  return cachedTS;
30
30
  }
@@ -4,19 +4,19 @@ const chalk = require('chalk');
4
4
 
5
5
  const RWSWebpackPlugin = require('./webpack/rws_webpack_plugin');
6
6
 
7
- const buildInfo = require('./cfg/build_steps/webpack/_info');
8
- const { loadAliases } = require('./cfg/build_steps/webpack/_aliases');
9
- const { timingStart, timingStop, timeLog, toggleLogging } = require('./cfg/build_steps/webpack/_timing');
10
- const { getRWSProductionSetup } = require('./cfg/build_steps/webpack/_production');
11
- const { rwsExternals } = require('./cfg/build_steps/webpack/_rws_externals');
12
-
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');
7
+ const buildInfo = require('../../cfg/build_steps/webpack/_info');
8
+ const { loadAliases } = require('../../cfg/build_steps/webpack/_aliases');
9
+ const { timingStart, timingStop, timeLog, toggleLogging } = require('../../cfg/build_steps/webpack/_timing');
10
+ const { getRWSProductionSetup } = require('../../cfg/build_steps/webpack/_production');
11
+ const { rwsExternals } = require('../../cfg/build_steps/webpack/_rws_externals');
12
+
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');
20
20
 
21
21
  const _MAIN_PACKAGE = rwsPath.findRootWorkspacePath(process.cwd());
22
22
 
@@ -68,6 +68,11 @@ const RWSWebpackWrapper = async (rwsFrontendConfig) => {
68
68
  let optimConfig = null;
69
69
  let aliases = rwsFrontendConfig.aliases || {};
70
70
 
71
+ console.log({
72
+ __filename,
73
+ _packageDir
74
+ });
75
+
71
76
  aliases = { ...aliases, ...loadAliases(__dirname, path.resolve(_MAIN_PACKAGE, 'node_modules'), executionDir) }
72
77
 
73
78
  // #SECTION PLUGIN STARTING HOOKS
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,106 @@
1
+ import chalk from 'chalk';
2
+ import { RWSConfigBuilder, rwsPath } from '@rws-framework/console';
3
+ import { _DEFAULT_CONFIG } from '../../_default.cfg';
4
+
5
+ import { IRWSPlugin } from '../../../src/types/IRWSPlugin';
6
+
7
+ interface IRWSViteConfig {
8
+ executionDir: string;
9
+ isWatcher: boolean;
10
+ isDev: boolean;
11
+ isHotReload: boolean;
12
+ isReport: boolean;
13
+ isParted: boolean;
14
+ partedPrefix?: string | null;
15
+ partedDirUrlPrefix?: string | null;
16
+ partedComponentsLocations?: string[];
17
+ customServiceLocations?: string[];
18
+ outputDir: string;
19
+ outputFileName: string;
20
+ publicDir?: string | null;
21
+ serviceWorkerPath?: string | null,
22
+ publicIndex?: string | null,
23
+ devTools?: string | null,
24
+ devDebug?: any,
25
+ devRouteProxy?: any,
26
+ tsConfigPath: string,
27
+ rwsPlugins?: {
28
+ [key: string]: IRWSPlugin
29
+ },
30
+ _packageDir?: string,
31
+ BuildConfigurator: RWSConfigBuilder<any>
32
+ }
33
+
34
+ async function getBuildConfig(rwsFrontBuildConfig): Promise<IRWSViteConfig>
35
+ {
36
+ const BuildConfigurator = new RWSConfigBuilder(rwsPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...rwsFrontBuildConfig});
37
+ const _packageDir = rwsPath.findPackageDir(process.cwd());
38
+
39
+ const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || rwsFrontBuildConfig.executionDir || process.cwd(), _packageDir);
40
+ const isWatcher = process.argv.includes('--watch') || false;
41
+
42
+ const isDev = isWatcher ? true : (BuildConfigurator.get('dev', rwsFrontBuildConfig.dev) || false);
43
+ const isHotReload = BuildConfigurator.get('hot', rwsFrontBuildConfig.hot);
44
+ const isReport = BuildConfigurator.get('report', rwsFrontBuildConfig.report);
45
+ const isParted = BuildConfigurator.get('parted', rwsFrontBuildConfig.parted || false);
46
+
47
+ const partedPrefix = BuildConfigurator.get('partedPrefix', rwsFrontBuildConfig.partedPrefix);
48
+ const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix', rwsFrontBuildConfig.partedDirUrlPrefix);
49
+
50
+ let partedComponentsLocations = BuildConfigurator.get('partedComponentsLocations', rwsFrontBuildConfig.partedComponentsLocations);
51
+ const customServiceLocations = BuildConfigurator.get('customServiceLocations', rwsFrontBuildConfig.customServiceLocations); //@todo: check if needed
52
+ const outputDir = rwsPath.relativize(BuildConfigurator.get('outputDir', rwsFrontBuildConfig.outputDir), _packageDir);
53
+
54
+ const outputFileName = BuildConfigurator.get('outputFileName') || rwsFrontBuildConfig.outputFileName;
55
+ const publicDir = BuildConfigurator.get('publicDir') || rwsFrontBuildConfig.publicDir;
56
+ const serviceWorkerPath = BuildConfigurator.get('serviceWorker') || rwsFrontBuildConfig.serviceWorker;
57
+
58
+ const publicIndex = BuildConfigurator.get('publicIndex') || rwsFrontBuildConfig.publicIndex;
59
+
60
+ const devTools = isDev ? (BuildConfigurator.get('devtool') || 'source-map') : false;
61
+
62
+ const _DEFAULT_DEV_DEBUG = { build: false, timing: false, rwsCache: false, profiling: false };
63
+
64
+ let devDebug = isDev ? (BuildConfigurator.get('devDebug') || rwsFrontBuildConfig.devDebug || {}) : {};
65
+ devDebug = {..._DEFAULT_DEV_DEBUG, ...devDebug}
66
+
67
+ const devRouteProxy = BuildConfigurator.get('devRouteProxy') || rwsFrontBuildConfig.devRouteProxy;
68
+
69
+ const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || rwsFrontBuildConfig.tsConfigPath, executionDir);
70
+
71
+ const rwsPlugins = {};
72
+
73
+ if(rwsFrontBuildConfig.rwsPlugins){
74
+ for(const pluginEntry of rwsFrontBuildConfig.rwsPlugins){
75
+ const pluginBuilder = (await import(`${pluginEntry}`)).default;
76
+ rwsPlugins[pluginEntry] = new pluginBuilder(BuildConfigurator, rwsFrontBuildConfig);
77
+ }
78
+ }
79
+
80
+ return {
81
+ executionDir,
82
+ isWatcher,
83
+ isDev,
84
+ isHotReload,
85
+ isReport,
86
+ isParted,
87
+ partedPrefix,
88
+ partedDirUrlPrefix,
89
+ partedComponentsLocations,
90
+ customServiceLocations,
91
+ outputDir,
92
+ outputFileName,
93
+ publicDir,
94
+ serviceWorkerPath,
95
+ publicIndex,
96
+ devTools,
97
+ devDebug,
98
+ devRouteProxy,
99
+ tsConfigPath,
100
+ rwsPlugins,
101
+ _packageDir,
102
+ BuildConfigurator
103
+ }
104
+ }
105
+
106
+ export { getBuildConfig }
@@ -0,0 +1,17 @@
1
+ import { RWSViteConfig } from "./types";
2
+
3
+ export function processEnvDefines(frontCfg: RWSViteConfig, defaults: RWSViteConfig, devDebug: any = null) {
4
+ let _rws_defines = {
5
+ '_RWS_DEV_DEBUG': JSON.stringify(devDebug),
6
+ '_RWS_DEFAULTS': JSON.stringify(defaults),
7
+ '_RWS_BUILD_OVERRIDE': JSON.stringify(frontCfg)
8
+ }
9
+
10
+ const rwsDefines = frontCfg.defines || null;
11
+
12
+ if (rwsDefines) {
13
+ _rws_defines = { ..._rws_defines, ...rwsDefines }
14
+ }
15
+
16
+ return _rws_defines;
17
+ }
@@ -0,0 +1,185 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import JSON5 from 'json5';
4
+ import chalk from 'chalk';
5
+ import { RWSScssPlugin } from './rws_scss_plugin';
6
+ import { scssLoader, tsLoader, htmlLoader } from './loaders';
7
+ import { HTMLLoaderParams, IRWSViteLoader, LoaderContent, SCSSLoaderParams, TSLoaderParams } from './loaders/loader.type';
8
+ import { PluginOption } from 'vite';
9
+
10
+ const scssPlugin = new RWSScssPlugin();
11
+
12
+ interface RWSLoaderOptions {
13
+ packageDir: string;
14
+ nodeModulesPath: string;
15
+ cssOutputPath: string;
16
+ tsConfigPath: string;
17
+ dev: boolean;
18
+ }
19
+
20
+ interface ViewDecoratorData {
21
+ tagName: string;
22
+ className: string | null;
23
+ classNamePrefix: string | null;
24
+ decoratorArgs: any;
25
+ }
26
+
27
+ export function getRWSVitePlugins({ packageDir, nodeModulesPath, tsConfigPath, cssOutputPath, dev }: RWSLoaderOptions): PluginOption[] {
28
+ return [
29
+ tsLoader({dev, scssPlugin: scssPlugin}), scssLoader({dev, scssPlugin: scssPlugin, cssOutputPath}), htmlLoader({dev})
30
+ ];
31
+ }
32
+
33
+ function _extractRWSViewDefs(fastOptions: Record<string, any> = {}, decoratorArgs: Record<string, any> = {}) {
34
+ const addedParamDefs: string[] = [];
35
+ const addedParams: string[] = [];
36
+
37
+ for (const key in fastOptions) {
38
+ addedParamDefs.push(`const ${key} = ${JSON.stringify(fastOptions[key])};`);
39
+ addedParams.push(key);
40
+ }
41
+
42
+ return [addedParamDefs, addedParams];
43
+ }
44
+
45
+ export function extractRWSViewArgs(content: string, noReplace = false): { viewDecoratorData: ViewDecoratorData, replacedDecorator: string | null } | null {
46
+ const viewReg = /@RWSView\(\s*["']([^"']+)["'](?:\s*,\s*([\s\S]*?))?\s*\)\s*(.*?\s+)?class\s+([a-zA-Z0-9_-]+)\s+extends\s+RWSViewComponent/gm;
47
+ let m;
48
+ let tagName: string | null = null;
49
+ let className: string | null = null;
50
+ let classNamePrefix: string | null = null;
51
+ let decoratorArgs: any = null;
52
+
53
+ const _defaultRWSLoaderOptions = {
54
+ templatePath: 'template.html',
55
+ stylesPath: 'styles.scss',
56
+ fastOptions: { shadowOptions: { mode: 'open' } }
57
+ };
58
+
59
+ while ((m = viewReg.exec(content)) !== null) {
60
+ if (m.index === viewReg.lastIndex) {
61
+ viewReg.lastIndex++;
62
+ }
63
+
64
+ m.forEach((match, groupIndex) => {
65
+ if (groupIndex === 1) {
66
+ tagName = match;
67
+ }
68
+ if (groupIndex === 2) {
69
+ if (match) {
70
+ try {
71
+ decoratorArgs = JSON5.parse(match);
72
+ } catch(e) {
73
+ console.log(chalk.red('Decorator options parse error: ') + e.message + '\n Problematic line:');
74
+ console.log(`@RWSView(${tagName}, ${match})`);
75
+ console.log(chalk.yellowBright(`Decorator options failed to parse for "${tagName}" component.`) + ' { decoratorArgs } defaulting to null.');
76
+ console.log(match);
77
+ throw new Error('Failed parsing @RWSView');
78
+ }
79
+ }
80
+ }
81
+ if (groupIndex === 3) {
82
+ classNamePrefix = match || null;
83
+ }
84
+ if (groupIndex === 4) {
85
+ className = match;
86
+ }
87
+ });
88
+ }
89
+
90
+ if (!tagName) {
91
+ return null;
92
+ }
93
+
94
+ let processedContent = content;
95
+ let fastOptions = _defaultRWSLoaderOptions.fastOptions;
96
+
97
+ if (decoratorArgs?.fastElementOptions) {
98
+ fastOptions = decoratorArgs.fastElementOptions;
99
+ }
100
+
101
+ let replacedDecorator: string | null = null;
102
+
103
+ if (!noReplace) {
104
+ const [addedParamDefs, addedParams] = _extractRWSViewDefs(fastOptions, decoratorArgs);
105
+ const replacedViewDecoratorContent = processedContent.replace(
106
+ viewReg,
107
+ `@RWSView('$1', null, { template: rwsTemplate, styles${addedParams.length ? ', options: {' + (addedParams.join(', ')) + '}' : ''} })\n$3class $4 extends RWSViewComponent `
108
+ );
109
+ replacedDecorator = `${addedParamDefs.join('\n')}\n${replacedViewDecoratorContent}`;
110
+ }
111
+
112
+ return {
113
+ viewDecoratorData: {
114
+ tagName,
115
+ className,
116
+ classNamePrefix,
117
+ decoratorArgs
118
+ },
119
+ replacedDecorator
120
+ };
121
+ }
122
+
123
+ export async function getStyles(
124
+ filePath: string,
125
+ addDependency: (path: string) => void,
126
+ templateExists: boolean,
127
+ stylesPath: string | null = null,
128
+ isDev = false
129
+ ): Promise<string> {
130
+ if (!stylesPath) {
131
+ stylesPath = 'styles/layout.scss';
132
+ }
133
+
134
+ let styles = 'const styles: null = null;';
135
+ const stylesFilePath = path.dirname(filePath) + '/' + stylesPath;
136
+
137
+ if (fs.existsSync(stylesFilePath)) {
138
+ const scsscontent = fs.readFileSync(stylesFilePath, 'utf-8');
139
+
140
+ const codeData = await cssPlugin.compileScssCode(
141
+ scsscontent,
142
+ path.dirname(filePath) + '/styles'
143
+ );
144
+
145
+ const cssCode = codeData.code;
146
+ styles = isDev ? `import './${stylesPath}';\n` : '';
147
+
148
+ if (!templateExists) {
149
+ styles += `import { css } from '@microsoft/fast-element';\n`;
150
+ }
151
+
152
+ styles += `const styles = ${templateExists ? 'T.' : ''}css\`${cssCode}\`;\n`;
153
+ addDependency(path.dirname(filePath) + '/' + stylesPath);
154
+ }
155
+
156
+ return styles;
157
+ }
158
+
159
+ export async function getTemplate(
160
+ filePath: string,
161
+ addDependency: (path: string) => void,
162
+ templateName: string | null = null,
163
+ isDev = false
164
+ ): Promise<[string, string | null, boolean]> {
165
+ if (!templateName) {
166
+ templateName = 'template';
167
+ }
168
+
169
+ const templatePath = path.dirname(filePath) + `/${templateName}.html`;
170
+ let htmlFastImports: string | null = null;
171
+ const templateExists = fs.existsSync(templatePath);
172
+ let template = 'const rwsTemplate: null = null;';
173
+
174
+ if (templateExists) {
175
+ const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
176
+ htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
177
+ template = `
178
+ //@ts-ignore
179
+ let rwsTemplate: any = T.html\`${templateContent}\`;
180
+ `;
181
+ addDependency(templatePath);
182
+ }
183
+
184
+ return [template, htmlFastImports, templateExists];
185
+ }
@@ -0,0 +1,3 @@
1
+ import { createViteConfig } from './vite_config';
2
+
3
+ export { createViteConfig };
@@ -0,0 +1,12 @@
1
+ import { HTMLLoaderParams, IRWSViteLoader } from "./loader.type";
2
+
3
+ const loader: IRWSViteLoader<HTMLLoaderParams> = async (params: HTMLLoaderParams) => ({
4
+ name: 'rws-html',
5
+ async transform(code: string, id: string) {
6
+ if (!id.endsWith('.html')) return null;
7
+
8
+ return null;
9
+ }
10
+ });
11
+
12
+ export default loader;
@@ -0,0 +1,9 @@
1
+ import scssLoader from './scss';
2
+ import tsLoader from './ts';
3
+ import htmlLoader from './html';
4
+
5
+ export {
6
+ scssLoader,
7
+ tsLoader,
8
+ htmlLoader
9
+ }
@@ -0,0 +1,28 @@
1
+ import { PluginOption } from 'vite';
2
+ import { RWSScssPlugin } from '../rws_scss_plugin';
3
+
4
+ export interface LoaderParams {
5
+ dev: boolean
6
+ }
7
+
8
+ export interface TSLoaderParams extends LoaderParams {
9
+ scssPlugin: RWSScssPlugin
10
+
11
+ }
12
+
13
+ export interface SCSSLoaderParams extends LoaderParams {
14
+ scssPlugin: RWSScssPlugin,
15
+ cssOutputPath: string
16
+ }
17
+
18
+ export interface HTMLLoaderParams extends LoaderParams {
19
+
20
+ }
21
+
22
+ export type LoaderContent = {
23
+ name: string,
24
+ enforce?: string,
25
+ transform(code: string, id: string): Promise<{ code: string, map: any } | null>
26
+ } | null;
27
+
28
+ export type IRWSViteLoader<P extends LoaderParams = LoaderParams> = (params: P) => PluginOption;
@@ -0,0 +1,33 @@
1
+ import { IRWSViteLoader, SCSSLoaderParams } from "./loader.type";
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+
5
+ const loader: IRWSViteLoader<SCSSLoaderParams> = async (params: SCSSLoaderParams) => ({
6
+ name: 'rws-scss',
7
+ enforce: 'pre',
8
+ async transform(code: string, id: string) {
9
+
10
+ if (!id.endsWith('.scss')) return null;
11
+
12
+ if(code.indexOf('@save') > -1){
13
+ const result = await params.scssPlugin.compileScssCode(
14
+ code,
15
+ path.dirname(id),
16
+ );
17
+
18
+ const fileName: string = id.split('/').pop() as string;
19
+ const dirName: string = params.cssOutputPath ? params.cssOutputPath : path.dirname(id);
20
+
21
+ const fileNameArray = fileName.split('.');
22
+
23
+ const newFileName: string = path.join(dirName, fileNameArray.at(-2) + '.css')
24
+
25
+
26
+ fs.writeFileSync(newFileName, result.code);
27
+ }
28
+
29
+ return { code: '' };
30
+ }
31
+ });
32
+
33
+ export default loader;