-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-local-environment.js
128 lines (117 loc) · 4.5 KB
/
install-local-environment.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
const compose = require('docker-compose');
const path = require('path');
const fs = require('fs');
const { setTimeout } = require('timers/promises')
async function init() {
log ('Starting installation of local environment.');
await downloadDockerImage().then(async () => {
await startServerAndDbContainer().then(async () => {
log('Finished core and database setup.');
log('Giving database time to get ready (try to increase timeout in install-local-environment.js if this step fails)', false);
await setTimeout(10000); // ugly hack to give SQL server more time until it is actually really ready
await installCore().then(async () => {
await installPlugins().then(async () => {
await installThemes().then(async () => {
await installAddonsAndCleanup().then(async () => {
log('Finished installing WordPress on localhost. Looking for content to import...')
if (fs.existsSync('./content.xml')) {
compose.run(
'wordpress-cli',
'wp import ./content.xml --authors=create',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Content import finished successfully.')},
err => { console.error('Content import failed:', err)}
);
} else {
console.error('Missing content import file (content.xml).');
}
});
});
});
});
});
});
}
init().catch(console.error.bind(console));
/**
* @param {string} msg
* @param {boolean} reverseColor
*/
function log (msg, reverseColor= true) {
console.log ( (reverseColor ? '\x1b[7m' : '') + msg + '\x1b[0m');
}
async function downloadDockerImage() {
log('Dowloading WordPress docker image...');
return await compose.pullAll({ cwd: path.join(__dirname), log: true});
}
async function startServerAndDbContainer() {
log('Starting WordPress server and database docker containers...');
return await compose.upAll({ cwd: path.join(__dirname), log: true, commandOptions: ['--force-recreate', '--build']});
}
async function installCore() {
log('Installing and configuring Wordpress core and admin...');
return await compose.run(
'wordpress-cli',
'wp core install --path=/var/www/html --url=http://localhost:1234" --title=TestSetup --admin_user=admin --admin_password=secret --admin_email=foo@bar.com',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
}
async function installPlugins() {
log('Installing WordPress plugins...');
return await compose.run(
'wordpress-cli',
/* specify the technical names (text domain) of plugins to be installed */
'wp plugin install --activate advanced-custom-fields contact-form-7 flamingo incompatibility-status polylang svg-support',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] });
}
async function installThemes() {
log('Installing and activating WordPress themes...');
/* add and activate (child) themes for your project here: */
await compose.run(
'wordpress-cli',
'wp theme install --activate twentytwentythree',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] });
}
async function installAddonsAndCleanup() {
log('Installing additional components and cleaning up...');
await compose.run(
'wordpress-cli',
'wp language core install --activate de_DE',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Installed core languages')},
err => { console.error('something went wrong:', err)}
);
await compose.run(
'wordpress-cli',
'wp language plugin install --all de_DE',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Installed plugin languages')},
err => { console.error('something went wrong:', err)}
);
await compose.run(
'wordpress-cli',
'wp language theme install --all de_DE',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Installed theme languages')},
err => { console.error('something went wrong:', err)}
);
await compose.run(
'wordpress-cli',
'wp theme delete twentytwentytwo twentytwentyone twentytwenty twentynineteen twentyseventeen twentysixteen twentyfifteen twentyfourteen twentythirteen twentytwelve twentyeleven twentyten',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Deleted unnsecessary themes')},
err => { console.error('something went wrong:', err)}
);
compose.run(
'wordpress-cli',
'wp plugin delete akismet hello',
{ cwd: path.join(__dirname), commandOptions: ['--rm'] })
.then(
() => { log('Deleted unnsecessary plugins')},
err => { console.error('something went wrong:', err)}
);
}