@rws-framework/client 2.11.0 → 2.13.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.
- package/builder/vite/index.ts +5 -0
- package/builder/vite/rws.vite.config.ts +44 -0
- package/{webpack → builder/webpack}/index.js +3 -1
- package/{webpack → builder/webpack}/loaders/rws_fast_ts_loader.js +1 -1
- package/{rws.webpack.config.js → builder/webpack/rws.webpack.config.js} +18 -13
- package/cfg/build_steps/vite/_build_config.ts +106 -0
- package/cfg/build_steps/vite/_env_defines.ts +17 -0
- package/cfg/build_steps/vite/_loaders.ts +183 -0
- package/cfg/build_steps/vite/index.ts +3 -0
- package/cfg/build_steps/vite/loaders/html.ts +14 -0
- package/cfg/build_steps/vite/loaders/index.ts +9 -0
- package/cfg/build_steps/vite/loaders/loader.type.ts +4 -0
- package/cfg/build_steps/vite/loaders/scss.ts +20 -0
- package/cfg/build_steps/vite/loaders/ts.ts +19 -0
- package/cfg/build_steps/vite/rws_scss_plugin.ts +63 -0
- package/cfg/build_steps/vite/scss/_compiler.ts +101 -0
- package/cfg/build_steps/vite/scss/_fonts.ts +81 -0
- package/cfg/build_steps/vite/scss/_fs.ts +82 -0
- package/cfg/build_steps/vite/scss/_import.ts +185 -0
- package/cfg/build_steps/vite/types.ts +7 -0
- package/cfg/build_steps/webpack/_actions.js +0 -0
- package/cfg/build_steps/webpack/_build_config.js +0 -0
- package/cfg/build_steps/webpack/_component_handling.js +0 -0
- package/cfg/build_steps/webpack/_dev_servers.js +0 -0
- package/cfg/build_steps/webpack/_env_defines.js +2 -7
- package/cfg/build_steps/webpack/_loaders.js +0 -6
- package/cfg/build_steps/webpack/_plugins.js +0 -0
- package/cfg/build_steps/webpack/_webpack_config.js +6 -1
- package/package.json +3 -2
- package/src/client/config.ts +2 -2
- package/src/client.ts +1 -1
- package/src/components/_component.ts +4 -2
- package/src/components/_container.ts +2 -6
- package/src/components/_decorator.ts +1 -1
- package/src/components/_definitions.ts +0 -1
- package/src/components/_event_handling.ts +1 -1
- package/src/index.ts +60 -70
- package/src/services/ApiService.ts +1 -8
- package/src/services/_service.ts +2 -2
- package/src/styles/_grid.scss +16 -8
- package/src/styles/_scrollbars.scss +1 -0
- package/src/styles/includes.scss +0 -1
- package/src/types/IRWSConfig.ts +2 -2
- package/src/types/IRWSPlugin.ts +3 -5
- /package/{webpack → builder/webpack}/after/copy.js +0 -0
- /package/{webpack → builder/webpack}/after/sw.js +0 -0
- /package/{webpack → builder/webpack}/loaders/rws_fast_html_loader.js +0 -0
- /package/{webpack → builder/webpack}/loaders/rws_fast_scss_loader.js +0 -0
- /package/{webpack → builder/webpack}/loaders/ts/html_error.js +0 -0
- /package/{webpack → builder/webpack}/rws_scss_plugin.js +0 -0
- /package/{webpack → builder/webpack}/rws_webpack_plugin.js +0 -0
- /package/{webpack → builder/webpack}/scss/_compiler.js +0 -0
- /package/{webpack → builder/webpack}/scss/_fonts.js +0 -0
- /package/{webpack → builder/webpack}/scss/_fs.js +0 -0
- /package/{webpack → builder/webpack}/scss/_import.js +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
};
|
|
16
|
+
|
|
17
|
+
export function rwsViteBuilder(config: Partial<RWSViteConfig> = _DEFAULT_CFG, devDebug = false): UserConfig {
|
|
18
|
+
if(!config.tsConfigPath){
|
|
19
|
+
config.tsConfigPath = _DEFAULT_CFG.tsConfigPath;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const theConfig: RWSViteConfig = {..._DEFAULT_CFG, ...config};
|
|
23
|
+
|
|
24
|
+
// Return a plain configuration object
|
|
25
|
+
return {
|
|
26
|
+
define: processEnvDefines(theConfig, _DEFAULT_CFG, devDebug),
|
|
27
|
+
plugins: getRWSVitePlugins({
|
|
28
|
+
packageDir: rwsPath.findPackageDir(process.cwd()),
|
|
29
|
+
nodeModulesPath: `${rwsPath.findRootWorkspacePath(process.cwd())}/node_modules`,
|
|
30
|
+
tsConfigPath: theConfig.tsConfigPath,
|
|
31
|
+
devDebug: true
|
|
32
|
+
}),
|
|
33
|
+
build: {
|
|
34
|
+
minify: !config.dev,
|
|
35
|
+
sourcemap: config.dev,
|
|
36
|
+
outDir: 'dist',
|
|
37
|
+
rollupOptions: {
|
|
38
|
+
input: {
|
|
39
|
+
main: path.resolve(process.cwd(), 'index.html')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -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
|
|
@@ -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('
|
|
8
|
-
const { loadAliases } = require('
|
|
9
|
-
const { timingStart, timingStop, timeLog, toggleLogging } = require('
|
|
10
|
-
const { getRWSProductionSetup } = require('
|
|
11
|
-
const { rwsExternals } = require('
|
|
12
|
-
|
|
13
|
-
const tools = require('
|
|
14
|
-
const { setComponentsChunks, scanComponents, generateRWSInfoFile, partedComponentsEvents } = require('
|
|
15
|
-
const { getBuildConfig } = require('
|
|
16
|
-
const { createWebpackConfig } = require('
|
|
17
|
-
const { executeRWSStartActions, timingActions, devActions } = require('
|
|
18
|
-
const { webpackDevServer } = require('
|
|
19
|
-
const { RWS_WEBPACK_PLUGINS_BAG, addStartPlugins } = require('
|
|
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
|
|
@@ -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,183 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import JSON5 from 'json5';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { Plugin } from 'vite';
|
|
6
|
+
import { RWSScssPlugin } from './rws_scss_plugin';
|
|
7
|
+
import { scssLoader, tsLoader, htmlLoader } from './loaders';
|
|
8
|
+
|
|
9
|
+
const cssPlugin = new RWSScssPlugin();
|
|
10
|
+
|
|
11
|
+
interface RWSLoaderOptions {
|
|
12
|
+
packageDir: string;
|
|
13
|
+
nodeModulesPath: string;
|
|
14
|
+
tsConfigPath: string;
|
|
15
|
+
devDebug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ViewDecoratorData {
|
|
19
|
+
tagName: string;
|
|
20
|
+
className: string | null;
|
|
21
|
+
classNamePrefix: string | null;
|
|
22
|
+
decoratorArgs: any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getRWSVitePlugins({ packageDir, nodeModulesPath, tsConfigPath, devDebug }: RWSLoaderOptions): Plugin[] {
|
|
26
|
+
return [
|
|
27
|
+
tsLoader, scssLoader, htmlLoader
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _extractRWSViewDefs(fastOptions: Record<string, any> = {}, decoratorArgs: Record<string, any> = {}) {
|
|
32
|
+
const addedParamDefs: string[] = [];
|
|
33
|
+
const addedParams: string[] = [];
|
|
34
|
+
|
|
35
|
+
for (const key in fastOptions) {
|
|
36
|
+
addedParamDefs.push(`const ${key} = ${JSON.stringify(fastOptions[key])};`);
|
|
37
|
+
addedParams.push(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [addedParamDefs, addedParams];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function extractRWSViewArgs(content: string, noReplace = false): { viewDecoratorData: ViewDecoratorData, replacedDecorator: string | null } | null {
|
|
44
|
+
const viewReg = /@RWSView\(\s*["']([^"']+)["'](?:\s*,\s*([\s\S]*?))?\s*\)\s*(.*?\s+)?class\s+([a-zA-Z0-9_-]+)\s+extends\s+RWSViewComponent/gm;
|
|
45
|
+
let m;
|
|
46
|
+
let tagName: string | null = null;
|
|
47
|
+
let className: string | null = null;
|
|
48
|
+
let classNamePrefix: string | null = null;
|
|
49
|
+
let decoratorArgs: any = null;
|
|
50
|
+
|
|
51
|
+
const _defaultRWSLoaderOptions = {
|
|
52
|
+
templatePath: 'template.html',
|
|
53
|
+
stylesPath: 'styles.scss',
|
|
54
|
+
fastOptions: { shadowOptions: { mode: 'open' } }
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
while ((m = viewReg.exec(content)) !== null) {
|
|
58
|
+
if (m.index === viewReg.lastIndex) {
|
|
59
|
+
viewReg.lastIndex++;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
m.forEach((match, groupIndex) => {
|
|
63
|
+
if (groupIndex === 1) {
|
|
64
|
+
tagName = match;
|
|
65
|
+
}
|
|
66
|
+
if (groupIndex === 2) {
|
|
67
|
+
if (match) {
|
|
68
|
+
try {
|
|
69
|
+
decoratorArgs = JSON5.parse(match);
|
|
70
|
+
} catch(e) {
|
|
71
|
+
console.log(chalk.red('Decorator options parse error: ') + e.message + '\n Problematic line:');
|
|
72
|
+
console.log(`@RWSView(${tagName}, ${match})`);
|
|
73
|
+
console.log(chalk.yellowBright(`Decorator options failed to parse for "${tagName}" component.`) + ' { decoratorArgs } defaulting to null.');
|
|
74
|
+
console.log(match);
|
|
75
|
+
throw new Error('Failed parsing @RWSView');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (groupIndex === 3) {
|
|
80
|
+
classNamePrefix = match || null;
|
|
81
|
+
}
|
|
82
|
+
if (groupIndex === 4) {
|
|
83
|
+
className = match;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!tagName) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let processedContent = content;
|
|
93
|
+
let fastOptions = _defaultRWSLoaderOptions.fastOptions;
|
|
94
|
+
|
|
95
|
+
if (decoratorArgs?.fastElementOptions) {
|
|
96
|
+
fastOptions = decoratorArgs.fastElementOptions;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let replacedDecorator: string | null = null;
|
|
100
|
+
|
|
101
|
+
if (!noReplace) {
|
|
102
|
+
const [addedParamDefs, addedParams] = _extractRWSViewDefs(fastOptions, decoratorArgs);
|
|
103
|
+
const replacedViewDecoratorContent = processedContent.replace(
|
|
104
|
+
viewReg,
|
|
105
|
+
`@RWSView('$1', null, { template: rwsTemplate, styles${addedParams.length ? ', options: {' + (addedParams.join(', ')) + '}' : ''} })\n$3class $4 extends RWSViewComponent `
|
|
106
|
+
);
|
|
107
|
+
replacedDecorator = `${addedParamDefs.join('\n')}\n${replacedViewDecoratorContent}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
viewDecoratorData: {
|
|
112
|
+
tagName,
|
|
113
|
+
className,
|
|
114
|
+
classNamePrefix,
|
|
115
|
+
decoratorArgs
|
|
116
|
+
},
|
|
117
|
+
replacedDecorator
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function getStyles(
|
|
122
|
+
filePath: string,
|
|
123
|
+
addDependency: (path: string) => void,
|
|
124
|
+
templateExists: boolean,
|
|
125
|
+
stylesPath: string | null = null,
|
|
126
|
+
isDev = false
|
|
127
|
+
): Promise<string> {
|
|
128
|
+
if (!stylesPath) {
|
|
129
|
+
stylesPath = 'styles/layout.scss';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let styles = 'const styles: null = null;';
|
|
133
|
+
const stylesFilePath = path.dirname(filePath) + '/' + stylesPath;
|
|
134
|
+
|
|
135
|
+
if (fs.existsSync(stylesFilePath)) {
|
|
136
|
+
const scsscontent = fs.readFileSync(stylesFilePath, 'utf-8');
|
|
137
|
+
|
|
138
|
+
const codeData = await cssPlugin.compileScssCode(
|
|
139
|
+
scsscontent,
|
|
140
|
+
path.dirname(filePath) + '/styles'
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const cssCode = codeData.code;
|
|
144
|
+
styles = isDev ? `import './${stylesPath}';\n` : '';
|
|
145
|
+
|
|
146
|
+
if (!templateExists) {
|
|
147
|
+
styles += `import { css } from '@microsoft/fast-element';\n`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
styles += `const styles = ${templateExists ? 'T.' : ''}css\`${cssCode}\`;\n`;
|
|
151
|
+
addDependency(path.dirname(filePath) + '/' + stylesPath);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return styles;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function getTemplate(
|
|
158
|
+
filePath: string,
|
|
159
|
+
addDependency: (path: string) => void,
|
|
160
|
+
templateName: string | null = null,
|
|
161
|
+
isDev = false
|
|
162
|
+
): Promise<[string, string | null, boolean]> {
|
|
163
|
+
if (!templateName) {
|
|
164
|
+
templateName = 'template';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const templatePath = path.dirname(filePath) + `/${templateName}.html`;
|
|
168
|
+
let htmlFastImports: string | null = null;
|
|
169
|
+
const templateExists = fs.existsSync(templatePath);
|
|
170
|
+
let template = 'const rwsTemplate: null = null;';
|
|
171
|
+
|
|
172
|
+
if (templateExists) {
|
|
173
|
+
const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
|
|
174
|
+
htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
|
|
175
|
+
template = `
|
|
176
|
+
//@ts-ignore
|
|
177
|
+
let rwsTemplate: any = T.html\`${templateContent}\`;
|
|
178
|
+
`;
|
|
179
|
+
addDependency(templatePath);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return [template, htmlFastImports, templateExists];
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IRWSViteLoader } from "./loader.type";
|
|
2
|
+
|
|
3
|
+
export default (): IRWSViteLoader => ({
|
|
4
|
+
name: 'rws-html',
|
|
5
|
+
async transform(code: string, id: string) {
|
|
6
|
+
if (!id.endsWith('.html')) return null;
|
|
7
|
+
|
|
8
|
+
// Process HTML files
|
|
9
|
+
return {
|
|
10
|
+
code,
|
|
11
|
+
map: null
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IRWSViteLoader } from "./loader.type";
|
|
2
|
+
import { RWSScssPlugin } from '../rws_scss_plugin';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default (cssPlugin: RWSScssPlugin): IRWSViteLoader => ({
|
|
6
|
+
name: 'rws-scss',
|
|
7
|
+
async transform(code: string, id: string) {
|
|
8
|
+
if (!id.endsWith('.scss')) return null;
|
|
9
|
+
|
|
10
|
+
const result = await cssPlugin.compileScssCode(
|
|
11
|
+
code,
|
|
12
|
+
path.dirname(id) + '/styles',
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
code: result.code,
|
|
17
|
+
map: null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IRWSViteLoader } from "./loader.type";
|
|
2
|
+
export default (): IRWSViteLoader => ({
|
|
3
|
+
name: 'rws-typescript',
|
|
4
|
+
async transform(code: string, id: string) {
|
|
5
|
+
console.log({code});
|
|
6
|
+
if (!id.endsWith('.ts')) return null;
|
|
7
|
+
|
|
8
|
+
// Skip .debug.ts and .d.ts files
|
|
9
|
+
if (id.endsWith('.debug.ts') || id.endsWith('.d.ts')) return null;
|
|
10
|
+
|
|
11
|
+
// Skip non-@rws-framework node_modules
|
|
12
|
+
if (id.includes('node_modules') && !id.includes('@rws-framework')) return null;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
code,
|
|
16
|
+
map: null
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { rwsPath } from '@rws-framework/console';
|
|
3
|
+
|
|
4
|
+
import _scss_compiler_builder from './scss/_compiler';
|
|
5
|
+
import _scss_import_builder from './scss/_import';
|
|
6
|
+
|
|
7
|
+
import _scss_fs_builder from './scss/_fs';
|
|
8
|
+
|
|
9
|
+
type PluginParams = { autoCompile: string[] };
|
|
10
|
+
|
|
11
|
+
class RWSScssPlugin {
|
|
12
|
+
protected autoCompile: string[] = [];
|
|
13
|
+
protected node_modules_dir: (fileDir: string) => void;
|
|
14
|
+
|
|
15
|
+
private _scss_import: any;
|
|
16
|
+
private _scss_fs: any;
|
|
17
|
+
private _scss_compiler: any;
|
|
18
|
+
|
|
19
|
+
constructor(params: PluginParams = { autoCompile: [] }) {
|
|
20
|
+
this.node_modules_dir = (fileDir) => path.relative(fileDir, rwsPath.findRootWorkspacePath(process.cwd())) + '/node_modules/'
|
|
21
|
+
this._scss_import = _scss_import_builder(this);
|
|
22
|
+
this._scss_fs = _scss_fs_builder(this);
|
|
23
|
+
this._scss_compiler = _scss_compiler_builder(this);
|
|
24
|
+
|
|
25
|
+
if (!!params.autoCompile && params.autoCompile.length > 0) {
|
|
26
|
+
this.autoCompile = params.autoCompile;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (let index in this.autoCompile) {
|
|
30
|
+
const sassFile = this.autoCompile[index];
|
|
31
|
+
this.compileFile(sassFile);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
apply(compiler) {
|
|
37
|
+
const _self = this;
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async compileFile(scssPath): Promise<{ code: string, dependencies: string[]}>
|
|
43
|
+
{
|
|
44
|
+
scssPath = this._scss_import.processImportPath(scssPath, path.dirname(scssPath))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
let scssCode = this._scss_fs.getCodeFromFile(scssPath);
|
|
48
|
+
|
|
49
|
+
return await this._scss_compiler.compileScssCode(scssCode, path.dirname(scssPath), null, scssPath);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async compileScssCode(scssCode: string, scssPath: string): Promise<{ code: string, dependencies: string[]}>
|
|
53
|
+
{
|
|
54
|
+
return await this._scss_compiler.compileScssCode(scssCode, scssPath, null, scssPath);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
writeCssFile(scssFilePath: string, cssContent: string): string
|
|
58
|
+
{
|
|
59
|
+
return this._scss_fs.writeCssFile(scssFilePath, cssContent);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {RWSScssPlugin};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const sass = require('sass');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const emojiRegex = require('emoji-regex');
|
|
5
|
+
|
|
6
|
+
import _scss_fonts_builder from './_fonts';
|
|
7
|
+
let _scss_fonts: any = null;
|
|
8
|
+
|
|
9
|
+
import _scss_import_builder from './_import';
|
|
10
|
+
let _scss_import: any = null;
|
|
11
|
+
|
|
12
|
+
function compileScssCode(scssCode, fileRootDir, createFile = false, filePath = null, minify = false): {
|
|
13
|
+
code: string,
|
|
14
|
+
dependencies: string[]
|
|
15
|
+
}
|
|
16
|
+
{
|
|
17
|
+
_scss_fonts = _scss_fonts_builder(this);
|
|
18
|
+
_scss_import = _scss_import_builder(this);
|
|
19
|
+
|
|
20
|
+
const [scssImports] = _scss_import.extractScssImports(scssCode, fileRootDir);
|
|
21
|
+
|
|
22
|
+
const dependencies = scssImports.map((item) => item[2]);
|
|
23
|
+
|
|
24
|
+
if (scssImports && scssImports.length) {
|
|
25
|
+
scssCode = _scss_import.replaceImports(_scss_import.processImports(scssImports, fileRootDir), scssCode);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const uses = _scss_import.extractScssUses(scssCode)[0];
|
|
29
|
+
let scssUses = '';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
uses.forEach(scssUse => {
|
|
33
|
+
const useLine = scssUse[1];
|
|
34
|
+
if(scssCode.indexOf(useLine) === -1){
|
|
35
|
+
scssUses += useLine + '\n';
|
|
36
|
+
scssCode = scssCode.replace(useLine + '\n', '');
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
scssCode = removeComments(scssUses + scssCode);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = sass.compileString(scssCode, { loadPaths: [fileRootDir]});
|
|
44
|
+
|
|
45
|
+
let compiledCode = result.css.toString();
|
|
46
|
+
compiledCode = _scss_fonts.replaceFontUrlWithBase64(compiledCode);
|
|
47
|
+
compiledCode = replaceEmojisWithQuestionMark(compiledCode, fileRootDir);
|
|
48
|
+
return { code: compiledCode, dependencies};
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error('SASS Error in', fileRootDir);
|
|
51
|
+
|
|
52
|
+
console.error(err);
|
|
53
|
+
throw err;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function checkForImporterType(_module, checkTypeExt) {
|
|
58
|
+
let importingFileExtension = '';
|
|
59
|
+
|
|
60
|
+
if (_module && _module.issuer && _module.issuer.resource) {
|
|
61
|
+
importingFileExtension = path.extname(_module.issuer.resource);
|
|
62
|
+
if (importingFileExtension === ('.' + checkTypeExt)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function replaceEmojisWithQuestionMark(code, componentDir) {
|
|
73
|
+
const regex = emojiRegex();
|
|
74
|
+
let hasEmoji = false;
|
|
75
|
+
|
|
76
|
+
const result = code.replace(regex, (match) => {
|
|
77
|
+
hasEmoji = true;
|
|
78
|
+
return '?';
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (hasEmoji) {
|
|
82
|
+
console.log(chalk.yellow(`Emojis in css detected and replaced with "?" in "${path.dirname(componentDir)}" component`));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function removeComments(code) {
|
|
89
|
+
code = code.replace(/\/\/.*$/gm, '');
|
|
90
|
+
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
91
|
+
code = code.replace(/^\s*$(?:\r\n?|\n)/gm, '');
|
|
92
|
+
|
|
93
|
+
return code;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default function(element) {
|
|
97
|
+
return {
|
|
98
|
+
checkForImporterType: checkForImporterType.bind(element),
|
|
99
|
+
compileScssCode: compileScssCode.bind(element)
|
|
100
|
+
};
|
|
101
|
+
};
|