rnsup 1.0.1 ā 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/README.md +36 -0
- package/dist/commands/generateFolder.js +102 -0
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -194,6 +194,42 @@ src/components/ui/forms/Input.tsx
|
|
|
194
194
|
|
|
195
195
|
---
|
|
196
196
|
|
|
197
|
+
### Generate Folder / Directory
|
|
198
|
+
|
|
199
|
+
> Here `d` mean `directory`, and `g` mean `generate`
|
|
200
|
+
|
|
201
|
+
Create folders/directories at any location with automatic alias registration and optional `index.ts` generation:
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
rnsup g d features
|
|
205
|
+
rnsup g d src/store
|
|
206
|
+
rnsup g d src/utils/helpers
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Examples created:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
features/
|
|
213
|
+
src/store/
|
|
214
|
+
src/utils/helpers/
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Features:**
|
|
218
|
+
|
|
219
|
+
- š Colored output showing folder details
|
|
220
|
+
- ā
Confirmation before creating
|
|
221
|
+
- š Optional `index.ts` file generation (for exports)
|
|
222
|
+
- š Auto-alias registration for `src/` folders
|
|
223
|
+
- š History tracking
|
|
224
|
+
|
|
225
|
+
**Notes:**
|
|
226
|
+
|
|
227
|
+
- If folder path starts with `src/`, it will be created inside `src/` and alias will be registered
|
|
228
|
+
- If just a name is provided (e.g., `rnsup g d config`), folder is created at project root
|
|
229
|
+
- Supports nested paths: `rnsup g d src/features/auth/screens`
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
197
233
|
## Auto Alias Support
|
|
198
234
|
|
|
199
235
|
You can import without relative paths.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateFolder = generateFolder;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const history_1 = require("../utils/history");
|
|
12
|
+
const aliasManager_1 = require("../utils/aliasManager");
|
|
13
|
+
async function generateFolder(input) {
|
|
14
|
+
try {
|
|
15
|
+
// normalize slashes and clean input
|
|
16
|
+
let cleaned = input.replace(/\\/g, '/').trim();
|
|
17
|
+
// resolve folder path
|
|
18
|
+
let fullDir;
|
|
19
|
+
let relativeDir;
|
|
20
|
+
// if path starts with src/, use as-is
|
|
21
|
+
if (cleaned.startsWith('src/')) {
|
|
22
|
+
relativeDir = cleaned;
|
|
23
|
+
fullDir = path_1.default.join(process.cwd(), cleaned);
|
|
24
|
+
}
|
|
25
|
+
// if path contains /, but doesn't start with src/
|
|
26
|
+
else if (cleaned.includes('/')) {
|
|
27
|
+
fullDir = path_1.default.join(process.cwd(), cleaned);
|
|
28
|
+
relativeDir = cleaned;
|
|
29
|
+
}
|
|
30
|
+
// just a folder name, create at root
|
|
31
|
+
else {
|
|
32
|
+
fullDir = path_1.default.join(process.cwd(), cleaned);
|
|
33
|
+
relativeDir = cleaned;
|
|
34
|
+
}
|
|
35
|
+
const folderName = path_1.default.basename(fullDir);
|
|
36
|
+
// show colored info
|
|
37
|
+
console.log('\n' + chalk_1.default.cyan.bold('š Folder Creation Details'));
|
|
38
|
+
console.log(chalk_1.default.gray('ā'.repeat(50)));
|
|
39
|
+
console.log(chalk_1.default.yellow('Folder Name:'), chalk_1.default.white(folderName));
|
|
40
|
+
console.log(chalk_1.default.yellow('Location: '), chalk_1.default.white(relativeDir));
|
|
41
|
+
console.log(chalk_1.default.yellow('Full Path: '), chalk_1.default.dim(fullDir));
|
|
42
|
+
console.log(chalk_1.default.gray('ā'.repeat(50)));
|
|
43
|
+
// check if folder already exists
|
|
44
|
+
if (await fs_extra_1.default.pathExists(fullDir)) {
|
|
45
|
+
console.log(chalk_1.default.yellow(`\nā ļø Folder ${relativeDir} already exists.`));
|
|
46
|
+
const { proceed } = await inquirer_1.default.prompt([
|
|
47
|
+
{
|
|
48
|
+
type: 'confirm',
|
|
49
|
+
name: 'proceed',
|
|
50
|
+
message: 'Do you want to continue anyway?',
|
|
51
|
+
default: false
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
if (!proceed) {
|
|
55
|
+
console.log(chalk_1.default.yellow('Cancelled.'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// ask to create index.ts
|
|
60
|
+
const { createIndex } = await inquirer_1.default.prompt([
|
|
61
|
+
{
|
|
62
|
+
type: 'confirm',
|
|
63
|
+
name: 'createIndex',
|
|
64
|
+
message: 'Create index.ts file?',
|
|
65
|
+
default: true
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
68
|
+
// final confirmation
|
|
69
|
+
const { confirm } = await inquirer_1.default.prompt([
|
|
70
|
+
{
|
|
71
|
+
type: 'confirm',
|
|
72
|
+
name: 'confirm',
|
|
73
|
+
message: chalk_1.default.green(`Create folder ${chalk_1.default.bold(folderName)}?`),
|
|
74
|
+
default: true
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
if (!confirm) {
|
|
78
|
+
console.log(chalk_1.default.yellow('Cancelled.'));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// create folder
|
|
82
|
+
await fs_extra_1.default.ensureDir(fullDir);
|
|
83
|
+
// register alias if it's under src/
|
|
84
|
+
if (relativeDir.startsWith('src/')) {
|
|
85
|
+
await (0, aliasManager_1.registerAlias)(relativeDir);
|
|
86
|
+
}
|
|
87
|
+
// create index.ts if requested
|
|
88
|
+
if (createIndex) {
|
|
89
|
+
const indexFile = path_1.default.join(fullDir, 'index.ts');
|
|
90
|
+
if (!(await fs_extra_1.default.pathExists(indexFile))) {
|
|
91
|
+
await fs_extra_1.default.writeFile(indexFile, '// Add your exports here\n');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await (0, history_1.addHistory)(`Created folder ${relativeDir}`);
|
|
95
|
+
console.log(chalk_1.default.green(`\n⨠Folder ${chalk_1.default.bold(folderName)} created successfully!`));
|
|
96
|
+
console.log(chalk_1.default.gray(`Location: ${relativeDir}`));
|
|
97
|
+
console.log();
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(chalk_1.default.red('Error creating folder:'), err);
|
|
101
|
+
}
|
|
102
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const commander_1 = require("commander");
|
|
|
4
4
|
const setup_1 = require("./commands/setup");
|
|
5
5
|
const generateScreen_1 = require("./commands/generateScreen");
|
|
6
6
|
const generateComponent_1 = require("./commands/generateComponent");
|
|
7
|
+
const generateFolder_1 = require("./commands/generateFolder");
|
|
7
8
|
const program = new commander_1.Command();
|
|
8
9
|
program
|
|
9
10
|
.name('rnsup')
|
|
@@ -24,11 +25,18 @@ generate
|
|
|
24
25
|
.alias('s')
|
|
25
26
|
.description('Generate a screen')
|
|
26
27
|
.action(generateScreen_1.generateScreen);
|
|
28
|
+
/* ---------- Component ---------- */
|
|
27
29
|
generate
|
|
28
30
|
.command('component <name>')
|
|
29
31
|
.alias('c')
|
|
30
32
|
.description('Generate a component')
|
|
31
33
|
.action(generateComponent_1.generateComponent);
|
|
34
|
+
/* ---------- Folder ---------- */
|
|
35
|
+
generate
|
|
36
|
+
.command('folder <name>')
|
|
37
|
+
.alias('d')
|
|
38
|
+
.description('Create a folder / directory')
|
|
39
|
+
.action(generateFolder_1.generateFolder);
|
|
32
40
|
/* attach to main program */
|
|
33
41
|
program.addCommand(generate);
|
|
34
42
|
program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rnsup",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "RNSUP is a CLI tool that converts a fresh React Native CLI project into a production-ready architecture with navigation, alias paths, utilities and code generators.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|