-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
78 lines (58 loc) · 2.21 KB
/
index.ts
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
#! /usr/bin/env node
import sh from 'shelljs'
import { colors } from './src/colors.js'
import { program } from './src/commander.js'
import { getRuntime } from './src/getRuntime.js'
import { getTemplate } from './src/getTemplate.js'
import { precheck } from './src/precheck.js'
import { initAnimation } from './src/animation.js'
export const main = () => {
const dupVal = 5
let animations: NodeJS.Timeout[] = []
try {
console.log(colors.info('\nStarting...'))
console.log(colors.info('Running Pre-checks...'))
// Check to see if sh deps are installed
precheck()
// Read params from cli
program.parse(process.argv)
const options = program.opts()
if (!options.projectName) {
console.log(colors.error('Error: No Project Name specified. Please include "--project-name <project-name>"'))
sh.exit(0)
}
const result = getTemplate(options)
if (result?.path && result?.replacementName && result?.repo) {
const projectName = options.projectName
const { path, replacementName, repo } = result
console.log(colors.warning(`Creating project ${projectName} in ${path}`))
animations = Array.from(Array(dupVal).keys()).map(_ => initAnimation())
const runtime = getRuntime(options)
sh.exec(`git clone ${repo} ${projectName}`)
sh.cd(path)
// Remove the .git folder
sh.exec(`rm -rf .git`)
// Replace all instances of template name with new project name
sh.ls('*.*').forEach((file: string) => {
sh.sed('-i', replacementName, projectName, file)
})
console.log(colors.info(`Running with ${runtime.name}`))
// Install deps
sh.exec(runtime.install)
if (sh.error()) {
sh.exec(runtime.curl)
sh.exec(runtime.install)
}
sh.cd('../')
Array.from(Array(dupVal).keys()).forEach((_, i) => clearInterval(animations[i]))
// Print our done message
console.log(colors.info.bold('Complete! 🎉'))
}
} catch (error) {
console.error(
colors.error(`Uh oh - Something happened, please create an issue here: \n\nhttps://github.com/lundjrl/repo-cli`),
)
Array.from(Array(dupVal).keys()).forEach((_, i) => clearInterval(animations[i]))
}
}
main()