@wavemaker/react-codegen 11.14.2-rc.6311 → 11.14.4-rc.647538
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/build-react-web.js +3 -8
- package/build-react-web.js.map +1 -1
- package/command.js +1 -1
- package/command.js.map +1 -1
- package/index.js +0 -2
- package/index.js.map +1 -1
- package/package-lock.json +364 -257
- package/package.json +1 -1
- package/src/app.generator.js +7 -16
- package/src/app.generator.js.map +1 -1
- package/src/gen-app-override-css.js +245 -316
- package/src/gen-app-override-css.js.map +1 -1
- package/src/handlebar-helpers.js +0 -186
- package/src/handlebar-helpers.js.map +1 -1
- package/src/transpile/bind.ex.transformer.js +0 -30
- package/src/transpile/bind.ex.transformer.js.map +1 -1
- package/src/transpile/components/container/panel.transformer.js +1 -0
- package/src/transpile/components/container/panel.transformer.js.map +1 -1
- package/src/transpile/components/container/wizardaction.transformer.js +19 -34
- package/src/transpile/components/container/wizardaction.transformer.js.map +1 -1
- package/src/transpile/components/container/wizardstep.transformer.js +5 -62
- package/src/transpile/components/container/wizardstep.transformer.js.map +1 -1
- package/src/transpile/components/data/form/form-field.transformer.js +1 -27
- package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
- package/src/transpile/components/data/list/list-transformer.js +2 -29
- package/src/transpile/components/data/list/list-transformer.js.map +1 -1
- package/src/transpile/components/data/live-filter-field.transformer.js +1 -13
- package/src/transpile/components/data/live-filter-field.transformer.js.map +1 -1
- package/src/transpile/components/data/liveform.transformer.js +4 -15
- package/src/transpile/components/data/liveform.transformer.js.map +1 -1
- package/src/transpile/components/data/table/table-column.transformer.js +3 -40
- package/src/transpile/components/data/table/table-column.transformer.js.map +1 -1
- package/src/transpile/components/data/table/table-row-action.transformer.js +1 -1
- package/src/transpile/components/dialogs/dialog-actions.transformer.js +0 -19
- package/src/transpile/components/dialogs/dialog-actions.transformer.js.map +1 -1
- package/src/transpile/components/dialogs/dialog.transformer.js +11 -0
- package/src/transpile/components/dialogs/dialog.transformer.js.map +1 -1
- package/src/transpile/components/input/checkbox-set.transformer.js +1 -1
- package/src/transpile/components/input/checkbox-set.transformer.js.map +1 -1
- package/src/transpile/components/input/checkbox.transformer.js +1 -29
- package/src/transpile/components/input/checkbox.transformer.js.map +1 -1
- package/src/transpile/components/input/currency.transformer.js +1 -1
- package/src/transpile/components/input/currency.transformer.js.map +1 -1
- package/src/transpile/components/input/radio-set.transformer.js +1 -1
- package/src/transpile/components/input/radio-set.transformer.js.map +1 -1
- package/src/transpile/components/input/switch.transformer.js.map +1 -1
- package/src/transpile/components/nav/nav.transformer.js +1 -33
- package/src/transpile/components/nav/nav.transformer.js.map +1 -1
- package/src/transpile/components/navigation/menu.transformer.js.map +1 -1
- package/src/transpile/components/navigation/popover.transformer.js +1 -1
- package/src/transpile/components/navigation/popover.transformer.js.map +1 -1
- package/src/transpile/components/utils.js +6 -19
- package/src/transpile/components/utils.js.map +1 -1
- package/src/transpile/style/dimension-style.parser.js +2 -13
- package/src/transpile/style/dimension-style.parser.js.map +1 -1
- package/src/transpile/style/style.parser.js +1 -1
- package/src/transpile/style/style.parser.js.map +1 -1
- package/src/transpile/style.transformer.js +1 -1
- package/src/transpile/style.transformer.js.map +1 -1
- package/src/transpile/transpile.js +20 -42
- package/src/transpile/transpile.js.map +1 -1
- package/src/utils.js +2 -6
- package/src/utils.js.map +1 -1
- package/src/variables/variable.transformer.js +7 -165
- package/src/variables/variable.transformer.js.map +1 -1
- package/templates/component/component.hbs +10 -0
- package/templates/component/partial.hbs +3 -0
- package/templates/project/app/components.css +0 -5
- package/templates/project/package.json +3 -3
- package/src/download-packages.js +0 -193
- package/src/download-packages.js.map +0 -1
- package/src/genappoverridecssold-file.js +0 -311
- package/src/genappoverridecssold-file.js.map +0 -1
|
@@ -33,347 +33,276 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
|
|
36
|
+
exports.OVERRIDE_TOKENS_PATH = exports.APP_OVERRIDE_CSS_PATH = exports.DESIGN_TOKENS_DIR_NAME = void 0;
|
|
37
|
+
exports.generateOverrideCSS = generateOverrideCSS;
|
|
38
38
|
const fs = __importStar(require("fs"));
|
|
39
|
-
const
|
|
40
|
-
const
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const project_service_1 = require("./project.service");
|
|
41
41
|
const utils_1 = require("./utils");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
modeGroups[mode].push(...subGroup[mode]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else if (stats.isFile() && path.extname(itemPath) === ".json") {
|
|
66
|
-
const match = item.match(/\.([^.]+)\.json$/); // Matches ".dark.json" or ".light.json"
|
|
67
|
-
if (match) {
|
|
68
|
-
const mode = match[1]; // 'dark' or 'light' etc.
|
|
69
|
-
if (!modeGroups[mode]) {
|
|
70
|
-
modeGroups[mode] = [];
|
|
71
|
-
}
|
|
72
|
-
modeGroups[mode].push(itemPath);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
modeGroups.default.push(itemPath);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return modeGroups;
|
|
80
|
-
};
|
|
81
|
-
const generateModeConfigs = (modeGroups, sourceDir, cssVarCalcMixFormatter, componentVariantsFormatter) => {
|
|
82
|
-
const baseCssFormatName = (cssVarCalcMixFormatter && cssVarCalcMixFormatter.name) || "css/variables";
|
|
83
|
-
const variantCssFormatName = (componentVariantsFormatter && componentVariantsFormatter.name) || "css/variables";
|
|
84
|
-
const configs = [];
|
|
85
|
-
for (const mode in modeGroups) {
|
|
86
|
-
const tokenFiles = modeGroups[mode];
|
|
87
|
-
const buildPaths = tokenFiles.flatMap((filePath) => {
|
|
88
|
-
const relativePath = filePath.replace(sourceDir + "/", "");
|
|
89
|
-
return [
|
|
90
|
-
{
|
|
91
|
-
destination: relativePath.replace(/\.json$/, ".css"),
|
|
92
|
-
options: { outputReferences: true, selector: ":root" },
|
|
93
|
-
format: baseCssFormatName,
|
|
94
|
-
filter: function (token) {
|
|
95
|
-
var tokenPath;
|
|
96
|
-
// Extract file path from token['@'].filePath (used in some token formats) or fallback to token.filePath.
|
|
97
|
-
if (token["@"] && token["@"].filePath) {
|
|
98
|
-
tokenPath = token["@"].filePath;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
tokenPath = token.filePath;
|
|
102
|
-
}
|
|
103
|
-
// normalize paths for Windows
|
|
104
|
-
const normalizePath = (p) => (p ? p.replace(/\\/g, "/") : p);
|
|
105
|
-
tokenPath = normalizePath(tokenPath);
|
|
106
|
-
filePath = normalizePath(filePath);
|
|
107
|
-
// Only include tokens originating from "overrides" files (i.e., filter out foundation CSS tokens)
|
|
108
|
-
var isOverrideToken = (tokenPath && tokenPath.indexOf("overrides") !== -1) ||
|
|
109
|
-
(token.filePath && token.filePath.indexOf("overrides") !== -1);
|
|
110
|
-
// Ensure the token is written only to the correct CSS file
|
|
111
|
-
var matchesOutputFile = tokenPath &&
|
|
112
|
-
(filePath.includes(tokenPath) || filePath.includes(normalizePath(token.filePath))) &&
|
|
113
|
-
!token.path.includes("appearances") &&
|
|
114
|
-
!token.path.includes("states");
|
|
115
|
-
return isOverrideToken && matchesOutputFile;
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
destination: relativePath.replace(/\.json$/, "variant.css"),
|
|
120
|
-
options: { outputReferences: true, selector: ":root" },
|
|
121
|
-
format: variantCssFormatName,
|
|
122
|
-
filter: (token) => {
|
|
123
|
-
let tokenPath;
|
|
124
|
-
if (token["@"] && token["@"].filePath) {
|
|
125
|
-
tokenPath = token["@"].filePath;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
tokenPath = token.filePath;
|
|
129
|
-
}
|
|
130
|
-
const isOverrideToken = tokenPath && tokenPath.indexOf("overrides") !== -1;
|
|
131
|
-
const matchesOutputFile = tokenPath &&
|
|
132
|
-
(filePath.includes(tokenPath) || filePath.includes(token.filePath)) &&
|
|
133
|
-
(token.path.includes("appearances") || token.path.includes("states"));
|
|
134
|
-
return isOverrideToken && matchesOutputFile;
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
];
|
|
138
|
-
});
|
|
139
|
-
configs.push({
|
|
140
|
-
mode,
|
|
141
|
-
files: buildPaths,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return configs;
|
|
145
|
-
};
|
|
146
|
-
const accessFile = (filePath) => {
|
|
147
|
-
const dirPath = path.dirname(filePath); // Get directory from file path
|
|
148
|
-
// Ensure the directory exists
|
|
149
|
-
if (!fs.existsSync(dirPath)) {
|
|
150
|
-
fs.mkdirSync(dirPath, { recursive: true });
|
|
151
|
-
console.log(`Directory created: ${dirPath}`);
|
|
152
|
-
}
|
|
153
|
-
fs.access(filePath, fs.constants.F_OK, err => {
|
|
154
|
-
if (err) {
|
|
155
|
-
console.log(`${filePath} does not exist. Creating file...`);
|
|
156
|
-
// File does not exist, create it
|
|
157
|
-
const fileContent = JSON.stringify({});
|
|
158
|
-
fs.writeFile(filePath, fileContent, err => {
|
|
159
|
-
if (err)
|
|
160
|
-
throw err;
|
|
161
|
-
console.log(`${filePath} was created successfully.`);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
async function setupSymlink(from, to) {
|
|
167
|
-
try {
|
|
168
|
-
// Ensure the parent directory of the symlink exists
|
|
169
|
-
await fs.promises.mkdir(path.dirname(to), { recursive: true });
|
|
170
|
-
try {
|
|
171
|
-
if (fs.existsSync(to))
|
|
172
|
-
await fs.promises.unlink(to);
|
|
173
|
-
}
|
|
174
|
-
catch (unlinkErr) {
|
|
175
|
-
console.error("Error removing existing symlink:", unlinkErr);
|
|
176
|
-
}
|
|
177
|
-
// Create the symlink
|
|
178
|
-
const isWindows = process.platform === "win32";
|
|
179
|
-
const symlinkType = isWindows ? "junction" : "dir";
|
|
180
|
-
await fs.promises.symlink(from, to, symlinkType);
|
|
181
|
-
console.log("Symlink created successfully at:", to);
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
184
|
-
console.error("Error creating symlink:", to, err);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// Function to generate Style Dictionary configuration
|
|
188
|
-
const getStyleDictionaryConfig = (files, tempFoundationTokensSymlink, mode, sourceDir) => {
|
|
189
|
-
if (!sourceDir.endsWith("/")) {
|
|
190
|
-
sourceDir += "/";
|
|
191
|
-
}
|
|
192
|
-
let sourcePattern = "";
|
|
193
|
-
if (mode === "default") {
|
|
194
|
-
// Files without any mode like dark/light in the name
|
|
195
|
-
sourcePattern = `${sourceDir}/src/main/webapp/${utils_1.OVERRIDE_TOKENS_PATH}/**/!(*.*).json`;
|
|
42
|
+
// Constants
|
|
43
|
+
exports.DESIGN_TOKENS_DIR_NAME = "design-tokens";
|
|
44
|
+
exports.APP_OVERRIDE_CSS_PATH = `${exports.DESIGN_TOKENS_DIR_NAME}/app.override.css`;
|
|
45
|
+
exports.OVERRIDE_TOKENS_PATH = `${exports.DESIGN_TOKENS_DIR_NAME}/overrides`;
|
|
46
|
+
/**
|
|
47
|
+
* Install a package if it's not already installed
|
|
48
|
+
* @param projectRoot project root directory
|
|
49
|
+
* @param packageName name of the package to install
|
|
50
|
+
* @param version version of the package
|
|
51
|
+
*/
|
|
52
|
+
async function installPackageIfNeeded(projectRoot, packageName, version) {
|
|
53
|
+
const packagePath = path.join(projectRoot, "node_modules", packageName);
|
|
54
|
+
if (!fs.existsSync(packagePath)) {
|
|
55
|
+
console.log(`Installing ${packageName}@${version}...`);
|
|
56
|
+
const installCmd = `npm install ${packageName}@${version} --save-dev --legacy-peer-deps`;
|
|
57
|
+
(0, utils_1.executeSyncCmd)(`cd ${projectRoot} && ${installCmd}`, (errMsg) => {
|
|
58
|
+
console.log(`Error installing ${packageName}:`, errMsg);
|
|
59
|
+
throw Error(errMsg);
|
|
60
|
+
}, `Installing ${packageName}: `);
|
|
61
|
+
console.log(`Successfully installed ${packageName}@${version}`);
|
|
196
62
|
}
|
|
197
63
|
else {
|
|
198
|
-
|
|
199
|
-
sourcePattern = `${sourceDir}/src/main/webapp/${utils_1.OVERRIDE_TOKENS_PATH}/**/*.${mode}.json`;
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
log: {
|
|
203
|
-
verbosity: "verbose",
|
|
204
|
-
},
|
|
205
|
-
source: [sourcePattern],
|
|
206
|
-
include: [
|
|
207
|
-
`${tempFoundationTokensSymlink.replace(/\\/g, "/")}/**/!(*.dark|*.light).json`,
|
|
208
|
-
`${sourceDir.replace(/\\/g, "/")}/src/main/webapp/${utils_1.OVERRIDE_TOKENS_PATH}/global/**/*.json`,
|
|
209
|
-
],
|
|
210
|
-
platforms: {
|
|
211
|
-
css: {
|
|
212
|
-
transformGroup: "css",
|
|
213
|
-
prefix: "--wm",
|
|
214
|
-
files: files,
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
async function removeSymlink(symlinkPath) {
|
|
220
|
-
const resolvedPath = path.resolve(symlinkPath);
|
|
221
|
-
try {
|
|
222
|
-
const stats = fs.lstatSync(resolvedPath);
|
|
223
|
-
if (stats.isSymbolicLink()) {
|
|
224
|
-
await fs.promises.unlink(resolvedPath);
|
|
225
|
-
console.log("Symlink removed successfully:", resolvedPath);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
console.warn("Not a symlink, skipping unlink:", resolvedPath);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
console.error("Error during symlink removal:", err);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async function getCustomFormatters(STYLE_DICTIONARY_PATH, FOUNDATION_CSS_PATH) {
|
|
236
|
-
try {
|
|
237
|
-
// Import utils from Style Dictionary
|
|
238
|
-
const utilsModule = await importFromFile(`${STYLE_DICTIONARY_PATH}/node_modules/style-dictionary/lib/utils/index.js`);
|
|
239
|
-
const { usesReferences, getReferences } = utilsModule;
|
|
240
|
-
// Import formatter utility from foundation-css
|
|
241
|
-
const formatterModule = await importFromFile(`${FOUNDATION_CSS_PATH}/node_modules/@wavemaker/foundation-css/src/utils/style-dictionary-utils.js`);
|
|
242
|
-
const { cssVarCalcMixFormatter, componentVariantsFormatter } = formatterModule;
|
|
243
|
-
const platform = "web";
|
|
244
|
-
return {
|
|
245
|
-
cssVarCalcMixFormatter: cssVarCalcMixFormatter(usesReferences, getReferences),
|
|
246
|
-
componentVariantsFormatter: componentVariantsFormatter(usesReferences, getReferences, platform),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
console.error("Failed to load CssVarCalcMixFormatter:", error);
|
|
251
|
-
return null;
|
|
64
|
+
console.log(`${packageName} already installed`);
|
|
252
65
|
}
|
|
253
66
|
}
|
|
254
67
|
/**
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* @param
|
|
258
|
-
* @
|
|
68
|
+
* Process a single override JSON file to generate CSS variables
|
|
69
|
+
* @param jsonFilePath path to the override JSON file
|
|
70
|
+
* @param foundationTokensDir path to foundation tokens
|
|
71
|
+
* @param baseDir base directory
|
|
72
|
+
* @returns map of token name to value
|
|
259
73
|
*/
|
|
260
|
-
function
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
74
|
+
async function processOverrideFile(jsonFilePath, foundationTokensDir, baseDir) {
|
|
75
|
+
const tokens = new Map();
|
|
76
|
+
try {
|
|
77
|
+
// Read override file
|
|
78
|
+
const content = JSON.parse(fs.readFileSync(jsonFilePath, "utf-8"));
|
|
79
|
+
// Read foundation tokens for reference resolution
|
|
80
|
+
const foundationTokens = new Map();
|
|
81
|
+
function loadFoundationTokens(dir, prefix = "") {
|
|
82
|
+
if (!fs.existsSync(dir))
|
|
83
|
+
return;
|
|
84
|
+
const items = fs.readdirSync(dir);
|
|
85
|
+
items.forEach(item => {
|
|
86
|
+
const itemPath = path.join(dir, item);
|
|
87
|
+
const stat = fs.statSync(itemPath);
|
|
88
|
+
if (stat.isDirectory()) {
|
|
89
|
+
loadFoundationTokens(itemPath, prefix ? `${prefix}-${item}` : item);
|
|
275
90
|
}
|
|
276
|
-
else {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
91
|
+
else if (item.endsWith(".json") && !item.includes(".dark") && !item.includes(".light")) {
|
|
92
|
+
try {
|
|
93
|
+
const tokenContent = JSON.parse(fs.readFileSync(itemPath, "utf-8"));
|
|
94
|
+
flattenTokens(tokenContent, foundationTokens, prefix ? `${prefix}-${path.basename(item, ".json")}` : path.basename(item, ".json"));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// Skip invalid JSON files
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function flattenTokens(obj, tokenMap, prefix = "") {
|
|
103
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
104
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
105
|
+
if (value.value !== undefined) {
|
|
106
|
+
// This is a token definition
|
|
107
|
+
const tokenName = prefix ? `${prefix}.${key}` : key;
|
|
108
|
+
tokenMap.set(tokenName, value.value);
|
|
285
109
|
}
|
|
286
110
|
else {
|
|
287
|
-
|
|
111
|
+
// Continue traversing
|
|
112
|
+
const newPrefix = prefix ? `${prefix}.${key}` : key;
|
|
113
|
+
flattenTokens(value, tokenMap, newPrefix);
|
|
288
114
|
}
|
|
289
115
|
}
|
|
290
|
-
// Delete the processed file
|
|
291
|
-
fs.unlink(destination, () => { });
|
|
292
116
|
}
|
|
293
117
|
}
|
|
294
|
-
|
|
295
|
-
|
|
118
|
+
// Load foundation tokens
|
|
119
|
+
loadFoundationTokens(foundationTokensDir);
|
|
120
|
+
// Process override tokens
|
|
121
|
+
function processTokens(obj, prefix = "") {
|
|
122
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
123
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
124
|
+
if (value.value !== undefined) {
|
|
125
|
+
// This is a token definition - skip @ keys for token names
|
|
126
|
+
const cleanKey = key === "@" ? "" : key;
|
|
127
|
+
const tokenName = cleanKey
|
|
128
|
+
? `--wm-${prefix ? `${prefix}-${cleanKey}` : cleanKey}`
|
|
129
|
+
: `--wm-${prefix}`;
|
|
130
|
+
let tokenValue = value.value;
|
|
131
|
+
// Resolve references like {color.white.@.value} to CSS variables
|
|
132
|
+
if (typeof tokenValue === "string" &&
|
|
133
|
+
tokenValue.includes("{") &&
|
|
134
|
+
tokenValue.includes("}")) {
|
|
135
|
+
const referenceMatch = tokenValue.match(/\{([^}]+)\}/g);
|
|
136
|
+
if (referenceMatch) {
|
|
137
|
+
referenceMatch.forEach(ref => {
|
|
138
|
+
const refKey = ref.slice(1, -1); // Remove { }
|
|
139
|
+
// Convert foundation token path to CSS variable name
|
|
140
|
+
let cssVarName = refKey
|
|
141
|
+
.replace(".@.value", "")
|
|
142
|
+
.replace(".value", "")
|
|
143
|
+
.replace(/\./g, "-");
|
|
144
|
+
// Convert to CSS variable format
|
|
145
|
+
const cssVariable = `var(--wm-${cssVarName})`;
|
|
146
|
+
tokenValue = tokenValue.replace(ref, cssVariable);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
tokens.set(tokenName, tokenValue);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Continue traversing - skip @ keys in paths
|
|
154
|
+
const cleanKey = key === "@" ? "" : key;
|
|
155
|
+
const newPrefix = prefix && cleanKey ? `${prefix}-${cleanKey}` : cleanKey || prefix;
|
|
156
|
+
processTokens(value, newPrefix);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
296
160
|
}
|
|
161
|
+
processTokens(content);
|
|
297
162
|
}
|
|
298
|
-
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error(`Error processing ${jsonFilePath}:`, error);
|
|
165
|
+
}
|
|
166
|
+
return tokens;
|
|
299
167
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
168
|
+
async function generateOverrideCSS(runtimeUIVersion, sourceDir, appTarget) {
|
|
169
|
+
// Use existing LocalProjectService to check if this is a Prism project
|
|
170
|
+
const projectService = new project_service_1.LocalProjectService(sourceDir + "/src/main/webapp");
|
|
171
|
+
const isPrismProject = await projectService.getWmProjectType();
|
|
172
|
+
if (isPrismProject) {
|
|
173
|
+
const overridesDir = path.join(sourceDir + `/src/main/webapp/`, exports.OVERRIDE_TOKENS_PATH);
|
|
174
|
+
const overrideCssFile = sourceDir + `/src/main/webapp/${exports.APP_OVERRIDE_CSS_PATH}`;
|
|
175
|
+
if (fs.existsSync(overridesDir)) {
|
|
176
|
+
console.log("CODEGEN REACT APP: generating override css...");
|
|
177
|
+
// Use the react-codegen package directory as baseDir
|
|
178
|
+
// __dirname will be the 'build/src' directory after compilation,
|
|
179
|
+
// so we go up one level to get the react-codegen root
|
|
180
|
+
const baseDir = path.resolve(__dirname, "..");
|
|
181
|
+
console.log("baseDir for npm packages (react-codegen path):", baseDir);
|
|
182
|
+
// Install required packages
|
|
183
|
+
await installPackageIfNeeded(baseDir, "style-dictionary", "4.1.0");
|
|
184
|
+
await installPackageIfNeeded(baseDir, "@wavemaker/foundation-css", runtimeUIVersion || "latest");
|
|
185
|
+
const foundationTokensDir = path.join(baseDir, "node_modules", "@wavemaker", "foundation-css", "tokens");
|
|
186
|
+
// Find all override JSON files
|
|
187
|
+
const overrideFiles = [];
|
|
188
|
+
function findOverrideFiles(dir) {
|
|
189
|
+
if (!fs.existsSync(dir))
|
|
190
|
+
return;
|
|
191
|
+
const items = fs.readdirSync(dir);
|
|
192
|
+
items.forEach(item => {
|
|
193
|
+
const itemPath = path.join(dir, item);
|
|
194
|
+
const stat = fs.statSync(itemPath);
|
|
195
|
+
if (stat.isDirectory()) {
|
|
196
|
+
findOverrideFiles(itemPath);
|
|
197
|
+
}
|
|
198
|
+
else if (item.endsWith(".json")) {
|
|
199
|
+
overrideFiles.push(itemPath);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
findOverrideFiles(overridesDir);
|
|
204
|
+
console.log(`Processing ${overrideFiles.length} override files...`);
|
|
205
|
+
// Collect all tokens with source tracking
|
|
206
|
+
const defaultTokens = new Map();
|
|
207
|
+
const lightTokens = new Map();
|
|
208
|
+
const darkTokens = new Map();
|
|
209
|
+
for (const overrideFile of overrideFiles) {
|
|
210
|
+
const fileName = path.basename(overrideFile);
|
|
211
|
+
const fileTokens = await processOverrideFile(overrideFile, foundationTokensDir, baseDir);
|
|
212
|
+
// Sort tokens by mode
|
|
213
|
+
if (fileName.includes(".light.")) {
|
|
214
|
+
fileTokens.forEach((value, name) => {
|
|
215
|
+
lightTokens.set(name, value);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else if (fileName.includes(".dark.")) {
|
|
219
|
+
fileTokens.forEach((value, name) => {
|
|
220
|
+
darkTokens.set(name, value);
|
|
221
|
+
});
|
|
337
222
|
}
|
|
338
|
-
|
|
339
|
-
|
|
223
|
+
else {
|
|
224
|
+
fileTokens.forEach((value, name) => {
|
|
225
|
+
defaultTokens.set(name, value);
|
|
226
|
+
});
|
|
340
227
|
}
|
|
341
228
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
229
|
+
// Generate final CSS with mode-specific attribute selectors like Angular
|
|
230
|
+
const cssLines = [];
|
|
231
|
+
// Add default tokens
|
|
232
|
+
if (defaultTokens.size > 0) {
|
|
233
|
+
cssLines.push(":root {");
|
|
234
|
+
defaultTokens.forEach((value, name) => {
|
|
235
|
+
cssLines.push(`${name}: ${value};`);
|
|
236
|
+
});
|
|
237
|
+
cssLines.push("}");
|
|
238
|
+
}
|
|
239
|
+
// Add light mode tokens with attribute selectors (like Angular does)
|
|
240
|
+
if (lightTokens.size > 0) {
|
|
241
|
+
if (cssLines.length > 0)
|
|
242
|
+
cssLines.push("");
|
|
243
|
+
cssLines.push(":root[color='light'] {");
|
|
244
|
+
lightTokens.forEach((value, name) => {
|
|
245
|
+
cssLines.push(`${name}: ${value};`);
|
|
246
|
+
});
|
|
247
|
+
cssLines.push("}");
|
|
248
|
+
}
|
|
249
|
+
// Add dark mode tokens with attribute selectors (like Angular does)
|
|
250
|
+
if (darkTokens.size > 0) {
|
|
251
|
+
if (cssLines.length > 0)
|
|
252
|
+
cssLines.push("");
|
|
253
|
+
cssLines.push(":root[color='dark'] {");
|
|
254
|
+
darkTokens.forEach((value, name) => {
|
|
255
|
+
cssLines.push(`${name}: ${value};`);
|
|
256
|
+
});
|
|
257
|
+
cssLines.push("}");
|
|
258
|
+
}
|
|
259
|
+
const totalTokens = defaultTokens.size + lightTokens.size + darkTokens.size;
|
|
260
|
+
// Only generate CSS files if there are actual tokens
|
|
261
|
+
if (totalTokens > 0) {
|
|
262
|
+
const finalCSS = cssLines.join("\n");
|
|
263
|
+
fs.writeFileSync(overrideCssFile, finalCSS);
|
|
264
|
+
// Also copy to public directory for React app if appTarget is provided
|
|
265
|
+
if (appTarget) {
|
|
266
|
+
const publicCssPath = path.join(appTarget, "public", exports.APP_OVERRIDE_CSS_PATH);
|
|
267
|
+
const publicDir = path.dirname(publicCssPath);
|
|
268
|
+
const globalCSSPath = path.join(appTarget, "app", "globals.css");
|
|
269
|
+
if (!fs.existsSync(publicDir)) {
|
|
270
|
+
fs.mkdirSync(publicDir, { recursive: true });
|
|
362
271
|
}
|
|
363
|
-
|
|
364
|
-
|
|
272
|
+
fs.writeFileSync(publicCssPath, finalCSS);
|
|
273
|
+
console.log(`✅ CSS copied to React app public directory`);
|
|
274
|
+
// Now that we've generated the override CSS, add its import to globals.css
|
|
275
|
+
if (fs.existsSync(globalCSSPath)) {
|
|
276
|
+
const content = fs.readFileSync(globalCSSPath, "utf-8");
|
|
277
|
+
// Check if the import is already present
|
|
278
|
+
if (!content.includes("public/design-tokens/app.override.css")) {
|
|
279
|
+
// Add the import after the existing imports
|
|
280
|
+
const lines = content.split("\n");
|
|
281
|
+
let insertIndex = 0;
|
|
282
|
+
// Find the last import line
|
|
283
|
+
for (let i = 0; i < lines.length; i++) {
|
|
284
|
+
if (lines[i].startsWith("@import")) {
|
|
285
|
+
insertIndex = i + 1;
|
|
286
|
+
}
|
|
287
|
+
else if (lines[i].trim() === "" && insertIndex > 0) {
|
|
288
|
+
insertIndex = i;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Insert the override CSS import
|
|
293
|
+
lines.splice(insertIndex, 0, '@import "../public/design-tokens/app.override.css";');
|
|
294
|
+
fs.writeFileSync(globalCSSPath, lines.join("\n"), "utf-8");
|
|
295
|
+
console.log("✅ Added CSS override import to globals.css");
|
|
296
|
+
}
|
|
365
297
|
}
|
|
366
298
|
}
|
|
367
|
-
console.log(
|
|
368
|
-
|
|
369
|
-
catch (err) {
|
|
370
|
-
console.error("Error setting up symlink or processing modes:", err);
|
|
299
|
+
console.log(`✅ Generated CSS with ${totalTokens} override tokens`);
|
|
300
|
+
console.log("CODEGEN REACT APP: generating overrides success!");
|
|
371
301
|
}
|
|
372
|
-
|
|
373
|
-
|
|
302
|
+
else {
|
|
303
|
+
console.log("ℹ️ No design tokens found, skipping CSS generation");
|
|
374
304
|
}
|
|
375
|
-
}
|
|
305
|
+
}
|
|
376
306
|
}
|
|
377
|
-
}
|
|
378
|
-
exports.generateOverrideCSS = generateOverrideCSS;
|
|
307
|
+
}
|
|
379
308
|
//# sourceMappingURL=gen-app-override-css.js.map
|