@caweb/cli 1.14.2 → 1.14.3
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 +10 -8
- package/lib/wordpress/setup/divi.js +21 -3
- package/lib/wordpress/setup/index.js +38 -21
- 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)){
|
|
@@ -57,6 +59,6 @@ async function configureCAWeb( {environment, cwd, configs} ) {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
export {
|
|
60
|
-
|
|
62
|
+
isCAWeb,
|
|
61
63
|
configureCAWeb,
|
|
62
64
|
};
|
|
@@ -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' ],
|
|
@@ -86,5 +103,6 @@ async function configureDivi( {environment, cwd, configs} ) {
|
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
export {
|
|
106
|
+
isDivi,
|
|
89
107
|
configureDivi
|
|
90
108
|
};
|
|
@@ -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,38 @@ let configs = {};
|
|
|
55
55
|
configs[item.name] = item.value;
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
|
|
59
|
+
let cawebInstalled = await isCAWeb({
|
|
60
|
+
environment: 'development',
|
|
61
|
+
cwd: workingDirectoryPath,
|
|
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;
|
|
58
72
|
// wp cli commands that will be ran.
|
|
59
73
|
// process.stdout.write(`\nConfiguring WordPress...\n`);
|
|
60
74
|
let cmds = [
|
|
61
75
|
...await configureWordPress({
|
|
62
76
|
environment: 'development',
|
|
63
77
|
cwd: workingDirectoryPath,
|
|
64
|
-
multisite
|
|
78
|
+
multisite,
|
|
65
79
|
configs
|
|
66
80
|
})
|
|
67
81
|
];
|
|
68
82
|
|
|
69
83
|
// Download any resources required for CAWeb.
|
|
70
|
-
if(
|
|
84
|
+
if( cawebInstalled ){
|
|
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
|
+
cmds.push('wp config set WP_DEFAULT_THEME CAWeb');
|
|
89
|
+
|
|
71
90
|
// Delete all default themes.
|
|
72
91
|
let defaultThemes = [
|
|
73
92
|
'twentyten',
|
|
@@ -86,10 +105,11 @@ if( ! flagExists('--bare') || ( flagExists('--bare') && getArgVal('--bare') ) ){
|
|
|
86
105
|
'twentytwentyfour',
|
|
87
106
|
'twentytwentyfive'
|
|
88
107
|
];
|
|
108
|
+
|
|
89
109
|
cmds.push( `wp theme delete ${defaultThemes.join(' ')} --force` );
|
|
90
110
|
|
|
91
111
|
// If Elegant Themes credentials are available, download Divi.
|
|
92
|
-
if( configs.ET_USERNAME && configs.ET_API_KEY ){
|
|
112
|
+
if( configs.ET_USERNAME && configs.ET_API_KEY && ! diviInstalled ){
|
|
93
113
|
// generate Divi download URL.
|
|
94
114
|
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
115
|
|
|
@@ -103,23 +123,20 @@ if( ! flagExists('--bare') || ( flagExists('--bare') && getArgVal('--bare') ) ){
|
|
|
103
123
|
// Activate CAWeb theme.
|
|
104
124
|
cmds.push( 'wp theme activate CAWeb' );
|
|
105
125
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
120
|
-
);
|
|
126
|
+
// Configure CAWeb and Divi options.
|
|
127
|
+
cmds.push(
|
|
128
|
+
...await configureCAWeb({
|
|
129
|
+
environment: 'development',
|
|
130
|
+
cwd: workingDirectoryPath,
|
|
131
|
+
configs,
|
|
132
|
+
}),
|
|
133
|
+
...await configureDivi({
|
|
134
|
+
environment: 'development',
|
|
135
|
+
cwd: workingDirectoryPath,
|
|
136
|
+
configs,
|
|
137
|
+
})
|
|
138
|
+
);
|
|
121
139
|
|
|
122
|
-
if( cmds.length ){
|
|
123
140
|
process.stdout.write(`\nConfiguring CAWeb...\n`);
|
|
124
141
|
await runCLICmds({
|
|
125
142
|
environment: 'development',
|