@caweb/cli 1.0.5 → 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 +52 -68
- package/lib/commands/stop.js +41 -0
- package/lib/commands/tasks/update-plugins.js +15 -8
- package/lib/commands/test.js +16 -69
- package/lib/configs.js +9 -19
- 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 -27
- package/package.json +8 -3
- package/lib/commands/tasks/index.js +0 -13
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,38 +90,26 @@ module.exports = async function start({
|
|
|
93
90
|
( await canAccessWPORG() );
|
|
94
91
|
|
|
95
92
|
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
// Save pretext from wp-env if it exists for later.
|
|
99
|
-
let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
// We aren't done lets clear the default WordPress text.
|
|
103
|
-
spinner.prefixText = '';
|
|
104
|
-
spinner.text = '';
|
|
105
|
-
|
|
106
|
-
await checkDatabaseConnection( config );
|
|
107
|
-
} catch ( error ) {
|
|
108
|
-
// Wait 30 seconds for MySQL to accept connections.
|
|
109
|
-
await retry( () => checkDatabaseConnection( config ), {
|
|
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
|
-
}
|
|
93
|
+
// Save pretext from wp-env if it exists for later.
|
|
94
|
+
let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
|
|
117
95
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
+
);
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
126
|
-
yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
|
|
127
|
-
);
|
|
111
|
+
// Only run configurations when config has changed.
|
|
112
|
+
if( shouldConfigureWp ){
|
|
128
113
|
|
|
129
114
|
// We need to bring the WordPress and CLI instances up again so they pick up
|
|
130
115
|
// any config changes that may have been added to the docker-compose.override.yml.
|
|
@@ -158,24 +143,23 @@ module.exports = async function start({
|
|
|
158
143
|
} ),
|
|
159
144
|
] );
|
|
160
145
|
|
|
161
|
-
|
|
162
|
-
spinner.text = 'Starting phpMyAdmin Service';
|
|
146
|
+
}
|
|
163
147
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
// Start phpMyAdmin Service.
|
|
149
|
+
spinner.text = 'Starting phpMyAdmin Service';
|
|
150
|
+
|
|
151
|
+
await dockerCompose.upOne(
|
|
152
|
+
'phpmyadmin',
|
|
153
|
+
{
|
|
168
154
|
cwd: workDirectoryPath,
|
|
169
155
|
commandOptions: ['--build', '--force-recreate'],
|
|
170
156
|
log: debug
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
spinner.prefixText = preText +
|
|
174
|
-
`phpMyAdmin development site started at http://localhost:8080\n` +
|
|
175
|
-
`phpMyAdmin test site started at http://localhost:9090\n\n`;
|
|
157
|
+
}
|
|
158
|
+
)
|
|
176
159
|
|
|
177
|
-
|
|
160
|
+
spinner.prefixText = preText +
|
|
161
|
+
`phpMyAdmin site started at http://localhost:8080\n\n`;
|
|
178
162
|
|
|
179
|
-
|
|
163
|
+
spinner.text = 'Done!';
|
|
180
164
|
|
|
181
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,50 +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' );
|
|
13
|
-
const yaml = require( 'js-yaml' );
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
14
6
|
|
|
15
7
|
/**
|
|
16
8
|
* Internal dependencies
|
|
17
9
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = require('../docker');
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
buildWPEnvConfig,
|
|
24
|
-
buildDockerComposeConfig
|
|
25
|
-
} = require('../configs');
|
|
26
|
-
|
|
27
|
-
const pkg = require( '../../package.json' );
|
|
28
|
-
const { DIVI_OPTIONS } = require('../options');
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
isDiviThemeActive,
|
|
32
|
-
configureDivi
|
|
33
|
-
} = require('../divi');
|
|
34
|
-
|
|
35
|
-
const {
|
|
36
|
-
activateCAWeb,
|
|
37
|
-
configureCAWeb
|
|
38
|
-
} = require('../caweb');
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
generateHTAccess
|
|
42
|
-
} = require( '../wordpress' );
|
|
10
|
+
import { runCLICmds } from '../docker.js';
|
|
11
|
+
import { activateCAWeb } from '../caweb.js';
|
|
43
12
|
|
|
44
13
|
/**
|
|
45
14
|
* Promisified dependencies
|
|
46
15
|
*/
|
|
47
|
-
const { writeFile } = fs.promises;
|
|
48
16
|
|
|
49
17
|
/**
|
|
50
18
|
* Test code.
|
|
@@ -54,46 +22,25 @@ const { writeFile } = fs.promises;
|
|
|
54
22
|
* @param {boolean} options.environment Which environment to test in.
|
|
55
23
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
56
24
|
*/
|
|
57
|
-
|
|
25
|
+
export default async function test({
|
|
58
26
|
spinner,
|
|
59
|
-
environment,
|
|
60
27
|
debug,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}) {
|
|
28
|
+
environment
|
|
29
|
+
} ) {
|
|
64
30
|
|
|
65
|
-
|
|
31
|
+
spinner.text = "Testing Code Functionality";
|
|
66
32
|
const config = await loadConfig(path.resolve('.'));
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
spinner.text = "Testing code...";
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
spinner.text = 'Completed Testing code...'
|
|
77
|
-
|
|
78
|
-
/*
|
|
79
|
-
let result = await runDockerCmds(
|
|
80
|
-
environment,
|
|
81
|
-
['wp theme is-installed CAWeb'],
|
|
82
|
-
config
|
|
33
|
+
|
|
34
|
+
let result = await runCLICmds(
|
|
35
|
+
'development',
|
|
36
|
+
['wp --version'],
|
|
37
|
+
config,
|
|
38
|
+
spinner
|
|
83
39
|
)
|
|
84
40
|
|
|
85
|
-
if( '' !== result.out ) {
|
|
86
|
-
console.log( JSON.parse(result.out))
|
|
87
|
-
}else{
|
|
88
|
-
console.log(result);
|
|
89
|
-
}
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
41
|
|
|
93
|
-
|
|
94
|
-
console.log(error)
|
|
42
|
+
console.log( result );
|
|
95
43
|
|
|
96
|
-
|
|
97
|
-
}
|
|
44
|
+
spinner.text = "Done!";
|
|
98
45
|
|
|
99
46
|
};
|
package/lib/configs.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const getHostUser = require( '@wordpress/env/lib/get-host-user' );
|
|
9
|
-
|
|
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';
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Promisified dependencies
|
|
13
11
|
*/
|
|
14
12
|
const { writeFile } = fs.promises;
|
|
15
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) );
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* Build .wp-env.json
|
|
18
19
|
*
|
|
@@ -64,18 +65,7 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
|
64
65
|
restart: 'always',
|
|
65
66
|
ports: ['8080:80'],
|
|
66
67
|
environment: {
|
|
67
|
-
|
|
68
|
-
UPLOAD_LIMIT: '3G',
|
|
69
|
-
MEMORY_LIMIT: '5G',
|
|
70
|
-
MAX_EXECUTION_TIME: 7200
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
"tests-phpmyadmin": {
|
|
74
|
-
image: `phpmyadmin:latest`,
|
|
75
|
-
restart: 'always',
|
|
76
|
-
ports: ['9090:80'],
|
|
77
|
-
environment: {
|
|
78
|
-
PMA_HOST : 'tests-mysql',
|
|
68
|
+
PMA_HOSTS : 'mysql,tests-mysql',
|
|
79
69
|
UPLOAD_LIMIT: '3G',
|
|
80
70
|
MEMORY_LIMIT: '5G',
|
|
81
71
|
MAX_EXECUTION_TIME: 7200
|
|
@@ -175,7 +165,7 @@ async function generateCLIConfig(workDirectoryPath){
|
|
|
175
165
|
yaml.dump(yml));
|
|
176
166
|
}
|
|
177
167
|
|
|
178
|
-
|
|
168
|
+
export {
|
|
179
169
|
buildWPEnvConfig,
|
|
180
170
|
buildDockerComposeConfig
|
|
181
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
|
};
|
package/lib/docker.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
/**
|
|
3
2
|
* External dependencies
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import dockerCompose from 'docker-compose';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
8
|
+
import getHostUser from '@wordpress/env/lib/get-host-user.js';
|
|
9
|
+
import { env } from 'node:process';
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -17,24 +19,30 @@ const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
|
17
19
|
* @param {string} environment Which environment to run docker command on.
|
|
18
20
|
* @param {string[]} cmds Array of commands to run.
|
|
19
21
|
* @param {WPConfig} config The wp-env config object.
|
|
22
|
+
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
20
23
|
*
|
|
21
|
-
* @returns {
|
|
24
|
+
* @returns {Promise}
|
|
22
25
|
*/
|
|
23
|
-
async function
|
|
26
|
+
async function runCLICmds(
|
|
24
27
|
environment,
|
|
25
28
|
cmds,
|
|
26
|
-
config
|
|
29
|
+
config,
|
|
30
|
+
spinner
|
|
27
31
|
) {
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return await dockerCompose.run(
|
|
33
|
+
// We return the promise whether there is an output or an error.
|
|
34
|
+
return await dockerCompose.run(
|
|
32
35
|
environment === 'development' ? 'cli' : 'tests-cli',
|
|
33
36
|
[ 'bash', '-c', cmds.join( ' && ' ) ],
|
|
34
37
|
{
|
|
35
38
|
cwd: config.workDirectoryPath,
|
|
36
|
-
commandOptions: [
|
|
39
|
+
commandOptions: [],
|
|
37
40
|
log: config.debug,
|
|
41
|
+
callback: (buffer, result) => {
|
|
42
|
+
if( config.debug ){
|
|
43
|
+
spinner.text = buffer.toString();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
).then(
|
|
40
48
|
(output) => {
|
|
@@ -44,23 +52,17 @@ async function runDockerCmds(
|
|
|
44
52
|
|
|
45
53
|
return '' !== output.out ? output.out : output.err;
|
|
46
54
|
},
|
|
47
|
-
(
|
|
55
|
+
(error) => {
|
|
48
56
|
// Remove the Container information and new lines.
|
|
49
|
-
|
|
57
|
+
error.err = error.err.replace(/\s*Container .*Running\n|\n/g, '')
|
|
50
58
|
|
|
51
|
-
return
|
|
59
|
+
return error;
|
|
52
60
|
}
|
|
53
61
|
);
|
|
54
62
|
|
|
55
|
-
} catch(error) {
|
|
56
|
-
console.log(error)
|
|
57
|
-
|
|
58
|
-
process.exit( 1 );
|
|
59
|
-
}
|
|
60
|
-
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
export {
|
|
67
|
+
runCLICmds
|
|
66
68
|
};
|