@caweb/cli 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/caweb +3 -17
- package/lib/caweb.js +20 -17
- package/lib/cli.js +194 -136
- package/lib/commands/destroy.js +66 -0
- package/lib/commands/index.js +29 -9
- package/lib/commands/shell.js +2 -3
- package/lib/commands/start.js +64 -72
- package/lib/commands/stop.js +41 -0
- package/lib/commands/tasks/update-plugins.js +15 -8
- package/lib/commands/test.js +15 -63
- package/lib/configs.js +79 -35
- package/lib/divi.js +28 -26
- package/lib/docker.js +24 -22
- package/lib/download-sources.js +14 -14
- package/lib/env.js +12 -7
- package/lib/options.js +1 -1
- package/lib/spinner.js +70 -0
- package/lib/wordpress.js +45 -35
- package/package.json +8 -3
- package/lib/commands/tasks/index.js +0 -13
- package/lib/config.yml +0 -3
package/lib/commands/start.js
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const path = require( 'path' );
|
|
10
|
-
const fs = require( 'fs-extra' );
|
|
11
|
-
const wpEnvStart = require('@wordpress/env/lib/commands/start');
|
|
12
|
-
const util = require( 'util' );
|
|
13
|
-
const { didCacheChange, getCache } = require( '@wordpress/env/lib/cache' );
|
|
14
|
-
const {
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import util from 'node:util';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import yaml from 'js-yaml';
|
|
5
|
+
import dockerCompose from 'docker-compose';
|
|
6
|
+
|
|
7
|
+
import { default as wpEnvStart} from '@wordpress/env/lib/commands/start.js';
|
|
8
|
+
import {
|
|
15
9
|
checkDatabaseConnection,
|
|
16
10
|
canAccessWPORG
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const yaml = require( 'js-yaml' );
|
|
21
|
-
const dockerCompose = require( 'docker-compose' );
|
|
11
|
+
} from '@wordpress/env/lib/wordpress.js';
|
|
12
|
+
|
|
13
|
+
import retry from '@wordpress/env/lib/retry.js';
|
|
22
14
|
|
|
23
15
|
const CONFIG_CACHE_KEY = 'config_checksum';
|
|
24
16
|
|
|
17
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
18
|
+
import { didCacheChange, getCache } from '@wordpress/env/lib/cache.js';
|
|
19
|
+
|
|
25
20
|
/**
|
|
26
21
|
* Internal dependencies
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
|
|
24
|
+
import { configureCAWeb } from '../caweb.js';
|
|
25
|
+
import {downloadSources } from '../download-sources.js';
|
|
26
|
+
import { configureWordPress } from '../wordpress.js';
|
|
27
|
+
import { buildWPEnvConfig, buildDockerComposeConfig } from '../configs.js';
|
|
32
28
|
|
|
33
29
|
/**
|
|
34
30
|
* Promisified dependencies
|
|
35
31
|
*/
|
|
36
|
-
const { writeFile } = fs.promises;
|
|
37
32
|
const sleep = util.promisify( setTimeout );
|
|
33
|
+
const { writeFile } = fs.promises;
|
|
38
34
|
|
|
39
35
|
/**
|
|
40
36
|
* Starts the development server.
|
|
@@ -50,7 +46,7 @@ const sleep = util.promisify( setTimeout );
|
|
|
50
46
|
* @param {boolean} options.subdomain True if converting to multisite subdomain.
|
|
51
47
|
*
|
|
52
48
|
*/
|
|
53
|
-
|
|
49
|
+
export default async function start({
|
|
54
50
|
spinner,
|
|
55
51
|
update,
|
|
56
52
|
xdebug,
|
|
@@ -60,6 +56,7 @@ module.exports = async function start({
|
|
|
60
56
|
multisite,
|
|
61
57
|
subdomain
|
|
62
58
|
}) {
|
|
59
|
+
|
|
63
60
|
spinner.text = 'Writing configuration file...';
|
|
64
61
|
|
|
65
62
|
// Write CAWeb .wp-env.json file.
|
|
@@ -93,27 +90,38 @@ module.exports = async function start({
|
|
|
93
90
|
( await canAccessWPORG() );
|
|
94
91
|
|
|
95
92
|
|
|
93
|
+
// Save pretext from wp-env if it exists for later.
|
|
94
|
+
let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
|
|
95
|
+
|
|
96
|
+
// We aren't done lets clear the default WordPress text.
|
|
97
|
+
spinner.prefixText = '';
|
|
98
|
+
spinner.text = '';
|
|
99
|
+
|
|
100
|
+
// Download any resources required for CAWeb.
|
|
101
|
+
if( shouldConfigureWp && ! bare ){
|
|
102
|
+
await downloadSources({spinner, config});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Write docker-compose.override.yml file to workDirectoryPath.
|
|
106
|
+
await writeFile(
|
|
107
|
+
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
108
|
+
yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
|
|
109
|
+
);
|
|
110
|
+
|
|
96
111
|
// Only run configurations when config has changed.
|
|
97
112
|
if( shouldConfigureWp ){
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
times: 30,
|
|
111
|
-
delay: 1000,
|
|
112
|
-
} );
|
|
113
|
-
|
|
114
|
-
// It takes 3-4 seconds for MySQL to be ready after it starts accepting connections.
|
|
115
|
-
await sleep( 4000 );
|
|
116
|
-
}
|
|
113
|
+
|
|
114
|
+
// We need to bring the WordPress and CLI instances up again so they pick up
|
|
115
|
+
// any config changes that may have been added to the docker-compose.override.yml.
|
|
116
|
+
await dockerCompose.upMany(
|
|
117
|
+
[
|
|
118
|
+
'wordpress', 'tests-wordpress',
|
|
119
|
+
'cli', 'tests-cli'
|
|
120
|
+
], {
|
|
121
|
+
cwd: workDirectoryPath,
|
|
122
|
+
commandOptions: ['--build', '--force-recreate'],
|
|
123
|
+
log: debug
|
|
124
|
+
})
|
|
117
125
|
|
|
118
126
|
// Make additional WordPress Configurations.
|
|
119
127
|
await Promise.all( [
|
|
@@ -125,17 +133,6 @@ module.exports = async function start({
|
|
|
125
133
|
} )
|
|
126
134
|
] );
|
|
127
135
|
|
|
128
|
-
// Download any resources required for CAWeb.
|
|
129
|
-
if( ! bare ){
|
|
130
|
-
await downloadSources({spinner, config});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Write docker-compose.override.yml file to workDirectoryPath.
|
|
134
|
-
await writeFile(
|
|
135
|
-
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
136
|
-
yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
|
|
137
|
-
);
|
|
138
|
-
|
|
139
136
|
// Make CAWeb WordPress Configurations.
|
|
140
137
|
await Promise.all( [
|
|
141
138
|
retry( () => configureCAWeb( 'development', config, spinner ), {
|
|
@@ -146,28 +143,23 @@ module.exports = async function start({
|
|
|
146
143
|
} ),
|
|
147
144
|
] );
|
|
148
145
|
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Start phpMyAdmin Service.
|
|
149
|
+
spinner.text = 'Starting phpMyAdmin Service';
|
|
151
150
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
[
|
|
156
|
-
'phpmyadmin','tests-phpmyadmin',
|
|
157
|
-
'wordpress', 'tests-wordpress',
|
|
158
|
-
'cli', 'tests-cli'
|
|
159
|
-
], {
|
|
151
|
+
await dockerCompose.upOne(
|
|
152
|
+
'phpmyadmin',
|
|
153
|
+
{
|
|
160
154
|
cwd: workDirectoryPath,
|
|
161
155
|
commandOptions: ['--build', '--force-recreate'],
|
|
162
156
|
log: debug
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
spinner.prefixText = preText +
|
|
166
|
-
`phpMyAdmin development site started at http://localhost:8080\n` +
|
|
167
|
-
`phpMyAdmin test site started at http://localhost:9090\n\n`;
|
|
157
|
+
}
|
|
158
|
+
)
|
|
168
159
|
|
|
169
|
-
|
|
160
|
+
spinner.prefixText = preText +
|
|
161
|
+
`phpMyAdmin site started at http://localhost:8080\n\n`;
|
|
170
162
|
|
|
171
|
-
|
|
163
|
+
spinner.text = 'Done!';
|
|
172
164
|
|
|
173
165
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
4
|
+
import { v2 as dockerCompose } from 'docker-compose';
|
|
5
|
+
|
|
6
|
+
import { default as wpEnvStop } from '@wordpress/env/lib/commands/stop.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Promisified dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Starts the development server.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
21
|
+
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
22
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export default async function stop({
|
|
26
|
+
spinner,
|
|
27
|
+
debug,
|
|
28
|
+
}) {
|
|
29
|
+
const config = await loadConfig(path.resolve('.'));
|
|
30
|
+
const { workDirectoryPath } = config;
|
|
31
|
+
|
|
32
|
+
// Stop wp-env services
|
|
33
|
+
await wpEnvStop({spinner, debug });
|
|
34
|
+
|
|
35
|
+
// Stop phpMyAdmin as well
|
|
36
|
+
await dockerCompose.down( {
|
|
37
|
+
config: path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
38
|
+
log: debug,
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* External dependencies
|
|
4
3
|
*/
|
|
5
|
-
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
const path = require( 'path' );
|
|
12
|
-
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
10
|
+
import {runCLICmds} from '../../docker.js';
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Promisified dependencies
|
|
@@ -22,15 +20,24 @@ const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
|
22
20
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
23
21
|
* @param {string} options.environment Which environment to updated.
|
|
24
22
|
*/
|
|
25
|
-
|
|
23
|
+
export default async function updatePlugins({
|
|
26
24
|
spinner,
|
|
27
|
-
environment
|
|
25
|
+
environment,
|
|
26
|
+
slug
|
|
28
27
|
}) {
|
|
29
28
|
|
|
30
29
|
spinner.text = "Updating plugins...";
|
|
31
30
|
const config = await loadConfig(path.resolve('.'));
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
let plugin = 'all' === slug ? '--all' : slug;
|
|
33
|
+
|
|
34
|
+
let result = await runCLICmds(
|
|
35
|
+
environment,
|
|
36
|
+
[`wp plugin update ${plugin}`],
|
|
37
|
+
config
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
spinner.prefixText = `${result}\n`;
|
|
34
41
|
|
|
35
42
|
spinner.text = 'Completed updating plugins!'
|
|
36
43
|
|
package/lib/commands/test.js
CHANGED
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* External dependencies
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const SimpleGit = require( 'simple-git' );
|
|
8
|
-
const { execSync } = require( 'child_process' );
|
|
9
|
-
const dockerCompose = require( 'docker-compose' );
|
|
10
|
-
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
11
|
-
const run = require('@wordpress/env/lib/commands/run');
|
|
12
|
-
const getHostUser = require( '@wordpress/env/lib/get-host-user' );
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* Internal dependencies
|
|
16
9
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = require('../docker');
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
buildWPEnvConfig,
|
|
23
|
-
buildDockerComposeConfig
|
|
24
|
-
} = require('../configs');
|
|
25
|
-
|
|
26
|
-
const pkg = require( '../../package.json' );
|
|
27
|
-
const { DIVI_OPTIONS } = require('../options');
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
isDiviThemeActive,
|
|
31
|
-
configureDivi
|
|
32
|
-
} = require('../divi');
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
activateCAWeb,
|
|
36
|
-
configureCAWeb
|
|
37
|
-
} = require('../caweb');
|
|
38
|
-
|
|
39
|
-
const {
|
|
40
|
-
generateHTAccess
|
|
41
|
-
} = require( '../wordpress' );
|
|
10
|
+
import { runCLICmds } from '../docker.js';
|
|
11
|
+
import { activateCAWeb } from '../caweb.js';
|
|
42
12
|
|
|
43
13
|
/**
|
|
44
14
|
* Promisified dependencies
|
|
45
15
|
*/
|
|
46
|
-
const { writeFile } = fs.promises;
|
|
47
16
|
|
|
48
17
|
/**
|
|
49
18
|
* Test code.
|
|
@@ -53,42 +22,25 @@ const { writeFile } = fs.promises;
|
|
|
53
22
|
* @param {boolean} options.environment Which environment to test in.
|
|
54
23
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
55
24
|
*/
|
|
56
|
-
|
|
25
|
+
export default async function test({
|
|
57
26
|
spinner,
|
|
58
|
-
environment,
|
|
59
27
|
debug,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}) {
|
|
28
|
+
environment
|
|
29
|
+
} ) {
|
|
63
30
|
|
|
64
|
-
|
|
31
|
+
spinner.text = "Testing Code Functionality";
|
|
65
32
|
const config = await loadConfig(path.resolve('.'));
|
|
66
|
-
const {WP_PERMALINK} = config.env[ environment ].config
|
|
67
|
-
const { workDirectoryPath} = config;
|
|
68
|
-
const {name} = getHostUser();
|
|
69
|
-
|
|
70
|
-
spinner.text = "Testing code...";
|
|
71
33
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
34
|
+
let result = await runCLICmds(
|
|
35
|
+
'development',
|
|
36
|
+
['wp --version'],
|
|
37
|
+
config,
|
|
38
|
+
spinner
|
|
77
39
|
)
|
|
78
40
|
|
|
79
|
-
if( '' !== result.out ) {
|
|
80
|
-
console.log( JSON.parse(result.out))
|
|
81
|
-
}else{
|
|
82
|
-
console.log(result);
|
|
83
|
-
}
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
spinner.text = 'Completed Testing code...'
|
|
87
41
|
|
|
88
|
-
|
|
89
|
-
console.log(error)
|
|
42
|
+
console.log( result );
|
|
90
43
|
|
|
91
|
-
|
|
92
|
-
}
|
|
44
|
+
spinner.text = "Done!";
|
|
93
45
|
|
|
94
46
|
};
|
package/lib/configs.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
import getHostUser from '@wordpress/env/lib/get-host-user.js';
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Promisified dependencies
|
|
11
|
+
*/
|
|
12
|
+
const { writeFile } = fs.promises;
|
|
13
|
+
|
|
14
|
+
const localPath = path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/package.json') )
|
|
15
|
+
const pkg = JSON.parse( await fs.readFile(localPath) );
|
|
8
16
|
|
|
9
17
|
/**
|
|
10
18
|
* Build .wp-env.json
|
|
@@ -44,6 +52,11 @@ const buildWPEnvConfig = (bare, multisite) => {
|
|
|
44
52
|
* @returns object
|
|
45
53
|
*/
|
|
46
54
|
const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
55
|
+
const {name} = getHostUser();
|
|
56
|
+
|
|
57
|
+
// generate cli config file for cli containers.
|
|
58
|
+
generateCLIConfig(workDirectoryPath);
|
|
59
|
+
|
|
47
60
|
let dockerConfig = {
|
|
48
61
|
version: '3.7',
|
|
49
62
|
services: {
|
|
@@ -52,21 +65,36 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
|
52
65
|
restart: 'always',
|
|
53
66
|
ports: ['8080:80'],
|
|
54
67
|
environment: {
|
|
55
|
-
|
|
68
|
+
PMA_HOSTS : 'mysql,tests-mysql',
|
|
56
69
|
UPLOAD_LIMIT: '3G',
|
|
57
70
|
MEMORY_LIMIT: '5G',
|
|
58
71
|
MAX_EXECUTION_TIME: 7200
|
|
59
72
|
}
|
|
60
73
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
cli: {
|
|
75
|
+
build: {
|
|
76
|
+
context: '.',
|
|
77
|
+
dockerfile: 'CLI.Dockerfile'
|
|
78
|
+
},
|
|
79
|
+
volumes: [ path.join(workDirectoryPath, 'config.yml') + `:/home/${name}/.wp-cli/config.yml` ]
|
|
80
|
+
},
|
|
81
|
+
"tests-cli": {
|
|
82
|
+
build: {
|
|
83
|
+
context: '.',
|
|
84
|
+
dockerfile: 'Tests-CLI.Dockerfile'
|
|
85
|
+
},
|
|
86
|
+
volumes: [ path.join(workDirectoryPath, 'config.yml') + `:/home/${name}/.wp-cli/config.yml`]
|
|
87
|
+
},
|
|
88
|
+
wordpress: {
|
|
89
|
+
build: {
|
|
90
|
+
context: '.',
|
|
91
|
+
dockerfile: 'WordPress.Dockerfile'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"tests-wordpress": {
|
|
95
|
+
build: {
|
|
96
|
+
context: '.',
|
|
97
|
+
dockerfile: 'Tests-WordPress.Dockerfile'
|
|
70
98
|
}
|
|
71
99
|
}
|
|
72
100
|
}
|
|
@@ -87,41 +115,57 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
|
87
115
|
|
|
88
116
|
// Add extra volumes to WordPress instances.
|
|
89
117
|
if( extraVolumes.length ){
|
|
90
|
-
|
|
91
118
|
dockerConfig.services.wordpress = {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
volumes: extraVolumes,
|
|
119
|
+
...dockerConfig.services.wordpress,
|
|
120
|
+
volumes: [
|
|
121
|
+
...extraVolumes
|
|
122
|
+
],
|
|
97
123
|
};
|
|
98
124
|
dockerConfig.services.cli = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
125
|
+
...dockerConfig.services.cli,
|
|
126
|
+
volumes: [
|
|
127
|
+
...dockerConfig.services.cli.volumes,
|
|
128
|
+
...extraVolumes
|
|
129
|
+
],
|
|
104
130
|
};
|
|
105
131
|
dockerConfig.services['tests-wordpress'] = {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
volumes: extraVolumes,
|
|
132
|
+
...dockerConfig.services['tests-wordpress'],
|
|
133
|
+
volumes: [
|
|
134
|
+
...extraVolumes
|
|
135
|
+
],
|
|
111
136
|
};
|
|
112
137
|
dockerConfig.services['tests-cli'] = {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
...dockerConfig.services['tests-cli'],
|
|
139
|
+
volumes: [
|
|
140
|
+
...dockerConfig.services['tests-cli'].volumes,
|
|
141
|
+
...extraVolumes
|
|
142
|
+
],
|
|
118
143
|
};
|
|
144
|
+
|
|
119
145
|
}
|
|
120
146
|
|
|
121
147
|
return dockerConfig;
|
|
122
148
|
}
|
|
123
149
|
|
|
124
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Generate config.yml
|
|
152
|
+
*
|
|
153
|
+
* @param {string} workDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
154
|
+
*
|
|
155
|
+
* @returns void
|
|
156
|
+
*/
|
|
157
|
+
async function generateCLIConfig(workDirectoryPath){
|
|
158
|
+
const yml = {
|
|
159
|
+
path: '/var/www/html',
|
|
160
|
+
apache_modules: ['mod_rewrite']
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
await writeFile(
|
|
164
|
+
path.join(workDirectoryPath, 'config.yml'),
|
|
165
|
+
yaml.dump(yml));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export {
|
|
125
169
|
buildWPEnvConfig,
|
|
126
170
|
buildDockerComposeConfig
|
|
127
171
|
}
|
package/lib/divi.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* External dependencies
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* Internal dependencies
|
|
9
3
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { runCLICmds } from './docker.js';
|
|
5
|
+
import { DIVI_OPTIONS } from './options.js';
|
|
12
6
|
|
|
13
7
|
|
|
14
8
|
/**
|
|
15
9
|
* Checks if Divi Theme is active for the WordPress Environment.
|
|
16
10
|
*
|
|
17
|
-
* @param {string}
|
|
18
|
-
* @param {WPConfig}
|
|
11
|
+
* @param {string} environment Which environment to activate the theme on.
|
|
12
|
+
* @param {WPConfig} config The wp-env config object.
|
|
13
|
+
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
19
14
|
*/
|
|
20
15
|
async function isDiviThemeActive(
|
|
21
16
|
environment,
|
|
22
|
-
config
|
|
17
|
+
config,
|
|
18
|
+
spinner
|
|
23
19
|
){
|
|
24
20
|
|
|
25
|
-
return await
|
|
21
|
+
return await runCLICmds(
|
|
26
22
|
environment,
|
|
27
23
|
['wp theme is-active Divi'],
|
|
28
|
-
config
|
|
24
|
+
config,
|
|
25
|
+
spinner
|
|
29
26
|
);
|
|
30
27
|
|
|
31
28
|
}
|
|
@@ -40,31 +37,34 @@ async function isDiviThemeActive(
|
|
|
40
37
|
*/
|
|
41
38
|
async function configureDivi( environment, config, spinner ) {
|
|
42
39
|
|
|
43
|
-
const activeTheme = await isDiviThemeActive( environment, config );
|
|
40
|
+
const activeTheme = await isDiviThemeActive( environment, config, spinner );
|
|
44
41
|
|
|
45
42
|
// if Divi theme is active.
|
|
46
43
|
if( false !== activeTheme ){
|
|
47
44
|
let cmds = [];
|
|
48
|
-
let diviOptions = await
|
|
45
|
+
let diviOptions = await runCLICmds(
|
|
49
46
|
environment,
|
|
50
47
|
[ 'wp option get et_divi --format=json' ],
|
|
51
|
-
config
|
|
48
|
+
config,
|
|
49
|
+
spinner
|
|
52
50
|
)
|
|
53
|
-
let diviBuilderOptions = await
|
|
51
|
+
let diviBuilderOptions = await runCLICmds(
|
|
54
52
|
environment,
|
|
55
53
|
[ 'wp option get et_bfb_settings --format=json' ],
|
|
56
|
-
config
|
|
54
|
+
config,
|
|
55
|
+
spinner
|
|
57
56
|
)
|
|
58
|
-
let diviUpdateOptions = await
|
|
57
|
+
let diviUpdateOptions = await runCLICmds(
|
|
59
58
|
environment,
|
|
60
59
|
[ 'wp option get et_automatic_updates_options --format=json' ],
|
|
61
|
-
config
|
|
60
|
+
config,
|
|
61
|
+
spinner
|
|
62
62
|
)
|
|
63
63
|
|
|
64
64
|
// parse the options into a json object.
|
|
65
|
-
diviOptions = diviOptions ? JSON.parse( diviOptions ) : {};
|
|
66
|
-
diviBuilderOptions = diviBuilderOptions ? JSON.parse( diviBuilderOptions ) : {};
|
|
67
|
-
diviUpdateOptions =
|
|
65
|
+
diviOptions = typeof result === 'object' && ! diviOptions.exitCode ? JSON.parse( diviOptions ) : {};
|
|
66
|
+
diviBuilderOptions = typeof result === 'object' && ! diviBuilderOptions.exitCode ? JSON.parse( diviBuilderOptions ) : {};
|
|
67
|
+
diviUpdateOptions = typeof result === 'object' && ! diviUpdateOptions.exitCode ? JSON.parse( diviUpdateOptions ) : {};
|
|
68
68
|
|
|
69
69
|
// iterate over mapped Divi option groups.
|
|
70
70
|
Object.entries(DIVI_OPTIONS).forEach(([group, options]) => {
|
|
@@ -95,6 +95,7 @@ async function configureDivi( environment, config, spinner ) {
|
|
|
95
95
|
diviBuilderOptions = JSON.stringify( diviBuilderOptions );
|
|
96
96
|
diviUpdateOptions = JSON.stringify( diviUpdateOptions );
|
|
97
97
|
|
|
98
|
+
// update each option.
|
|
98
99
|
cmds.push(`wp option update et_divi '${diviOptions}' --format=json`);
|
|
99
100
|
cmds.push(`wp option update et_bfb_settings '${diviBuilderOptions}' --format=json`);
|
|
100
101
|
cmds.push(`wp option update et_automatic_updates_options '${diviUpdateOptions}' --format=json`);
|
|
@@ -109,17 +110,18 @@ async function configureDivi( environment, config, spinner ) {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
// Execute theme option commands.
|
|
112
|
-
await
|
|
113
|
+
await runCLICmds(
|
|
113
114
|
environment,
|
|
114
115
|
cmds,
|
|
115
|
-
config
|
|
116
|
+
config,
|
|
117
|
+
spinner
|
|
116
118
|
)
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
|
|
120
122
|
}
|
|
121
123
|
|
|
122
|
-
|
|
124
|
+
export {
|
|
123
125
|
configureDivi,
|
|
124
126
|
isDiviThemeActive
|
|
125
127
|
};
|