astrod-cli 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/bin/cli.js CHANGED
@@ -46,15 +46,46 @@ async function listFiles(dir, baseDir = '') {
46
46
  return results;
47
47
  }
48
48
 
49
+ async function updateViteMainFile(targetDir) {
50
+ const mainFiles = ['main.jsx', 'main.tsx'];
51
+ for (const file of mainFiles) {
52
+ const filePath = path.join(targetDir, file);
53
+ if (fs.existsSync(filePath)) {
54
+ let content = await fs.readFile(filePath, 'utf8');
55
+
56
+ // Update App import if it was looking for App.jsx/App.tsx directly in src
57
+ // Since we are copying a new App.jsx to src/
58
+ content = content.replace(/import App from '\.\/App'/g, "import App from './App'");
59
+
60
+ // Remove the import of App.css if it exists
61
+ content = content.replace(/import '\.\/App\.css';?\n?/g, "");
62
+
63
+ await fs.writeFile(filePath, content, 'utf8');
64
+ console.log(`\x1b[32mUpdated ${file} to match new structure.\x1b[0m`);
65
+ }
66
+ }
67
+ }
68
+
69
+ async function cleanupViteFiles(targetDir) {
70
+ const filesToDelete = ['App.jsx', 'App.tsx', 'App.css'];
71
+ for (const file of filesToDelete) {
72
+ const filePath = path.join(targetDir, file);
73
+ if (fs.existsSync(filePath)) {
74
+ await fs.remove(filePath);
75
+ console.log(`\x1b[33mRemoved existing ${file} for clean initialization.\x1b[0m`);
76
+ }
77
+ }
78
+ }
79
+
49
80
  program
50
- .name('my-struct')
81
+ .name('astrod')
51
82
  .description('CLI to inject folder structures into Vite, Next, and React Native projects')
52
83
  .version('1.0.0');
53
84
 
54
85
  program
55
86
  .command('init')
56
87
  .description('Initialize the folder structure')
57
- .option('-f, --force', 'Overwrite existing src directory')
88
+ .option('-f, --force', 'Overwrite conflicting files if src directory already exists')
58
89
  .option('-d, --dry-run', 'List files that would be created without actually creating them')
59
90
  .action(async (options) => {
60
91
  try {
@@ -91,16 +122,23 @@ program
91
122
  return;
92
123
  }
93
124
 
94
- if (fs.existsSync(targetDir) && !options.force) {
95
- console.warn('\x1b[33mWarning: The "src" directory already exists. Use --force to overwrite.\x1b[0m');
96
- process.exit(1);
125
+ if (fs.existsSync(targetDir)) {
126
+ console.log('\x1b[33mNotice: The "src" directory already exists. Merging new structure into it...\x1b[0m');
127
+ }
128
+
129
+ if (framework === 'vite') {
130
+ await cleanupViteFiles(targetDir);
97
131
  }
98
132
 
99
133
  await fs.copy(templateDir, targetDir, {
100
134
  overwrite: options.force,
101
- errorOnExist: !options.force
135
+ errorOnExist: false
102
136
  });
103
137
 
138
+ if (framework === 'vite') {
139
+ await updateViteMainFile(targetDir);
140
+ }
141
+
104
142
  console.log(`\x1b[32mSuccessfully injected ${structureType} structure for ${framework} into src/ folder!\x1b[0m`);
105
143
 
106
144
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astrod-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A CLI tool that injects folder structures into existing Vite, Next, and React Native projects.",
5
5
  "type": "module",
6
6
  "main": "./bin/cli.js",
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+
3
+ function App() {
4
+ return (
5
+ <div className="App">
6
+ <h1>Welcome to ASTROD (Module-based Structure)</h1>
7
+ <p>Your modular Vite project has been successfully initialized.</p>
8
+ </div>
9
+ );
10
+ }
11
+
12
+ export default App;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+
3
+ function App() {
4
+ return (
5
+ <div className="App">
6
+ <h1>Welcome to ASTROD (Open Structure)</h1>
7
+ <p>Your Vite project has been successfully initialized.</p>
8
+ </div>
9
+ );
10
+ }
11
+
12
+ export default App;