react-apps-ui 1.0.3 → 1.0.4
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/index.js +14 -8
- package/package.json +1 -1
- package/src/index.ts +29 -12
package/dist/index.js
CHANGED
|
@@ -61,11 +61,10 @@ program
|
|
|
61
61
|
const hasSrcDir = fs_1.default.existsSync(path_1.default.join(process.cwd(), "src"));
|
|
62
62
|
// 4. Loop through the files and write them smartly
|
|
63
63
|
for (const file of themeComponent.files) {
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
const safeTarget = file.target || file.name;
|
|
64
|
+
// A. Force the target to be a string so it can never be undefined
|
|
65
|
+
const safeTarget = String(file.target || file.name || "unknown-file");
|
|
67
66
|
let finalTargetPath = path_1.default.join(process.cwd(), safeTarget);
|
|
68
|
-
//
|
|
67
|
+
//B. Safely check includes on the guaranteed string
|
|
69
68
|
const isRootConfig = safeTarget.includes("tailwind") ||
|
|
70
69
|
safeTarget.endsWith(".config.js") ||
|
|
71
70
|
safeTarget.endsWith(".json");
|
|
@@ -81,10 +80,17 @@ program
|
|
|
81
80
|
if (file.type === "css" ||
|
|
82
81
|
finalTargetPath.endsWith(".css")) {
|
|
83
82
|
console.log(chalk_1.default.yellow(` ⚠️ ${file.target} already exists. Appending theme variables safely...`));
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
try {
|
|
84
|
+
// C. Read the file and forcefully convert it to a String
|
|
85
|
+
const rawContent = fs_1.default.readFileSync(finalTargetPath, "utf-8");
|
|
86
|
+
const safeExistingContent = String(rawContent || "");
|
|
87
|
+
// D. Safely check includes (This line can no longer crash!)
|
|
88
|
+
if (!safeExistingContent.includes("--background:")) {
|
|
89
|
+
fs_1.default.appendFileSync(finalTargetPath, `\n/* React Apps UI Theme */\n${file.content || ""}`, "utf-8");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.log(chalk_1.default.red(` ❌ Error reading or appending to ${safeTarget}`));
|
|
88
94
|
}
|
|
89
95
|
}
|
|
90
96
|
else {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -75,16 +75,18 @@ program
|
|
|
75
75
|
|
|
76
76
|
// 4. Loop through the files and write them smartly
|
|
77
77
|
for (const file of themeComponent.files) {
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
// A. Force the target to be a string so it can never be undefined
|
|
79
|
+
const safeTarget = String(
|
|
80
|
+
file.target || file.name || "unknown-file",
|
|
81
|
+
);
|
|
81
82
|
let finalTargetPath = path.join(process.cwd(), safeTarget);
|
|
82
83
|
|
|
83
|
-
//
|
|
84
|
+
//B. Safely check includes on the guaranteed string
|
|
84
85
|
const isRootConfig =
|
|
85
86
|
safeTarget.includes("tailwind") ||
|
|
86
87
|
safeTarget.endsWith(".config.js") ||
|
|
87
88
|
safeTarget.endsWith(".json");
|
|
89
|
+
|
|
88
90
|
if (hasSrcDir && !isRootConfig) {
|
|
89
91
|
finalTargetPath = path.join(
|
|
90
92
|
process.cwd(),
|
|
@@ -109,18 +111,33 @@ program
|
|
|
109
111
|
` ⚠️ ${file.target} already exists. Appending theme variables safely...`,
|
|
110
112
|
),
|
|
111
113
|
);
|
|
112
|
-
const existingContent = fs.readFileSync(
|
|
113
|
-
finalTargetPath,
|
|
114
|
-
"utf-8",
|
|
115
|
-
);
|
|
116
114
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
fs.
|
|
115
|
+
try {
|
|
116
|
+
// C. Read the file and forcefully convert it to a String
|
|
117
|
+
const rawContent = fs.readFileSync(
|
|
120
118
|
finalTargetPath,
|
|
121
|
-
`\n/* React Apps UI Theme */\n${file.content}`,
|
|
122
119
|
"utf-8",
|
|
123
120
|
);
|
|
121
|
+
const safeExistingContent = String(
|
|
122
|
+
rawContent || "",
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// D. Safely check includes (This line can no longer crash!)
|
|
126
|
+
if (
|
|
127
|
+
!safeExistingContent.includes("--background:")
|
|
128
|
+
) {
|
|
129
|
+
fs.appendFileSync(
|
|
130
|
+
finalTargetPath,
|
|
131
|
+
`\n/* React Apps UI Theme */\n${file.content || ""}`,
|
|
132
|
+
"utf-8",
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
console.log(
|
|
137
|
+
chalk.red(
|
|
138
|
+
` ❌ Error reading or appending to ${safeTarget}`,
|
|
139
|
+
),
|
|
140
|
+
);
|
|
124
141
|
}
|
|
125
142
|
} else {
|
|
126
143
|
console.log(
|