@madhusha_99/exp-gen 1.2.3 â 1.4.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 +253 -37
- package/bin/assets/Regex.gif +0 -0
- package/bin/assets/RegexWeb.png +0 -0
- package/bin/assets/Scaffold.gif +0 -0
- package/bin/copyTemplates.js +1 -0
- package/bin/copyTemplates.js.map +1 -1
- package/bin/regexSimulator.js +233 -0
- package/bin/regexSimulator.js.map +1 -0
- package/bin/script.js +17 -3
- package/bin/script.js.map +1 -1
- package/package.json +1 -1
- package/src/templates/js/sqlite/app.js +42 -0
- package/src/templates/js/sqlite/configs/config.js +13 -0
- package/src/templates/js/sqlite/configs/db.js +77 -0
- package/src/templates/js/sqlite/controllers/auth.controller.js +83 -0
- package/src/templates/js/sqlite/controllers/user.controller.js +27 -0
- package/src/templates/js/sqlite/default.env +5 -0
- package/src/templates/js/sqlite/middlewares/auth.middleware.js +64 -0
- package/src/templates/js/sqlite/models/user.model.js +22 -0
- package/src/templates/js/sqlite/package.json +29 -0
- package/src/templates/js/sqlite/repositories/user.repository.js +84 -0
- package/src/templates/js/sqlite/routes/auth.route.js +9 -0
- package/src/templates/js/sqlite/routes/user.route.js +24 -0
- package/src/templates/js/sqlite/services/user.service.js +50 -0
- package/src/templates/js/sqlite/utils/asyncHandler.js +5 -0
- package/src/templates/js/sqlite/utils/response.js +13 -0
- package/src/templates/js/mysql/package-lock.json +0 -4386
- package/src/templates/js/sqlite/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -1,59 +1,110 @@
|
|
|
1
1
|
# exp-gen ð
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@madhusha_99/exp-gen)
|
|
4
|
+
|
|
5
|
+
**exp-gen** a lightning-fast, interactive CLI tool designed to scaffold **Express.js REST APIs** in seconds.
|
|
6
|
+
|
|
7
|
+
Whether you're starting a project with **TypeScript** or **JavaScript**, `exp-gen` generates a clean layered architecture, configures your preferred database boilerplate so you can start coding immediately, and now includes a **built-in web-based Regex Simulator** to help you build and debug regular expressions visually.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## âĻ Features
|
|
12
|
+
|
|
13
|
+
- ð Interactive CLI powered by `@clack/prompts`
|
|
14
|
+
- ⥠Scaffold Express.js APIs in seconds
|
|
15
|
+
- ðĶ TypeScript support
|
|
16
|
+
- ðĻ JavaScript support
|
|
17
|
+
- ð Professional layered architecture
|
|
18
|
+
- ð MongoDB (Mongoose)
|
|
19
|
+
- ðŽ MySQL
|
|
20
|
+
- ðŠķ SQLite
|
|
21
|
+
- ð PostgreSQL (JavaScript projects)
|
|
22
|
+
- ðĶ Optional automatic dependency installation
|
|
23
|
+
- ðŽ Built-in **Regex Simulator**
|
|
24
|
+
- ð Opens automatically in your browser
|
|
25
|
+
- ðĻ Modern developer-friendly UI
|
|
26
|
+
- ð Live regex explanation & validation
|
|
4
27
|
|
|
5
28
|
---
|
|
6
29
|
|
|
7
|
-
|
|
30
|
+
# ð Installation
|
|
8
31
|
|
|
9
|
-
|
|
32
|
+
Install globally using npm:
|
|
10
33
|
|
|
11
34
|
```bash
|
|
12
35
|
npm install -g @madhusha_99/exp-gen
|
|
13
36
|
```
|
|
14
37
|
|
|
15
|
-
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# ð Usage
|
|
41
|
+
|
|
42
|
+
After installation you can launch the CLI using any of the following commands:
|
|
16
43
|
|
|
17
44
|
```bash
|
|
18
45
|
exp
|
|
19
|
-
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```bash
|
|
20
51
|
gen
|
|
21
|
-
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
or
|
|
55
|
+
|
|
56
|
+
```bash
|
|
22
57
|
express-draft
|
|
23
58
|
```
|
|
24
59
|
|
|
60
|
+
When the CLI starts you'll be greeted with an interactive menu.
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
ð Scaffold a new Express API
|
|
64
|
+
|
|
65
|
+
ðŽ Run Regex Simulator
|
|
66
|
+
```
|
|
67
|
+
|
|
25
68
|
---
|
|
26
69
|
|
|
27
|
-
|
|
70
|
+
# ð Scaffold Express API
|
|
28
71
|
|
|
29
|
-
|
|
72
|
+
Choose **Scaffold a new Express API** and answer a few questions.
|
|
30
73
|
|
|
31
|
-
|
|
74
|
+
The CLI will ask for:
|
|
32
75
|
|
|
33
|
-
|
|
76
|
+
- Project name
|
|
77
|
+
- Language
|
|
78
|
+
- Database
|
|
79
|
+
- Install dependencies
|
|
34
80
|
|
|
35
|
-
|
|
36
|
-
- **Language:** Choose between **TypeScript** (Recommended) or **JavaScript**.
|
|
37
|
-
- **Database:** Select your preferred database.
|
|
38
|
-
- _Currently Supported:_ **MongoDB** (via Mongoose), **MySQL**, and **PostgreSQL** (only for JavaScript projects).
|
|
39
|
-
- _Coming Soon:_ **PostgreSQL** (Prisma), and **SQLite**.
|
|
40
|
-
- **Install Dependencies:** Choose `Yes` to let the CLI run `npm install` for you automatically.
|
|
81
|
+
Supported languages
|
|
41
82
|
|
|
42
|
-
|
|
83
|
+
- **TypeScript** _(Recommended for type safety)_ â Currently available with **MongoDB (Mongoose)** and **No Database** templates. More database integrations will be added in future releases.
|
|
84
|
+
- **JavaScript** â Full template support for all currently available databases, including **MongoDB (Mongoose)**, **MySQL (mysql2)**, **SQLite (sqlite3)**, **PostgreSQL (pg)**, and **No Database**.
|
|
43
85
|
|
|
44
|
-
|
|
86
|
+
## ðïļ Supported Databases
|
|
45
87
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
| Database | JavaScript | TypeScript | Driver / ORM | Status |
|
|
89
|
+
| ------------------- | :--------: | :--------: | ------------ | :-----: |
|
|
90
|
+
| MongoDB | â
| â
| Mongoose | Stable |
|
|
91
|
+
| MySQL | â
| â | mysql2 | Stable |
|
|
92
|
+
| SQLite | â
| â | sqlite3 | Stable |
|
|
93
|
+
| PostgreSQL | â
| â | pg | Stable |
|
|
94
|
+
| None (No Database) | â
| â
| â | Stable |
|
|
95
|
+
| Prisma (MongoDB) | ð§ | ð§ | Prisma ORM | Planned |
|
|
96
|
+
| Prisma (MySQL) | ð§ | ð§ | Prisma ORM | Planned |
|
|
97
|
+
| Prisma (PostgreSQL) | ð§ | ð§ | Prisma ORM | Planned |
|
|
98
|
+
| Prisma (SQLite) | ð§ | ð§ | Prisma ORM | Planned |
|
|
99
|
+
|
|
100
|
+
#### Preview
|
|
101
|
+
|
|
102
|
+

|
|
50
103
|
|
|
51
104
|
---
|
|
52
105
|
|
|
53
106
|
## ð Project Structure
|
|
54
107
|
|
|
55
|
-
`exp-gen` scaffolds a professional **Layered Architecture**, ensuring your code remains scalable and maintainable as it grows:
|
|
56
|
-
|
|
57
108
|
- **`configs/`**: Environment variables and database connection logic.
|
|
58
109
|
- **`controllers/`**: Bridges the routes and the business logic; handles requests/responses.
|
|
59
110
|
- **`dtos/`**: Data Transfer Objects for validating and shaping incoming data.
|
|
@@ -66,32 +117,197 @@ npm run dev
|
|
|
66
117
|
- **`utils/`**: Shared helper functions and utility classes.
|
|
67
118
|
- **`app.ts`**: The application entry point.
|
|
68
119
|
|
|
120
|
+
The generated architecture **follows a clean layered design making projects easier to maintain and scale.**
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
# ðŽ Regex Simulator
|
|
125
|
+
|
|
126
|
+
Starting from **v1.4.0**, `exp-gen` includes a fully interactive **Regex Simulator**.
|
|
127
|
+
|
|
128
|
+
Simply choose:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
ðŽ Run Regex Simulator
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The CLI automatically starts a lightweight local server and opens the Regex Simulator in your default web browser.
|
|
135
|
+
|
|
136
|
+
> â
**No additional dependencies are required.** The simulator is built into `exp-gen` and runs entirely on your local machine.
|
|
137
|
+
|
|
138
|
+
#### Preview
|
|
139
|
+
|
|
140
|
+

|
|
141
|
+
|
|
142
|
+

|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Features in Regex Simulator
|
|
147
|
+
|
|
148
|
+
- ⥠Live regex matching
|
|
149
|
+
- ð Regex rule explanations
|
|
150
|
+
- ðŊ Capture group visualization
|
|
151
|
+
- ð Match position detection
|
|
152
|
+
- ðĻ Friendly validation errors
|
|
153
|
+
- ð§ Beginner-friendly regex guidance
|
|
154
|
+
- ð· Regex flag helper
|
|
155
|
+
- ð Modern dark developer UI
|
|
156
|
+
- ð Runs completely locally
|
|
157
|
+
|
|
158
|
+
**Example**
|
|
159
|
+
|
|
160
|
+
```regex
|
|
161
|
+
(?<name>\w+)-(\d+)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Input:**
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
hello-123
|
|
168
|
+
world-456
|
|
169
|
+
invalid-value
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Output:**
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
â Match 1
|
|
176
|
+
hello-123
|
|
177
|
+
|
|
178
|
+
Group 1:
|
|
179
|
+
hello
|
|
180
|
+
|
|
181
|
+
Group 2:
|
|
182
|
+
123
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**The simulator also explains regex tokens such as:**
|
|
186
|
+
|
|
187
|
+
| Token | Description |
|
|
188
|
+
| ----------- | ------------------- |
|
|
189
|
+
| `\d` | Digit |
|
|
190
|
+
| `\w` | Word character |
|
|
191
|
+
| `.` | Any character |
|
|
192
|
+
| `+` | One or more |
|
|
193
|
+
| `*` | Zero or more |
|
|
194
|
+
| `?` | Optional |
|
|
195
|
+
| `^` | Start of input |
|
|
196
|
+
| `$` | End of input |
|
|
197
|
+
| `()` | Capture group |
|
|
198
|
+
| `(?<name>)` | Named capture group |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
# ð Example Workflow
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
exp
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
â What would you like to do?
|
|
210
|
+
|
|
211
|
+
âŊ ð Scaffold a new Express API
|
|
212
|
+
ðŽ Run Regex Simulator
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
or
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
â What would you like to do?
|
|
219
|
+
|
|
220
|
+
ð Scaffold a new Express API
|
|
221
|
+
âŊ ðŽ Run Regex Simulator
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
# ðĶ After Scaffolding
|
|
227
|
+
|
|
228
|
+
Navigate into your project
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
cd my-project
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
If dependencies were installed
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
npm run dev
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Otherwise
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
npm install
|
|
244
|
+
npm run dev
|
|
245
|
+
```
|
|
246
|
+
|
|
69
247
|
---
|
|
70
248
|
|
|
71
249
|
## ðĪ Contributing
|
|
72
250
|
|
|
73
|
-
We love open source! `exp-gen` is a community-driven project, and we welcome contributions to make it better
|
|
251
|
+
**We love open source! `exp-gen` is a community-driven project, and we welcome contributions to make it better.**
|
|
252
|
+
|
|
253
|
+
You can help by:
|
|
254
|
+
|
|
255
|
+
- Adding new database templates
|
|
256
|
+
- Improving generated project templates
|
|
257
|
+
- Improving the Regex Simulator
|
|
258
|
+
- Reporting bugs
|
|
259
|
+
- Suggesting new CLI features
|
|
260
|
+
|
|
261
|
+
**Clone the project**
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
git clone https://github.com/Open-Core-Lab/exp-gen.git
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Install dependencies**
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npm install
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Run locally**
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
npm run dev
|
|
277
|
+
```
|
|
74
278
|
|
|
75
|
-
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
# ð Roadmap
|
|
76
282
|
|
|
77
|
-
|
|
78
|
-
2. **Report Bugs:** Found a glitch? Open an [issue](https://github.com/Open-Core-Lab/exp-gen/issues).
|
|
79
|
-
3. **Feature Requests:** Have an idea for a new feature? Let us know!
|
|
283
|
+
**Upcoming features include:**
|
|
80
284
|
|
|
81
|
-
|
|
285
|
+
- **Prisma support**
|
|
286
|
+
- **Docker template generation**
|
|
287
|
+
- **JWT Authentication template**
|
|
288
|
+
- **Swagger/OpenAPI generation**
|
|
289
|
+
- **Testing templates (Vitest/Jest)**
|
|
290
|
+
- **Redis integration**
|
|
291
|
+
- **Prisma PostgreSQL template**
|
|
292
|
+
- **Environment profile generator**
|
|
293
|
+
- **More Regex Simulator utilities**
|
|
294
|
+
|
|
295
|
+
---
|
|
82
296
|
|
|
83
|
-
|
|
297
|
+
## â Support
|
|
84
298
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
299
|
+
If you enjoy using **exp-gen**, consider giving the repository a â on GitHub.
|
|
300
|
+
|
|
301
|
+
It helps the project grow and supports future development.
|
|
302
|
+
|
|
303
|
+
**Repository: [exp-gen](https://github.com/Open-Core-Lab/exp-gen)**
|
|
88
304
|
|
|
89
305
|
---
|
|
90
306
|
|
|
91
|
-
|
|
307
|
+
# ð License
|
|
92
308
|
|
|
93
309
|
This project is licensed under the **[MIT License](https://github.com/Open-Core-Lab/exp-gen/blob/main/LICENSE)**.
|
|
94
310
|
|
|
95
|
-
|
|
311
|
+
**Happy coding! ð**
|
|
96
312
|
|
|
97
|
-
|
|
313
|
+
_Maintained with âĪïļ by [Madhusha Prasad](https://github.com/MadhushaPrasad)_
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/bin/copyTemplates.js
CHANGED
|
@@ -20,6 +20,7 @@ async function copyAssets() {
|
|
|
20
20
|
{ src: "LICENSE", dest: "LICENSE" },
|
|
21
21
|
{ src: "README.md", dest: "README.md" },
|
|
22
22
|
{ src: "package-config/package.json", dest: "package.json" },
|
|
23
|
+
{ src: "bin/assets", dest: "bin/assets" },
|
|
23
24
|
];
|
|
24
25
|
for (const file of filesToCopy) {
|
|
25
26
|
const srcFile = path.resolve(rootDir, file.src);
|
package/bin/copyTemplates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyTemplates.js","sourceRoot":"","sources":["../../bin/copyTemplates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAE3C,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC;QACH,eAAe;QACf,wEAAwE;QACxE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAE9C,wBAAwB;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAC5D,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAC7D,MAAM,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAC3C,OAAO,CAAC,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|
|
3
|
+
import { exec } from "child_process";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
import * as p from "@clack/prompts";
|
|
6
|
+
function findAvailablePort(port) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const server = net.createServer();
|
|
9
|
+
server.listen(port, () => {
|
|
10
|
+
server.close(() => resolve(port));
|
|
11
|
+
});
|
|
12
|
+
server.on("error", () => resolve(findAvailablePort(port + 1)));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function openBrowser(url) {
|
|
16
|
+
const commands = {
|
|
17
|
+
win32: `start "" "${url}"`,
|
|
18
|
+
darwin: `open "${url}"`,
|
|
19
|
+
linux: `xdg-open "${url}"`,
|
|
20
|
+
};
|
|
21
|
+
const command = commands[process.platform] ?? commands.linux;
|
|
22
|
+
exec(command);
|
|
23
|
+
}
|
|
24
|
+
// --- Regex simulator Logic ---
|
|
25
|
+
const clientScript = `
|
|
26
|
+
const pattern = document.querySelector("#pattern");
|
|
27
|
+
const flags = document.querySelector("#flags");
|
|
28
|
+
const input = document.querySelector("#input");
|
|
29
|
+
const results = document.querySelector("#results");
|
|
30
|
+
const error = document.querySelector("#error");
|
|
31
|
+
const count = document.querySelector("#count");
|
|
32
|
+
const explain = document.querySelector("#explain");
|
|
33
|
+
|
|
34
|
+
function explainRegex(value) {
|
|
35
|
+
const rules = {
|
|
36
|
+
"\\\\d": "Matches any digit (0-9)",
|
|
37
|
+
"\\\\w": "Matches word characters",
|
|
38
|
+
"+": "Requires one or more repetitions",
|
|
39
|
+
"*": "Allows zero or more repetitions",
|
|
40
|
+
"^": "Start of line/input anchor",
|
|
41
|
+
"$": "End of line/input anchor",
|
|
42
|
+
"(?<": "Named capture group"
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
explain.innerHTML = "";
|
|
46
|
+
|
|
47
|
+
Object.keys(rules)
|
|
48
|
+
.filter(x => value.includes(x))
|
|
49
|
+
.forEach(x => {
|
|
50
|
+
explain.innerHTML += \`
|
|
51
|
+
<div>
|
|
52
|
+
<span class="token">\${x}</span> - \${rules[x]}
|
|
53
|
+
</div>
|
|
54
|
+
\`;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!explain.innerHTML) {
|
|
58
|
+
explain.innerHTML = "âđ No special tokens detected";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function run() {
|
|
63
|
+
results.innerHTML = "";
|
|
64
|
+
error.classList.add("hidden");
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
let combinedFlags = flags.value;
|
|
68
|
+
if (!combinedFlags.includes("g")) combinedFlags += "g";
|
|
69
|
+
if (!combinedFlags.includes("m")) combinedFlags += "m";
|
|
70
|
+
|
|
71
|
+
const regex = new RegExp(pattern.value, combinedFlags);
|
|
72
|
+
let matches = [];
|
|
73
|
+
let m;
|
|
74
|
+
|
|
75
|
+
while ((m = regex.exec(input.value)) !== null) {
|
|
76
|
+
matches.push(m);
|
|
77
|
+
if (m[0] === "") {
|
|
78
|
+
regex.lastIndex++;
|
|
79
|
+
}
|
|
80
|
+
if (matches.length > 100) break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
count.innerText = \`\${matches.length} match\${matches.length === 1 ? "" : "es"}\`;
|
|
84
|
+
|
|
85
|
+
if (!matches.length) {
|
|
86
|
+
results.innerHTML = \`<div class="text-yellow-400">No matches found</div>\`;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
matches.forEach((m, i) => {
|
|
91
|
+
results.innerHTML += \`
|
|
92
|
+
<div class="bg-slate-950 border border-slate-800 rounded-lg p-4">
|
|
93
|
+
<div class="text-green-400">â Match #\${i + 1}</div>
|
|
94
|
+
<div class="mt-2">Value: <b>\${m[0]}</b></div>
|
|
95
|
+
<div class="text-xs text-slate-500">Index: \${m.index}</div>
|
|
96
|
+
\${m.slice(1).map((g, n) => \`
|
|
97
|
+
<div class="text-cyan-400 pl-2 border-l border-slate-800 mt-1 text-xs">
|
|
98
|
+
Group \${n + 1}: \${g !== undefined ? g : 'undefined'}
|
|
99
|
+
</div>
|
|
100
|
+
\`).join("")}
|
|
101
|
+
</div>
|
|
102
|
+
\`;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
explainRegex(pattern.value);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
error.classList.remove("hidden");
|
|
108
|
+
error.innerHTML = \`
|
|
109
|
+
<strong>Invalid Regex</strong><br>
|
|
110
|
+
\${e.message}<br><br>
|
|
111
|
+
Tip: Check brackets (), [], {}, and flags.
|
|
112
|
+
\`;
|
|
113
|
+
count.innerText = "error";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[pattern, flags, input].forEach(x => x.addEventListener("input", run));
|
|
118
|
+
run();
|
|
119
|
+
`;
|
|
120
|
+
// --- Static Pure HTML Template ---
|
|
121
|
+
const htmlContent = `
|
|
122
|
+
<!DOCTYPE html>
|
|
123
|
+
<html>
|
|
124
|
+
<head>
|
|
125
|
+
<meta charset="UTF-8">
|
|
126
|
+
<title>exp-gen Regex Simulator</title>
|
|
127
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
128
|
+
<style>
|
|
129
|
+
body { font-family: "JetBrains Mono", "Fira Code", monospace; }
|
|
130
|
+
textarea, input { outline: none; }
|
|
131
|
+
.glow { box-shadow: 0 0 25px rgba(34, 211, 238, .15); }
|
|
132
|
+
.token { padding: 4px 8px; border-radius: 6px; background: #1e293b; color: #38bdf8; font-size: 12px; }
|
|
133
|
+
.flag-token { padding: 2px 6px; border-radius: 4px; background: #2e1065; color: #c084fc; font-size: 11px; font-weight: bold; }
|
|
134
|
+
</style>
|
|
135
|
+
</head>
|
|
136
|
+
<body class="bg-[#020617] text-slate-200 min-h-screen">
|
|
137
|
+
<header class="p-5 border-b border-slate-800 bg-[#0f172a] flex justify-between">
|
|
138
|
+
<div>
|
|
139
|
+
<h1 class="text-xl font-bold text-cyan-400">ð exp-gen Regex Simulator</h1>
|
|
140
|
+
<p class="text-xs text-slate-400">Interactive JavaScript Regex Debugger</p>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="text-xs text-slate-500">CLI Powered Tool</div>
|
|
143
|
+
</header>
|
|
144
|
+
|
|
145
|
+
<main class="grid lg:grid-cols-2 gap-5 p-5">
|
|
146
|
+
<section class="space-y-5">
|
|
147
|
+
<div class="bg-[#0f172a] border border-slate-800 rounded-xl p-5 glow">
|
|
148
|
+
<div class="flex flex-col md:flex-row md:items-center justify-between gap-2 mb-3">
|
|
149
|
+
<h2 class="text-sm text-slate-400">REGEX PATTERN & FLAGS</h2>
|
|
150
|
+
|
|
151
|
+
<div class="flex flex-wrap gap-1.5 items-center">
|
|
152
|
+
<span class="text-[11px] text-slate-500 mr-1">Flags:</span>
|
|
153
|
+
<span class="flag-token" title="Global: Find all matches">g â global</span>
|
|
154
|
+
<span class="flag-token" title="Multiline: ^ and $ match line boundaries">m â multiline</span>
|
|
155
|
+
<span class="flag-token" title="Insensitive: Case-blind matching">i â insensitive</span>
|
|
156
|
+
<span class="flag-token" title="Single-line: Dot matches newline">s â dotAll</span>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
<div class="flex">
|
|
161
|
+
<span class="bg-slate-900 px-3 py-3 text-cyan-400">/</span>
|
|
162
|
+
<input id="pattern" class="flex-1 bg-slate-950 p-3 font-mono" value="(?<name>\\w+)-(\\d+)">
|
|
163
|
+
<span class="bg-slate-900 px-3 py-3 text-cyan-400">/</span>
|
|
164
|
+
<input id="flags" class="w-20 bg-slate-950 p-3 text-purple-400 font-bold tracking-wide placeholder-slate-700" value="m" placeholder="flags">
|
|
165
|
+
</div>
|
|
166
|
+
<div id="error" class="hidden mt-3 bg-red-950 border border-red-900 text-red-300 p-3 rounded-lg text-xs"></div>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<div class="bg-[#0f172a] border border-slate-800 rounded-xl p-5">
|
|
170
|
+
<h2 class="text-sm text-slate-400 mb-3">TEST STRING</h2>
|
|
171
|
+
<textarea id="input" class="w-full h-52 bg-slate-950 rounded-lg p-4 font-mono">hello-123\nworld-456\nbad-value\nMadhusha@gmail.com\nmadushaprasad21@gmail.com</textarea>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<div class="bg-[#0f172a] border border-slate-800 rounded-xl p-5">
|
|
175
|
+
<h2 class="text-sm text-slate-400 mb-3">COMMON RULES</h2>
|
|
176
|
+
<div class="flex flex-wrap gap-2">
|
|
177
|
+
<span class="token">\\d â number</span>
|
|
178
|
+
<span class="token">\\w â word</span>
|
|
179
|
+
<span class="token">+ â repeat</span>
|
|
180
|
+
<span class="token">* â optional</span>
|
|
181
|
+
<span class="token">^ â start</span>
|
|
182
|
+
<span class="token">$ â end</span>
|
|
183
|
+
<span class="token">() â group</span>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</section>
|
|
187
|
+
|
|
188
|
+
<section class="bg-[#0f172a] border border-slate-800 rounded-xl p-5">
|
|
189
|
+
<div class="flex justify-between">
|
|
190
|
+
<h2 class="text-sm text-slate-400">MATCH RESULTS</h2>
|
|
191
|
+
<span id="count" class="text-xs text-green-400">0 matches</span>
|
|
192
|
+
</div>
|
|
193
|
+
<div id="results" class="mt-5 space-y-3"></div>
|
|
194
|
+
|
|
195
|
+
<div class="mt-5 border-t border-slate-800 pt-5">
|
|
196
|
+
<h2 class="text-sm text-slate-400 mb-3">PATTERN EXPLANATION</h2>
|
|
197
|
+
<div id="explain" class="text-xs text-slate-300 space-y-2"></div>
|
|
198
|
+
</div>
|
|
199
|
+
</section>
|
|
200
|
+
</main>
|
|
201
|
+
|
|
202
|
+
<script>${clientScript}</script>
|
|
203
|
+
</body>
|
|
204
|
+
</html>
|
|
205
|
+
`;
|
|
206
|
+
export async function runRegexSimulator() {
|
|
207
|
+
console.clear();
|
|
208
|
+
// Native HTTP Server Setup
|
|
209
|
+
const server = http.createServer((req, res) => {
|
|
210
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
211
|
+
res.end(htmlContent);
|
|
212
|
+
});
|
|
213
|
+
const port = await findAvailablePort(4000);
|
|
214
|
+
await new Promise((resolve) => {
|
|
215
|
+
server.listen(port, () => {
|
|
216
|
+
const url = `http://localhost:${port}`;
|
|
217
|
+
p.outro(pc.green("â Regex simulator environment started"));
|
|
218
|
+
// Print a clean visual card in the terminal console
|
|
219
|
+
// Pixel-perfect console dashboard card
|
|
220
|
+
console.log(pc.cyan("ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ"));
|
|
221
|
+
console.log(`${pc.cyan("â")} ðŽ ${pc.bold("Live Regex Simulator Environment Active")}`);
|
|
222
|
+
console.log(`${pc.cyan("â")}`);
|
|
223
|
+
console.log(`${pc.cyan("â")} ${pc.dim("Portal URL:")} ${pc.underline(pc.yellow(url.padEnd(38)))}`);
|
|
224
|
+
console.log(`${pc.cyan("â")}`);
|
|
225
|
+
console.log(`${pc.cyan("â")} ${pc.dim("Control:")} Press ${pc.inverse(pc.bold(" Ctrl + C "))} to terminate server`);
|
|
226
|
+
console.log(pc.cyan("ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ\n"));
|
|
227
|
+
openBrowser(url);
|
|
228
|
+
resolve();
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
return new Promise(() => { });
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=regexSimulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexSimulator.js","sourceRoot":"","sources":["../../bin/regexSimulator.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AAEpC,SAAS,iBA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AAK,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,sBAAsB,CAC5G,CAAC;YACF,OAAO,CAAC,GAAG,CACT,EAAE,CAAC,IAAI,CACL,oEAAoE,CACrE,CACF,CAAC;YACF,WAAW,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
package/bin/script.js
CHANGED
|
@@ -6,6 +6,7 @@ import fs from "fs/promises";
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import scaffoldProject from "./scaffoldProject.js";
|
|
9
|
+
import { runRegexSimulator } from "./regexSimulator.js";
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = path.dirname(__filename);
|
|
11
12
|
async function getAppVersion() {
|
|
@@ -39,6 +40,19 @@ async function main() {
|
|
|
39
40
|
console.clear();
|
|
40
41
|
const appVersion = await getAppVersion();
|
|
41
42
|
p.intro(`${pc.bgCyan(pc.black(" EXPRESS GENERATOR "))} ${pc.dim(`v${appVersion}`)}\n${pc.dim("Scaffold your Express API in seconds ð")}`);
|
|
43
|
+
// choose scaffold or regex simulator
|
|
44
|
+
const action = await safePrompt(p.select({
|
|
45
|
+
message: "What would you like to do?\n",
|
|
46
|
+
options: [
|
|
47
|
+
{ value: "scaffold", label: "ð Scaffold a new Express API" },
|
|
48
|
+
{ value: "regex", label: "ðŽ Run Regex Simulator" },
|
|
49
|
+
],
|
|
50
|
+
}));
|
|
51
|
+
// check user input
|
|
52
|
+
if (action === "regex") {
|
|
53
|
+
await runRegexSimulator();
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
42
56
|
const project = await p.group({
|
|
43
57
|
name: () => safePrompt(p.text({
|
|
44
58
|
message: "Project name",
|
|
@@ -87,7 +101,7 @@ async function main() {
|
|
|
87
101
|
{
|
|
88
102
|
value: "sqlite",
|
|
89
103
|
label: pc.gray("SQLite"),
|
|
90
|
-
hint: pc.dim("
|
|
104
|
+
hint: pc.dim("via SQLite (Available)"),
|
|
91
105
|
},
|
|
92
106
|
{
|
|
93
107
|
value: "none",
|
|
@@ -107,10 +121,10 @@ async function main() {
|
|
|
107
121
|
},
|
|
108
122
|
});
|
|
109
123
|
//Stop if user selected a "coming soon" DB
|
|
110
|
-
const comingSoonDBs = [
|
|
124
|
+
const comingSoonDBs = [];
|
|
111
125
|
if (comingSoonDBs.includes(project.db)) {
|
|
112
126
|
p.cancel(pc.yellow(`ð§ ${project.db.toUpperCase()} support is coming soon!\n\n` +
|
|
113
|
-
pc.dim("Currently only MongoDB, MySQL and PostgreSQL (only for js project) supported.\n") +
|
|
127
|
+
pc.dim("Currently only MongoDB, MySQL, SQLite and PostgreSQL (only for js project) supported.\n") +
|
|
114
128
|
pc.dim("Stay tuned for future updates ð")));
|
|
115
129
|
process.exit(0);
|
|
116
130
|
}
|