react-apps-ui 1.0.2 → 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.
Files changed (3) hide show
  1. package/dist/index.js +17 -11
  2. package/package.json +1 -1
  3. package/src/index.ts +32 -15
package/dist/index.js CHANGED
@@ -61,14 +61,13 @@ 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
- // DEFENSIVE FALLBACK: If 'target' is missing from the JSON, use the file.name
65
- // This ensures path.join() never receives 'undefined' again.
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
- // SMART ROUTING: If they use 'src/' and it's not a root config file, put it inside src/
69
- const isRootConfig = file.target.includes("tailwind") ||
70
- file.target.endsWith(".config.js") ||
71
- file.target.endsWith(".json");
67
+ //B. Safely check includes on the guaranteed string
68
+ const isRootConfig = safeTarget.includes("tailwind") ||
69
+ safeTarget.endsWith(".config.js") ||
70
+ safeTarget.endsWith(".json");
72
71
  if (hasSrcDir && !isRootConfig) {
73
72
  finalTargetPath = path_1.default.join(process.cwd(), "src", safeTarget);
74
73
  }
@@ -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
- const existingContent = fs_1.default.readFileSync(finalTargetPath, "utf-8");
85
- // Only append if it doesn't already contain our theme variables to prevent infinite duplication
86
- if (!existingContent.includes("--background:")) {
87
- fs_1.default.appendFileSync(finalTargetPath, `\n/* React Apps UI Theme */\n${file.content}`, "utf-8");
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-apps-ui",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "The React Native UI CLI",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
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
- // DEFENSIVE FALLBACK: If 'target' is missing from the JSON, use the file.name
79
- // This ensures path.join() never receives 'undefined' again.
80
- const safeTarget = file.target || file.name;
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
- // SMART ROUTING: If they use 'src/' and it's not a root config file, put it inside src/
84
+ //B. Safely check includes on the guaranteed string
84
85
  const isRootConfig =
85
- file.target.includes("tailwind") ||
86
- file.target.endsWith(".config.js") ||
87
- file.target.endsWith(".json");
86
+ safeTarget.includes("tailwind") ||
87
+ safeTarget.endsWith(".config.js") ||
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
- // Only append if it doesn't already contain our theme variables to prevent infinite duplication
118
- if (!existingContent.includes("--background:")) {
119
- fs.appendFileSync(
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(