@ui5/webcomponents-tools 0.0.0-cb061e041 → 0.0.0-cddf8ba1c
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/CHANGELOG.md +375 -0
- package/README.md +2 -1
- package/assets-meta.js +16 -7
- package/components-package/eslint.js +1 -0
- package/components-package/nps.js +34 -29
- package/components-package/postcss.components.js +1 -21
- package/components-package/postcss.themes.js +1 -26
- package/components-package/wdio.js +15 -3
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +8 -6
- package/lib/create-illustrations/index.js +14 -0
- package/lib/create-new-component/index.js +1 -1
- package/lib/css-processors/css-processor-components.mjs +77 -0
- package/lib/css-processors/css-processor-themes.mjs +79 -0
- package/lib/css-processors/scope-variables.mjs +46 -0
- package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
- package/lib/dev-server/custom-hot-update-plugin.js +39 -0
- package/lib/esm-abs-to-rel/index.js +4 -1
- package/lib/generate-custom-elements-manifest/index.js +1 -1
- package/lib/generate-js-imports/illustrations.js +78 -64
- package/lib/generate-json-imports/i18n.js +10 -5
- package/lib/generate-json-imports/themes.js +10 -5
- package/lib/jsdoc/preprocess.js +1 -1
- package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
- package/lib/scoping/get-all-tags.js +1 -1
- package/lib/scoping/scope-test-pages.js +2 -1
- package/package.json +6 -9
- package/lib/postcss-css-to-json/index.js +0 -47
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/postcss-p/postcss-p.mjs +0 -14
@@ -1,3 +1,5 @@
|
|
1
|
+
const dns = require("node:dns");
|
2
|
+
|
1
3
|
exports.config = {
|
2
4
|
//
|
3
5
|
// ====================
|
@@ -56,7 +58,15 @@ exports.config = {
|
|
56
58
|
'goog:chromeOptions': {
|
57
59
|
// to run chrome headless the following flags are required
|
58
60
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
61
|
+
args: [
|
62
|
+
'--headless',
|
63
|
+
'--start-maximized',
|
64
|
+
'--no-sandbox',
|
65
|
+
'--disable-gpu',
|
66
|
+
'--disable-infobars',
|
67
|
+
'--disable-extensions',
|
68
|
+
'--disable-dev-shm-usage',
|
69
|
+
],
|
60
70
|
// args: ['--disable-gpu'],
|
61
71
|
}
|
62
72
|
}],
|
@@ -99,8 +109,7 @@ exports.config = {
|
|
99
109
|
// Services take over a specific job you don't want to take care of. They enhance
|
100
110
|
// your test setup with almost no effort. Unlike plugins, they don't add new
|
101
111
|
// commands. Instead, they hook themselves up into the test process.
|
102
|
-
services: ['chromedriver', '
|
103
|
-
['static-server', {
|
112
|
+
services: ['chromedriver', ['static-server', {
|
104
113
|
folders: [
|
105
114
|
{ mount: '/', path: './dist' },
|
106
115
|
],
|
@@ -153,6 +162,9 @@ exports.config = {
|
|
153
162
|
*/
|
154
163
|
// beforeSession: function (config, capabilities, specs) {
|
155
164
|
// },
|
165
|
+
beforeSession: () => {
|
166
|
+
dns.setDefaultResultOrder('ipv4first');
|
167
|
+
},
|
156
168
|
/**
|
157
169
|
* Gets executed before test execution begins. At this point you can access to all global
|
158
170
|
* variables like `browser`. It is the perfect place to define custom commands.
|
@@ -56,7 +56,15 @@ exports.config = {
|
|
56
56
|
'goog:chromeOptions': {
|
57
57
|
// to run chrome headless the following flags are required
|
58
58
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
59
|
+
args: [
|
60
|
+
'--headless',
|
61
|
+
'--start-maximized',
|
62
|
+
'--no-sandbox',
|
63
|
+
'--disable-gpu',
|
64
|
+
'--disable-infobars',
|
65
|
+
'--disable-extensions',
|
66
|
+
'--disable-dev-shm-usage',
|
67
|
+
],
|
60
68
|
// args: ['--disable-gpu'],
|
61
69
|
}
|
62
70
|
}],
|
package/icons-collection/nps.js
CHANGED
@@ -21,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
|
|
21
21
|
return {
|
22
22
|
default: "nps copy.json-imports copy.icon-collection",
|
23
23
|
"json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
24
|
-
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json"
|
24
|
+
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
@@ -32,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
|
|
32
32
|
|
33
33
|
options.versions.forEach((v) => {
|
34
34
|
command.default += ` copy.icon-collection${v}`;
|
35
|
-
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json"
|
35
|
+
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
|
36
36
|
});
|
37
37
|
|
38
38
|
return command;
|
@@ -41,22 +41,24 @@ const copyIconAssetsCommand = (options) => {
|
|
41
41
|
const getScripts = (options) => {
|
42
42
|
const createJSImportsCmd = createIconImportsCommand(options);
|
43
43
|
const copyAssetsCmd = copyIconAssetsCommand(options);
|
44
|
-
const tsCommand = options.typescript ? "tsc" : "";
|
44
|
+
const tsCommand = options.typescript ? "tsc --build" : "";
|
45
45
|
const tsCrossEnv = options.typescript ? "cross-env UI5_TS=true" : "";
|
46
46
|
|
47
47
|
const scripts = {
|
48
48
|
clean: "rimraf dist && rimraf src/generated",
|
49
49
|
copy: copyAssetsCmd,
|
50
|
+
generate: `${tsCrossEnv} nps clean copy build.i18n build.icons build.jsonImports copyjson`,
|
51
|
+
copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
|
50
52
|
build: {
|
51
53
|
default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
|
52
54
|
i18n: {
|
53
55
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
54
56
|
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
55
|
-
json: `mkdirp
|
57
|
+
json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
|
56
58
|
},
|
57
59
|
jsonImports: {
|
58
|
-
default: "mkdirp
|
59
|
-
i18n: `node "${LIB}/generate-json-imports/i18n.js"
|
60
|
+
default: "mkdirp src/generated/json-imports && nps build.jsonImports.i18n",
|
61
|
+
i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
|
60
62
|
},
|
61
63
|
icons: createJSImportsCmd,
|
62
64
|
},
|
@@ -57,10 +57,20 @@ const generate = async () => {
|
|
57
57
|
const illustrationsPrefix = process.argv[4];
|
58
58
|
const illustrationSet = process.argv[5];
|
59
59
|
const destPath = process.argv[6];
|
60
|
+
const collection = process.argv[7];
|
60
61
|
const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
|
61
62
|
// collect each illustration name because each one should have Sample.js file
|
62
63
|
const fileNames = new Set();
|
63
64
|
|
65
|
+
try {
|
66
|
+
await fs.access(srcPath);
|
67
|
+
} catch (error) {
|
68
|
+
console.log(`The path ${srcPath} does not exist.`);
|
69
|
+
return Promise.resolve(null);
|
70
|
+
}
|
71
|
+
|
72
|
+
console.log(`Generating illustrations from ${srcPath} to ${destPath}`)
|
73
|
+
|
64
74
|
const svgImportTemplate = svgContent => {
|
65
75
|
return `export default \`${svgContent}\`;`
|
66
76
|
};
|
@@ -95,6 +105,7 @@ import {
|
|
95
105
|
|
96
106
|
const name = "${illustrationName}";
|
97
107
|
const set = "${illustrationSet}";
|
108
|
+
const collection = "${collection}";
|
98
109
|
const title = IM_TITLE_${illustrationNameUpperCase};
|
99
110
|
const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
|
100
111
|
|
@@ -105,6 +116,7 @@ registerIllustration(name, {
|
|
105
116
|
title,
|
106
117
|
subtitle,
|
107
118
|
set,
|
119
|
+
collection,
|
108
120
|
});
|
109
121
|
|
110
122
|
export {
|
@@ -119,12 +131,14 @@ import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
|
|
119
131
|
|
120
132
|
const name = "${illustrationName}";
|
121
133
|
const set = "${illustrationSet}";
|
134
|
+
const collection = "${collection}";
|
122
135
|
|
123
136
|
registerIllustration(name, {
|
124
137
|
dialogSvg,
|
125
138
|
sceneSvg,
|
126
139
|
spotSvg,
|
127
140
|
set,
|
141
|
+
collection,
|
128
142
|
});
|
129
143
|
|
130
144
|
export {
|
@@ -83,7 +83,7 @@ const generateFiles = (componentName, tagName, library, packageName, isTypeScrip
|
|
83
83
|
// Change the color of the output
|
84
84
|
console.warn('\x1b[33m%s\x1b[0m', `
|
85
85
|
Make sure to import the component in your bundle by using:
|
86
|
-
import
|
86
|
+
import "./dist/${componentName}.js";`);
|
87
87
|
}
|
88
88
|
|
89
89
|
// Main function
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { globby } from "globby";
|
2
|
+
import * as esbuild from 'esbuild'
|
3
|
+
import * as fs from "fs";
|
4
|
+
import * as path from "path";
|
5
|
+
import { writeFile, mkdir } from "fs/promises";
|
6
|
+
import chokidar from "chokidar";
|
7
|
+
import scopeVariables from "./scope-variables.mjs";
|
8
|
+
import { writeFileIfChanged, getFileContent } from "./shared.mjs";
|
9
|
+
|
10
|
+
const tsMode = process.env.UI5_TS === "true";
|
11
|
+
const extension = tsMode ? ".css.ts" : ".css.js";
|
12
|
+
|
13
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
|
14
|
+
const inputFilesGlob = "src/themes/*.css";
|
15
|
+
const restArgs = process.argv.slice(2);
|
16
|
+
|
17
|
+
let customPlugin = {
|
18
|
+
name: 'ui5-tools',
|
19
|
+
setup(build) {
|
20
|
+
build.initialOptions.write = false;
|
21
|
+
|
22
|
+
build.onEnd(result => {
|
23
|
+
result.outputFiles.forEach(async f => {
|
24
|
+
// scoping
|
25
|
+
const newText = scopeVariables(f.text, packageJSON);
|
26
|
+
await mkdir(path.dirname(f.path), {recursive: true});
|
27
|
+
writeFile(f.path, newText);
|
28
|
+
|
29
|
+
// JS/TS
|
30
|
+
const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
|
31
|
+
const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`", true);
|
32
|
+
writeFileIfChanged(jsPath, jsContent);
|
33
|
+
});
|
34
|
+
})
|
35
|
+
},
|
36
|
+
}
|
37
|
+
|
38
|
+
const getConfig = async () => {
|
39
|
+
const config = {
|
40
|
+
entryPoints: await globby(inputFilesGlob),
|
41
|
+
bundle: true,
|
42
|
+
minify: true,
|
43
|
+
outdir: 'dist/css',
|
44
|
+
outbase: 'src',
|
45
|
+
plugins: [
|
46
|
+
customPlugin,
|
47
|
+
]
|
48
|
+
};
|
49
|
+
return config;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (restArgs.includes("-w")) {
|
53
|
+
let ready;
|
54
|
+
let config = await getConfig();
|
55
|
+
let ctx = await esbuild.context(config);
|
56
|
+
await ctx.watch()
|
57
|
+
console.log('watching...')
|
58
|
+
|
59
|
+
// when new component css files are added, they do not trigger a build as no one directly imports them
|
60
|
+
// restart the watch mode with the new entry points if a css file is added.
|
61
|
+
const watcher = chokidar.watch(inputFilesGlob);
|
62
|
+
watcher.on("ready", () => {
|
63
|
+
ready = true; // Initial scan is over -> waiting for new files
|
64
|
+
});
|
65
|
+
watcher.on("add", async path => {
|
66
|
+
if (ready) {
|
67
|
+
// new file
|
68
|
+
ctx.dispose();
|
69
|
+
config = await getConfig();
|
70
|
+
ctx = await esbuild.context(config);
|
71
|
+
ctx.watch();
|
72
|
+
}
|
73
|
+
});
|
74
|
+
} else {
|
75
|
+
const config = await getConfig();
|
76
|
+
const result = await esbuild.build(config);
|
77
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { globby } from "globby";
|
2
|
+
import * as esbuild from 'esbuild'
|
3
|
+
import * as fs from "fs";
|
4
|
+
import * as path from "path";
|
5
|
+
import { writeFile, mkdir } from "fs/promises";
|
6
|
+
import postcss from "postcss";
|
7
|
+
import combineDuplicatedSelectors from "../postcss-combine-duplicated-selectors/index.js"
|
8
|
+
import { writeFileIfChanged, stripThemingBaseContent, getFileContent } from "./shared.mjs";
|
9
|
+
import scopeVariables from "./scope-variables.mjs";
|
10
|
+
|
11
|
+
const tsMode = process.env.UI5_TS === "true";
|
12
|
+
const extension = tsMode ? ".css.ts" : ".css.js";
|
13
|
+
|
14
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
|
15
|
+
|
16
|
+
let inputFiles = await globby("src/**/parameters-bundle.css");
|
17
|
+
const restArgs = process.argv.slice(2);
|
18
|
+
|
19
|
+
const removeDuplicateSelectors = async (text) => {
|
20
|
+
const result = await postcss(combineDuplicatedSelectors).process(text);
|
21
|
+
return result.css;
|
22
|
+
}
|
23
|
+
|
24
|
+
let scopingPlugin = {
|
25
|
+
name: 'scoping',
|
26
|
+
setup(build) {
|
27
|
+
build.initialOptions.write = false;
|
28
|
+
|
29
|
+
build.onEnd(result => {
|
30
|
+
result.outputFiles.forEach(async f => {
|
31
|
+
// remove duplicate selectors
|
32
|
+
let newText = await removeDuplicateSelectors(f.text);
|
33
|
+
|
34
|
+
// strip unnecessary theming-base-content
|
35
|
+
newText = stripThemingBaseContent(newText);
|
36
|
+
|
37
|
+
// scoping
|
38
|
+
newText = scopeVariables(newText, packageJSON, f.path);
|
39
|
+
await mkdir(path.dirname(f.path), {recursive: true});
|
40
|
+
writeFile(f.path, newText);
|
41
|
+
|
42
|
+
// JSON
|
43
|
+
const jsonPath = f.path.replace(/dist[\/\\]css/, "dist/generated/assets").replace(".css", ".css.json");
|
44
|
+
await mkdir(path.dirname(jsonPath), {recursive: true});
|
45
|
+
const data = {
|
46
|
+
packageName: packageJSON.name,
|
47
|
+
fileName: jsonPath.substr(jsonPath.lastIndexOf("themes")),
|
48
|
+
content: newText,
|
49
|
+
};
|
50
|
+
writeFileIfChanged(jsonPath, JSON.stringify({_: data}));
|
51
|
+
|
52
|
+
// JS/TS
|
53
|
+
const jsPath = f.path.replace(/dist[\/\\]css/, "src/generated/").replace(".css", extension);
|
54
|
+
const jsContent = getFileContent(tsMode, jsPath, packageJSON.name, "\`" + newText + "\`");
|
55
|
+
writeFileIfChanged(jsPath, jsContent);
|
56
|
+
});
|
57
|
+
})
|
58
|
+
},
|
59
|
+
}
|
60
|
+
|
61
|
+
const config = {
|
62
|
+
entryPoints: inputFiles,
|
63
|
+
bundle: true,
|
64
|
+
minify: true,
|
65
|
+
outdir: 'dist/css',
|
66
|
+
outbase: 'src',
|
67
|
+
plugins: [
|
68
|
+
scopingPlugin,
|
69
|
+
],
|
70
|
+
external: ["*.ttf", "*.woff", "*.woff2"],
|
71
|
+
};
|
72
|
+
|
73
|
+
if (restArgs.includes("-w")) {
|
74
|
+
let ctx = await esbuild.context(config);
|
75
|
+
await ctx.watch()
|
76
|
+
console.log('watching...')
|
77
|
+
} else {
|
78
|
+
const result = await esbuild.build(config);
|
79
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import * as path from "path";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Tries to detect an override for a package
|
5
|
+
* @param {*} filePath For example: /my_project/src/themes/overrides/@ui5/webcomponents/my_custom_theme/parameters-bundle.css
|
6
|
+
* @returns
|
7
|
+
*/
|
8
|
+
const getOverrideVersion = filePath => {
|
9
|
+
if (!filePath) {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
|
13
|
+
if (!filePath.includes(`overrides${path.sep}`)) {
|
14
|
+
return; // The "overrides/" directory is the marker
|
15
|
+
}
|
16
|
+
const override = filePath.split(`overrides${path.sep}`)[1]; // For example, this will be: @ui5/webcomponents/my_custom_theme/parameters-bundle.css
|
17
|
+
if (!override) {
|
18
|
+
return; // There must be other directories after overrides/, the path can't end with it
|
19
|
+
}
|
20
|
+
const parts = override.split(path.sep);
|
21
|
+
if (parts.length < 3) {
|
22
|
+
return; // There must be at least a directory for the theme that is being overridden (my_custom_theme) and the name of the CSS file after the name of the package that is overridden
|
23
|
+
}
|
24
|
+
const packageName = parts.slice(0, -2).join(path.sep); // After the last 2 parts are removed (my_custom_theme and parameters-bundle.css from the example), the rest is the package
|
25
|
+
|
26
|
+
let overrideVersion;
|
27
|
+
try {
|
28
|
+
overrideVersion = require(`${packageName}${path.sep}package.json`).version;
|
29
|
+
} catch (e) {
|
30
|
+
console.log(`Error requiring package ${packageName}: ${e.message}`);
|
31
|
+
}
|
32
|
+
|
33
|
+
return overrideVersion;
|
34
|
+
}
|
35
|
+
|
36
|
+
const scopeVariables = (cssText, packageJSON, inputFile) => {
|
37
|
+
const escapeVersion = version => "v" + version?.replaceAll(/[^0-9A-Za-z\-_]/g, "-");
|
38
|
+
const versionStr = escapeVersion(getOverrideVersion(inputFile) || packageJSON.version);
|
39
|
+
|
40
|
+
const expr = /(--_?ui5)([^\,\:\)\s]+)/g;
|
41
|
+
|
42
|
+
return cssText.replaceAll(expr, `$1-${versionStr}$2`);
|
43
|
+
}
|
44
|
+
|
45
|
+
export default scopeVariables;
|
46
|
+
|
@@ -1,7 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import { writeFile, readFile, mkdir } from "fs/promises";
|
2
|
+
import * as path from "path";
|
3
|
+
import assets from "../../assets-meta.js";
|
4
|
+
|
5
|
+
const readOldContent = async (fileName) => {
|
6
|
+
// it seems slower to read the old content, but writing the same content with no real changes
|
7
|
+
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
8
|
+
let oldContent = "";
|
9
|
+
try {
|
10
|
+
oldContent = (await readFile(fileName)).toString();
|
11
|
+
} catch (e) {
|
12
|
+
// file not found
|
13
|
+
}
|
14
|
+
return oldContent;
|
15
|
+
}
|
16
|
+
|
17
|
+
const writeFileIfChanged = async (fileName, content) => {
|
18
|
+
const oldContent = await readOldContent(fileName);
|
19
|
+
if (content !== oldContent) {
|
20
|
+
if (!oldContent) {
|
21
|
+
await mkdir(path.dirname(fileName), {recursive: true});
|
22
|
+
}
|
23
|
+
return writeFile(fileName, content);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
// strips the unnecessary theming data coming from @sap-theming/theming-base-content and leaves only the css parameters
|
28
|
+
const stripThemingBaseContent = css => {
|
29
|
+
css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
|
30
|
+
css = css.replace(/\.background-image.*{.*}/, "");
|
31
|
+
css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
|
32
|
+
css = css.replace(/--sapFontUrl.*\);?/, "");
|
33
|
+
return css;
|
34
|
+
}
|
35
|
+
|
5
36
|
|
6
37
|
const DEFAULT_THEME = assets.themes.default;
|
7
38
|
|
@@ -42,49 +73,4 @@ const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
|
|
42
73
|
return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
|
43
74
|
}
|
44
75
|
|
45
|
-
|
46
|
-
const proccessCSS = css => {
|
47
|
-
css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
|
48
|
-
css = css.replace(/\.background-image.*{.*}/, "");
|
49
|
-
css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
|
50
|
-
css = css.replace(/--sapFontUrl.*\);?/, "");
|
51
|
-
return JSON.stringify(css);
|
52
|
-
}
|
53
|
-
|
54
|
-
module.exports = function (opts) {
|
55
|
-
opts = opts || {};
|
56
|
-
|
57
|
-
const packageName = opts.packageName;
|
58
|
-
const includeDefaultTheme = opts.includeDefaultTheme;
|
59
|
-
const toReplace = opts.toReplace;
|
60
|
-
|
61
|
-
return {
|
62
|
-
postcssPlugin: 'postcss-css-to-esm',
|
63
|
-
Once (root) {
|
64
|
-
const tsMode = process.env.UI5_TS === "true";
|
65
|
-
|
66
|
-
let css = root.toString();
|
67
|
-
css = proccessCSS(css);
|
68
|
-
|
69
|
-
const targetFile = root.source.input.from.replace(`/${toReplace}/`, "/src/generated/").replace(`\\${toReplace}\\`, "\\src\\generated\\");
|
70
|
-
mkdirp.sync(path.dirname(targetFile));
|
71
|
-
|
72
|
-
const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
|
73
|
-
|
74
|
-
// it seems slower to read the old content, but writing the same content with no real changes
|
75
|
-
// (as in initial build and then watch mode) will cause an unnecessary dev server refresh
|
76
|
-
let oldContent = "";
|
77
|
-
try {
|
78
|
-
oldContent = fs.readFileSync(filePath).toString();
|
79
|
-
} catch (e) {
|
80
|
-
// file not found
|
81
|
-
}
|
82
|
-
|
83
|
-
const content = getFileContent(tsMode, targetFile, packageName, css, includeDefaultTheme);
|
84
|
-
if (content !== oldContent) {
|
85
|
-
fs.writeFileSync(filePath, content);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
};
|
89
|
-
};
|
90
|
-
module.exports.postcss = true;
|
76
|
+
export { writeFileIfChanged, stripThemingBaseContent, getFileContent}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
|
3
|
+
/**
|
4
|
+
* A change is observed on MacOS since 13.5, where the build generates a large amount
|
5
|
+
* of JSON file that spotlight search has to index, as they are considered new files.
|
6
|
+
*
|
7
|
+
* Starting the vitejs dev server reads all of these files and this triggers the indexing.
|
8
|
+
* The indexing has a side effect of changing some file metadata (can be checked with `mdls <path_to_file>`).
|
9
|
+
* This metadata change is changing the ctime of the file, but not the mtime. This can be checked with `stat -x <path_to_file>
|
10
|
+
*
|
11
|
+
* Essentially only metadata is changed, not content. This should not cause a page refresh,
|
12
|
+
* but chokidar reports this change and vite refreshes the page.
|
13
|
+
* The indexing is running with a 10 second interval, so for roughtly 20 minutes vite is refreshing the page every 10 seconds
|
14
|
+
*
|
15
|
+
* This plugin checks if the file causing the refresh is a generated json file (dist/*.json) and if ctime is changed after mtime
|
16
|
+
* In that case, returing an empty array tells vitejs that a custom update will be made by the plugin,
|
17
|
+
* which is in effect ignoring the page refresh.
|
18
|
+
*/
|
19
|
+
|
20
|
+
const customHotUpdate = async () => {
|
21
|
+
return {
|
22
|
+
name: 'custom-hot-update',
|
23
|
+
handleHotUpdate(ctx) {
|
24
|
+
// custom check for generated json files
|
25
|
+
if (ctx.file.endsWith(".json")) {
|
26
|
+
const stat = fs.statSync(ctx.file);
|
27
|
+
|
28
|
+
// metadata change only
|
29
|
+
if (stat.ctime > stat.mtime) {
|
30
|
+
// uncomment for debugging
|
31
|
+
// console.log("ignoring hot update for:", ctx.file);
|
32
|
+
return [];
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
module.exports = customHotUpdate;
|
@@ -7,8 +7,11 @@ const basePath = process.argv[2];
|
|
7
7
|
|
8
8
|
const convertImports = async (srcPath) => {
|
9
9
|
let changed = false;
|
10
|
-
// console.log("scanning imports of", srcPath);
|
11
10
|
let code = (await fs.readFile(srcPath)).toString();
|
11
|
+
if (code.includes("import(")) {
|
12
|
+
// esprima can't parse this, but it's from the project files
|
13
|
+
return;
|
14
|
+
}
|
12
15
|
const tree = esprima.parseModule(code);
|
13
16
|
const importer = srcPath.replace(basePath, "");
|
14
17
|
const importerDir = path.dirname(importer);
|