folder-generator 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 ADDED
@@ -0,0 +1,152 @@
1
+ šŸ“‚ Folder Structure Generator CLI
2
+ A powerful command-line tool to generate complete folder structures from a simple text diagram. Perfect for quickly scaffolding projects, boilerplates, or standardized directory layouts.
3
+
4
+ 🌟 Features
5
+ Generate nested folders and files with a single command
6
+
7
+ Supports both direct input and file input
8
+
9
+ Clear visual feedback with color-coded output
10
+
11
+ Flexible output directory specification
12
+
13
+ Lightweight with zero dependencies (except for development)
14
+
15
+ Cross-platform (Windows, macOS, Linux)
16
+
17
+ šŸ“¦ Installation
18
+ Global Installation (Recommended)
19
+ bash
20
+ npm install -g folder-structure-generator
21
+ (This allows running the tool from anywhere using foldgen)
22
+
23
+ Local Installation
24
+ bash
25
+ npm install folder-structure-generator --save-dev
26
+ (Useful when you want it as part of your project's dev tools)
27
+
28
+ šŸš€ Basic Usage
29
+ 1. Direct Input
30
+ bash
31
+ foldgen --input "src/
32
+ ā”œā”€ā”€ App.js
33
+ ā”œā”€ā”€ index.js
34
+ └── components/
35
+ ā”œā”€ā”€ Button.js
36
+ └── Header.js"
37
+ 2. From a File
38
+ bash
39
+ foldgen --file structure.txt
40
+ 3. From STDIN (Piping)
41
+ bash
42
+ echo "config/
43
+ ā”œā”€ā”€ default.json
44
+ └── production.json" | foldgen
45
+ šŸ”§ Advanced Usage
46
+ Specify Output Directory
47
+ bash
48
+ foldgen --input "lib/utils.js" --output ./my-project
49
+ Combine with Other Tools
50
+ bash
51
+ curl https://example.com/structure.txt | foldgen --output ./src
52
+ Generate in Current Directory
53
+ bash
54
+ foldgen --input "README.md" # Creates in current folder
55
+ šŸ“ Syntax Guide
56
+ The generator understands standard tree diagram notation:
57
+
58
+ text
59
+ root/
60
+ ā”œā”€ā”€ file.ext
61
+ └── folder/
62
+ ā”œā”€ā”€ nested_file.ext
63
+ └── empty_folder/
64
+ Special Characters:
65
+
66
+ ā”œā”€ā”€ for intermediate items
67
+
68
+ └── for the last item in a level
69
+
70
+ │ for vertical connections
71
+
72
+ (spaces) for indentation (4 spaces per level)
73
+
74
+ šŸ› ļø API Reference (for programmatic use)
75
+ javascript
76
+ const { parseStructure, createFiles } = require('folder-structure-generator');
77
+
78
+ // Parse text to structure object
79
+ const structure = parseStructure(`src/index.js`);
80
+
81
+ // Generate files
82
+ createFiles(structure, './output-path');
83
+ 🧩 Integration with Other Tools
84
+ With curl:
85
+ bash
86
+ curl -s https://raw.githubusercontent.com/your/repo/base-structure.txt | foldgen
87
+ In package.json scripts:
88
+ json
89
+ {
90
+ "scripts": {
91
+ "setup": "foldgen --file project-structure.txt --output ./src",
92
+ "create:components": "foldgen --input 'src/components/\nā”œā”€ā”€ Button.js\n└── Modal.js'"
93
+ }
94
+ }
95
+ šŸ—ļø Example Structures
96
+ React Project
97
+ text
98
+ src/
99
+ ā”œā”€ā”€ App.js
100
+ ā”œā”€ā”€ index.js
101
+ ā”œā”€ā”€ components/
102
+ │ ā”œā”€ā”€ Button/
103
+ │ │ ā”œā”€ā”€ index.js
104
+ │ │ ā”œā”€ā”€ styles.css
105
+ │ │ └── tests.js
106
+ │ └── Header.js
107
+ ā”œā”€ā”€ pages/
108
+ │ └── Home.js
109
+ └── utils/
110
+ └── api.js
111
+ Node.js API
112
+ text
113
+ app/
114
+ ā”œā”€ā”€ config/
115
+ │ └── database.js
116
+ ā”œā”€ā”€ controllers/
117
+ │ └── userController.js
118
+ ā”œā”€ā”€ models/
119
+ │ └── User.js
120
+ ā”œā”€ā”€ routes/
121
+ │ └── index.js
122
+ ā”œā”€ā”€ app.js
123
+ └── package.json
124
+ ā“ FAQ
125
+ Q: Can I add content to the generated files?
126
+ A: Currently the tool creates empty files. We're working on template support in the next version!
127
+
128
+ Q: How do I handle spaces in file names?
129
+ A: Just include them normally in your input: "My Document.docx"
130
+
131
+ Q: What if I make a mistake in the syntax?
132
+ A: The tool will show you an error with the problematic line number.
133
+
134
+ šŸ› Troubleshooting
135
+ Error: EACCES permission denied
136
+ Solution: Run with sudo or fix your npm permissions:
137
+
138
+ bash
139
+ sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
140
+ Error: Missing input
141
+ Solution: Either provide --input, --file, or pipe content to the command
142
+
143
+ šŸ¤ Contributing
144
+ Fork the repository
145
+
146
+ Create a feature branch (git checkout -b feature/awesome-feature)
147
+
148
+ Commit your changes (git commit -am 'Add awesome feature')
149
+
150
+ Push to the branch (git push origin feature/awesome-feature)
151
+
152
+ Open a Pull Request
package/bin/cli.js ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const chalk = require('chalk');
6
+ const figlet = require('figlet');
7
+ const yargs = require('yargs/yargs');
8
+ const { hideBin } = require('yargs/helpers');
9
+ const { parseStructure, createFiles } = require('../lib/generator');
10
+
11
+ // Parse command line arguments
12
+ const argv = yargs(hideBin(process.argv))
13
+ .usage('Usage: $0 [options]')
14
+ .option('input', {
15
+ alias: 'i',
16
+ type: 'string',
17
+ description: 'Folder structure text'
18
+ })
19
+ .option('file', {
20
+ alias: 'f',
21
+ type: 'string',
22
+ description: 'Path to file containing folder structure'
23
+ })
24
+ .option('output', {
25
+ alias: 'o',
26
+ type: 'string',
27
+ description: 'Output directory (default: current directory)',
28
+ default: process.cwd()
29
+ })
30
+ .help()
31
+ .alias('help', 'h')
32
+ .argv;
33
+
34
+ async function main() {
35
+ // Display banner
36
+ console.log(
37
+ chalk.blue(
38
+ figlet.textSync('FolderGen', { horizontalLayout: 'full' })
39
+ )
40
+ );
41
+
42
+ let input = argv.input;
43
+
44
+ // Read from file if specified
45
+ if (argv.file) {
46
+ try {
47
+ input = fs.readFileSync(argv.file, 'utf8');
48
+ } catch (err) {
49
+ console.error(chalk.red(`Error reading file: ${argv.file}`));
50
+ process.exit(1);
51
+ }
52
+ }
53
+
54
+ // Get input from stdin if no other source
55
+ if (!input && !process.stdin.isTTY) {
56
+ const chunks = [];
57
+ for await (const chunk of process.stdin) chunks.push(chunk);
58
+ input = Buffer.concat(chunks).toString('utf8');
59
+ }
60
+
61
+ if (!input) {
62
+ console.log(chalk.red('No input provided.'));
63
+ console.log(chalk.yellow('Provide input via --input, --file, or stdin'));
64
+ process.exit(1);
65
+ }
66
+
67
+ try {
68
+ const structure = parseStructure(input);
69
+ createFiles(structure, argv.output);
70
+ console.log(chalk.bold.green('\nFolder structure created successfully!'));
71
+ } catch (error) {
72
+ console.error(chalk.red('\nError creating folder structure:'), error.message);
73
+ process.exit(1);
74
+ }
75
+ }
76
+
77
+ main();
@@ -0,0 +1,52 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+
5
+ function parseStructure(text) {
6
+ const lines = text.split('\n');
7
+ const root = { name: '', children: [] };
8
+ let currentPath = [root];
9
+
10
+ for (const line of lines) {
11
+ if (!line.trim()) continue;
12
+
13
+ // Determine the depth based on indentation
14
+ const depth = (line.match(/[ā”œā””ā”€ā”€]/)?.index || 0) / 4;
15
+ const name = line.replace(/[ā”œā””ā”€ā”€ā”‚ ]/g, '').trim();
16
+
17
+ // Navigate to the correct parent
18
+ currentPath = currentPath.slice(0, depth + 1);
19
+
20
+ // Create new node
21
+ const newNode = { name, children: [] };
22
+ currentPath[currentPath.length - 1].children.push(newNode);
23
+
24
+ // Add to path for potential children
25
+ currentPath.push(newNode);
26
+ }
27
+
28
+ return root;
29
+ }
30
+
31
+ function createFiles(node, currentPath = '', rootPath = '') {
32
+ const fullPath = path.join(currentPath, node.name);
33
+
34
+ if (node.name.includes('.')) {
35
+ // It's a file
36
+ fs.writeFileSync(fullPath, '');
37
+ console.log(chalk.green(`Created file: ${path.relative(rootPath, fullPath)}`));
38
+ } else {
39
+ // It's a directory
40
+ if (node.name) { // Skip empty root name
41
+ fs.mkdirSync(fullPath, { recursive: true });
42
+ console.log(chalk.blue(`Created directory: ${path.relative(rootPath || currentPath, fullPath)}`));
43
+ }
44
+
45
+ // Create children
46
+ for (const child of node.children) {
47
+ createFiles(child, fullPath, rootPath || fullPath);
48
+ }
49
+ }
50
+ }
51
+
52
+ module.exports = { parseStructure, createFiles };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "folder-generator",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool to generate folder structures from text input",
5
+ "bin": {
6
+ "foldgen": "./bin/cli.js"
7
+ },
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "keywords": [
12
+ "folder",
13
+ "structure",
14
+ "generator",
15
+ "cli",
16
+ "scaffolding"
17
+ ],
18
+ "author": "shreyasghanekar35@gmail.com",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "chalk": "^4.1.2",
22
+ "figlet": "^1.5.2",
23
+ "yargs": "^17.3.1"
24
+ }
25
+ }