-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
240 lines (211 loc) · 7.34 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
const path = require('path')
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
const fs = require('fs')
const success = (code, lang) => console.log('\x1b[32m',`Successfully ✓ created new basic random ${lang} file! The file hash:`, code)
const simpleCode = () => {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
}
readline.question('Which file you want to create? (Write the extension without point): ', (ext) => {
if (ext.toLowerCase() == 'jsx') {
const randJsFile = () => {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('reactComponentFiles', (err) => {
if (err) {
}
})
fs.writeFile(`./reactComponentFiles/${code}.react.js`, `import React from "react";
export default function App() {
return (
<div className="container">
<h1>Hello World</h1>
</div>
);
};`, err => {
console.log('\x1b[32m','Successfully ✓ created new basic random react file! The file hash:', code)
if(err) {
console.log(err)
}
})
}
randJsFile()
readline.close()
}
if (ext.toLowerCase() == 'java') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
const randJavaFile = () => {
fs.mkdir('javaFiles', (err) => {
if (err) {
}
})
fs.writeFile(`./javaFiles/${code}.java`, `public static Main(String[] args) {
System.out.println('Hello World!');
}`, () => {
console.log('\x1b[32m','Successfully ✓ created new basic random java file! The file hash:', code)
})
}
randJavaFile()
readline.close()
}
if (ext.toLowerCase() == 'cs') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('csFiles', (err) => {
if (err) {
}
})
const randCsFile = () => {
fs.writeFile(`csFiles/${code}.cs`, `using System;
using System.Collections;
using System.Collections.Generic;
static void Main(string[] args)
{
Console.WriteLine('Hello World');
}
`, () => {
console.log('\x1b[32m','Successfully ✓ created new basic random c# file! The file hash:', code)
})
}
randCsFile()
readline.close()
}
if (ext.toLowerCase() == 'cpp') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('cppFiles', (err) => {
if (err) {
}
})
const randCppFiles = () => {
fs.writeFile(`cppFiles/${code}.cpp`, `#include <iostream>
using namespace std;
int main() {
std::cout << 'Hello World' << std::endl;
}`, () => {
console.log('\x1b[32m','Successfully ✓ created new basic random c++ file! The file hash:', code)
})
}
randCppFiles()
readline.close()
}
if (ext.toLowerCase() == 'c') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('cFiles', (err) => {
if (err) {
}
})
const randCFiles = () => {
fs.writeFile(`cFiles/${code}.c`, `#include <stdio.h>
int main() {
printf('Hello World');
}`, () => success(code, 'C'))
}
randCFiles()
readline.close()
}
if (ext.toLowerCase() == 'php') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('phpFiles', (err) => {
if (err) {
}
})
const randPhpFiles = () => {
fs.writeFile(`phpFiles/${code}.php`, `<?php
?>`, () => success(code, 'PHP'))
}
randPhpFiles()
readline.close()
}
if (ext.toLowerCase() == 'html') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('htmlSite', (err) => {
if (err) {}
})
const randHtmlFiles = () => {
fs.writeFile(`htmlSite/${code}.html`, `<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="${code}.css">
</head>
<body>
<script src="./${code}.js"></script>
</body>
</html>`, () => success(code, 'HTML'))
fs.writeFile(`htmlSite/${code}.js`, ``, (err) => {
if (err) {}
})
fs.writeFile(`htmlSite/${code}.css`, '', (err) => {
if (err) {}
})
}
randHtmlFiles()
readline.close()
}
if (ext.toLowerCase() == 'js') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir('jsFiles', (err) => {
if(err) {}
})
const randJsFiles = () => {
fs.writeFile(`jsFiles/${code}.js`, '', () => success(code, 'JS'))
}
randJsFiles()
readline.close()
}
if (ext != 'c' && ext != 'js' && ext != 'php' && ext != 'html' && ext != 'jsx' && ext != 'cpp' && ext != 'cs' && ext != 'java') {
let code = '';
let codeText = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for(let i = 0; i < 18; i++){
code = code + codeText.charAt(Math.floor(Math.random() * codeText.length));
}
fs.mkdir(`${ext}Files`, (err) => {
if (err) {}
})
const randFile = () => {
fs.writeFile(`${ext}Files/${code}.${ext}`, '', () => success(code, ext))
}
randFile()
readline.close()
}
})