forked from vuestorefront/vue-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall.js
117 lines (100 loc) · 2.79 KB
/
all.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
'use strict'
const shell = require('shelljs')
const jsonFile = require('jsonfile')
const installer = require('./installer')
class Manager extends installer.Manager {
/**
* {@inheritDoc}
*/
initBackend () {
if (Manager.isBackendInstalledLocally()) {
return this.backend.goToDirectory(Manager.getBackendDirectory())
.then(this.backend.dockerComposeUp.bind(this.backend))
.then(this.backend.runDevEnvironment.bind(this.backend))
} else {
return Promise.resolve()
}
}
/**
* {@inheritDoc}
*/
initStorefront () {
return this.storefront.goToDirectory()
.then(this.storefront.npmBuild.bind(this.storefront))
.then(this.storefront.runDevEnvironment.bind(this.storefront))
}
/**
* {@inheritDoc}
*/
static showWelcomeMessage () {
installer.Message.greeting([
'Hi, seat, relax...',
'I\'ll start everything for you ;)'
])
}
/**
* {@inheritDoc}
*/
showGoodbyeMessage () {
return new Promise((resolve, reject) => {
installer.Message.greeting([
'Congratulations!',
'',
'You\'ve just successfully started vue-storefront.',
'All required servers are running in background',
'',
'Storefront: http://localhost:3000',
'Backend: ' + (Manager.isBackendInstalledLocally() ? 'http://localhost:8080' : installer.STOREFRONT_REMOTE_BACKEND_URL),
'',
'Good Luck!'
], true)
resolve()
})
}
/**
* Check if backend was installed locally
*
* @returns {boolean}
*/
static isBackendInstalledLocally () {
if (typeof installer.Abstract.wasLocalBackendInstalled === 'undefined') {
let config = jsonFile.readFileSync(installer.TARGET_CONFIG_FILE)
installer.Abstract.wasLocalBackendInstalled = Boolean(config.install.is_local_backend)
}
return Boolean(installer.Abstract.wasLocalBackendInstalled)
}
/**
* Return backend directory
*
* @returns {string}
*/
static getBackendDirectory () {
if (typeof installer.Abstract.backendDir === 'undefined') {
let config = jsonFile.readFileSync(installer.TARGET_CONFIG_FILE)
installer.Abstract.backendDir = config.install.backend_dir
}
return installer.Abstract.backendDir
}
}
/**
* Predefine class static variables
*/
installer.Abstract.wasLocalBackendInstalled = undefined
installer.Abstract.backendDir = undefined
/**
* Pre-loading staff
*/
Manager.checkUserOS()
Manager.showWelcomeMessage();
/**
* This is where all the magic happens
*/
(async function () {
let manager = new Manager()
await manager.tryToCreateLogFiles()
.then(manager.initBackend.bind(manager))
.then(manager.initStorefront.bind(manager))
.then(manager.showGoodbyeMessage.bind(manager))
.catch(installer.Message.error)
shell.exit(0)
})()