@caweb/cli 1.14.2 → 1.14.4
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/commands/env/start.js +7 -18
- package/configs/wp-env.js +10 -14
- package/lib/cli.js +0 -5
- package/lib/index.js +2 -0
- package/lib/wordpress/index.js +4 -3
- package/lib/wordpress/setup/caweb.js +17 -10
- package/lib/wordpress/setup/divi.js +27 -4
- package/lib/wordpress/setup/index.js +47 -28
- package/lib/wordpress/wordpress.js +9 -4
- package/package.json +1 -1
package/commands/env/start.js
CHANGED
|
@@ -3,30 +3,20 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import fs from 'fs';
|
|
6
|
-
import * as dockerCompose from 'docker-compose';
|
|
7
|
-
import os from 'os';
|
|
8
6
|
import deepmerge from 'deepmerge';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
|
|
9
9
|
/**
|
|
10
10
|
* WordPress dependencies
|
|
11
11
|
*/
|
|
12
12
|
import WPEnv from '@wordpress/env';
|
|
13
|
-
import { md5} from '../../lib/helpers.js';
|
|
14
|
-
// import { canAccessWPORG } from '../../lib/wordpress/index.js';
|
|
15
|
-
|
|
16
|
-
const CONFIG_CACHE_KEY = 'config_checksum';
|
|
17
|
-
const CACHE_FILE_NAME = 'wp-env-cache.json';
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* Internal dependencies
|
|
21
16
|
*/
|
|
22
17
|
import {
|
|
23
18
|
appPath,
|
|
24
|
-
|
|
25
|
-
currentPath,
|
|
26
|
-
configureCAWeb,
|
|
27
|
-
configureWordPress,
|
|
28
|
-
runCmd,
|
|
29
|
-
runCLICmds
|
|
19
|
+
md5
|
|
30
20
|
} from '../../lib/index.js';
|
|
31
21
|
|
|
32
22
|
import { wpEnvConfig, wpEnvOverrideConfig } from '../../configs/wp-env.js';
|
|
@@ -74,7 +64,6 @@ async function getCacheDirectory() {
|
|
|
74
64
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
75
65
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
76
66
|
* @param {boolean} options.sync Will attempt to sync changes from a CAWebPublishing static site to this WordPress instance..
|
|
77
|
-
* @param {boolean} options.bare True if excluding any CAWeb Configurations.
|
|
78
67
|
* @param {boolean} options.plugin True if root directory is a plugin.
|
|
79
68
|
* @param {boolean} options.theme True if root directory is a theme.
|
|
80
69
|
* @param {boolean} options.multisite True if converting to multisite.
|
|
@@ -89,7 +78,6 @@ export default async function start({
|
|
|
89
78
|
debug,
|
|
90
79
|
spx,
|
|
91
80
|
sync,
|
|
92
|
-
bare,
|
|
93
81
|
plugin,
|
|
94
82
|
theme,
|
|
95
83
|
multisite,
|
|
@@ -98,6 +86,7 @@ export default async function start({
|
|
|
98
86
|
let configFilePath = path.resolve( appPath, '.wp-env.json' );
|
|
99
87
|
let configOverrideFilePath = path.resolve( appPath, '.wp-env.override.json' );
|
|
100
88
|
|
|
89
|
+
// taken from @wordpress/env source code so we can get the working directory path before the env starts.
|
|
101
90
|
const workDirectoryPath = path.resolve(
|
|
102
91
|
await getCacheDirectory(),
|
|
103
92
|
md5( configFilePath )
|
|
@@ -110,7 +99,7 @@ export default async function start({
|
|
|
110
99
|
|
|
111
100
|
fs.writeFileSync(
|
|
112
101
|
configOverrideFilePath,
|
|
113
|
-
JSON.stringify( await wpEnvOverrideConfig({workDirectoryPath,
|
|
102
|
+
JSON.stringify( await wpEnvOverrideConfig({workDirectoryPath, multisite, subdomain, plugin, theme}), null, 4 )
|
|
114
103
|
);
|
|
115
104
|
|
|
116
105
|
spinner.start('Writing .wp-env.override.json file...');
|
|
@@ -122,7 +111,7 @@ export default async function start({
|
|
|
122
111
|
if( ! overrideConfig.config.ET_USERNAME || ! overrideConfig.config.ET_API_KEY ){
|
|
123
112
|
spinner.stop()
|
|
124
113
|
|
|
125
|
-
let diviConfig = await wpEnvOverrideConfig({workDirectoryPath,
|
|
114
|
+
let diviConfig = await wpEnvOverrideConfig({workDirectoryPath, multisite, subdomain, plugin, theme});
|
|
126
115
|
|
|
127
116
|
fs.writeFileSync(
|
|
128
117
|
configOverrideFilePath,
|
|
@@ -138,7 +127,7 @@ export default async function start({
|
|
|
138
127
|
|
|
139
128
|
fs.writeFileSync(
|
|
140
129
|
configFilePath,
|
|
141
|
-
JSON.stringify( await wpEnvConfig({workDirectoryPath,
|
|
130
|
+
JSON.stringify( await wpEnvConfig({workDirectoryPath, multisite, subdomain, plugin, theme}), null, 4 )
|
|
142
131
|
);
|
|
143
132
|
|
|
144
133
|
spinner.start('Writing .wp-env.json file...');
|
package/configs/wp-env.js
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
projectPath
|
|
13
13
|
} from '../lib/helpers.js';
|
|
14
14
|
import { promptForDivi } from './prompts.js';
|
|
15
|
-
import { config, env } from 'process';
|
|
16
15
|
import { CAWEB_OPTIONS, DIVI_OPTIONS } from'../lib/wordpress/options.js';
|
|
16
|
+
import { env } from 'process';
|
|
17
17
|
|
|
18
18
|
const localFile = path.join(projectPath, 'package.json');
|
|
19
19
|
const pkg = JSON.parse( fs.readFileSync(localFile) );
|
|
@@ -25,7 +25,6 @@ const cawebJson = fs.existsSync( path.join(appPath, 'caweb.json') ) ?
|
|
|
25
25
|
/**
|
|
26
26
|
* Build .wp-env.json
|
|
27
27
|
*
|
|
28
|
-
* @param {boolean} bare True if excluding any CAWeb Configurations.
|
|
29
28
|
* @param {boolean} multisite True if converting to multisite.
|
|
30
29
|
* @param {boolean} subdomain True if converting to multisite subdomain.
|
|
31
30
|
* @param {boolean} plugin True if root directory is a plugin.
|
|
@@ -33,14 +32,19 @@ const cawebJson = fs.existsSync( path.join(appPath, 'caweb.json') ) ?
|
|
|
33
32
|
*
|
|
34
33
|
* @returns object
|
|
35
34
|
*/
|
|
36
|
-
async function wpEnvConfig ( {workDirectoryPath: cwd ,
|
|
35
|
+
async function wpEnvConfig ( {workDirectoryPath: cwd , multisite, subdomain, plugin, theme} ) {
|
|
37
36
|
let themes = [];
|
|
38
37
|
let plugins = [];
|
|
39
|
-
let args = {cwd,
|
|
38
|
+
let args = {cwd, multisite, subdomain, plugin, theme};
|
|
40
39
|
let argString = Object.entries( args ).map( ([k, v]) => `--${k} ${v}` ).join( ' ' );
|
|
41
40
|
|
|
42
41
|
let setupFile = path.join( projectPath, 'lib', 'wordpress', 'setup', 'index.js' );
|
|
43
42
|
|
|
43
|
+
if( multisite && subdomain ){
|
|
44
|
+
// if subdomain add the subdomain constant
|
|
45
|
+
pkg.config.DEFAULTS.SUBDOMAIN_INSTALL= true;
|
|
46
|
+
}
|
|
47
|
+
|
|
44
48
|
let envConfig = {
|
|
45
49
|
core: `WordPress/WordPress#${pkg.config.WP_VER}`,
|
|
46
50
|
phpVersion: `${pkg.config.PHP_VER}`,
|
|
@@ -72,16 +76,9 @@ async function wpEnvConfig ( {workDirectoryPath: cwd , bare, multisite, subdomai
|
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
if( multisite ){
|
|
76
|
-
if( ! bare ){
|
|
77
|
-
// if multisite set default theme to CAWeb
|
|
78
|
-
// this allows for any new sites created to use CAWeb as the default theme.
|
|
79
|
-
pkg.config.DEFAULTS.WP_DEFAULT_THEME = 'CAWeb';
|
|
80
|
-
}
|
|
79
|
+
if( multisite && subdomain ){
|
|
81
80
|
// if subdomain add the subdomain constant
|
|
82
|
-
|
|
83
|
-
pkg.config.DEFAULTS.SUBDOMAIN_INSTALL= true;
|
|
84
|
-
}
|
|
81
|
+
envConfig.config.SUBDOMAIN_INSTALL= true;
|
|
85
82
|
}
|
|
86
83
|
|
|
87
84
|
// iterate over available CAWeb options.
|
|
@@ -182,7 +179,6 @@ async function wpEnvConfig ( {workDirectoryPath: cwd , bare, multisite, subdomai
|
|
|
182
179
|
/**
|
|
183
180
|
* Build .wp-env.override.json
|
|
184
181
|
*
|
|
185
|
-
* @param {boolean} bare True if excluding any CAWeb Configurations.
|
|
186
182
|
* @param {boolean} multisite True if converting to multisite.
|
|
187
183
|
* @param {boolean} subdomain True if converting to multisite subdomain.
|
|
188
184
|
* @param {boolean} plugin True if root directory is a plugin.
|
package/lib/cli.js
CHANGED
|
@@ -181,11 +181,6 @@ function addWPEnvCommands(){
|
|
|
181
181
|
'Will attempt to sync changes from a CAWebPublishing static site to this WordPress instance.',
|
|
182
182
|
false
|
|
183
183
|
)
|
|
184
|
-
.option(
|
|
185
|
-
'--bare',
|
|
186
|
-
'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.',
|
|
187
|
-
false
|
|
188
|
-
)
|
|
189
184
|
.option(
|
|
190
185
|
'-p, --plugin',
|
|
191
186
|
'True if root directory is a plugin.',
|
package/lib/index.js
CHANGED
package/lib/wordpress/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { configureDivi } from "./setup/divi.js";
|
|
1
|
+
import { isCAWeb, configureCAWeb } from "./setup/caweb.js";
|
|
2
|
+
import { isDivi, configureDivi } from "./setup/divi.js";
|
|
3
3
|
import {
|
|
4
4
|
configureWordPress
|
|
5
5
|
} from "./wordpress.js";
|
|
@@ -7,8 +7,9 @@ import { getTaxonomies, createTaxonomies } from "./api.js";
|
|
|
7
7
|
import { CAWEB_OPTIONS, DIVI_OPTIONS } from './options.js';
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
isCAWeb,
|
|
11
11
|
configureCAWeb,
|
|
12
|
+
isDivi,
|
|
12
13
|
configureDivi,
|
|
13
14
|
configureWordPress,
|
|
14
15
|
getTaxonomies,
|
|
@@ -9,18 +9,20 @@ import { CAWEB_OPTIONS } from'../options.js';
|
|
|
9
9
|
import { runCLICmds } from'../../helpers.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Checks for the CAWeb Theme in the WordPress Environment.
|
|
13
13
|
*
|
|
14
14
|
* @param {string} environment Which environment to activate the theme on.
|
|
15
15
|
* @param {WPConfig} config The wp-env config object.
|
|
16
16
|
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
17
17
|
*/
|
|
18
|
-
async function
|
|
19
|
-
|
|
18
|
+
async function isCAWeb({environment, cwd, is = 'active'}) {
|
|
19
|
+
let answer = await runCLICmds({
|
|
20
20
|
environment,
|
|
21
|
-
cmds: [
|
|
21
|
+
cmds: [`wp theme is-${is} CAWeb && echo $?`],
|
|
22
22
|
cwd
|
|
23
|
-
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return '0' === answer;
|
|
24
26
|
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -35,11 +37,11 @@ async function isCAWebActive({environment, cwd}){
|
|
|
35
37
|
*/
|
|
36
38
|
async function configureCAWeb( {environment, cwd, configs} ) {
|
|
37
39
|
|
|
38
|
-
const
|
|
40
|
+
const isThemeActive = await isCAWeb({environment, cwd});
|
|
39
41
|
let cmds = [];
|
|
40
42
|
|
|
41
43
|
// if our theme is active.
|
|
42
|
-
if( false !==
|
|
44
|
+
if( false !== isThemeActive ){
|
|
43
45
|
|
|
44
46
|
// iterate over possible CAWeb Options.
|
|
45
47
|
for(const [k,v] of Object.entries(CAWEB_OPTIONS)){
|
|
@@ -52,11 +54,16 @@ async function configureCAWeb( {environment, cwd, configs} ) {
|
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
+
// execute CAWeb Theme Configuration commands.
|
|
58
|
+
await runCLICmds({
|
|
59
|
+
environment,
|
|
60
|
+
cmds,
|
|
61
|
+
cwd,
|
|
62
|
+
debug: true
|
|
63
|
+
});
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
export {
|
|
60
|
-
|
|
67
|
+
isCAWeb,
|
|
61
68
|
configureCAWeb,
|
|
62
69
|
};
|
|
@@ -3,9 +3,26 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { runCLICmds } from '../../helpers.js';
|
|
5
5
|
import { DIVI_OPTIONS } from '../options.js';
|
|
6
|
-
import { isCAWebActive } from './caweb.js';
|
|
7
6
|
|
|
8
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Checks for the Divi Theme in the WordPress Environment.
|
|
10
|
+
*
|
|
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.
|
|
14
|
+
*/
|
|
15
|
+
async function isDivi({environment, cwd, is = 'active'}) {
|
|
16
|
+
let answer = await runCLICmds({
|
|
17
|
+
environment,
|
|
18
|
+
cmds: [`wp theme is-${is} Divi && echo $?`],
|
|
19
|
+
cwd
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return '0' === answer;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
9
26
|
/**
|
|
10
27
|
* Configures Divi for CAWebPublishing Service for the given environment by configure settings.
|
|
11
28
|
* These steps are performed sequentially so as to not overload the WordPress instance.
|
|
@@ -16,11 +33,11 @@ import { isCAWebActive } from './caweb.js';
|
|
|
16
33
|
*/
|
|
17
34
|
async function configureDivi( {environment, cwd, configs} ) {
|
|
18
35
|
|
|
19
|
-
const
|
|
36
|
+
const isThemeInstalled = await isDivi( {environment, cwd, is: 'installed'} );
|
|
20
37
|
let cmds = [];
|
|
21
38
|
|
|
22
39
|
// if CAWeb theme is active.
|
|
23
|
-
if( false !==
|
|
40
|
+
if( false !== isThemeInstalled ){
|
|
24
41
|
let diviOptions = await runCLICmds({
|
|
25
42
|
environment,
|
|
26
43
|
cmds: [ 'wp option get et_divi --format=json' ],
|
|
@@ -79,12 +96,18 @@ async function configureDivi( {environment, cwd, configs} ) {
|
|
|
79
96
|
`wp option update et_automatic_updates_options '${diviUpdateOptions}' --format=json`
|
|
80
97
|
);
|
|
81
98
|
|
|
82
|
-
|
|
99
|
+
await runCLICmds({
|
|
100
|
+
environment,
|
|
101
|
+
cmds,
|
|
102
|
+
cwd,
|
|
103
|
+
debug: true
|
|
104
|
+
});
|
|
83
105
|
}
|
|
84
106
|
|
|
85
107
|
|
|
86
108
|
}
|
|
87
109
|
|
|
88
110
|
export {
|
|
111
|
+
isDivi,
|
|
89
112
|
configureDivi
|
|
90
113
|
};
|
|
@@ -10,8 +10,8 @@ import { format } from 'util';
|
|
|
10
10
|
*/
|
|
11
11
|
import { runCLICmds } from '../../helpers.js';
|
|
12
12
|
import { configureWordPress } from '../wordpress.js';
|
|
13
|
-
import { configureCAWeb } from './caweb.js';
|
|
14
|
-
import { configureDivi } from './divi.js';
|
|
13
|
+
import { isCAWeb, configureCAWeb } from './caweb.js';
|
|
14
|
+
import { isDivi, configureDivi } from './divi.js';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
function processArgs( arr ){
|
|
@@ -55,19 +55,40 @@ let configs = {};
|
|
|
55
55
|
configs[item.name] = item.value;
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let cmds = [
|
|
61
|
-
...await configureWordPress({
|
|
58
|
+
|
|
59
|
+
let cawebInstalled = await isCAWeb({
|
|
62
60
|
environment: 'development',
|
|
63
61
|
cwd: workingDirectoryPath,
|
|
64
|
-
|
|
62
|
+
is: 'installed'
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let diviInstalled = await isDivi({
|
|
66
|
+
environment: 'development',
|
|
67
|
+
cwd: workingDirectoryPath,
|
|
68
|
+
is: 'installed'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let multisite = flagExists('--multisite') ? getArgVal('--multisite') : false;
|
|
72
|
+
|
|
73
|
+
process.stdout.write(`\nConfiguring WordPress...\n`);
|
|
74
|
+
await configureWordPress({
|
|
75
|
+
environment: 'development',
|
|
76
|
+
cwd: workingDirectoryPath,
|
|
77
|
+
multisite,
|
|
65
78
|
configs
|
|
66
79
|
})
|
|
67
|
-
|
|
80
|
+
|
|
68
81
|
|
|
69
82
|
// Download any resources required for CAWeb.
|
|
70
|
-
if(
|
|
83
|
+
if( cawebInstalled ){
|
|
84
|
+
let cmds = [];
|
|
85
|
+
|
|
86
|
+
// if multisite set default theme to CAWeb
|
|
87
|
+
// this allows for any new sites created to use CAWeb as the default theme.
|
|
88
|
+
if( multisite ){
|
|
89
|
+
cmds.push('wp config set WP_DEFAULT_THEME CAWeb');
|
|
90
|
+
}
|
|
91
|
+
|
|
71
92
|
// Delete all default themes.
|
|
72
93
|
let defaultThemes = [
|
|
73
94
|
'twentyten',
|
|
@@ -86,10 +107,11 @@ if( ! flagExists('--bare') || ( flagExists('--bare') && getArgVal('--bare') ) ){
|
|
|
86
107
|
'twentytwentyfour',
|
|
87
108
|
'twentytwentyfive'
|
|
88
109
|
];
|
|
110
|
+
|
|
89
111
|
cmds.push( `wp theme delete ${defaultThemes.join(' ')} --force` );
|
|
90
112
|
|
|
91
113
|
// If Elegant Themes credentials are available, download Divi.
|
|
92
|
-
if( configs.ET_USERNAME && configs.ET_API_KEY ){
|
|
114
|
+
if( configs.ET_USERNAME && configs.ET_API_KEY && ! diviInstalled ){
|
|
93
115
|
// generate Divi download URL.
|
|
94
116
|
let et_url = `https://www.elegantthemes.com/api/api_downloads.php?api_update=1&theme=%s&api_key=${configs.ET_API_KEY}&username=${configs.ET_USERNAME}`;
|
|
95
117
|
|
|
@@ -103,28 +125,25 @@ if( ! flagExists('--bare') || ( flagExists('--bare') && getArgVal('--bare') ) ){
|
|
|
103
125
|
// Activate CAWeb theme.
|
|
104
126
|
cmds.push( 'wp theme activate CAWeb' );
|
|
105
127
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
cmds.push(
|
|
110
|
-
...await configureCAWeb({
|
|
111
|
-
environment: 'development',
|
|
112
|
-
cwd: workingDirectoryPath,
|
|
113
|
-
configs,
|
|
114
|
-
}),
|
|
115
|
-
...await configureDivi({
|
|
116
|
-
environment: 'development',
|
|
117
|
-
cwd: workingDirectoryPath,
|
|
118
|
-
configs,
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
if( cmds.length ){
|
|
123
|
-
process.stdout.write(`\nConfiguring CAWeb...\n`);
|
|
128
|
+
// make additional configurations.
|
|
124
129
|
await runCLICmds({
|
|
125
130
|
environment: 'development',
|
|
126
131
|
cmds,
|
|
127
132
|
cwd: workingDirectoryPath,
|
|
128
133
|
debug: true
|
|
129
134
|
});
|
|
135
|
+
|
|
136
|
+
// Configure CAWeb and Divi options.
|
|
137
|
+
process.stdout.write(`\nConfiguring CAWeb...\n`);
|
|
138
|
+
await configureCAWeb({
|
|
139
|
+
environment: 'development',
|
|
140
|
+
cwd: workingDirectoryPath,
|
|
141
|
+
configs,
|
|
142
|
+
})
|
|
143
|
+
await configureDivi({
|
|
144
|
+
environment: 'development',
|
|
145
|
+
cwd: workingDirectoryPath,
|
|
146
|
+
configs,
|
|
147
|
+
})
|
|
148
|
+
|
|
130
149
|
}
|
|
@@ -120,10 +120,15 @@ async function configureWordPress({environment, cwd, multisite, subdomain, confi
|
|
|
120
120
|
await networkActivatePlugins( {environment, cwd} );
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
await runCLICmds({
|
|
124
|
+
environment,
|
|
125
|
+
cmds: [
|
|
126
|
+
`wp option update permalink_structure "${configs.WP_PERMALINK}"`,
|
|
127
|
+
`wp rewrite structure ${configs.WP_PERMALINK} --hard`
|
|
128
|
+
],
|
|
129
|
+
cwd,
|
|
130
|
+
debug: true
|
|
131
|
+
});
|
|
127
132
|
|
|
128
133
|
}
|
|
129
134
|
|