quick-struct-gen 1.6.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/LICENSE +5 -0
- package/README.md +84 -0
- package/package.json +15 -0
- package/src/colors.js +9 -0
- package/src/generator.js +76 -0
- package/src/index.js +75 -0
- package/src/presets.js +37 -0
- package/struct-gen.js +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2026 (C) kljj04
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# 🚀 quick-struct-gen
|
|
2
|
+
|
|
3
|
+
**Text-to-File System Generator** - Transform your tree structure blueprints into a real project file system in a split second. Simply copy, paste, and watch the magic happen!
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/quick-struct-gen)
|
|
6
|
+
[](https://www.npmjs.com/package/quick-struct-gen)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 🌟 Why quick-struct-gen?
|
|
11
|
+
Stop wasting time manually creating folders and files. Whether you're starting a new React app, a complex Backend server, or a simple script, just describe your structure and let `quick-struct-gen` do the heavy lifting.
|
|
12
|
+
|
|
13
|
+
## 🔥 Key Features
|
|
14
|
+
- **⚡ Auto-Build**: No `Ctrl+Z` or `Enter` required. Paste your structure, wait 0.5s, and it starts building!
|
|
15
|
+
- **📦 Smart Presets**: Instant scaffolding for popular frameworks (`--react`, `--electron`, `--node`).
|
|
16
|
+
- **🧠 Hybrid Parsing**: Supports both classic tree symbols (`├──`) and simple indentation (spaces).
|
|
17
|
+
- **🪟 Windows Friendly**: Support for `folder\` backslash notation.
|
|
18
|
+
- **🎨 Colorful UI**: Clear, color-coded logs for directories and files.
|
|
19
|
+
- **💬 Comment Friendly**: Ignores anything after `#`, allowing you to keep notes in your blueprint.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
Install globally to use it anywhere:
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g quick-struct-gen
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 🛠 Usage
|
|
32
|
+
|
|
33
|
+
### 1. Interactive Mode (The Magic Way)
|
|
34
|
+
Just run the command and paste your tree structure. It will detect your input and start building automatically after a 0.5s pause.
|
|
35
|
+
```bash
|
|
36
|
+
struct-gen
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 2. Using Presets (Scaffolding)
|
|
40
|
+
Instantly create industry-standard project structures:
|
|
41
|
+
```bash
|
|
42
|
+
struct-gen --react # Create a React project structure
|
|
43
|
+
struct-gen --electron # Create an Electron project structure
|
|
44
|
+
struct-gen --node # Create a Node.js backend structure
|
|
45
|
+
struct-gen --list # Show all available presets
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Generate from File
|
|
49
|
+
```bash
|
|
50
|
+
struct-gen my-structure.txt
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 📝 Blueprint Examples
|
|
56
|
+
|
|
57
|
+
### Option A: Classic Tree (Copy from Docs/GPT)
|
|
58
|
+
```text
|
|
59
|
+
my-app/
|
|
60
|
+
├── src/
|
|
61
|
+
│ ├── App.js
|
|
62
|
+
│ └── index.js
|
|
63
|
+
└── package.json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Option B: Quick Indentation (Fast Typing)
|
|
67
|
+
```text
|
|
68
|
+
my-project\
|
|
69
|
+
README.md
|
|
70
|
+
src\
|
|
71
|
+
main.js
|
|
72
|
+
utils.js
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🚀 Roadmap
|
|
78
|
+
- [ ] **Content Injection**: Support for `file.js { console.log('hi') }` to insert code.
|
|
79
|
+
- [ ] **Interactive Init**: A wizard-style setup for complex projects.
|
|
80
|
+
- [ ] **Custom Presets**: Save your own favorite structures as presets.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
**Built with ❤️ for developers who hate manual work.** 🎈
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "quick-struct-gen",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Tree structure to file system generator",
|
|
5
|
+
"main": "struct-gen.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"struct-gen": "struct-gen.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["cli", "generator", "tree"],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC"
|
|
15
|
+
}
|
package/src/colors.js
ADDED
package/src/generator.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const colors = require('./colors');
|
|
4
|
+
|
|
5
|
+
function parseAndGenerate(input) {
|
|
6
|
+
const lines = input.split('\n').filter(line => line.trim() !== '');
|
|
7
|
+
const stack = [];
|
|
8
|
+
const rootPath = process.cwd();
|
|
9
|
+
let stats = { dirs: 0, files: 0 };
|
|
10
|
+
|
|
11
|
+
console.log(`${colors.gray}Target Directory: ${rootPath}${colors.reset}\n`);
|
|
12
|
+
|
|
13
|
+
lines.forEach((line, index) => {
|
|
14
|
+
const cleanLine = line.split('#')[0];
|
|
15
|
+
if (!cleanLine.trim()) return;
|
|
16
|
+
|
|
17
|
+
const symbols = cleanLine.match(/[│├└─]/g);
|
|
18
|
+
let depth = 0;
|
|
19
|
+
let name = "";
|
|
20
|
+
|
|
21
|
+
if (symbols) {
|
|
22
|
+
const lastSymbol = cleanLine.lastIndexOf(symbols[symbols.length - 1]);
|
|
23
|
+
depth = Math.floor(lastSymbol / 4) + 1;
|
|
24
|
+
name = cleanLine.replace(/[│├└─]/g, '').trim();
|
|
25
|
+
} else {
|
|
26
|
+
const leadingSpaces = cleanLine.match(/^\s*/)[0].length;
|
|
27
|
+
depth = leadingSpaces;
|
|
28
|
+
name = cleanLine.trim();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!name) return;
|
|
32
|
+
|
|
33
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
34
|
+
stack.pop();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const currentParent = stack.length > 0 ? stack[stack.length - 1].path : rootPath;
|
|
38
|
+
const normalizedName = name.replace(/[\\\/]$/, '');
|
|
39
|
+
const fullPath = path.join(currentParent, normalizedName);
|
|
40
|
+
|
|
41
|
+
const isDirectory = name.endsWith('/') || name.endsWith('\\') || lines.some((l, i) => {
|
|
42
|
+
if (i <= index) return false;
|
|
43
|
+
const nextClean = l.split('#')[0];
|
|
44
|
+
const nextSyms = nextClean.match(/[│├└─]/g);
|
|
45
|
+
let nextDepth = 0;
|
|
46
|
+
if (nextSyms) {
|
|
47
|
+
nextDepth = Math.floor(nextClean.lastIndexOf(nextSyms[nextSyms.length - 1]) / 4) + 1;
|
|
48
|
+
} else {
|
|
49
|
+
nextDepth = nextClean.match(/^\s*/)[0].length;
|
|
50
|
+
}
|
|
51
|
+
return nextDepth > depth && nextClean.includes(normalizedName);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (isDirectory) {
|
|
55
|
+
if (!fs.existsSync(fullPath)) {
|
|
56
|
+
fs.mkdirSync(fullPath, { recursive: true });
|
|
57
|
+
console.log(`${colors.blue} DIR ${colors.reset}${normalizedName}`);
|
|
58
|
+
stats.dirs++;
|
|
59
|
+
}
|
|
60
|
+
stack.push({ depth, path: fullPath });
|
|
61
|
+
} else {
|
|
62
|
+
const dir = path.dirname(fullPath);
|
|
63
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
64
|
+
if (!fs.existsSync(fullPath)) {
|
|
65
|
+
fs.writeFileSync(fullPath, '');
|
|
66
|
+
console.log(`${colors.green} FILE ${colors.reset}${normalizedName}`);
|
|
67
|
+
stats.files++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(`\n${colors.bright}${colors.green}✔ Creation Complete!${colors.reset}`);
|
|
73
|
+
console.log(`${colors.gray}Total: ${stats.dirs} Directories, ${stats.files} Files${colors.reset}\n`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { parseAndGenerate };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const colors = require('./colors');
|
|
3
|
+
const presets = require('./presets');
|
|
4
|
+
const { parseAndGenerate } = require('./generator');
|
|
5
|
+
|
|
6
|
+
function printBanner() {
|
|
7
|
+
console.log(`\n${colors.bright}${colors.cyan}╔══════════════════════════════════════════════╗${colors.reset}`);
|
|
8
|
+
console.log(`${colors.bright}${colors.cyan}║ STRUCT-GEN BUILDER v1.6.0 ║${colors.reset}`);
|
|
9
|
+
console.log(`${colors.bright}${colors.cyan}╚══════════════════════════════════════════════╝${colors.reset}\n`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function run() {
|
|
13
|
+
const args = process.argv.slice(2);
|
|
14
|
+
printBanner();
|
|
15
|
+
|
|
16
|
+
if (args.length > 0) {
|
|
17
|
+
const target = args[0];
|
|
18
|
+
|
|
19
|
+
if (target.startsWith('--')) {
|
|
20
|
+
const presetName = target.slice(2);
|
|
21
|
+
if (presetName === 'list') {
|
|
22
|
+
console.log(`${colors.cyan}Available Presets:${colors.reset}`);
|
|
23
|
+
Object.keys(presets).forEach(name => console.log(` - --${name}`));
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (presets[presetName]) {
|
|
28
|
+
console.log(`${colors.cyan}>> Using preset: ${presetName}${colors.reset}`);
|
|
29
|
+
parseAndGenerate(presets[presetName]);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
} else {
|
|
32
|
+
console.error(`${colors.yellow}Error: Unknown preset "--${presetName}". Use --list to see available presets.${colors.reset}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (fs.existsSync(target) && fs.lstatSync(target).isFile()) {
|
|
38
|
+
const content = fs.readFileSync(target, 'utf8');
|
|
39
|
+
parseAndGenerate(content);
|
|
40
|
+
} else {
|
|
41
|
+
if (target.includes('\n') || target.includes('├') || target.includes('└')) {
|
|
42
|
+
parseAndGenerate(target);
|
|
43
|
+
} else {
|
|
44
|
+
console.error(`${colors.yellow}Error: File not found or invalid tree structure provided.${colors.reset}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`${colors.yellow}Paste your tree structure below.${colors.reset}`);
|
|
49
|
+
console.log(`${colors.gray}(Will start automatically 0.5s after pasting)${colors.reset}\n`);
|
|
50
|
+
|
|
51
|
+
let data = '';
|
|
52
|
+
let timeout = null;
|
|
53
|
+
|
|
54
|
+
process.stdin.setEncoding('utf8');
|
|
55
|
+
process.stdin.on('data', chunk => {
|
|
56
|
+
data += chunk;
|
|
57
|
+
if (timeout) clearTimeout(timeout);
|
|
58
|
+
timeout = setTimeout(() => {
|
|
59
|
+
if (data.trim()) {
|
|
60
|
+
console.log(`\n${colors.cyan}>> Input detected, starting build...${colors.reset}`);
|
|
61
|
+
parseAndGenerate(data);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
}, 500);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
process.stdin.on('end', () => {
|
|
68
|
+
if (data.trim() && !timeout) {
|
|
69
|
+
parseAndGenerate(data);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { run };
|
package/src/presets.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
electron: `my-electron-app/
|
|
3
|
+
├── package.json
|
|
4
|
+
├── main.js
|
|
5
|
+
├── preload.js
|
|
6
|
+
├── renderer/
|
|
7
|
+
│ ├── index.html
|
|
8
|
+
│ ├── style.css
|
|
9
|
+
│ └── renderer.js
|
|
10
|
+
└── assets/`,
|
|
11
|
+
|
|
12
|
+
react: `my-react-app/
|
|
13
|
+
├── public/
|
|
14
|
+
│ ├── index.html
|
|
15
|
+
│ └── favicon.ico
|
|
16
|
+
├── src/
|
|
17
|
+
│ ├── assets/
|
|
18
|
+
│ ├── components/
|
|
19
|
+
│ ├── hooks/
|
|
20
|
+
│ ├── App.js
|
|
21
|
+
│ └── index.js
|
|
22
|
+
├── package.json
|
|
23
|
+
└── README.md`,
|
|
24
|
+
|
|
25
|
+
node: `my-node-server/
|
|
26
|
+
├── src/
|
|
27
|
+
│ ├── controllers/
|
|
28
|
+
│ ├── models/
|
|
29
|
+
│ ├── routes/
|
|
30
|
+
│ ├── services/
|
|
31
|
+
│ └── app.js
|
|
32
|
+
├── config/
|
|
33
|
+
├── tests/
|
|
34
|
+
├── .env
|
|
35
|
+
├── .gitignore
|
|
36
|
+
└── package.json`
|
|
37
|
+
};
|
package/struct-gen.js
ADDED