-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpm-init.js
216 lines (213 loc) · 6.23 KB
/
wpm-init.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const inquirer = require('inquirer');
const fs = require('fs');
const exists = require('path-exists');
clear();
console.log(
chalk.blue.bgWhite.bold(
figlet.textSync('Initialize', { horizontalLayout: 'full' })
)
);
exists(`${process.cwd()}/Migrate.json`).then(exists => {
if (!exists) {
console.log(chalk.blue('You\'r first run, please spesify params, or simply create Migrate.json'));
console.log(chalk.red.bgWhite.bold('https://github.com/cagataycali/wordpress-migrate-tool/blob/master/example/Migrate.json'));
var questions = [
{
type: 'input',
name: 'host',
message: 'What is your remote host dns or ip?',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a dns or ip';
}
},
{
type: 'input',
name: 'local',
message: 'What is your local wordpress directory?',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a directory';
}
},
{
type: 'input',
name: 'remote',
message: 'What is your remote wordpress directory?',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a directory';
}
},
{
type: 'input',
name: 'username',
message: 'What is your remote ssh username?',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a username';
}
},
{
type: 'input',
name: 'password',
message: 'What is your remote ssh password?',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a username';
}
},
{
type: 'confirm',
name: 'allowPassword',
message: 'Is ssh needs password?',
default: false
},
{
type: 'input',
name: 'port',
message: 'What is your remote ssh port?',
default: 22,
validate: function (value) {
var valid = value > 0;
return valid || 'Please enter a port';
}
},
{
type: 'input',
name: 'key',
message: 'What is your local ssh keygen dir?',
default: '/.ssh/id_rsa',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter a directory';
}
},
{
type: 'input',
name: 'mysql_local_host',
message: 'What is your local mysql host?',
default: 'localhost',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your local mysql host';
}
},
{
type: 'input',
name: 'mysql_local_username',
message: 'What is your local mysql username?',
default: 'root',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your local mysql username';
}
},
{
type: 'input',
name: 'mysql_local_password',
message: 'What is your local mysql password?',
default: 'root',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your local mysql password';
}
},
{
type: 'input',
name: 'mysql_local_database',
message: 'What is your local mysql database?',
default: 'wordpress',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your local mysql database';
}
},
{
type: 'input',
name: 'mysql_remote_host',
message: 'What is your remote mysql host?',
default: 'remotehost',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your remote mysql host';
}
},
{
type: 'input',
name: 'mysql_remote_username',
message: 'What is your remote mysql username?',
default: 'root',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your remote mysql username';
}
},
{
type: 'input',
name: 'mysql_remote_password',
message: 'What is your remote mysql password?',
default: 'root',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your remote mysql password';
}
},
{
type: 'input',
name: 'mysql_remote_database',
message: 'What is your remote mysql database?',
default: 'wordpress',
validate: function (value) {
var valid = value.trim().length > 0;
return valid || 'Please enter your remote mysql database';
}
}
];
inquirer.prompt(questions).then(function (answers) {
console.log('\nPreferences:');
let pref = {
"host": answers.host,
"user": answers.username,
"password": answers.allowPassword ? answers.password : '',
"local": answers.local,
"remote": answers.remote,
"port": answers.port,
"mysql": {
"local": {
"host": answers.mysql_local_host,
"username": answers.mysql_local_username,
"password": answers.mysql_local_password,
"database": answers.mysql_local_database,
},
"remote": {
"host": answers.mysql_remote_host,
"username": answers.mysql_remote_username,
"password": answers.mysql_remote_password,
"database": answers.mysql_remote_database,
}
},
"key": answers.key
}
fs.writeFileSync(`${process.cwd()}/Migrate.json`, JSON.stringify(pref, null, '\t'));
clear();
console.log(
chalk.blue.bgWhite.bold(
figlet.textSync('Done!', { horizontalLayout: 'full' })
)
);
});
} else {
const config = require(`${process.cwd()}/Migrate.json`);
console.log(config);
clear();
console.log(
chalk.blue.bgWhite.bold(
figlet.textSync('Done!', { horizontalLayout: 'full' })
)
);
}
});