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 +44 -6
- package/package.json +1 -1
- package/templates/vite/module/src/App.jsx +12 -0
- package/templates/vite/open/src/App.jsx +12 -0
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('
|
|
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
|
|
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)
|
|
95
|
-
console.
|
|
96
|
-
|
|
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:
|
|
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