react-apps-ui 1.0.0 → 1.0.1

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