@hanzogui/generate-themes 3.0.6 → 4.4.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/dist/cjs/generate-themes.cjs +100 -59
- package/dist/cjs/generate-themes.native.js +118 -76
- package/dist/cjs/generate-themes.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/write-generate-themes.cjs +32 -24
- package/dist/cjs/write-generate-themes.native.js +39 -33
- package/dist/cjs/write-generate-themes.native.js.map +1 -1
- package/dist/esm/generate-themes.mjs +88 -49
- package/dist/esm/generate-themes.mjs.map +1 -1
- package/dist/esm/generate-themes.native.js +105 -65
- package/dist/esm/generate-themes.native.js.map +1 -1
- package/dist/esm/write-generate-themes.mjs +8 -2
- package/dist/esm/write-generate-themes.mjs.map +1 -1
- package/dist/esm/write-generate-themes.native.js +15 -11
- package/dist/esm/write-generate-themes.native.js.map +1 -1
- package/package.json +5 -5
- package/src/generate-themes.ts +4 -4
|
@@ -2,33 +2,35 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var write_generate_themes_exports = {};
|
|
33
35
|
__export(write_generate_themes_exports, {
|
|
34
36
|
writeGeneratedThemes: () => writeGeneratedThemes
|
|
@@ -40,8 +42,14 @@ async function writeGeneratedThemes(guiDotDir, outPath, generatedOutput) {
|
|
|
40
42
|
const {
|
|
41
43
|
generated
|
|
42
44
|
} = generatedOutput;
|
|
43
|
-
process.env.DEBUG === "@hanzo/gui"
|
|
45
|
+
if (process.env.DEBUG === "@hanzo/gui") {
|
|
46
|
+
console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));
|
|
47
|
+
}
|
|
44
48
|
const newContent = `// @ts-nocheck
|
|
45
49
|
` + generated;
|
|
46
|
-
|
|
50
|
+
const existingContent = await fs.readFile(outPath, "utf-8").catch(() => null);
|
|
51
|
+
if (existingContent === newContent) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await fs.writeFile(outPath, newContent);
|
|
47
55
|
}
|
|
@@ -4,33 +4,35 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var write_generate_themes_exports = {};
|
|
35
37
|
__export(write_generate_themes_exports, {
|
|
36
38
|
writeGeneratedThemes: () => writeGeneratedThemes
|
|
@@ -38,17 +40,21 @@ __export(write_generate_themes_exports, {
|
|
|
38
40
|
module.exports = __toCommonJS(write_generate_themes_exports);
|
|
39
41
|
var fs = __toESM(require("fs-extra"), 1);
|
|
40
42
|
async function writeGeneratedThemes(guiDotDir, outPath, generatedOutput) {
|
|
41
|
-
if (generatedOutput)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
if (!generatedOutput) return;
|
|
44
|
+
var {
|
|
45
|
+
generated
|
|
46
|
+
} = generatedOutput;
|
|
47
|
+
if (process.env.DEBUG === "@hanzo/gui") {
|
|
48
|
+
console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));
|
|
49
|
+
}
|
|
50
|
+
var newContent = `// @ts-nocheck
|
|
51
|
+
` + generated;
|
|
52
|
+
var existingContent = await fs.readFile(outPath, "utf-8").catch(function () {
|
|
53
|
+
return null;
|
|
54
|
+
});
|
|
55
|
+
if (existingContent === newContent) {
|
|
56
|
+
return;
|
|
52
57
|
}
|
|
58
|
+
await fs.writeFile(outPath, newContent);
|
|
53
59
|
}
|
|
54
60
|
//# sourceMappingURL=write-generate-themes.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","write_generate_themes_exports","writeGeneratedThemes","module","exports","fs","require","guiDotDir","outPath","generatedOutput","generated","process","env","DEBUG","console","info","JSON","stringify","newContent","existingContent","readFile","catch","writeFile"],"sources":["write-generate-themes.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar write_generate_themes_exports = {};\n__export(write_generate_themes_exports, {\n writeGeneratedThemes: () => writeGeneratedThemes\n});\nmodule.exports = __toCommonJS(write_generate_themes_exports);\nvar fs = __toESM(require(\"fs-extra\"), 1);\nasync function writeGeneratedThemes(guiDotDir, outPath, generatedOutput) {\n if (!generatedOutput) return;\n var { generated } = generatedOutput;\n if (process.env.DEBUG === \"@hanzo/gui\") {\n console.info(`Generated themes:`, JSON.stringify(generatedOutput, null, 2));\n }\n var newContent = `// @ts-nocheck\n` + generated;\n var existingContent = await fs.readFile(outPath, \"utf-8\").catch(function() {\n return null;\n });\n if (existingContent === newContent) {\n return;\n }\n await fs.writeFile(outPath, newContent);\n}\n//# sourceMappingURL=write-generate-themes.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,QAAQ,GAAGC,MAAM,CAACC,MAAM;AAC5B,IAAIC,SAAS,GAAGF,MAAM,CAACG,cAAc;AACrC,IAAIC,gBAAgB,GAAGJ,MAAM,CAACK,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGN,MAAM,CAACO,mBAAmB;AAClD,IAAIC,YAAY,GAAGR,MAAM,CAACS,cAAc;AACxC,IAAIC,YAAY,GAAGV,MAAM,CAACW,SAAS,CAACC,cAAc;AAClD,IAAIC,QAAQ,GAAGA,CAACC,MAAM,EAAEC,GAAG,KAAK;EAC9B,KAAK,IAAIC,IAAI,IAAID,GAAG,EAClBb,SAAS,CAACY,MAAM,EAAEE,IAAI,EAAE;IAAEC,GAAG,EAAEF,GAAG,CAACC,IAAI,CAAC;IAAEE,UAAU,EAAE;EAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIlB,iBAAiB,CAACe,IAAI,CAAC,EACrC,IAAI,CAACX,YAA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C,eAAe,EAAE;EACvE,IAAI,CAACA,eAAe,EAAE;EACtB,IAAI;IAAEC;EAAU,CAAC,GAAGD,eAAe;EACnC,IAAIE,OAAO,CAACC,GAAG,CAACC,KAAK,KAAK,YAAY,EAAE;IACtCC,OAAO,CAACC,IAAI,CAAC,mBAAmB,EAAEC,IAAI,CAACC,SAAS,CAACR,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EAC7E;EACA,IAAIS,UAAU,GAAG;AACnB,CAAC,GAAGR,SAAS;EACX,IAAIS,eAAe,GAAG,MAAMd,EAAE,CAACe,QAAQ,CAACZ,OAAO,EAAE,OAAO,CAAC,CAACa,KAAK,CAAC,YAAW;IACzE,OAAO,IAAI;EACb,CAAC,CAAC;EACF,IAAIF,eAAe,KAAKD,UAAU,EAAE;IAClC;EACF;EACA,MAAMb,EAAE,CAACiB,SAAS,CAACd,OAAO,EAAEU,UAAU,CAAC;AACzC","ignoreList":[]}
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
let didRegisterOnce =
|
|
2
|
+
let didRegisterOnce = false;
|
|
3
3
|
async function generateThemes(inputFile) {
|
|
4
4
|
const inputFilePath = inputFile[0] === "." ? join(process.cwd(), inputFile) : inputFile;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
if (!didRegisterOnce) {
|
|
6
|
+
didRegisterOnce = true;
|
|
7
|
+
require("esbuild-register/dist/node").register({
|
|
8
|
+
hookIgnoreNodeModules: false
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
purgeCache(inputFilePath);
|
|
12
|
+
}
|
|
13
|
+
let og = process.env.GUI_KEEP_THEMES;
|
|
14
|
+
process.env.GUI_KEEP_THEMES = "1";
|
|
15
|
+
process.env.GUI_RUN_THEMEBUILDER = "1";
|
|
10
16
|
try {
|
|
11
|
-
const requiredThemes = require(inputFilePath)
|
|
12
|
-
|
|
17
|
+
const requiredThemes = require(inputFilePath);
|
|
18
|
+
const themes = requiredThemes["default"] || requiredThemes["themes"] || requiredThemes[Object.keys(requiredThemes)[0]];
|
|
19
|
+
const generatedThemes = generatedThemesToTypescript(themes);
|
|
13
20
|
return {
|
|
14
|
-
generated:
|
|
21
|
+
generated: generatedThemes
|
|
15
22
|
};
|
|
16
23
|
} catch (err) {
|
|
17
24
|
console.warn(` \u26A0\uFE0F Error running theme builder:
|
|
18
|
-
`, err?.stack || err);
|
|
25
|
+
`, err?.["stack"] || err);
|
|
19
26
|
} finally {
|
|
20
|
-
process.env.
|
|
27
|
+
process.env.GUI_KEEP_THEMES = og;
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
const dedupedTokens = /* @__PURE__ */new Map();
|
|
24
31
|
function generatedThemesToTypescript(themes) {
|
|
25
|
-
const dedupedThemes = /* @__PURE__ */new Map()
|
|
26
|
-
|
|
32
|
+
const dedupedThemes = /* @__PURE__ */new Map();
|
|
33
|
+
const dedupedThemeToNames = /* @__PURE__ */new Map();
|
|
27
34
|
let i = 0;
|
|
28
35
|
for (const name in themes) {
|
|
29
36
|
i++;
|
|
@@ -32,17 +39,29 @@ function generatedThemesToTypescript(themes) {
|
|
|
32
39
|
for (const [key2, value] of Object.entries(theme)) {
|
|
33
40
|
i++;
|
|
34
41
|
const uniqueKey = `t${i}${j}`;
|
|
35
|
-
dedupedTokens.has(value)
|
|
42
|
+
if (!dedupedTokens.has(value)) {
|
|
43
|
+
dedupedTokens.set(value, uniqueKey);
|
|
44
|
+
}
|
|
36
45
|
}
|
|
37
46
|
const key = JSON.stringify(theme);
|
|
38
|
-
dedupedThemes.has(key)
|
|
47
|
+
if (dedupedThemes.has(key)) {
|
|
48
|
+
dedupedThemeToNames.set(key, [...dedupedThemeToNames.get(key), name]);
|
|
49
|
+
} else {
|
|
50
|
+
dedupedThemes.set(key, theme);
|
|
51
|
+
dedupedThemeToNames.set(key, [name]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!themes) {
|
|
55
|
+
throw new Error(`Didn't find any themes exported or returned`);
|
|
39
56
|
}
|
|
40
|
-
if (!themes) throw new Error("Didn't find any themes exported or returned");
|
|
41
57
|
const baseKeys = Object.entries(themes.light || themes[Object.keys(themes)[0]]);
|
|
42
|
-
|
|
43
|
-
${baseKeys.map(([k]) =>
|
|
44
|
-
`
|
|
45
|
-
|
|
58
|
+
const baseTypeString = `export type Theme = {
|
|
59
|
+
${baseKeys.map(([k]) => {
|
|
60
|
+
return ` ${k}: string;
|
|
61
|
+
`;
|
|
62
|
+
}).join("")}
|
|
63
|
+
}`;
|
|
64
|
+
let out = `${baseTypeString}
|
|
46
65
|
`;
|
|
47
66
|
out += `
|
|
48
67
|
function t(a: [number, number][]) {
|
|
@@ -52,52 +71,61 @@ function t(a: [number, number][]) {
|
|
|
52
71
|
}
|
|
53
72
|
return res as Theme
|
|
54
73
|
}
|
|
55
|
-
|
|
74
|
+
`;
|
|
75
|
+
out += `export const colors = [
|
|
56
76
|
`;
|
|
57
77
|
let index = 0;
|
|
58
78
|
const valueToIndex = {};
|
|
59
79
|
dedupedTokens.forEach((name, value) => {
|
|
60
|
-
valueToIndex[value] = index
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
valueToIndex[value] = index;
|
|
81
|
+
index++;
|
|
82
|
+
out += ` '${value}',
|
|
64
83
|
`;
|
|
84
|
+
});
|
|
85
|
+
out += "]\n\n";
|
|
65
86
|
const keys = baseKeys.map(([k]) => k);
|
|
66
87
|
out += `const ks = [
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
`;
|
|
89
|
+
out += keys.map(k => `'${k}'`).join(",\n");
|
|
90
|
+
out += `]
|
|
69
91
|
|
|
70
92
|
`;
|
|
71
|
-
let nameI = 0
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
let nameI = 0;
|
|
94
|
+
let themeTypes = `export type ThemeNames =`;
|
|
95
|
+
let exported = `export type Themes = Record<ThemeNames, Theme>
|
|
74
96
|
|
|
75
97
|
export const themes: Themes = {`;
|
|
76
|
-
|
|
98
|
+
dedupedThemes.forEach(theme => {
|
|
77
99
|
nameI++;
|
|
78
|
-
const key = JSON.stringify(theme)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
const key = JSON.stringify(theme);
|
|
101
|
+
const names = dedupedThemeToNames.get(key);
|
|
102
|
+
const name = `n${nameI}`;
|
|
103
|
+
const baseTheme = `const ${name} = ${objectToJsString(theme, keys, valueToIndex)}`;
|
|
82
104
|
out += `
|
|
83
|
-
${baseTheme}
|
|
105
|
+
${baseTheme}`;
|
|
106
|
+
names.forEach(n => {
|
|
84
107
|
exported += `
|
|
85
|
-
${n}: ${name}
|
|
86
|
-
|
|
108
|
+
${n}: ${name},`;
|
|
109
|
+
if (n.toLowerCase() === n) {
|
|
110
|
+
themeTypes += `
|
|
111
|
+
| '${n}'`;
|
|
112
|
+
}
|
|
87
113
|
});
|
|
88
|
-
})
|
|
114
|
+
});
|
|
115
|
+
out += `
|
|
89
116
|
|
|
90
117
|
${themeTypes}
|
|
91
118
|
|
|
92
119
|
${exported}
|
|
93
120
|
}
|
|
94
|
-
|
|
121
|
+
`;
|
|
122
|
+
return out;
|
|
95
123
|
}
|
|
96
124
|
function objectToJsString(obj, keys, valueToIndex) {
|
|
97
125
|
let arrItems = [];
|
|
98
126
|
for (const key in obj) {
|
|
99
|
-
const ki = keys.indexOf(key)
|
|
100
|
-
|
|
127
|
+
const ki = keys.indexOf(key);
|
|
128
|
+
const vi = valueToIndex[obj[key]];
|
|
101
129
|
arrItems.push(`[${ki}, ${vi}]`);
|
|
102
130
|
}
|
|
103
131
|
return `t([${arrItems.join(",")}])`;
|
|
@@ -105,17 +133,28 @@ function objectToJsString(obj, keys, valueToIndex) {
|
|
|
105
133
|
function purgeCache(moduleName) {
|
|
106
134
|
searchCache(moduleName, mod => {
|
|
107
135
|
delete require.cache[mod.id];
|
|
108
|
-
})
|
|
109
|
-
|
|
136
|
+
});
|
|
137
|
+
if (!module.constructor || !module.constructor._pathCache) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
Object.keys(module.constructor._pathCache).forEach(cacheKey => {
|
|
141
|
+
if (cacheKey.indexOf(moduleName) > 0) {
|
|
142
|
+
delete module.constructor._pathCache[cacheKey];
|
|
143
|
+
}
|
|
110
144
|
});
|
|
111
145
|
}
|
|
112
146
|
function searchCache(moduleName, callback) {
|
|
113
147
|
let mod = require.resolve(moduleName);
|
|
114
|
-
mod && (mod = require.cache[mod]) !== void 0
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
148
|
+
if (mod && (mod = require.cache[mod]) !== void 0) {
|
|
149
|
+
;
|
|
150
|
+
(function traverse(mod2, depth = 0) {
|
|
151
|
+
if (depth > 10) return;
|
|
152
|
+
mod2.children.forEach(child => {
|
|
153
|
+
traverse(child, depth + 1);
|
|
154
|
+
});
|
|
155
|
+
callback(mod2);
|
|
156
|
+
})(mod);
|
|
157
|
+
}
|
|
119
158
|
}
|
|
120
159
|
export { generateThemes };
|
|
121
160
|
//# sourceMappingURL=generate-themes.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["join","didRegisterOnce","generateThemes","inputFile","inputFilePath","process","cwd","
|
|
1
|
+
{"version":3,"names":["join","didRegisterOnce","generateThemes","inputFile","inputFilePath","process","cwd","require","register","hookIgnoreNodeModules","purgeCache","og","env","GUI_KEEP_THEMES","GUI_RUN_THEMEBUILDER","requiredThemes","themes","Object","keys","generatedThemes","generatedThemesToTypescript","generated","err","console","warn","dedupedTokens","Map","dedupedThemes","dedupedThemeToNames","i","name","theme","j","key2","value","entries","uniqueKey","has","set","key","JSON","stringify","get","Error","baseKeys","light","baseTypeString","map","k","out","index","valueToIndex","forEach","nameI","themeTypes","exported","names","baseTheme","objectToJsString","n","toLowerCase","obj","arrItems","ki","indexOf","vi","push","moduleName","searchCache","mod","cache","id","module","constructor","_pathCache","cacheKey","callback","resolve","traverse","mod2","depth","children","child"],"sources":["../../src/generate-themes.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,IAAA,QAAY;AAMrB,IAAIC,eAAA,GAAkB;AAEtB,eAAsBC,eAAeC,SAAA,EAAmB;EACtD,MAAMC,aAAA,GAAgBD,SAAA,CAAU,CAAC,MAAM,MAAMH,IAAA,CAAKK,OAAA,CAAQC,GAAA,CAAI,GAAGH,SAAS,IAAIA,SAAA;EAE9E,IAAI,CAACF,eAAA,EAAiB;IACpBA,eAAA,GAAkB;IAElBM,OAAA,CAAQ,4BAA4B,EAAEC,QAAA,CAAS;MAC7CC,qBAAA,EAAuB;IACzB,CAAC;EACH,OAAO;IACLC,UAAA,CAAWN,aAAa;EAC1B;EAEA,IAAIO,EAAA,GAAKN,OAAA,CAAQO,GAAA,CAAIC,eAAA;EACrBR,OAAA,CAAQO,GAAA,CAAIC,eAAA,GAAkB;EAC9BR,OAAA,CAAQO,GAAA,CAAIE,oBAAA,GAAuB;EAEnC,IAAI;IACF,MAAMC,cAAA,GAAiBR,OAAA,CAAQH,aAAa;IAE5C,MAAMY,MAAA,GACJD,cAAA,CAAe,SAAS,KACxBA,cAAA,CAAe,QAAQ,KACvBA,cAAA,CAAeE,MAAA,CAAOC,IAAA,CAAKH,cAAc,EAAE,CAAC,CAAC;IAE/C,MAAMI,eAAA,GAAkBC,2BAAA,CAA4BJ,MAAM;IAE1D,OAAO;MACLK,SAAA,EAAWF;IACb;EACF,SAASG,GAAA,EAAK;IACZC,OAAA,CAAQC,IAAA,CAAK;AAAA,GAAsCF,GAAA,GAAM,OAAO,KAAKA,GAAG;EAC1E,UAAE;IACAjB,OAAA,CAAQO,GAAA,CAAIC,eAAA,GAAkBF,EAAA;EAChC;AACF;AAKA,MAAMc,aAAA,GAAgB,mBAAIC,GAAA,CAAoB;AAE9C,SAASN,4BAA4BJ,MAAA,EAA6B;EAChE,MAAMW,aAAA,GAAgB,mBAAID,GAAA,CAAoB;EAC9C,MAAME,m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