react-apps-ui 1.0.0 → 1.0.2
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 +38 -8
- package/package.json +1 -1
- package/src/index.ts +63 -11
package/dist/index.js
CHANGED
|
@@ -57,15 +57,45 @@ program
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
console.log(chalk_1.default.green(`✓ Found theme provider. Installing...`));
|
|
60
|
-
//
|
|
60
|
+
// Check if the user's project uses a 'src' directory
|
|
61
|
+
const hasSrcDir = fs_1.default.existsSync(path_1.default.join(process.cwd(), "src"));
|
|
62
|
+
// 4. Loop through the files and write them smartly
|
|
61
63
|
for (const file of themeComponent.files) {
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
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;
|
|
67
|
+
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");
|
|
72
|
+
if (hasSrcDir && !isRootConfig) {
|
|
73
|
+
finalTargetPath = path_1.default.join(process.cwd(), "src", safeTarget);
|
|
74
|
+
}
|
|
75
|
+
// Ensure the folder exists
|
|
76
|
+
fs_1.default.mkdirSync(path_1.default.dirname(finalTargetPath), {
|
|
77
|
+
recursive: true,
|
|
78
|
+
});
|
|
79
|
+
// SAFE WRITE: Check if the file already exists
|
|
80
|
+
if (fs_1.default.existsSync(finalTargetPath)) {
|
|
81
|
+
if (file.type === "css" ||
|
|
82
|
+
finalTargetPath.endsWith(".css")) {
|
|
83
|
+
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");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(chalk_1.default.yellow(` ⚠️ ${file.target} already exists. Skipping to prevent overwrite.`));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// File doesn't exist, safe to write normally
|
|
96
|
+
fs_1.default.writeFileSync(finalTargetPath, file.content, "utf-8");
|
|
97
|
+
console.log(chalk_1.default.green(` Created ${safeTarget}`));
|
|
98
|
+
}
|
|
69
99
|
}
|
|
70
100
|
console.log(chalk_1.default.blue("\n🎉 Initialization complete!"));
|
|
71
101
|
console.log(chalk_1.default.dim("Wrap your app in the <ThemeProvider> to get started."));
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -70,18 +70,70 @@ program
|
|
|
70
70
|
|
|
71
71
|
console.log(chalk.green(`✓ Found theme provider. Installing...`));
|
|
72
72
|
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
// file.target is exactly what we wrote earlier (e.g., "theme/tokens.ts")
|
|
76
|
-
const targetPath = path.join(process.cwd(), file.target);
|
|
77
|
-
|
|
78
|
-
// Ensure the folder exists (e.g., creates the "theme/" folder if it doesn't exist)
|
|
79
|
-
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
73
|
+
// Check if the user's project uses a 'src' directory
|
|
74
|
+
const hasSrcDir = fs.existsSync(path.join(process.cwd(), "src"));
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
// 4. Loop through the files and write them smartly
|
|
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;
|
|
81
|
+
let finalTargetPath = path.join(process.cwd(), safeTarget);
|
|
82
|
+
|
|
83
|
+
// SMART ROUTING: If they use 'src/' and it's not a root config file, put it inside src/
|
|
84
|
+
const isRootConfig =
|
|
85
|
+
file.target.includes("tailwind") ||
|
|
86
|
+
file.target.endsWith(".config.js") ||
|
|
87
|
+
file.target.endsWith(".json");
|
|
88
|
+
if (hasSrcDir && !isRootConfig) {
|
|
89
|
+
finalTargetPath = path.join(
|
|
90
|
+
process.cwd(),
|
|
91
|
+
"src",
|
|
92
|
+
safeTarget,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Ensure the folder exists
|
|
97
|
+
fs.mkdirSync(path.dirname(finalTargetPath), {
|
|
98
|
+
recursive: true,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// SAFE WRITE: Check if the file already exists
|
|
102
|
+
if (fs.existsSync(finalTargetPath)) {
|
|
103
|
+
if (
|
|
104
|
+
file.type === "css" ||
|
|
105
|
+
finalTargetPath.endsWith(".css")
|
|
106
|
+
) {
|
|
107
|
+
console.log(
|
|
108
|
+
chalk.yellow(
|
|
109
|
+
` ⚠️ ${file.target} already exists. Appending theme variables safely...`,
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
const existingContent = fs.readFileSync(
|
|
113
|
+
finalTargetPath,
|
|
114
|
+
"utf-8",
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// Only append if it doesn't already contain our theme variables to prevent infinite duplication
|
|
118
|
+
if (!existingContent.includes("--background:")) {
|
|
119
|
+
fs.appendFileSync(
|
|
120
|
+
finalTargetPath,
|
|
121
|
+
`\n/* React Apps UI Theme */\n${file.content}`,
|
|
122
|
+
"utf-8",
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
console.log(
|
|
127
|
+
chalk.yellow(
|
|
128
|
+
` ⚠️ ${file.target} already exists. Skipping to prevent overwrite.`,
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
// File doesn't exist, safe to write normally
|
|
134
|
+
fs.writeFileSync(finalTargetPath, file.content, "utf-8");
|
|
135
|
+
console.log(chalk.green(` Created ${safeTarget}`));
|
|
136
|
+
}
|
|
85
137
|
}
|
|
86
138
|
|
|
87
139
|
console.log(chalk.blue("\n🎉 Initialization complete!"));
|