-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.js
More file actions
89 lines (76 loc) · 2.48 KB
/
Copy pathgenerator.js
File metadata and controls
89 lines (76 loc) · 2.48 KB
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
#!/usr/bin/env node
import yargs from 'yargs'
import chalk from 'chalk'
import inqurer from 'inquirer'
import { createSpinner } from 'nanospinner';
import fs from 'fs'
// run terminal command
import { exec } from 'child_process';
let project = {};
const commmon_files = [
"package.json",
"loading.html",
"index.js",
"public/worker.js",
"public/global.css",
"complie.js",
"app/index.waterx",
"PostLoadHTML.js",
"postLoadJavascript.js",
"workerInit.js",
"webpack.config.js"
]
const cdn = "https://pub-3d17685d6a884313b28a5105af37d0b1.r2.dev/"
async function main() {
await askName();
await create();
}
async function askName() {
const answers = await inqurer.prompt({
name: "project name",
type: "input",
message: "Project name"
})
project.name = answers["project name"]
}
async function create() {
console.log(chalk.green(`Creating ${project.name}...`))
const spinner = createSpinner('Creating nesscessary folder and downloading file ...').start()
// create project
fs.mkdirSync(project.name)
// Create public and app folder
fs.mkdirSync(project.name + "/public");
fs.mkdirSync(project.name + "/app");
for(var file of commmon_files) {
// log
// const spinner2 = createSpinner(`Creating ${file}...`).start()
try {
// console.log(chalk.green(`Creating ${file}...`))
// Fetch the file from intenet
const response = await fetch(cdn + file)
// console.log(chalk.green(`Downloaded ${file}...`))
// spinner.success({ text: `Done! ${file}` })
const code = await response.text()
fs.writeFileSync(project.name + "/" + file, code)
} catch (error) {
spinner2.error({ text: error })
return
}
}
spinner.success({ text: 'Success!' })
const spinner2 = createSpinner('Running build').start()
// run npm install
exec(`cd ${project.name} && npm install`, (error, stdout, stderr) => {
if (error) {
spinner2.error({ text: error })
return
} else {
spinner2.success({ text: 'Success!' })
console.log(chalk.green(stdout))
console.log(chalk.blue(`\t\tCreated ${project.name}!`))
console.log(chalk.blue(`\t\tRun script using npm run dev`))
console.log(chalk.blue(`\t\tIf you want to deploy it. Just find some server and npm run start`))
}
})
}
main()