-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.coffee
More file actions
76 lines (70 loc) · 2.23 KB
/
start.coffee
File metadata and controls
76 lines (70 loc) · 2.23 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
shell = require 'shelljs'
prompt = require 'prompt'
sudo = require 'sudo-prompt'
prompts = require './prompts.coffee'
colors = require 'colors/safe'
fs = require 'fs'
path = require 'path'
homedir = require('os').homedir()
tenshidir = path.join(homedir, 'tenshi')
TinstallCheck = ->
if !fs.existsSync(tenshidir)
console.log ' '
console.log colors.green(':: Installing Tenshii-chan ::')
console.log ' '
shell.cd homedir
shell.exec 'git clone git://github.com/VNBot-Developers/Tenshi.git'
return firstTimeSetupTenshi()
checkForUpdates false
checkForUpdates = (comingFromInstall) ->
typebot = require "#{tenshidir}/config.json"
console.log colors.green(':: Checking for updates ::')
if comingFromInstall
console.log ' '
console.log colors.green(':: Tenshi has been installed to ' + tenshidir + ' ::')
shell.cd tenshidir
shell.exec 'git pull'
console.log ' '
console.log colors.green(':: Almost Finish <3 ::')
shell.exec 'npm update'
if typebot.type is "self"
shell.exec 'npm start'
else if typebot.type is "group"
shell.exec 'npm run group'
else
shell.exec 'npm start'
return
firstTimeSetupTenshi = ->
console.log colors.green(':: Installing dependencies ::')
shell.cd tenshidir
shell.exec 'npm install'
prompt.start()
prompt.message = ''
console.log ' '
console.log colors.green(':: Let\'s configure Tenshi-chan ::')
console.log ' '
prompt.get prompts, (err, result) ->
if err
console.error err
return process.exit(1)
if result.confirm == 'yes' or result.confirm == 'y'
return buildConfigFile(result)
console.log ' '
console.log colors.red(':: Your data not save, please run this tool again or edit config file by hand ::')
process.exit()
return
buildConfigFile = (result) ->
config =
username: result.username
password: result.password
type: result.type
prefix: result.prefix
fs.writeFile path.join(tenshidir, 'config.json'), JSON.stringify(config, null, '\u0009'), 'utf-8', (err) ->
if err
throw err
console.log ' '
console.log colors.green(':: Tenshi setup is done ::')
checkForUpdates true
return
shell.cd path.resolve(process.cwd())
TinstallCheck()