astrod-cli 1.0.0
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/README.md +66 -0
- package/bin/cli.js +112 -0
- package/package.json +33 -0
- package/templates/next/module/src/app/.gitkeep +0 -0
- package/templates/next/module/src/modules/.gitkeep +0 -0
- package/templates/next/module/src/shared/components/.gitkeep +0 -0
- package/templates/next/module/src/shared/lib/.gitkeep +0 -0
- package/templates/next/open/src/app/.gitkeep +0 -0
- package/templates/next/open/src/components/.gitkeep +0 -0
- package/templates/next/open/src/lib/.gitkeep +0 -0
- package/templates/react-native/module/src/modules/.gitkeep +0 -0
- package/templates/react-native/module/src/shared/components/.gitkeep +0 -0
- package/templates/react-native/module/src/shared/navigation/.gitkeep +0 -0
- package/templates/react-native/open/src/components/.gitkeep +0 -0
- package/templates/react-native/open/src/navigation/.gitkeep +0 -0
- package/templates/react-native/open/src/screens/.gitkeep +0 -0
- package/templates/vite/module/src/modules/.gitkeep +0 -0
- package/templates/vite/module/src/shared/components/.gitkeep +0 -0
- package/templates/vite/module/src/shared/hooks/.gitkeep +0 -0
- package/templates/vite/module/src/shared/utils/.gitkeep +0 -0
- package/templates/vite/open/src/components/.gitkeep +0 -0
- package/templates/vite/open/src/hooks/.gitkeep +0 -0
- package/templates/vite/open/src/pages/.gitkeep +0 -0
- package/templates/vite/open/src/utils/.gitkeep +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# astrod-cli
|
|
2
|
+
|
|
3
|
+
A CLI tool that injects pre-defined folder structures into existing **Vite**, **Next**, and **React Native** projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package globally or use it directly with `npx`.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g astrod-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or run without installation:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx astrod-cli init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Navigate to your project's root directory and run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
astrod init
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Options
|
|
28
|
+
|
|
29
|
+
- `-f, --force`: Overwrite the existing `src/` directory if it exists.
|
|
30
|
+
- `-d, --dry-run`: List the files and folders that would be created without actually creating them.
|
|
31
|
+
|
|
32
|
+
## Supported Frameworks
|
|
33
|
+
|
|
34
|
+
The tool automatically detects the project framework by checking your `package.json` dependencies:
|
|
35
|
+
|
|
36
|
+
- **Vite**
|
|
37
|
+
- **Next.js**
|
|
38
|
+
- **React Native**
|
|
39
|
+
|
|
40
|
+
## Structure Types
|
|
41
|
+
|
|
42
|
+
You can choose between two types of folder structures:
|
|
43
|
+
|
|
44
|
+
### 1. Open Structure (Standard)
|
|
45
|
+
A traditional flat structure for smaller projects.
|
|
46
|
+
|
|
47
|
+
- **Vite**: `src/components`, `src/pages`, `src/hooks`, `src/utils`
|
|
48
|
+
- **Next**: `src/app`, `src/components`, `src/lib`
|
|
49
|
+
- **React Native**: `src/components`, `src/screens`, `src/navigation`
|
|
50
|
+
|
|
51
|
+
### 2. Module-based (Feature-driven)
|
|
52
|
+
A modular structure ideal for large-scale applications.
|
|
53
|
+
|
|
54
|
+
- **Vite**: `src/modules`, `src/shared/components`, `src/shared/hooks`, `src/shared/utils`
|
|
55
|
+
- **Next**: `src/app`, `src/modules`, `src/shared/components`, `src/shared/lib`
|
|
56
|
+
- **React Native**: `src/modules`, `src/shared/components`, `src/shared/navigation`
|
|
57
|
+
|
|
58
|
+
## Requirements
|
|
59
|
+
|
|
60
|
+
- Node.js (v14 or higher)
|
|
61
|
+
- A project with a `package.json` file.
|
|
62
|
+
- ES Modules enabled (`"type": "module"` in your project's `package.json` is recommended but not required for the target project).
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
ISC
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import inquirer from 'inquirer';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
const program = new Command();
|
|
13
|
+
|
|
14
|
+
async function detectFramework() {
|
|
15
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
16
|
+
if (!fs.existsSync(pkgPath)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const pkg = await fs.readJson(pkgPath);
|
|
21
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
22
|
+
|
|
23
|
+
if (deps['next']) return 'next';
|
|
24
|
+
if (deps['vite']) return 'vite';
|
|
25
|
+
if (deps['react-native']) return 'react-native';
|
|
26
|
+
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function listFiles(dir, baseDir = '') {
|
|
31
|
+
const files = await fs.readdir(dir);
|
|
32
|
+
let results = [];
|
|
33
|
+
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const fullPath = path.join(dir, file);
|
|
36
|
+
const relativePath = path.join(baseDir, file);
|
|
37
|
+
const stat = await fs.stat(fullPath);
|
|
38
|
+
|
|
39
|
+
if (stat.isDirectory()) {
|
|
40
|
+
results = results.concat(await listFiles(fullPath, relativePath));
|
|
41
|
+
} else {
|
|
42
|
+
results.push(relativePath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
program
|
|
50
|
+
.name('my-struct')
|
|
51
|
+
.description('CLI to inject folder structures into Vite, Next, and React Native projects')
|
|
52
|
+
.version('1.0.0');
|
|
53
|
+
|
|
54
|
+
program
|
|
55
|
+
.command('init')
|
|
56
|
+
.description('Initialize the folder structure')
|
|
57
|
+
.option('-f, --force', 'Overwrite existing src directory')
|
|
58
|
+
.option('-d, --dry-run', 'List files that would be created without actually creating them')
|
|
59
|
+
.action(async (options) => {
|
|
60
|
+
try {
|
|
61
|
+
const framework = await detectFramework();
|
|
62
|
+
|
|
63
|
+
if (!framework) {
|
|
64
|
+
console.error('\x1b[31mError: No supported framework (Vite, Next, or React Native) detected in package.json.\x1b[0m');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log(`\x1b[34mDetected framework: ${framework}\x1b[0m`);
|
|
69
|
+
|
|
70
|
+
const { structureType } = await inquirer.prompt([
|
|
71
|
+
{
|
|
72
|
+
type: 'list',
|
|
73
|
+
name: 'structureType',
|
|
74
|
+
message: 'Which folder structure would you like to use?',
|
|
75
|
+
choices: [
|
|
76
|
+
{ name: 'Open Structure (Standard)', value: 'open' },
|
|
77
|
+
{ name: 'Module-based (Feature-driven)', value: 'module' }
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const templateDir = path.join(__dirname, '..', 'templates', framework, structureType, 'src');
|
|
83
|
+
const targetDir = path.join(process.cwd(), 'src');
|
|
84
|
+
|
|
85
|
+
if (options.dryRun) {
|
|
86
|
+
console.log('\x1b[33m--- Dry Run: The following files would be created ---\x1b[0m');
|
|
87
|
+
const files = await listFiles(templateDir);
|
|
88
|
+
files.forEach(file => {
|
|
89
|
+
console.log(`src/${file}`);
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
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);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await fs.copy(templateDir, targetDir, {
|
|
100
|
+
overwrite: options.force,
|
|
101
|
+
errorOnExist: !options.force
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
console.log(`\x1b[32mSuccessfully injected ${structureType} structure for ${framework} into src/ folder!\x1b[0m`);
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('\x1b[31mAn error occurred:\x1b[0m', error.message);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "astrod-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A CLI tool that injects folder structures into existing Vite, Next, and React Native projects.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./bin/cli.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"astrod": "./bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"templates",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"cli",
|
|
20
|
+
"folder-structure",
|
|
21
|
+
"vite",
|
|
22
|
+
"next",
|
|
23
|
+
"react-native"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"commander": "^11.1.0",
|
|
29
|
+
"fs-extra": "^11.2.0",
|
|
30
|
+
"inquirer": "^9.2.12",
|
|
31
|
+
"path": "^0.12.7"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|