This repository has been archived by the owner on Nov 27, 2021. It is now read-only.
/
installation.js
179 lines (157 loc) · 4.46 KB
/
installation.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
const url = require('url')
const inquirer = require('inquirer')
const WpApiPrompt = require('./wp-api')
class InstallationPrompt {
constructor(project) {
this.project = project || undefined
this.privateKey = undefined
}
async init() {
const answers = await inquirer.prompt({
type: 'list',
name: 'origin',
message: 'Do you want to install WordPress from scratch (New) or install from a local/remote source',
choices: [
{name: 'New', value: 'new'},
{name: 'Remote/Local wordup archive', value: 'wordup-archive'},
{name: 'Wordpress hosted website (wordup-connect)', value: 'wordup-connect'},
],
})
this.origin = answers.origin
if (answers.origin === 'new') {
await this.askNew()
} else if (answers.origin === 'wordup-archive') {
await this.askWordupArchive()
} else if (answers.origin === 'wordup-connect') {
await this.askWordupConnect()
}
}
async askWordupArchive() {
const questions = [{
type: 'input',
name: 'path',
message: 'Local or remote wordup archive file to build on the project',
validate: function (val) {
if (!val) {
return 'Please provide a path or an url'
}
return true
},
}]
const answers = await inquirer.prompt(questions)
const wpInstall = 'archive:'+answers.path
if(this.project){
this.project.setWordupPkg('wpInstall',wpInstall)
}else{
return wpInstall
}
}
async askWordupConnect(defaultUrl = undefined) {
const questions = [{
type: 'input',
name: 'url',
message: 'Public URL of your WordPress hosted website (with wordup-connect installed)',
validate: function (value) {
const parsedUrl = url.parse(value)
if (parsedUrl.protocol !== 'https:') {
return 'Please enter a valid secure domain (https://)'
}
if (parsedUrl.hostname === 'localhost' || parsedUrl.hostname === '127.0.0.1') {
return 'You cannot use localhost as a source domain'
}
return true
},
when: function () {
return !defaultUrl
},
}, {
type: 'input',
name: 'privateKey',
message: function (answers) {
const website = answers.url || defaultUrl
return 'Secret key (Visit wordup settings on ' + website + ', to get key)'
},
transformer: function (val) {
let transformed = val
if (val.length > 1) {
const lastDigit = val.substr(-1)
transformed = lastDigit.padStart(val.length, '*')
}
return transformed
},
validate: function (val) {
if (!val) {
return 'Please provide a key'
}
return true
},
}]
const answers = await inquirer.prompt(questions)
this.privateKey = answers.privateKey
if(answers.url){
const wpInstall = 'wordup-connect:'+answers.url
if(this.project){
this.project.setWordupPkg('wpInstall',wpInstall)
}else{
return wpInstall
}
}
}
async askNew(projectName = '') {
if(this.project){
projectName = this.project.wPkg('projectName')
}
const questions = [{
type: 'input',
name: 'title',
message: 'Title of the WordPress installation',
default: projectName,
},
{
type: 'input',
name: 'admin',
message: 'Admin user',
default: 'admin',
},
{
type: 'input',
name: 'password',
message: 'Admin password (Just for development purposes)',
default: 123456,
},
{
type: 'input',
name: 'email',
message: 'Admin email',
validate: function (val) {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val)) {
return 'Please provide at least a dummy E-Mail like test@example.com'
}
return true
},
}]
const answers = await inquirer.prompt(questions)
const plugins = new WpApiPrompt('plugins')
await plugins.ask()
const themes = new WpApiPrompt('themes')
await themes.ask()
const wpInstall = {
title: answers.title,
language:"en_US",
users:[{
name: answers.admin,
password: answers.password,
email: answers.email,
role:"administrator"
}],
plugins:plugins.getList(),
themes:themes.getList()
}
if(this.project){
this.project.setWordupPkg('wpInstall', wpInstall)
}else{
return wpInstall
}
}
}
module.exports = InstallationPrompt