@caweb/cli 1.0.0 → 1.0.2
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/lib/caweb.js +74 -83
- package/lib/cli.js +28 -2
- package/lib/commands/index.js +4 -1
- package/lib/commands/shell.js +3 -5
- package/lib/commands/start.js +35 -14
- package/lib/commands/tasks/index.js +13 -0
- package/lib/commands/tasks/update-plugins.js +37 -0
- package/lib/commands/test.js +40 -37
- package/lib/configs.js +15 -8
- package/lib/divi.js +119 -0
- package/lib/docker.js +66 -0
- package/lib/download-sources.js +19 -9
- package/lib/options.js +249 -11
- package/lib/wordpress.js +121 -0
- package/package.json +27 -13
package/lib/caweb.js
CHANGED
|
@@ -2,97 +2,48 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
6
|
-
const path = require( 'path' );
|
|
7
|
-
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
8
|
-
|
|
5
|
+
const retry = require( '@wordpress/env/lib/retry' );
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* Internal dependencies
|
|
12
9
|
*/
|
|
13
10
|
const { CAWEB_OPTIONS } = require('./options');
|
|
11
|
+
const { runDockerCmds } = require('./docker');
|
|
12
|
+
const { isMultisite } = require('./wordpress');
|
|
13
|
+
const { configureDivi } = require('./divi');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
+
* Activates the CAWeb Theme for the WordPress Environment if it's installed.
|
|
16
17
|
*
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {boolean} options.environment Which environment to open terminal in.
|
|
20
|
-
* @param {Array} options.cmds Array of commands to run.
|
|
21
|
-
*
|
|
22
|
-
* @returns {Object}
|
|
18
|
+
* @param {string} environment Which environment to activate the theme on.
|
|
19
|
+
* @param {WPConfig} config The wp-env config object.
|
|
23
20
|
*/
|
|
24
|
-
async function
|
|
25
|
-
spinner,
|
|
21
|
+
async function activateCAWeb(
|
|
26
22
|
environment,
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
config
|
|
24
|
+
){
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
const config = await loadConfig(path.resolve('.'));
|
|
32
|
-
|
|
33
|
-
// -eo pipefail exits the command as soon as anything fails in bash.
|
|
34
|
-
//const setupCommands = [ 'set -eo pipefail' ];
|
|
35
|
-
|
|
36
|
-
// Execute all setup commands in a batch.
|
|
37
|
-
return await dockerCompose.run(
|
|
38
|
-
environment === 'development' ? 'cli' : 'tests-cli',
|
|
39
|
-
[ 'bash', '-c', cmds.join( ' && ' ) ],
|
|
40
|
-
{
|
|
41
|
-
cwd: config.workDirectoryPath,
|
|
42
|
-
commandOptions: [ '--rm' ],
|
|
43
|
-
log: config.debug,
|
|
44
|
-
}
|
|
45
|
-
).then(
|
|
46
|
-
(result) => {
|
|
47
|
-
if( '' !== result.out ){
|
|
48
|
-
console.log( result.out )
|
|
49
|
-
}else{
|
|
50
|
-
console.log(result.err)
|
|
51
|
-
}
|
|
52
|
-
return result;
|
|
53
|
-
},
|
|
54
|
-
(err) => {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
)
|
|
26
|
+
const isMulti = await isMultisite( environment, config );
|
|
58
27
|
|
|
59
|
-
|
|
60
|
-
console.log(error)
|
|
28
|
+
let cmds = ['wp theme is-installed CAWeb'];
|
|
61
29
|
|
|
62
|
-
|
|
30
|
+
if( false !== isMulti ){
|
|
31
|
+
cmds.push( 'wp theme enable CAWeb --network --activate' );
|
|
32
|
+
}else{
|
|
33
|
+
cmds.push( 'wp theme activate CAWeb' );
|
|
63
34
|
}
|
|
64
|
-
|
|
65
|
-
};
|
|
66
35
|
|
|
67
|
-
|
|
68
|
-
* Activates the CAWeb Theme for the WordPress Environment if it's installed.
|
|
69
|
-
*
|
|
70
|
-
* @param {Object} options
|
|
71
|
-
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
72
|
-
* @param {boolean} options.environment Which environment to activate the theme on.
|
|
73
|
-
*/
|
|
74
|
-
async function activateCAWeb({
|
|
75
|
-
spinner,
|
|
76
|
-
environment
|
|
77
|
-
}){
|
|
78
|
-
return await runDockerCmd( {
|
|
79
|
-
spinner,
|
|
36
|
+
return await runDockerCmds(
|
|
80
37
|
environment,
|
|
81
|
-
cmds
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return true;
|
|
85
|
-
},
|
|
86
|
-
(err) => {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
)
|
|
38
|
+
cmds,
|
|
39
|
+
config
|
|
40
|
+
);
|
|
90
41
|
|
|
91
42
|
}
|
|
92
43
|
|
|
93
44
|
/**
|
|
94
|
-
* Configures
|
|
95
|
-
*
|
|
45
|
+
* Configures CAWebPublishing Service for the given environment by configure settings,
|
|
46
|
+
* and activating the CAWeb theme. These steps are
|
|
96
47
|
* performed sequentially so as to not overload the WordPress instance.
|
|
97
48
|
*
|
|
98
49
|
* @param {WPEnvironment} environment The environment to configure. Either 'development' or 'tests'.
|
|
@@ -102,39 +53,79 @@ async function activateCAWeb({
|
|
|
102
53
|
async function configureCAWeb( environment, config, spinner ) {
|
|
103
54
|
|
|
104
55
|
|
|
105
|
-
const isThemeActivated = await activateCAWeb(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
56
|
+
const isThemeActivated = await activateCAWeb( environment, config );
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
DESIGN_SYSTEM_ENABLED,
|
|
60
|
+
WP_PERMALINK
|
|
61
|
+
} = config.env[ environment ].config
|
|
109
62
|
|
|
110
63
|
// if our theme is active.
|
|
111
|
-
if( isThemeActivated ){
|
|
64
|
+
if( false !== isThemeActivated ){
|
|
112
65
|
let themeOptions = [];
|
|
113
66
|
|
|
114
67
|
// iterate over config options.
|
|
115
68
|
Object.entries(config.env[ environment ].config).forEach(([k,v]) => {
|
|
116
69
|
// if the option is prefixed with CAWEB_ and is a valid CAWeb Option.
|
|
117
70
|
if ( `${k}`.startsWith('CAWEB_') && undefined !== CAWEB_OPTIONS[k] ){
|
|
71
|
+
const option = CAWEB_OPTIONS[k];
|
|
118
72
|
// set the option.
|
|
119
73
|
themeOptions.push(
|
|
120
|
-
`wp option set '${
|
|
74
|
+
`wp option set '${option.name}' "${v}"`
|
|
121
75
|
);
|
|
122
76
|
}
|
|
123
77
|
})
|
|
124
78
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
79
|
+
if ( config.debug ) {
|
|
80
|
+
spinner.info(
|
|
81
|
+
`Running the following setup commands on the ${ environment } instance:\n - ${ setupCommands.join(
|
|
82
|
+
'\n - '
|
|
83
|
+
) }\n`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Execute theme option commands.
|
|
88
|
+
await runDockerCmds(
|
|
128
89
|
environment,
|
|
129
|
-
|
|
130
|
-
|
|
90
|
+
themeOptions,
|
|
91
|
+
config
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Make Divi WordPress Configurations.
|
|
95
|
+
await Promise.all( [
|
|
96
|
+
retry( () => configureDivi( 'development', config, spinner ), {
|
|
97
|
+
times: 2,
|
|
98
|
+
} ),
|
|
99
|
+
retry( () => configureDivi( 'tests', config, spinner ), {
|
|
100
|
+
times: 2,
|
|
101
|
+
} ),
|
|
102
|
+
] );
|
|
131
103
|
}
|
|
132
104
|
|
|
105
|
+
// Activate Design System plugin
|
|
106
|
+
if( undefined !== DESIGN_SYSTEM_ENABLED && DESIGN_SYSTEM_ENABLED ){
|
|
107
|
+
await runDockerCmds(
|
|
108
|
+
environment,
|
|
109
|
+
[
|
|
110
|
+
'wp plugin is-installed design-system-wordpress',
|
|
111
|
+
'wp plugin activate design-system-wordpress'
|
|
112
|
+
],
|
|
113
|
+
config
|
|
114
|
+
)
|
|
115
|
+
}
|
|
133
116
|
|
|
117
|
+
// rewrite and flush permalink structure.
|
|
118
|
+
await runDockerCmds(
|
|
119
|
+
environment,
|
|
120
|
+
[
|
|
121
|
+
`wp rewrite structure ${WP_PERMALINK} --hard`,
|
|
122
|
+
'wp rewrite flush --hard'
|
|
123
|
+
],
|
|
124
|
+
config
|
|
125
|
+
);
|
|
134
126
|
}
|
|
135
127
|
|
|
136
128
|
module.exports = {
|
|
137
129
|
activateCAWeb,
|
|
138
130
|
configureCAWeb,
|
|
139
|
-
runDockerCmd
|
|
140
131
|
};
|
package/lib/cli.js
CHANGED
|
@@ -96,14 +96,24 @@ module.exports = function cli() {
|
|
|
96
96
|
describe: 'True if excluding any downloads from CAWeb, use this if you want to use a local version of the CAWeb Theme, Configurations will still be applied.',
|
|
97
97
|
default: false,
|
|
98
98
|
} );
|
|
99
|
-
|
|
99
|
+
args.option( 'multisite', {
|
|
100
|
+
alias: 'm',
|
|
101
|
+
type: 'boolean',
|
|
102
|
+
describe: 'True if converting to multisite.',
|
|
103
|
+
default: false,
|
|
104
|
+
} );
|
|
105
|
+
args.option( 'subdomain', {
|
|
106
|
+
type: 'boolean',
|
|
107
|
+
describe: 'If passed, the network will use subdomains, instead of subdirectories. Doesn’t work with ‘localhost’.',
|
|
108
|
+
default: false,
|
|
109
|
+
} );
|
|
100
110
|
},
|
|
101
111
|
withSpinner( env.start )
|
|
102
112
|
);
|
|
103
113
|
|
|
104
114
|
// Shell Terminal Command.
|
|
105
115
|
yargs.command(
|
|
106
|
-
'shell
|
|
116
|
+
'shell [environment]',
|
|
107
117
|
'Open shell terminal in WordPress environment.',
|
|
108
118
|
(args) => {
|
|
109
119
|
args.positional( 'environment', {
|
|
@@ -116,6 +126,21 @@ module.exports = function cli() {
|
|
|
116
126
|
withSpinner( env.shell )
|
|
117
127
|
)
|
|
118
128
|
|
|
129
|
+
// Update Plugin Command.
|
|
130
|
+
yargs.command(
|
|
131
|
+
'update-plugins [environment]',
|
|
132
|
+
'Updates all plugins in the WordPress environment.',
|
|
133
|
+
(args) => {
|
|
134
|
+
args.positional( 'environment', {
|
|
135
|
+
type: 'string',
|
|
136
|
+
describe: "Which environment to update.",
|
|
137
|
+
choices: [ 'development', 'tests' ],
|
|
138
|
+
default: 'development',
|
|
139
|
+
} );
|
|
140
|
+
},
|
|
141
|
+
withSpinner( env.updatePlugins )
|
|
142
|
+
)
|
|
143
|
+
|
|
119
144
|
// Test Command.
|
|
120
145
|
yargs.command(
|
|
121
146
|
'test [environment]',
|
|
@@ -127,6 +152,7 @@ module.exports = function cli() {
|
|
|
127
152
|
choices: [ 'development', 'tests' ],
|
|
128
153
|
default: 'development',
|
|
129
154
|
} );
|
|
155
|
+
|
|
130
156
|
},
|
|
131
157
|
withSpinner( env.test )
|
|
132
158
|
)
|
package/lib/commands/index.js
CHANGED
package/lib/commands/shell.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
5
|
+
const run = require( '@wordpress/env/lib/commands/run' );
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
@@ -22,10 +22,8 @@ module.exports = async function shell({
|
|
|
22
22
|
debug
|
|
23
23
|
}) {
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await wpEnvRun({
|
|
28
|
-
container: container,
|
|
25
|
+
await run({
|
|
26
|
+
container: 'tests' === environment ? 'tests-cli' : 'cli',
|
|
29
27
|
command: ['bash'],
|
|
30
28
|
"": "",
|
|
31
29
|
envCwd: '.',
|
package/lib/commands/start.js
CHANGED
|
@@ -28,6 +28,7 @@ const CONFIG_CACHE_KEY = 'config_checksum';
|
|
|
28
28
|
const { configureCAWeb } = require('../caweb');
|
|
29
29
|
const { buildWPEnvConfig, buildDockerComposeConfig } = require('../configs');
|
|
30
30
|
const {downloadSources } = require('../download-sources');
|
|
31
|
+
const { convertToMultisite } = require('../wordpress');
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Promisified dependencies
|
|
@@ -45,6 +46,8 @@ const sleep = util.promisify( setTimeout );
|
|
|
45
46
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
46
47
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
47
48
|
* @param {boolean} options.bare True if excluding any CAWeb Configurations.
|
|
49
|
+
* @param {boolean} options.multisite True if converting to multisite.
|
|
50
|
+
* @param {boolean} options.subdomain True if converting to multisite subdomain.
|
|
48
51
|
*
|
|
49
52
|
*/
|
|
50
53
|
module.exports = async function start({
|
|
@@ -53,14 +56,16 @@ module.exports = async function start({
|
|
|
53
56
|
xdebug,
|
|
54
57
|
scripts,
|
|
55
58
|
debug,
|
|
56
|
-
bare
|
|
59
|
+
bare,
|
|
60
|
+
multisite,
|
|
61
|
+
subdomain
|
|
57
62
|
}) {
|
|
58
63
|
spinner.text = 'Writing configuration file...';
|
|
59
64
|
|
|
60
65
|
// Write CAWeb .wp-env.json file.
|
|
61
66
|
await writeFile(
|
|
62
67
|
path.join(process.cwd(), '.wp-env.json'),
|
|
63
|
-
JSON.stringify( buildWPEnvConfig(
|
|
68
|
+
JSON.stringify( buildWPEnvConfig(bare, multisite), null, 4 )
|
|
64
69
|
);
|
|
65
70
|
|
|
66
71
|
// Get current wp-env cache key
|
|
@@ -110,17 +115,45 @@ module.exports = async function start({
|
|
|
110
115
|
await sleep( 4000 );
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
|
|
113
119
|
// Download any resources required for CAWeb.
|
|
114
120
|
if( ! bare ){
|
|
115
121
|
await downloadSources({spinner, config});
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
// if multisite.
|
|
125
|
+
if( multisite ){
|
|
126
|
+
spinner.text = 'Converting to multisite ' + ( subdomain ? 'subdomain' : 'subdirectory') + '...'
|
|
127
|
+
|
|
128
|
+
await Promise.all( [
|
|
129
|
+
retry( () => convertToMultisite( 'development', config, subdomain ), {
|
|
130
|
+
times: 2,
|
|
131
|
+
} ),
|
|
132
|
+
retry( () => convertToMultisite( 'tests', config, subdomain ), {
|
|
133
|
+
times: 2,
|
|
134
|
+
} ),
|
|
135
|
+
] );
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
118
139
|
// Write docker-compose.override.yml file to workDirectoryPath.
|
|
119
140
|
await writeFile(
|
|
120
141
|
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
121
142
|
yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
|
|
122
143
|
);
|
|
123
144
|
|
|
145
|
+
spinner.text = 'Configuring CAWebPublishing Environments...';
|
|
146
|
+
|
|
147
|
+
// Make CAWeb WordPress Configurations.
|
|
148
|
+
await Promise.all( [
|
|
149
|
+
retry( () => configureCAWeb( 'development', config, spinner ), {
|
|
150
|
+
times: 2,
|
|
151
|
+
} ),
|
|
152
|
+
retry( () => configureCAWeb( 'tests', config, spinner ), {
|
|
153
|
+
times: 2,
|
|
154
|
+
} ),
|
|
155
|
+
] );
|
|
156
|
+
|
|
124
157
|
// Start phpMyAdmin Service.
|
|
125
158
|
spinner.text = 'Starting phpMyAdmin Service';
|
|
126
159
|
|
|
@@ -137,18 +170,6 @@ module.exports = async function start({
|
|
|
137
170
|
log: debug
|
|
138
171
|
})
|
|
139
172
|
|
|
140
|
-
spinner.text = 'Configuring CAWebPublishing Environments...';
|
|
141
|
-
|
|
142
|
-
// Make CAWeb WordPress Configurations.
|
|
143
|
-
await Promise.all( [
|
|
144
|
-
retry( () => configureCAWeb( 'development', config, spinner ), {
|
|
145
|
-
times: 2,
|
|
146
|
-
} ),
|
|
147
|
-
retry( () => configureCAWeb( 'tests', config, spinner ), {
|
|
148
|
-
times: 2,
|
|
149
|
-
} ),
|
|
150
|
-
] );
|
|
151
|
-
|
|
152
173
|
spinner.prefixText = preText +
|
|
153
174
|
`phpMyAdmin development site started at http://localhost:8080\n` +
|
|
154
175
|
`phpMyAdmin development site started at http://localhost:9090\n\n`;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
const run = require('@wordpress/env/lib/commands/run');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
const { runDockerCmds } = require('../../docker');
|
|
11
|
+
const path = require( 'path' );
|
|
12
|
+
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Promisified dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Updates all plugins for a given environment.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
23
|
+
* @param {string} options.environment Which environment to updated.
|
|
24
|
+
*/
|
|
25
|
+
module.exports = async function updatePlugins({
|
|
26
|
+
spinner,
|
|
27
|
+
environment
|
|
28
|
+
}) {
|
|
29
|
+
|
|
30
|
+
spinner.text = "Updating plugins...";
|
|
31
|
+
const config = await loadConfig(path.resolve('.'));
|
|
32
|
+
|
|
33
|
+
await runDockerCmds( environment, ['wp plugin update --all'], config );
|
|
34
|
+
|
|
35
|
+
spinner.text = 'Completed updating plugins!'
|
|
36
|
+
|
|
37
|
+
};
|
package/lib/commands/test.js
CHANGED
|
@@ -8,19 +8,36 @@ const SimpleGit = require( 'simple-git' );
|
|
|
8
8
|
const { execSync } = require( 'child_process' );
|
|
9
9
|
const dockerCompose = require( 'docker-compose' );
|
|
10
10
|
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
11
|
+
const run = require('@wordpress/env/lib/commands/run');
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
15
16
|
const {
|
|
16
|
-
|
|
17
|
-
} = require('../
|
|
17
|
+
runDockerCmds,
|
|
18
|
+
} = require('../docker');
|
|
18
19
|
|
|
19
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
buildWPEnvConfig,
|
|
22
|
+
buildDockerComposeConfig
|
|
23
|
+
} = require('../configs');
|
|
20
24
|
|
|
21
25
|
const pkg = require( '../../package.json' );
|
|
22
|
-
const {
|
|
26
|
+
const { DIVI_OPTIONS } = require('../options');
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
isDiviThemeActive,
|
|
30
|
+
configureDivi
|
|
31
|
+
} = require('../divi');
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
activateCAWeb,
|
|
35
|
+
configureCAWeb
|
|
36
|
+
} = require('../caweb');
|
|
23
37
|
|
|
38
|
+
const {
|
|
39
|
+
generateHTAccess
|
|
40
|
+
} = require( '../wordpress' );
|
|
24
41
|
|
|
25
42
|
/**
|
|
26
43
|
* Promisified dependencies
|
|
@@ -33,51 +50,37 @@ const { writeFile } = fs.promises;
|
|
|
33
50
|
* @param {Object} options
|
|
34
51
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
35
52
|
* @param {boolean} options.environment Which environment to test in.
|
|
53
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
36
54
|
*/
|
|
37
55
|
module.exports = async function test({
|
|
38
56
|
spinner,
|
|
39
|
-
environment
|
|
57
|
+
environment,
|
|
58
|
+
debug,
|
|
59
|
+
multisite,
|
|
60
|
+
subdomain
|
|
40
61
|
}) {
|
|
41
62
|
|
|
42
63
|
try {
|
|
43
64
|
const config = await loadConfig(path.resolve('.'));
|
|
65
|
+
const {WP_PERMALINK} = config.env[ environment ].config
|
|
66
|
+
|
|
67
|
+
spinner.text = "Testing code...";
|
|
44
68
|
/*
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
Object.entries(config.env[ 'development' ].config).forEach(([k,v]) => {
|
|
48
|
-
// if the option is prefixed with CAWEB_ and is a valid CAWeb Option.
|
|
49
|
-
if ( `${k}`.startsWith('CAWEB_') && undefined !== CAWEB_OPTIONS[k] ){
|
|
50
|
-
console.log(CAWEB_OPTIONS[k])
|
|
51
|
-
// set the option.
|
|
52
|
-
themeOptions.push(
|
|
53
|
-
`wp option set '${CAWEB_OPTIONS[k]}' "${v}"`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
console.log(themeOptions);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Write CAWeb .wp-env.json file.
|
|
62
|
-
await writeFile(
|
|
63
|
-
path.join(process.cwd(), '.wp-env.json'),
|
|
64
|
-
JSON.stringify( buildWPEnvConfig({bare: false}), null, 4 )
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
let result = await runDockerCmd( {
|
|
68
|
-
spinner,
|
|
69
|
+
let result = await runDockerCmds(
|
|
69
70
|
environment,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Object.entries(result).forEach((k,v) => {
|
|
75
|
-
//console.log(`${k}:${v}`)
|
|
76
|
-
})
|
|
71
|
+
['wp theme is-installed CAWeb'],
|
|
72
|
+
config
|
|
73
|
+
)
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
if( '' !== result.out ) {
|
|
76
|
+
console.log( JSON.parse(result.out))
|
|
77
|
+
}else{
|
|
78
|
+
console.log(result);
|
|
79
|
+
}
|
|
79
80
|
*/
|
|
80
81
|
|
|
82
|
+
spinner.text = 'Completed Testing code...'
|
|
83
|
+
|
|
81
84
|
} catch(error) {
|
|
82
85
|
console.log(error)
|
|
83
86
|
|
package/lib/configs.js
CHANGED
|
@@ -9,10 +9,12 @@ const pkg = require( '../package.json' );
|
|
|
9
9
|
/**
|
|
10
10
|
* Build .wp-env.json
|
|
11
11
|
*
|
|
12
|
-
* @param {boolean}
|
|
12
|
+
* @param {boolean} bare True if excluding any CAWeb Configurations.
|
|
13
|
+
* @param {boolean} multisite True if converting to multisite.
|
|
14
|
+
*
|
|
13
15
|
* @returns object
|
|
14
16
|
*/
|
|
15
|
-
const buildWPEnvConfig = (
|
|
17
|
+
const buildWPEnvConfig = (bare, multisite) => {
|
|
16
18
|
let config = {
|
|
17
19
|
core: `WordPress/WordPress#${pkg.config.WP_VER}`,
|
|
18
20
|
phpVersion: `${pkg.config.PHP_VER}`,
|
|
@@ -26,6 +28,11 @@ const buildWPEnvConfig = ({bare}) => {
|
|
|
26
28
|
config['themes'] = [`CA-CODE-Works/CAWeb`];
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
// if is multisite
|
|
32
|
+
if( multisite ){
|
|
33
|
+
config.config['WP_ALLOW_MULTISITE'] = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
return config;
|
|
30
37
|
|
|
31
38
|
}
|
|
@@ -68,14 +75,14 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
|
68
75
|
|
|
69
76
|
let extraVolumes = [];
|
|
70
77
|
|
|
71
|
-
//
|
|
72
|
-
if( fs.existsSync(path.join(workDirectoryPath, '
|
|
73
|
-
extraVolumes = extraVolumes.concat(path.join(workDirectoryPath, '
|
|
78
|
+
// Add downloaded themes to services volumes.
|
|
79
|
+
if( fs.existsSync(path.join(workDirectoryPath, 'themes')) ){
|
|
80
|
+
extraVolumes = extraVolumes.concat(path.join(workDirectoryPath, 'themes') + ':/var/www/html/wp-content/themes');
|
|
74
81
|
}
|
|
75
82
|
|
|
76
|
-
//
|
|
77
|
-
if( fs.existsSync(path.join(workDirectoryPath, '
|
|
78
|
-
extraVolumes = extraVolumes.concat(path.join(workDirectoryPath, '
|
|
83
|
+
// Add downloaded plugins to services volumes.
|
|
84
|
+
if( fs.existsSync(path.join(workDirectoryPath, 'plugins')) ){
|
|
85
|
+
extraVolumes = extraVolumes.concat(path.join(workDirectoryPath, 'plugins') + ':/var/www/html/wp-content/plugins');
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
// Add extra volumes to WordPress instances.
|
package/lib/divi.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
const { runDockerCmds } = require('./docker');
|
|
11
|
+
const { DIVI_OPTIONS, DIVI_BUILDER_OPTIONS, DIVI_UPDATE_OPTIONS } = require('./options');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if Divi Theme is active for the WordPress Environment.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} environment Which environment to activate the theme on.
|
|
18
|
+
* @param {WPConfig} config The wp-env config object.
|
|
19
|
+
*/
|
|
20
|
+
async function isDiviThemeActive(
|
|
21
|
+
environment,
|
|
22
|
+
config
|
|
23
|
+
){
|
|
24
|
+
|
|
25
|
+
return await runDockerCmds(
|
|
26
|
+
environment,
|
|
27
|
+
['wp theme is-active Divi'],
|
|
28
|
+
config
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configures Divi for CAWebPublishing Service for the given environment by configure settings.
|
|
35
|
+
* These steps are performed sequentially so as to not overload the WordPress instance.
|
|
36
|
+
*
|
|
37
|
+
* @param {WPEnvironment} environment The environment to configure. Either 'development' or 'tests'.
|
|
38
|
+
* @param {WPConfig} config The wp-env config object.
|
|
39
|
+
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
40
|
+
*/
|
|
41
|
+
async function configureDivi( environment, config, spinner ) {
|
|
42
|
+
|
|
43
|
+
const activeTheme = await isDiviThemeActive( environment, config );
|
|
44
|
+
|
|
45
|
+
// if Divi theme is active.
|
|
46
|
+
if( false !== activeTheme ){
|
|
47
|
+
let cmds = [];
|
|
48
|
+
let diviOptions = await runDockerCmds(
|
|
49
|
+
environment,
|
|
50
|
+
[ 'wp option get et_divi --format=json' ],
|
|
51
|
+
config
|
|
52
|
+
)
|
|
53
|
+
let diviBuilderOptions = await runDockerCmds(
|
|
54
|
+
environment,
|
|
55
|
+
[ 'wp option get et_bfb_settings --format=json' ],
|
|
56
|
+
config
|
|
57
|
+
)
|
|
58
|
+
let diviUpdateOptions = await runDockerCmds(
|
|
59
|
+
environment,
|
|
60
|
+
[ 'wp option get et_automatic_updates_options --format=json' ],
|
|
61
|
+
config
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
// parse the options into a json object.
|
|
65
|
+
diviOptions = diviOptions ? JSON.parse( diviOptions ) : {};
|
|
66
|
+
diviBuilderOptions = diviBuilderOptions ? JSON.parse( diviBuilderOptions ) : {};
|
|
67
|
+
diviUpdateOptions = undefined !== diviUpdateOptions && diviUpdateOptions ? JSON.parse( diviUpdateOptions ) : {};
|
|
68
|
+
|
|
69
|
+
// iterate over config options.
|
|
70
|
+
Object.entries(config.env[ environment ].config).forEach(([k,v]) => {
|
|
71
|
+
// if the option is prefixed with ET_.
|
|
72
|
+
if ( `${k}`.startsWith('ET_') ){
|
|
73
|
+
|
|
74
|
+
// is a valid Divi Option.
|
|
75
|
+
if( undefined !== DIVI_OPTIONS[k] ){
|
|
76
|
+
diviOptions[DIVI_OPTIONS[k].name] = v;
|
|
77
|
+
// is a valid Divi Builder Option.
|
|
78
|
+
}else if( undefined !== DIVI_BUILDER_OPTIONS[k] ){
|
|
79
|
+
diviBuilderOptions[DIVI_BUILDER_OPTIONS[k].name] = v;
|
|
80
|
+
// is a valid Divi Update Option.
|
|
81
|
+
}else if( undefined !== DIVI_UPDATE_OPTIONS[k] ){
|
|
82
|
+
diviUpdateOptions[DIVI_UPDATE_OPTIONS[k].name] = v;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// parse option object back to string.
|
|
88
|
+
diviOptions = JSON.stringify( diviOptions );
|
|
89
|
+
diviBuilderOptions = JSON.stringify( diviBuilderOptions );
|
|
90
|
+
diviUpdateOptions = JSON.stringify( diviUpdateOptions );
|
|
91
|
+
|
|
92
|
+
cmds.push(`wp option update et_divi '${diviOptions}' --format=json`);
|
|
93
|
+
cmds.push(`wp option update et_bfb_settings '${diviBuilderOptions}' --format=json`);
|
|
94
|
+
cmds.push(`wp option update et_automatic_updates_options '${diviUpdateOptions}' --format=json`);
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if ( config.debug ) {
|
|
98
|
+
spinner.info(
|
|
99
|
+
`Running the following setup commands on the ${ environment } instance:\n - ${ setupCommands.join(
|
|
100
|
+
'\n - '
|
|
101
|
+
) }\n`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Execute theme option commands.
|
|
106
|
+
await runDockerCmds(
|
|
107
|
+
environment,
|
|
108
|
+
cmds,
|
|
109
|
+
config
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = {
|
|
117
|
+
configureDivi,
|
|
118
|
+
isDiviThemeActive
|
|
119
|
+
};
|
package/lib/docker.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
const dockerCompose = require( 'docker-compose' );
|
|
6
|
+
const path = require( 'path' );
|
|
7
|
+
const loadConfig = require( '@wordpress/env/lib/config/load-config' );
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Runs commands on the given WordPress environment.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} environment Which environment to run docker command on.
|
|
18
|
+
* @param {string[]} cmds Array of commands to run.
|
|
19
|
+
* @param {WPConfig} config The wp-env config object.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Object}
|
|
22
|
+
*/
|
|
23
|
+
async function runDockerCmds(
|
|
24
|
+
environment,
|
|
25
|
+
cmds,
|
|
26
|
+
config
|
|
27
|
+
) {
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Execute all setup commands in a batch.
|
|
31
|
+
return await dockerCompose.run(
|
|
32
|
+
environment === 'development' ? 'cli' : 'tests-cli',
|
|
33
|
+
[ 'bash', '-c', cmds.join( ' && ' ) ],
|
|
34
|
+
{
|
|
35
|
+
cwd: config.workDirectoryPath,
|
|
36
|
+
commandOptions: [ '--rm' ],
|
|
37
|
+
log: config.debug,
|
|
38
|
+
}
|
|
39
|
+
).then(
|
|
40
|
+
(output) => {
|
|
41
|
+
// Remove the Container information and new lines.
|
|
42
|
+
output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
|
|
43
|
+
output.out = output.out.replace(/\s*Container .*Running\n|\n/g, '')
|
|
44
|
+
|
|
45
|
+
return '' !== output.out ? output.out : output.err;
|
|
46
|
+
},
|
|
47
|
+
(output) => {
|
|
48
|
+
// Remove the Container information and new lines.
|
|
49
|
+
output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
} catch(error) {
|
|
56
|
+
console.log(error)
|
|
57
|
+
|
|
58
|
+
process.exit( 1 );
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
runDockerCmds
|
|
66
|
+
};
|
package/lib/download-sources.js
CHANGED
|
@@ -54,7 +54,20 @@ async function downloadSources(
|
|
|
54
54
|
|
|
55
55
|
const { workDirectoryPath } = config;
|
|
56
56
|
const { development: dev, tests: test } = config.env;
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
let pluginDir = path.resolve(workDirectoryPath, 'plugins');
|
|
59
|
+
let themeDir = path.resolve(workDirectoryPath, 'themes');
|
|
60
|
+
|
|
61
|
+
let sources = [
|
|
62
|
+
{
|
|
63
|
+
basename: 'Design System',
|
|
64
|
+
url: 'https://github.com/CA-CODE-Works/design-system-wordpress.git',
|
|
65
|
+
ref: 'main',
|
|
66
|
+
path: path.join(pluginDir, 'design-system-wordpress'),
|
|
67
|
+
clonePath: path.join(pluginDir, 'design-system-wordpress'),
|
|
68
|
+
type: 'git'
|
|
69
|
+
}
|
|
70
|
+
];
|
|
58
71
|
|
|
59
72
|
// Add Divi Theme and plugin to sources.
|
|
60
73
|
if( (undefined !== dev.config.ET_USERNAME &&
|
|
@@ -71,25 +84,22 @@ async function downloadSources(
|
|
|
71
84
|
{
|
|
72
85
|
basename: 'Divi',
|
|
73
86
|
url: `${url}?api_update=1&theme=Divi&api_key=${key}&username=${user}`,
|
|
74
|
-
path: path.join(
|
|
87
|
+
path: path.join(themeDir, 'Divi'),
|
|
75
88
|
type: 'zip'
|
|
76
89
|
},
|
|
77
90
|
{
|
|
78
91
|
basename: 'Divi Plugin',
|
|
79
92
|
url: `${url}?api_update=1&theme=divi-builder&api_key=${key}&username=${user}`,
|
|
80
|
-
path: path.join(
|
|
93
|
+
path: path.join(pluginDir, 'divi-builder'),
|
|
81
94
|
type: 'zip'
|
|
82
95
|
}
|
|
83
96
|
]);
|
|
84
97
|
}
|
|
85
98
|
|
|
99
|
+
// Ensure plugin/theme directory exists for downloading resources.
|
|
100
|
+
fs.ensureDir(themeDir);
|
|
101
|
+
fs.ensureDir(pluginDir);
|
|
86
102
|
|
|
87
|
-
// filter any undefined sources.
|
|
88
|
-
/*sources = sources.filter(function( element ) {
|
|
89
|
-
return element !== undefined;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
103
|
await Promise.all(
|
|
94
104
|
sources.map( ( source ) =>
|
|
95
105
|
downloadSource( source, {
|
package/lib/options.js
CHANGED
|
@@ -2,22 +2,260 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Missing options.
|
|
7
|
+
*
|
|
8
|
+
* CAWEB_FAV_ICON
|
|
9
|
+
* CAWEB_ORG_LOGO
|
|
10
|
+
* Social Media Links
|
|
11
|
+
* Custom CSS/JS
|
|
12
|
+
* Alert Banners
|
|
13
|
+
* Additional Features
|
|
14
|
+
*
|
|
15
|
+
* @todo Add missing options.
|
|
16
|
+
*/
|
|
5
17
|
const caweb_general_options = {
|
|
6
|
-
CAWEB_TEMPLATE_VER:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
CAWEB_TEMPLATE_VER: {
|
|
19
|
+
name: 'ca_site_version',
|
|
20
|
+
defaultValue: '5.5',
|
|
21
|
+
label: 'State Template Version'
|
|
22
|
+
},
|
|
23
|
+
CAWEB_NAV_MENU_STYLE: {
|
|
24
|
+
name: 'ca_default_navigation_menu',
|
|
25
|
+
defaultValue: 'singlelevel',
|
|
26
|
+
label: 'Header Menu Type'
|
|
27
|
+
},
|
|
28
|
+
CAWEB_COLORSCHEME: {
|
|
29
|
+
name: 'ca_site_color_scheme',
|
|
30
|
+
defaultValue: 'oceanside',
|
|
31
|
+
label: 'Color Scheme'
|
|
32
|
+
},
|
|
33
|
+
CAWEB_TITLE_DISPLAY: {
|
|
34
|
+
name: 'ca_default_post_title_display',
|
|
35
|
+
defaultValue: false,
|
|
36
|
+
label: 'Title Display Default'
|
|
37
|
+
},
|
|
38
|
+
CAWEB_STICKY_NAV: {
|
|
39
|
+
name: 'ca_sticky_navigation',
|
|
40
|
+
defaultValue: false,
|
|
41
|
+
label: 'Sticky Navigation'
|
|
42
|
+
},
|
|
43
|
+
CAWEB_MENU_HOME_LINK: {
|
|
44
|
+
name: 'ca_home_nav_link',
|
|
45
|
+
defaultValue: false,
|
|
46
|
+
label: 'Menu Home Link'
|
|
47
|
+
},
|
|
48
|
+
CAWEB_DISPLAY_POSTS_DATE: {
|
|
49
|
+
name: 'ca_default_post_date_display',
|
|
50
|
+
defaultValue: false,
|
|
51
|
+
label: 'Display Date for Non-Divi Posts'
|
|
52
|
+
},
|
|
53
|
+
CAWEB_X_UA_COMPATIBILITY: {
|
|
54
|
+
name: 'ca_x_ua_compatibility',
|
|
55
|
+
defaultValue: false,
|
|
56
|
+
label: 'Legacy Browser Support'
|
|
57
|
+
},
|
|
58
|
+
CAWEB_FRONTPAGE_SEARCH: {
|
|
59
|
+
name: 'ca_frontpage_search_enabled',
|
|
60
|
+
defaultValue: false,
|
|
61
|
+
label: 'Show Search on Front Page'
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let utility_links = [];
|
|
66
|
+
|
|
67
|
+
for( let c = 1; c < 4; c++ ){
|
|
68
|
+
utility_links[`CAWEB_UTILITY_LINK${c}_ENABLED`] = {
|
|
69
|
+
name: `ca_utility_link_${c}_enable`,
|
|
70
|
+
defaultValue: false,
|
|
71
|
+
label: `Custom Link ${c}`
|
|
72
|
+
}
|
|
73
|
+
utility_links[`CAWEB_UTILITY_LINK${c}_LABEL`] = {
|
|
74
|
+
name: `ca_utility_link_${c}_name`,
|
|
75
|
+
defaultValue: '',
|
|
76
|
+
label: `Custom Link ${c} Label`
|
|
77
|
+
}
|
|
78
|
+
utility_links[`CAWEB_UTILITY_LINK${c}_URL`] = {
|
|
79
|
+
name: `ca_utility_link_${c}`,
|
|
80
|
+
defaultValue: '',
|
|
81
|
+
label: `Custom Link ${c} URL`
|
|
82
|
+
}
|
|
83
|
+
utility_links[`CAWEB_UTILITY_LINK${c}_NEW_WINDOW`] = {
|
|
84
|
+
name: `ca_utility_link_${c}_new_window`,
|
|
85
|
+
defaultValue: false,
|
|
86
|
+
label: `Custom Link ${c} Open in New Tab`
|
|
87
|
+
}
|
|
15
88
|
}
|
|
16
89
|
|
|
90
|
+
const caweb_utility_header_options = {
|
|
91
|
+
CAWEB_CONTACT_US_PAGE : {
|
|
92
|
+
name: 'ca_contact_us_link',
|
|
93
|
+
defaultValue: '',
|
|
94
|
+
label: 'Contact Us Page'
|
|
95
|
+
},
|
|
96
|
+
CAWEB_GEO_LOCATOR : {
|
|
97
|
+
name: 'ca_geo_locator_enabled',
|
|
98
|
+
defaultValue: false,
|
|
99
|
+
label: 'Enable Geo Locator'
|
|
100
|
+
},
|
|
101
|
+
CAWEB_UTILITY_HOME_LINK : {
|
|
102
|
+
name: 'ca_utility_home_icon',
|
|
103
|
+
defaultValue: false,
|
|
104
|
+
label: 'Home Link'
|
|
105
|
+
},
|
|
106
|
+
...utility_links
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const page_header_options = {
|
|
110
|
+
CAWEB_CAWEB_ORG_LOGO_ALT_TEXT: {
|
|
111
|
+
name: '',
|
|
112
|
+
defaultValue: '',
|
|
113
|
+
label: 'Organization Logo-Alt Text'
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const google_options = {
|
|
118
|
+
CAWEB_GOOGLE_SEARCH_ENGINE_ID : {
|
|
119
|
+
name: 'ca_google_search_id',
|
|
120
|
+
defaultValue: '',
|
|
121
|
+
label: 'Search Engine ID'
|
|
122
|
+
},
|
|
123
|
+
CAWEB_GOOGLE_ANALYTICS_ID: {
|
|
124
|
+
name: 'ca_google_analytic_id',
|
|
125
|
+
defaultValue: '',
|
|
126
|
+
label: 'Analytics ID'
|
|
127
|
+
},
|
|
128
|
+
CAWEB_GOOGLE_ANALYTICS4_ID: {
|
|
129
|
+
name: 'ca_google_analytic4_id',
|
|
130
|
+
defaultValue: '',
|
|
131
|
+
label: 'Analytics 4 ID'
|
|
132
|
+
},
|
|
133
|
+
CAWEB_GOOGLE_TAG_MANAGER_ID: {
|
|
134
|
+
name: 'ca_google_tag_manager_id',
|
|
135
|
+
defaultValue: '',
|
|
136
|
+
label: 'Tag Manager ID'
|
|
137
|
+
},
|
|
138
|
+
CAWEB_GOOGLE_META_ID: {
|
|
139
|
+
name: 'ca_google_meta_id',
|
|
140
|
+
defaultValue: '',
|
|
141
|
+
label: 'Site Verification Meta ID'
|
|
142
|
+
},
|
|
143
|
+
CAWEB_GOOGLE_TRANSLATE_MODE: {
|
|
144
|
+
name: 'ca_google_trans_enabled',
|
|
145
|
+
defaultValue: 'none',
|
|
146
|
+
label: 'Enable Google Translate'
|
|
147
|
+
},
|
|
148
|
+
CAWEB_GOOGLE_TRANSLATE_PAGE: {
|
|
149
|
+
name: 'ca_google_trans_page',
|
|
150
|
+
defaultValue: '',
|
|
151
|
+
label: 'Translate Page'
|
|
152
|
+
},
|
|
153
|
+
CAWEB_GOOGLE_TRANSLATE_PAGE_NEW_WINDOW: {
|
|
154
|
+
name: 'ca_google_trans_page_new_window',
|
|
155
|
+
defaultValue: true,
|
|
156
|
+
label: 'Open in New Tab'
|
|
157
|
+
},
|
|
158
|
+
CAWEB_GOOGLE_TRANSLATE_ICON: {
|
|
159
|
+
name: 'ca_google_trans_icon',
|
|
160
|
+
defaultValue: 'globe',
|
|
161
|
+
label: 'Icon'
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const github_options = {
|
|
166
|
+
CAWEB_PRIVATE_REPO: {
|
|
167
|
+
name: 'caweb_private_theme_enabled',
|
|
168
|
+
defaultValue: false,
|
|
169
|
+
label: 'Is Private?'
|
|
170
|
+
},
|
|
171
|
+
CAWEB_GIT_USER: {
|
|
172
|
+
name: 'caweb_username',
|
|
173
|
+
defaultValue: 'CA-CODE-Works',
|
|
174
|
+
label: 'Username'
|
|
175
|
+
},
|
|
176
|
+
CAWEB_ACCESS_TOKEN: {
|
|
177
|
+
name: 'caweb_password',
|
|
178
|
+
defaultValue: '',
|
|
179
|
+
label: 'Token'
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
17
183
|
const CAWEB_OPTIONS = {
|
|
18
|
-
...caweb_general_options
|
|
184
|
+
...caweb_general_options,
|
|
185
|
+
...caweb_utility_header_options,
|
|
186
|
+
...page_header_options,
|
|
187
|
+
...google_options,
|
|
188
|
+
...github_options
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const DIVI_OPTIONS = {
|
|
192
|
+
ET_DYNAMIC_MODULE: {
|
|
193
|
+
name: 'divi_dynamic_module_framework',
|
|
194
|
+
defaultValue: 'on',
|
|
195
|
+
label: 'Dynamic Module Framework'
|
|
196
|
+
},
|
|
197
|
+
ET_DYNAMIC_CSS: {
|
|
198
|
+
name: 'divi_dynamic_css',
|
|
199
|
+
defaultValue: 'on',
|
|
200
|
+
label: 'Dynamic CSS'
|
|
201
|
+
},
|
|
202
|
+
ET_CRITICAL_CSS: {
|
|
203
|
+
name: 'divi_critical_css',
|
|
204
|
+
defaultValue: 'on',
|
|
205
|
+
label: 'Critical CSS'
|
|
206
|
+
},
|
|
207
|
+
ET_DYNAMIC_JS: {
|
|
208
|
+
name: 'divi_dynamic_js_libraries',
|
|
209
|
+
defaultValue: 'on',
|
|
210
|
+
label: 'Dynamic JavaScript Libraries'
|
|
211
|
+
},
|
|
212
|
+
ET_CLASSIC_EDITOR: {
|
|
213
|
+
name: 'et_enable_classic_editor',
|
|
214
|
+
defaultValue: 'on',
|
|
215
|
+
label: 'Enable Classic Editor'
|
|
216
|
+
},
|
|
217
|
+
ET_STATIC_CSS_GENERATION: {
|
|
218
|
+
name: 'et_pb_static_css_file',
|
|
219
|
+
defaultValue: 'on',
|
|
220
|
+
label: 'Static CSS File Generation'
|
|
221
|
+
},
|
|
222
|
+
ET_PRODUCT_TOUR: {
|
|
223
|
+
name: 'et_pb_product_tour_global',
|
|
224
|
+
defaultValue: 'off',
|
|
225
|
+
label: 'Product Tour'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const DIVI_BUILDER_OPTIONS = {
|
|
230
|
+
ET_NEW_BUILDER_EXPERIENCE: {
|
|
231
|
+
name: 'enable_bfb',
|
|
232
|
+
defaultValue: 'off',
|
|
233
|
+
label: 'Enable The Latest Divi Builder Experience'
|
|
234
|
+
},
|
|
235
|
+
ET_OUTPUT_STYLES_INLINE: {
|
|
236
|
+
name: 'et_pb_css_in_footer',
|
|
237
|
+
defaultValue: 'off',
|
|
238
|
+
label: 'Output Styles Inline'
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const DIVI_UPDATE_OPTIONS = {
|
|
243
|
+
ET_USERNAME: {
|
|
244
|
+
name: 'username',
|
|
245
|
+
defaultValue: '',
|
|
246
|
+
label: 'Username'
|
|
247
|
+
},
|
|
248
|
+
ET_API_KEY: {
|
|
249
|
+
name: 'api_key',
|
|
250
|
+
defaultValue: '',
|
|
251
|
+
label: 'API Key'
|
|
252
|
+
}
|
|
253
|
+
|
|
19
254
|
}
|
|
20
255
|
|
|
21
256
|
module.exports = {
|
|
22
|
-
CAWEB_OPTIONS
|
|
257
|
+
CAWEB_OPTIONS,
|
|
258
|
+
DIVI_OPTIONS,
|
|
259
|
+
DIVI_BUILDER_OPTIONS,
|
|
260
|
+
DIVI_UPDATE_OPTIONS
|
|
23
261
|
}
|
package/lib/wordpress.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { writeFile } = require('fs-extra');
|
|
3
|
+
const path = require( 'path' );
|
|
4
|
+
/**
|
|
5
|
+
* External dependencies
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
const {runDockerCmds} = require('./docker');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether WordPress environment is a multisite installation.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} environment Which environment to check for multisite installation.
|
|
17
|
+
* @param {WPConfig} config The wp-env config object.
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
async function isMultisite( environment, config ){
|
|
21
|
+
return await runDockerCmds(
|
|
22
|
+
environment,
|
|
23
|
+
[ 'wp config get MULTISITE' ],
|
|
24
|
+
config
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Transforms an existing single-site installation into a multisite installation.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} environment Which environment to convert into a multisite installation.
|
|
32
|
+
* @param {WPConfig} config The wp-env config object.
|
|
33
|
+
* @param {boolean} subdomain True if converting to multisite subdomain.
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
async function convertToMultisite( environment, config, subdomain ){
|
|
37
|
+
// before we can conver to multisite all plugins must be deactivated.
|
|
38
|
+
// first lets get all plugins
|
|
39
|
+
let activePlugins = await runDockerCmds(
|
|
40
|
+
environment,
|
|
41
|
+
['wp option get active_plugins --format=json'],
|
|
42
|
+
config
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
activePlugins = Object.values(JSON.parse( activePlugins ));
|
|
46
|
+
|
|
47
|
+
// deactivate all active plugins.
|
|
48
|
+
if( activePlugins.length ){
|
|
49
|
+
await runDockerCmds(
|
|
50
|
+
environment,
|
|
51
|
+
['wp plugin deactivate ' + activePlugins.join(' ')],
|
|
52
|
+
config
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// convert to multisite.
|
|
57
|
+
let command = 'wp core multisite-convert';
|
|
58
|
+
|
|
59
|
+
if( subdomain ){
|
|
60
|
+
command += ' --subdomains'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await runDockerCmds(
|
|
64
|
+
environment,
|
|
65
|
+
[command],
|
|
66
|
+
config
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
// generate .htaccess
|
|
70
|
+
await generateHTAccess( environment, config.workDirectoryPath, subdomain );
|
|
71
|
+
|
|
72
|
+
// network activate all active plugins again.
|
|
73
|
+
if( activePlugins.length ){
|
|
74
|
+
await runDockerCmds(
|
|
75
|
+
environment,
|
|
76
|
+
['wp plugin activate ' + activePlugins.join(' ') + ' --network'],
|
|
77
|
+
config
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generates .htaccess file content.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} environment Which environment to generate .htaccess for.
|
|
87
|
+
* @param {boolean} subdomain True if converting to multisite subdomain.
|
|
88
|
+
*/
|
|
89
|
+
async function generateHTAccess(environment, workDirectoryPath, subdomain){
|
|
90
|
+
let trailingSlash = subdomain ? '^wp-admin$ wp-admin/ [R=301,L]' : '^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/';
|
|
91
|
+
let writeRule1 = subdomain ? '^(wp-(content|admin|includes).*) $1 [L]' : '^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]';
|
|
92
|
+
let writeRule2 = subdomain ? '^(.*\.php)$ $1 [L]' : '^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]';
|
|
93
|
+
|
|
94
|
+
let htaccess = `
|
|
95
|
+
RewriteEngine On
|
|
96
|
+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
|
97
|
+
RewriteBase /
|
|
98
|
+
RewriteRule ^index\.php$ - [L]
|
|
99
|
+
|
|
100
|
+
# add a trailing slash to /wp-admin
|
|
101
|
+
RewriteRule ${trailingSlash}
|
|
102
|
+
|
|
103
|
+
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
|
104
|
+
RewriteCond %{REQUEST_FILENAME} -d
|
|
105
|
+
RewriteRule ^ - [L]
|
|
106
|
+
RewriteRule ${writeRule1}
|
|
107
|
+
RewriteRule ${writeRule2}
|
|
108
|
+
RewriteRule . index.php [L]
|
|
109
|
+
`.replace(/\t/g, '').trim();
|
|
110
|
+
|
|
111
|
+
let folder = 'development' === environment ? 'WordPress' : 'Tests-WordPress'
|
|
112
|
+
|
|
113
|
+
await writeFile(path.join(workDirectoryPath, folder, '.htaccess'), htaccess);
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
isMultisite,
|
|
119
|
+
convertToMultisite,
|
|
120
|
+
generateHTAccess
|
|
121
|
+
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CAWebPublishing Command Line Interface.",
|
|
5
5
|
"main": "lib/env.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"bin",
|
|
8
8
|
"lib"
|
|
9
9
|
],
|
|
10
|
+
"directories": {
|
|
11
|
+
"doc": "docs",
|
|
12
|
+
"lib": "lib"
|
|
13
|
+
},
|
|
10
14
|
"bin": {
|
|
11
15
|
"caweb": "bin/caweb"
|
|
12
16
|
},
|
|
13
17
|
"scripts": {
|
|
14
18
|
"caweb": "caweb",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
+
"test": "echo \"Error: run tests from root\" && exit 0",
|
|
20
|
+
"prelocaltest": "npm uninstall @caweb/cli",
|
|
21
|
+
"localtest": "npm pack && npm i caweb-cli-%npm_package_version%.tgz",
|
|
22
|
+
"postlocaltest": "del caweb-cli-%npm_package_version%.tgz"
|
|
19
23
|
},
|
|
20
24
|
"repository": {
|
|
21
25
|
"type": "git",
|
|
@@ -30,6 +34,9 @@
|
|
|
30
34
|
"bugs": {
|
|
31
35
|
"url": "https://github.com/CAWebPublishing/caweb-cli/issues"
|
|
32
36
|
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
33
40
|
"homepage": "https://github.com/CAWebPublishing/caweb-cli#readme",
|
|
34
41
|
"dependencies": {
|
|
35
42
|
"@wordpress/env": "^8.11.0",
|
|
@@ -37,7 +44,7 @@
|
|
|
37
44
|
"fs-extra": "^11.1.1"
|
|
38
45
|
},
|
|
39
46
|
"config": {
|
|
40
|
-
"WP_VER": "6.3.
|
|
47
|
+
"WP_VER": "6.3.2",
|
|
41
48
|
"PHP_VER": "8.1",
|
|
42
49
|
"DEFAULTS": {
|
|
43
50
|
"WP_DEFAULT_THEME": "CAWeb",
|
|
@@ -45,15 +52,22 @@
|
|
|
45
52
|
"WP_DEBUG": true,
|
|
46
53
|
"WP_DEBUG_LOG": true,
|
|
47
54
|
"WP_DEBUG_DISPLAY": false,
|
|
55
|
+
"WP_MEMORY_LIMIT": "256M",
|
|
56
|
+
"WP_MAX_MEMORY_LIMIT": "512M",
|
|
57
|
+
"WP_PERMALINK": "/%postname%/",
|
|
48
58
|
"ADMIN_COOKIE_PATH": "/",
|
|
49
59
|
"COOKIE_DOMAIN": "",
|
|
50
60
|
"COOKIEPATH": "",
|
|
51
|
-
"SITECOOKIEPATH": ""
|
|
61
|
+
"SITECOOKIEPATH": "",
|
|
62
|
+
"ET_DYNAMIC_MODULE": "on",
|
|
63
|
+
"ET_DYNAMIC_CSS": "on",
|
|
64
|
+
"ET_CRITICAL_CSS": "on",
|
|
65
|
+
"ET_DYNAMIC_JS": "on",
|
|
66
|
+
"ET_STATIC_CSS_GENERATION": "on",
|
|
67
|
+
"ET_OUTPUT_STYLES_INLINE": "off",
|
|
68
|
+
"ET_PRODUCT_TOUR": "off",
|
|
69
|
+
"ET_NEW_BUILDER_EXPERIENCE": "off",
|
|
70
|
+
"ET_CLASSIC_EDITOR": "on"
|
|
52
71
|
}
|
|
53
|
-
}
|
|
54
|
-
"directories": {
|
|
55
|
-
"doc": "docs",
|
|
56
|
-
"lib": "lib"
|
|
57
|
-
},
|
|
58
|
-
"devDependencies": {}
|
|
72
|
+
}
|
|
59
73
|
}
|