@caweb/cli 1.13.7 → 1.14.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/commands/env/shell.js +1 -1
- package/commands/env/start.js +84 -88
- package/commands/index.js +9 -8
- package/commands/sync/index.js +3 -5
- package/configs/wp-env.js +57 -14
- package/lib/cli.js +5 -9
- package/lib/helpers.js +36 -11
- package/lib/index.js +0 -12
- package/lib/wordpress/index.js +6 -10
- package/lib/wordpress/options.js +17 -4
- package/lib/wordpress/setup/caweb.js +62 -0
- package/lib/wordpress/setup/divi.js +90 -0
- package/lib/wordpress/setup/index.js +130 -0
- package/lib/wordpress/wordpress.js +45 -165
- package/package.json +6 -3
- package/commands/env/update-plugins.js +0 -44
- package/lib/admin.js +0 -40
- package/lib/wordpress/caweb.js +0 -114
- package/lib/wordpress/divi.js +0 -127
- package/lib/wordpress/download-sources.js +0 -286
package/lib/wordpress/caweb.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import retry from '@wordpress/env/lib/retry.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { CAWEB_OPTIONS } from'./options.js';
|
|
10
|
-
import { runCLICmds } from'../helpers.js';
|
|
11
|
-
import { isMultisite } from'./wordpress.js';
|
|
12
|
-
import { configureDivi } from'./divi.js';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Activates the CAWeb Theme for the WordPress Environment if it's installed.
|
|
16
|
-
*
|
|
17
|
-
* @param {string} environment Which environment to activate the theme on.
|
|
18
|
-
* @param {WPConfig} config The wp-env config object.
|
|
19
|
-
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
20
|
-
*/
|
|
21
|
-
async function activateCAWeb(
|
|
22
|
-
environment,
|
|
23
|
-
config,
|
|
24
|
-
spinner
|
|
25
|
-
){
|
|
26
|
-
|
|
27
|
-
const isMulti = await isMultisite( environment, config , spinner);
|
|
28
|
-
|
|
29
|
-
let cmds = ['wp theme is-installed CAWeb'];
|
|
30
|
-
|
|
31
|
-
if( false !== isMulti ){
|
|
32
|
-
cmds.push( 'wp theme enable CAWeb --network --activate' );
|
|
33
|
-
}else{
|
|
34
|
-
cmds.push( 'wp theme activate CAWeb' );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return await runCLICmds(
|
|
38
|
-
environment,
|
|
39
|
-
cmds,
|
|
40
|
-
config,
|
|
41
|
-
spinner
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Configures CAWebPublishing Service for the given environment by configure settings,
|
|
48
|
-
* and activating the CAWeb theme. These steps are
|
|
49
|
-
* performed sequentially so as to not overload the WordPress instance.
|
|
50
|
-
*
|
|
51
|
-
* @param {WPEnvironment} environment The environment to configure. Either 'development' or 'tests'.
|
|
52
|
-
* @param {WPConfig} config The wp-env config object.
|
|
53
|
-
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
54
|
-
*/
|
|
55
|
-
async function configureCAWeb( environment, config, spinner ) {
|
|
56
|
-
|
|
57
|
-
const isThemeActivated = await activateCAWeb( environment, config );
|
|
58
|
-
|
|
59
|
-
// if our theme is active.
|
|
60
|
-
if( false !== isThemeActivated ){
|
|
61
|
-
|
|
62
|
-
spinner.text = `Configuring CAWebPublishing ${environment} Environment...`;
|
|
63
|
-
|
|
64
|
-
// lets set the default theme to CAWeb.
|
|
65
|
-
let themeOptions = [
|
|
66
|
-
'wp config set WP_DEFAULT_THEME CAWeb',
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
// iterate over config options.
|
|
70
|
-
Object.entries(config.env[ environment ].config).forEach(([k,v]) => {
|
|
71
|
-
// if the option is prefixed with CAWEB_ and is a valid CAWeb Option.
|
|
72
|
-
if ( `${k}`.startsWith('CAWEB_') && undefined !== CAWEB_OPTIONS[k] ){
|
|
73
|
-
const option = CAWEB_OPTIONS[k];
|
|
74
|
-
// set the option.
|
|
75
|
-
themeOptions.push(
|
|
76
|
-
`wp option set '${option.name}' "${v}"`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
if ( config.debug ) {
|
|
82
|
-
spinner.info(
|
|
83
|
-
`Running the following setup commands on the ${ environment } instance:\n - ${ setupCommands.join(
|
|
84
|
-
'\n - '
|
|
85
|
-
) }\n`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Execute theme option commands.
|
|
90
|
-
await runCLICmds(
|
|
91
|
-
environment,
|
|
92
|
-
themeOptions,
|
|
93
|
-
config,
|
|
94
|
-
spinner
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
// Make Divi WordPress Configurations.
|
|
98
|
-
await Promise.all( [
|
|
99
|
-
retry( () => configureDivi( 'development', config, spinner ), {
|
|
100
|
-
times: 2,
|
|
101
|
-
} ),
|
|
102
|
-
retry( () => configureDivi( 'tests', config, spinner ), {
|
|
103
|
-
times: 2,
|
|
104
|
-
} ),
|
|
105
|
-
] );
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export {
|
|
112
|
-
activateCAWeb,
|
|
113
|
-
configureCAWeb,
|
|
114
|
-
};
|
package/lib/wordpress/divi.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { runCLICmds } from '../helpers.js';
|
|
5
|
-
import { DIVI_OPTIONS } from './options.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Checks if Divi Theme is active for 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 isDiviThemeActive(
|
|
16
|
-
environment,
|
|
17
|
-
config,
|
|
18
|
-
spinner
|
|
19
|
-
){
|
|
20
|
-
|
|
21
|
-
return await runCLICmds(
|
|
22
|
-
environment,
|
|
23
|
-
['wp theme is-active Divi'],
|
|
24
|
-
config,
|
|
25
|
-
spinner
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configures Divi for CAWebPublishing Service for the given environment by configure settings.
|
|
32
|
-
* These steps are performed sequentially so as to not overload the WordPress instance.
|
|
33
|
-
*
|
|
34
|
-
* @param {WPEnvironment} environment The environment to configure. Either 'development' or 'tests'.
|
|
35
|
-
* @param {WPConfig} config The wp-env config object.
|
|
36
|
-
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
37
|
-
*/
|
|
38
|
-
async function configureDivi( environment, config, spinner ) {
|
|
39
|
-
|
|
40
|
-
const activeTheme = await isDiviThemeActive( environment, config, spinner );
|
|
41
|
-
|
|
42
|
-
// if Divi theme is active.
|
|
43
|
-
if( false !== activeTheme ){
|
|
44
|
-
let cmds = [];
|
|
45
|
-
let diviOptions = await runCLICmds(
|
|
46
|
-
environment,
|
|
47
|
-
[ 'wp option get et_divi --format=json' ],
|
|
48
|
-
config,
|
|
49
|
-
spinner
|
|
50
|
-
)
|
|
51
|
-
let diviBuilderOptions = await runCLICmds(
|
|
52
|
-
environment,
|
|
53
|
-
[ 'wp option get et_bfb_settings --format=json' ],
|
|
54
|
-
config,
|
|
55
|
-
spinner
|
|
56
|
-
)
|
|
57
|
-
let diviUpdateOptions = await runCLICmds(
|
|
58
|
-
environment,
|
|
59
|
-
[ 'wp option get et_automatic_updates_options --format=json' ],
|
|
60
|
-
config,
|
|
61
|
-
spinner
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
// parse the options into a json object.
|
|
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
|
-
|
|
69
|
-
// iterate over mapped Divi option groups.
|
|
70
|
-
Object.entries(DIVI_OPTIONS).forEach(([group, options]) => {
|
|
71
|
-
// iterate over each group options.
|
|
72
|
-
Object.entries(options).forEach(([key, data]) => {
|
|
73
|
-
|
|
74
|
-
// if user config has a Divi option variable use that, otherwise use our default.
|
|
75
|
-
let option_value = undefined !== config.env[ environment ].config[key] ?
|
|
76
|
-
config.env[ environment ].config[key] :
|
|
77
|
-
data.defaultValue;
|
|
78
|
-
|
|
79
|
-
// is a valid Divi Option.
|
|
80
|
-
if( 'et_divi' === group ){
|
|
81
|
-
diviOptions[data.name] = option_value;
|
|
82
|
-
// is a valid Divi Builder Option.
|
|
83
|
-
}else if( 'et_bfb_settings' === group ){
|
|
84
|
-
diviBuilderOptions[data.name] = option_value;
|
|
85
|
-
// is a valid Divi Update Option.
|
|
86
|
-
}else if( 'et_automatic_updates_options' === group ){
|
|
87
|
-
diviUpdateOptions[data.name] = option_value;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
// parse option object back to string.
|
|
94
|
-
diviOptions = JSON.stringify( diviOptions );
|
|
95
|
-
diviBuilderOptions = JSON.stringify( diviBuilderOptions );
|
|
96
|
-
diviUpdateOptions = JSON.stringify( diviUpdateOptions );
|
|
97
|
-
|
|
98
|
-
// update each option.
|
|
99
|
-
cmds.push(`wp option update et_divi '${diviOptions}' --format=json`);
|
|
100
|
-
cmds.push(`wp option update et_bfb_settings '${diviBuilderOptions}' --format=json`);
|
|
101
|
-
cmds.push(`wp option update et_automatic_updates_options '${diviUpdateOptions}' --format=json`);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if ( config.debug ) {
|
|
105
|
-
spinner.info(
|
|
106
|
-
`Running the following setup commands on the ${ environment } instance:\n - ${ setupCommands.join(
|
|
107
|
-
'\n - '
|
|
108
|
-
) }\n`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Execute theme option commands.
|
|
113
|
-
await runCLICmds(
|
|
114
|
-
environment,
|
|
115
|
-
cmds,
|
|
116
|
-
config,
|
|
117
|
-
spinner
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
configureDivi,
|
|
126
|
-
isDiviThemeActive
|
|
127
|
-
};
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modified from wp-env
|
|
3
|
-
* Few modifications made:
|
|
4
|
-
* - Downloads CAWebPublishing Resources, excluding WordPress.
|
|
5
|
-
* - Ensure parent directory of source.path exists before attempting to extract in downloadZipSource, otherwise it will complain that file/directory doesn't exist.
|
|
6
|
-
* @see @wordpress/env/lib/download-sources.js
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* External dependencies
|
|
11
|
-
*/
|
|
12
|
-
import util from 'util';
|
|
13
|
-
import path from 'path';
|
|
14
|
-
import fs from 'fs-extra';
|
|
15
|
-
import SimpleGit from 'simple-git';
|
|
16
|
-
import got from 'got';
|
|
17
|
-
import stream from 'stream';
|
|
18
|
-
import zip from 'extract-zip';
|
|
19
|
-
import { rimraf } from 'rimraf';
|
|
20
|
-
import { env } from 'process';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Promisified dependencies
|
|
28
|
-
*/
|
|
29
|
-
const pipeline = util.promisify( stream.pipeline );
|
|
30
|
-
const extractZip = util.promisify( zip );
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Downloads the given source if necessary. The specific action taken depends
|
|
34
|
-
* on the source type. The source is downloaded to source.path.
|
|
35
|
-
*
|
|
36
|
-
* @param {WPSource} source The source to download.
|
|
37
|
-
* @param {Object} options
|
|
38
|
-
* @param {Function} options.onProgress A function called with download progress. Will be invoked with one argument: a number that ranges from 0 to 1 which indicates current download progress for this source.
|
|
39
|
-
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
40
|
-
* @param {boolean} options.debug True if debug mode is enabled.
|
|
41
|
-
*/
|
|
42
|
-
async function downloadSource(src, { onProgress, spinner, debug } ){
|
|
43
|
-
if( 'git' == src.type ){
|
|
44
|
-
await downloadGitSource(src, { onProgress, spinner, debug });
|
|
45
|
-
}else if( 'zip' == src.type ) {
|
|
46
|
-
await downloadZipSource(src, { onProgress, spinner, debug });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Clones the git repository at `source.url` into `source.path`. If the
|
|
52
|
-
* repository already exists, it is updated instead.
|
|
53
|
-
*
|
|
54
|
-
* @param {WPSource} source The source to download.
|
|
55
|
-
* @param {Object} options
|
|
56
|
-
* @param {Function} options.onProgress A function called with download progress. Will be invoked with one argument: a number that ranges from 0 to 1 which indicates current download progress for this source.
|
|
57
|
-
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
58
|
-
* @param {boolean} options.debug True if debug mode is enabled.
|
|
59
|
-
*/
|
|
60
|
-
async function downloadGitSource( source, { onProgress, spinner, debug } ) {
|
|
61
|
-
const log = debug
|
|
62
|
-
? ( message ) => {
|
|
63
|
-
spinner.info( `SimpleGit: ${ message }` );
|
|
64
|
-
spinner.start();
|
|
65
|
-
}
|
|
66
|
-
: () => {};
|
|
67
|
-
onProgress( 0 );
|
|
68
|
-
|
|
69
|
-
const progressHandler = ( { progress } ) => {
|
|
70
|
-
onProgress( progress / 100 );
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
log( 'Cloning or getting the repo.' );
|
|
74
|
-
const git = SimpleGit( { progress: progressHandler } );
|
|
75
|
-
|
|
76
|
-
const isRepo =
|
|
77
|
-
fs.existsSync( source.clonePath ) &&
|
|
78
|
-
( await git.cwd( source.clonePath ).checkIsRepo( 'root' ) );
|
|
79
|
-
|
|
80
|
-
// repository already exists.
|
|
81
|
-
if ( isRepo ) {
|
|
82
|
-
log( 'Repo already exists, using it.' );
|
|
83
|
-
} else {
|
|
84
|
-
// repository doesn't exists, but the directory does.
|
|
85
|
-
if( fs.existsSync( source.clonePath ) ){
|
|
86
|
-
// reinitialize repo.
|
|
87
|
-
await git.cwd( source.clonePath );
|
|
88
|
-
|
|
89
|
-
await git.init().addRemote('origin', source.url );
|
|
90
|
-
}else{
|
|
91
|
-
|
|
92
|
-
await git.clone( source.url, source.clonePath, {
|
|
93
|
-
'--depth': '1',
|
|
94
|
-
'--no-single-branch': null
|
|
95
|
-
} );
|
|
96
|
-
await git.cwd( source.clonePath );
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
log( 'Fetching the specified ref.' );
|
|
101
|
-
await git.fetch( 'origin', source.ref, {
|
|
102
|
-
'--tags': null,
|
|
103
|
-
} );
|
|
104
|
-
|
|
105
|
-
log( 'Checking out the specified ref.' );
|
|
106
|
-
await git.checkout( source.ref, {
|
|
107
|
-
'--force': null
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
onProgress( 1 );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Downloads and extracts the zip file at `source.url` into `source.path`.
|
|
115
|
-
*
|
|
116
|
-
* @param {WPSource} source The source to download.
|
|
117
|
-
* @param {Object} options
|
|
118
|
-
* @param {Function} options.onProgress A function called with download progress. Will be invoked with one argument: a number that ranges from 0 to 1 which indicates current download progress for this source.
|
|
119
|
-
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
120
|
-
* @param {boolean} options.debug True if debug mode is enabled.
|
|
121
|
-
*/
|
|
122
|
-
async function downloadZipSource( source, { onProgress, spinner, debug } ) {
|
|
123
|
-
const log = debug
|
|
124
|
-
? ( message ) => {
|
|
125
|
-
spinner.info( `NodeGit: ${ message }` );
|
|
126
|
-
spinner.start();
|
|
127
|
-
}
|
|
128
|
-
: () => {};
|
|
129
|
-
onProgress( 0 );
|
|
130
|
-
|
|
131
|
-
log( 'Downloading zip file.' );
|
|
132
|
-
const zipName = `${ source.path }.zip`;
|
|
133
|
-
const zipFile = fs.createWriteStream( zipName );
|
|
134
|
-
const responseStream = got.stream( source.url );
|
|
135
|
-
responseStream.on( 'downloadProgress', ( { percent } ) =>
|
|
136
|
-
onProgress( percent )
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
await pipeline( responseStream, zipFile );
|
|
140
|
-
|
|
141
|
-
log( 'Extracting to temporary directory.' );
|
|
142
|
-
// Target directory is expected to be absolute.
|
|
143
|
-
const tempDir = `${ source.path }.temp`;
|
|
144
|
-
await extractZip( zipName, { dir: tempDir } );
|
|
145
|
-
|
|
146
|
-
const files = (
|
|
147
|
-
await Promise.all( [
|
|
148
|
-
rimraf( zipName ),
|
|
149
|
-
rimraf( source.path ),
|
|
150
|
-
fs.promises.readdir( tempDir ),
|
|
151
|
-
] )
|
|
152
|
-
)[ 2 ];
|
|
153
|
-
/**
|
|
154
|
-
* The plugin container is the extracted directory which is the direct parent
|
|
155
|
-
* of the contents of the plugin. It seems a zip file can have two fairly
|
|
156
|
-
* common approaches to where the content lives:
|
|
157
|
-
* 1. The .zip is the direct container of the files. So after extraction, the
|
|
158
|
-
* extraction directory contains plugin contents.
|
|
159
|
-
* 2. The .zip contains a directory with the same name which is the container.
|
|
160
|
-
* So after extraction, the extraction directory contains another directory.
|
|
161
|
-
* That subdirectory is the actual container of the plugin contents.
|
|
162
|
-
*
|
|
163
|
-
* We support both situations with the following check.
|
|
164
|
-
*/
|
|
165
|
-
let pluginContainer = tempDir;
|
|
166
|
-
const firstSubItem = path.join( tempDir, files[ 0 ] );
|
|
167
|
-
if (
|
|
168
|
-
files.length === 1 &&
|
|
169
|
-
( await fs.promises.lstat( firstSubItem ) ).isDirectory()
|
|
170
|
-
) {
|
|
171
|
-
// In this case, only one sub directory exists, so use that as the container.
|
|
172
|
-
pluginContainer = firstSubItem;
|
|
173
|
-
}
|
|
174
|
-
await fs.promises.rename( pluginContainer, source.path );
|
|
175
|
-
await rimraf( tempDir );
|
|
176
|
-
|
|
177
|
-
onProgress( 1 );
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function defaultSources(pluginDir, themeDir){
|
|
181
|
-
return [
|
|
182
|
-
{
|
|
183
|
-
basename: 'CAWeb Theme',
|
|
184
|
-
url: 'https://github.com/CAWebPublishing/CAWeb/archive/refs/tags/1.13.3.zip',
|
|
185
|
-
path: path.join(themeDir, 'CAWeb'),
|
|
186
|
-
type: 'zip',
|
|
187
|
-
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
basename: 'CAWebPublishing Development Plugin',
|
|
191
|
-
url: 'https://github.com/CAWebPublishing/caweb-dev/archive/refs/tags/1.1.1.zip',
|
|
192
|
-
path: path.join(pluginDir, 'caweb-dev'),
|
|
193
|
-
type: 'zip',
|
|
194
|
-
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
basename: 'Query Monitor',
|
|
198
|
-
url: 'https://downloads.wordpress.org/plugin/query-monitor.3.17.2.zip',
|
|
199
|
-
path: path.join(pluginDir, 'query-monitor'),
|
|
200
|
-
type: 'zip',
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
]
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Download CAWeb Resources.
|
|
208
|
-
*
|
|
209
|
-
* @param {WPEnvironment} environment The environment to configure. Either 'development' or 'tests'.
|
|
210
|
-
* @param {Object} spinner The spinner object to show progress.
|
|
211
|
-
* @return {WPConfig} The config object we've loaded.
|
|
212
|
-
*/
|
|
213
|
-
export async function downloadSources( environment,
|
|
214
|
-
{
|
|
215
|
-
spinner,
|
|
216
|
-
config
|
|
217
|
-
}
|
|
218
|
-
) {
|
|
219
|
-
const progresses = {};
|
|
220
|
-
const getProgressSetter = ( id ) => ( progress ) => {
|
|
221
|
-
progresses[ id ] = progress;
|
|
222
|
-
spinner.text =
|
|
223
|
-
`Downloading ${id}.\n` +
|
|
224
|
-
Object.entries( progresses )
|
|
225
|
-
.map(
|
|
226
|
-
( [ key, value ] ) =>
|
|
227
|
-
` - ${ key }: ${ ( value * 100 ).toFixed( 0 ) }/100%`
|
|
228
|
-
)
|
|
229
|
-
.join( '\n' );
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const { workDirectoryPath } = config;
|
|
233
|
-
const { development: dev, tests: test } = config.env;
|
|
234
|
-
|
|
235
|
-
let instance = ('tests' === environment ? 'Tests-' : '') + 'WordPress';
|
|
236
|
-
|
|
237
|
-
let pluginDir = path.resolve(workDirectoryPath, instance , 'wp-content' , 'plugins');
|
|
238
|
-
let themeDir = path.resolve(workDirectoryPath, instance, 'wp-content' , 'themes');
|
|
239
|
-
|
|
240
|
-
let sources = defaultSources(pluginDir, themeDir);
|
|
241
|
-
|
|
242
|
-
// Add Divi Theme and plugin to sources.
|
|
243
|
-
if( (undefined !== dev.config.ET_USERNAME &&
|
|
244
|
-
undefined !== dev.config.ET_API_KEY) ||
|
|
245
|
-
(undefined !== test.config.ET_USERNAME &&
|
|
246
|
-
undefined !== test.config.ET_API_KEY)
|
|
247
|
-
){
|
|
248
|
-
let url = 'https://www.elegantthemes.com/api/api_downloads.php';
|
|
249
|
-
let user = undefined !== dev.config.ET_USERNAME ? dev.config.ET_USERNAME : test.config.ET_USERNAME;
|
|
250
|
-
let key = undefined !== dev.config.ET_API_KEY ? dev.config.ET_API_KEY : test.config.ET_API_KEY;
|
|
251
|
-
|
|
252
|
-
// Add Divi sources.
|
|
253
|
-
sources = sources.concat( [
|
|
254
|
-
{
|
|
255
|
-
basename: 'Divi',
|
|
256
|
-
url: `${url}?api_update=1&theme=Divi&api_key=${key}&username=${user}`,
|
|
257
|
-
path: path.join(themeDir, 'Divi'),
|
|
258
|
-
type: 'zip'
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
basename: 'Divi Plugin',
|
|
262
|
-
url: `${url}?api_update=1&theme=divi-builder&api_key=${key}&username=${user}`,
|
|
263
|
-
path: path.join(pluginDir, 'divi-builder'),
|
|
264
|
-
type: 'zip'
|
|
265
|
-
}
|
|
266
|
-
]);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Ensure plugin/theme directory exists for downloading resources.
|
|
270
|
-
// fs.ensureDir(themeDir);
|
|
271
|
-
// fs.ensureDir(pluginDir);
|
|
272
|
-
|
|
273
|
-
await Promise.all(
|
|
274
|
-
sources.map( ( source ) => {
|
|
275
|
-
if( 'development' === environment ){
|
|
276
|
-
downloadSource( source, {
|
|
277
|
-
onProgress: getProgressSetter( source.basename ),
|
|
278
|
-
spinner,
|
|
279
|
-
} )
|
|
280
|
-
}else{
|
|
281
|
-
downloadSource( source, {onProgress: () => {}, spinner} )
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
};
|