@caweb/cli 1.11.2 → 1.12.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/start.js +67 -68
- package/commands/gen-scripts.js +66 -0
- package/commands/index.js +12 -9
- package/commands/sites/convert-site.js +228 -75
- package/commands/sites/create-site.js +25 -3
- package/commands/sites/prompts.js +34 -15
- package/commands/sync/index.js +56 -15
- package/configs/prompts.js +64 -0
- package/configs/wp-env.js +114 -25
- package/lib/cli.js +84 -72
- package/lib/wordpress/api.js +18 -10
- package/lib/wordpress/caweb.js +6 -20
- package/lib/wordpress/download-sources.js +38 -16
- package/lib/wordpress/options.js +21 -18
- package/lib/wordpress/wordpress.js +105 -30
- package/package.json +10 -6
- package/commands/env/destroy.js +0 -49
- package/commands/env/stop.js +0 -35
- package/configs/docker-compose.js +0 -132
- /package/commands/{tasks → env}/shell.js +0 -0
- /package/commands/{tasks → env}/update-plugins.js +0 -0
package/commands/env/start.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import * as dockerCompose from 'docker-compose';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* WordPress dependencies
|
|
@@ -25,12 +24,14 @@ import {
|
|
|
25
24
|
projectPath,
|
|
26
25
|
configureCAWeb,
|
|
27
26
|
downloadSources,
|
|
27
|
+
generateCLIConfig,
|
|
28
28
|
configureWordPress,
|
|
29
|
-
runCmd
|
|
29
|
+
runCmd,
|
|
30
|
+
runCLICmds
|
|
30
31
|
} from '../../lib/index.js';
|
|
31
|
-
import wpEnvConfig from '../../configs/wp-env.js';
|
|
32
|
-
import dockerConfig from '../../configs/docker-compose.js';
|
|
33
32
|
|
|
33
|
+
import { wpEnvConfig, wpEnvOverrideConfig } from '../../configs/wp-env.js';
|
|
34
|
+
import {default as SyncProcess} from '../sync/index.js';
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Starts the development server.
|
|
@@ -41,6 +42,7 @@ import dockerConfig from '../../configs/docker-compose.js';
|
|
|
41
42
|
* @param {string} options.xdebug The Xdebug mode to set.
|
|
42
43
|
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
|
|
43
44
|
* @param {boolean} options.debug True if debug mode is enabled.
|
|
45
|
+
* @param {boolean} options.sync Will attempt to sync changes from a CAWebPublishing static site to this WordPress instance..
|
|
44
46
|
* @param {boolean} options.bare True if excluding any CAWeb Configurations.
|
|
45
47
|
* @param {boolean} options.plugin True if root directory is a plugin.
|
|
46
48
|
* @param {boolean} options.theme True if root directory is a theme.
|
|
@@ -54,6 +56,7 @@ export default async function start({
|
|
|
54
56
|
xdebug,
|
|
55
57
|
scripts,
|
|
56
58
|
debug,
|
|
59
|
+
sync,
|
|
57
60
|
bare,
|
|
58
61
|
plugin,
|
|
59
62
|
theme,
|
|
@@ -61,23 +64,51 @@ export default async function start({
|
|
|
61
64
|
subdomain
|
|
62
65
|
}) {
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Write CAWeb .wp-env.override.json file.
|
|
70
|
+
if( ! fs.existsSync( path.join(appPath, '.wp-env.override.json')) ){
|
|
71
|
+
spinner.stop()
|
|
72
|
+
|
|
73
|
+
// Keys should not be saved in the repository so we store them in the override.json file.
|
|
74
|
+
fs.writeFileSync(
|
|
75
|
+
path.join(appPath, '.wp-env.override.json'),
|
|
76
|
+
JSON.stringify( await wpEnvOverrideConfig(bare, multisite, subdomain, plugin, theme), null, 4 )
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
spinner.start('Writing .wp-env.override.json file...');
|
|
80
|
+
|
|
81
|
+
}
|
|
65
82
|
|
|
66
83
|
// Write CAWeb .wp-env.json file.
|
|
67
|
-
fs.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
if( ! fs.existsSync( path.join(appPath, '.wp-env.json')) || update ){
|
|
85
|
+
spinner.stop()
|
|
86
|
+
|
|
87
|
+
fs.writeFileSync(
|
|
88
|
+
path.join(appPath, '.wp-env.json'),
|
|
89
|
+
JSON.stringify( wpEnvConfig(bare, multisite, subdomain, plugin, theme), null, 4 )
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
spinner.start('Writing .wp-env.json file...');
|
|
93
|
+
}
|
|
71
94
|
|
|
72
95
|
// Get current wp-env cache key
|
|
73
96
|
const config = await loadConfig(path.resolve('.'));
|
|
74
97
|
const { workDirectoryPath } = config;
|
|
75
98
|
const cacheKey = await getCache(CONFIG_CACHE_KEY, {workDirectoryPath});
|
|
76
|
-
|
|
77
|
-
// Set extra
|
|
99
|
+
|
|
100
|
+
// Set extra configuration for WordPress.
|
|
78
101
|
// Increase max execution time to 300 seconds.
|
|
79
102
|
process.env.WORDPRESS_CONFIG_EXTRA = 'set_time_limit(300);';
|
|
80
103
|
|
|
104
|
+
// we can enable phpMyAdmin since @wordpress/env:10.14.0
|
|
105
|
+
if( config.env.development.config.WP_ENV_PHPMYADMIN_PORT ){
|
|
106
|
+
process.env.WP_ENV_PHPMYADMIN_PORT = config.env.development.config.WP_ENV_PHPMYADMIN_PORT;
|
|
107
|
+
}
|
|
108
|
+
if( config.env.tests.config.WP_ENV_TESTS_PHPMYADMIN_PORT ){
|
|
109
|
+
process.env.WP_ENV_TESTS_PHPMYADMIN_PORT = config.env.tests.config.WP_ENV_TESTS_PHPMYADMIN_PORT;
|
|
110
|
+
}
|
|
111
|
+
|
|
81
112
|
// wp-env launch.
|
|
82
113
|
await wpEnvStart({
|
|
83
114
|
spinner,
|
|
@@ -87,6 +118,13 @@ export default async function start({
|
|
|
87
118
|
debug,
|
|
88
119
|
})
|
|
89
120
|
|
|
121
|
+
// Save pretext from wp-env if it exists for later.
|
|
122
|
+
let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
|
|
123
|
+
|
|
124
|
+
// We aren't done lets clear the default WordPress text.
|
|
125
|
+
spinner.prefixText = '';
|
|
126
|
+
spinner.text = '';
|
|
127
|
+
|
|
90
128
|
// Check if we should configure settings.
|
|
91
129
|
const shouldConfigureWp = ( update ||
|
|
92
130
|
( await didCacheChange( CONFIG_CACHE_KEY, cacheKey, {
|
|
@@ -96,40 +134,18 @@ export default async function start({
|
|
|
96
134
|
// the majority of update tasks involve connecting to the internet. (Such
|
|
97
135
|
// as downloading sources and pulling docker images.)
|
|
98
136
|
( await canAccessWPORG() );
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Save pretext from wp-env if it exists for later.
|
|
102
|
-
let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
|
|
103
|
-
|
|
104
|
-
// We aren't done lets clear the default WordPress text.
|
|
105
|
-
spinner.prefixText = '';
|
|
106
|
-
spinner.text = '';
|
|
107
|
-
|
|
108
|
-
// Download any resources required for CAWeb.
|
|
109
|
-
if( shouldConfigureWp && ! bare ){
|
|
110
|
-
await downloadSources({spinner, config});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Write docker-compose.override.yml file to workDirectoryPath.
|
|
114
|
-
fs.writeFileSync(
|
|
115
|
-
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
116
|
-
yaml.dump( dockerConfig(workDirectoryPath) )
|
|
117
|
-
);
|
|
118
137
|
|
|
119
138
|
// Only run configurations when config has changed.
|
|
120
139
|
if( shouldConfigureWp ){
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
[
|
|
126
|
-
'
|
|
127
|
-
'
|
|
128
|
-
]
|
|
129
|
-
|
|
130
|
-
commandOptions: ['--build', '--force-recreate'],
|
|
131
|
-
log: debug
|
|
132
|
-
})
|
|
140
|
+
// Download any resources required for CAWeb.
|
|
141
|
+
if( ! bare ){
|
|
142
|
+
spinner.text = 'Downloading CAWeb resources...';
|
|
143
|
+
// Download sources for development and tests.
|
|
144
|
+
await Promise.all( [
|
|
145
|
+
downloadSources('development', {spinner, config}),
|
|
146
|
+
downloadSources('tests', {spinner, config})
|
|
147
|
+
] );
|
|
148
|
+
}
|
|
133
149
|
|
|
134
150
|
// Make additional WordPress Configurations.
|
|
135
151
|
await Promise.all( [
|
|
@@ -140,7 +156,7 @@ export default async function start({
|
|
|
140
156
|
times: 2,
|
|
141
157
|
} )
|
|
142
158
|
] );
|
|
143
|
-
|
|
159
|
+
|
|
144
160
|
// Make CAWeb WordPress Configurations.
|
|
145
161
|
await Promise.all( [
|
|
146
162
|
retry( () => configureCAWeb( 'development', config, spinner ), {
|
|
@@ -151,35 +167,18 @@ export default async function start({
|
|
|
151
167
|
} ),
|
|
152
168
|
] );
|
|
153
169
|
|
|
154
|
-
// Create an Application Password for the user.
|
|
155
|
-
/*
|
|
156
|
-
const devAppPwd = await runCLICmd(
|
|
157
|
-
'wp',
|
|
158
|
-
[
|
|
159
|
-
`user application-password create 1 caweb`,
|
|
160
|
-
'--porcelain'
|
|
161
|
-
]
|
|
162
|
-
);
|
|
163
|
-
*/
|
|
164
170
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
await dockerCompose.upOne(
|
|
171
|
-
'phpmyadmin',
|
|
172
|
-
{
|
|
173
|
-
cwd: workDirectoryPath,
|
|
174
|
-
commandOptions: ['--build', '--force-recreate'],
|
|
175
|
-
log: debug
|
|
171
|
+
if( sync ){
|
|
172
|
+
// sync any static information.
|
|
173
|
+
spinner.text = `Syncing CAWebPublishing development Environment...`;
|
|
174
|
+
// Sync the static site to the local WordPress instance.
|
|
175
|
+
await SyncProcess({spinner, debug, target: 'static', dest: 'local'})
|
|
176
176
|
}
|
|
177
|
-
|
|
177
|
+
|
|
178
|
+
}
|
|
178
179
|
|
|
179
|
-
spinner.prefixText = preText
|
|
180
|
-
`phpMyAdmin site started at http://localhost:8080\n\n`;
|
|
180
|
+
spinner.prefixText = preText;
|
|
181
181
|
|
|
182
182
|
|
|
183
183
|
spinner.text = 'Done!';
|
|
184
|
-
|
|
185
184
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate Scripts.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} options
|
|
16
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
17
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
18
|
+
*/
|
|
19
|
+
export default async function genScripts({
|
|
20
|
+
spinner,
|
|
21
|
+
debug,
|
|
22
|
+
environment
|
|
23
|
+
} ) {
|
|
24
|
+
let packageFile = path.join( process.cwd(), 'package.json' );
|
|
25
|
+
|
|
26
|
+
if( ! fs.existsSync( packageFile ) ) {
|
|
27
|
+
if( debug ) {
|
|
28
|
+
console.error( "No package.json found in the current directory." );
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
|
|
32
|
+
// only if the package.json file exists
|
|
33
|
+
}else{
|
|
34
|
+
|
|
35
|
+
let obj = JSON.parse( fs.readFileSync( packageFile ) );
|
|
36
|
+
let scripts = obj.scripts || {};
|
|
37
|
+
let basicScripts = {
|
|
38
|
+
"caweb": "caweb",
|
|
39
|
+
"create-site": "caweb create-site",
|
|
40
|
+
"serve": "caweb serve",
|
|
41
|
+
"build": "caweb build",
|
|
42
|
+
"convert-site": "caweb convert-site",
|
|
43
|
+
"launch": "caweb launch",
|
|
44
|
+
"launch:multi": "caweb launch --multisite",
|
|
45
|
+
"launch:multi:subdomain": "caweb launch --multisite --subdomain",
|
|
46
|
+
"launch:sync": "caweb launch --sync --update --bare",
|
|
47
|
+
"launch:update": "caweb launch --update",
|
|
48
|
+
"stop": "caweb stop",
|
|
49
|
+
"shutdown": "caweb destroy",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
obj.scripts = {
|
|
53
|
+
...scripts,
|
|
54
|
+
...basicScripts
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(
|
|
58
|
+
packageFile,
|
|
59
|
+
JSON.stringify( obj, null, 4 )
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
spinner.text = "Scripts generated successfully.";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
};
|
package/commands/index.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import clean from '@wordpress/env/lib/commands/clean.js';
|
|
6
6
|
import logs from '@wordpress/env/lib/commands/logs.js';
|
|
7
7
|
import run from '@wordpress/env/lib/commands/run.js';
|
|
8
|
+
import stop from '@wordpress/env/lib/commands/stop.js';
|
|
9
|
+
import destroy from '@wordpress/env/lib/commands/destroy.js';
|
|
8
10
|
import installPath from '@wordpress/env/lib/commands/install-path.js';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -21,35 +23,36 @@ const hint = new JSHintPlugin().hint;
|
|
|
21
23
|
import A11yPlugin from '@caweb/a11y-webpack-plugin';
|
|
22
24
|
const a11y = new A11yPlugin().a11yCheck;
|
|
23
25
|
|
|
24
|
-
import shell from './tasks/shell.js';
|
|
25
26
|
|
|
26
27
|
import sync from './sync/index.js';
|
|
27
28
|
|
|
28
|
-
import updatePlugins from './tasks/update-plugins.js';
|
|
29
29
|
import createBlock from './blocks/create-block.js';
|
|
30
30
|
import updateBlock from './blocks/update-block.js';
|
|
31
31
|
|
|
32
32
|
import createSite from './sites/create-site.js';
|
|
33
33
|
import convertSite from './sites/convert-site.js';
|
|
34
34
|
|
|
35
|
-
// These are
|
|
35
|
+
// These are wp-env commands
|
|
36
|
+
// we overwrite the start command so we can run additional steps.
|
|
36
37
|
import start from './env/start.js';
|
|
37
|
-
import
|
|
38
|
-
import
|
|
38
|
+
import shell from './env/shell.js';
|
|
39
|
+
import updatePlugins from './env/update-plugins.js';
|
|
39
40
|
|
|
40
41
|
// import test from './test.js';
|
|
42
|
+
import genScripts from './gen-scripts.js';
|
|
41
43
|
|
|
42
44
|
export {
|
|
45
|
+
genScripts,
|
|
43
46
|
a11y,
|
|
44
47
|
audit,
|
|
45
48
|
hint,
|
|
46
49
|
webpack,
|
|
47
50
|
clean,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
logs,
|
|
52
|
+
run,
|
|
53
|
+
installPath,
|
|
51
54
|
start,
|
|
52
|
-
|
|
55
|
+
stop,
|
|
53
56
|
destroy,
|
|
54
57
|
sync,
|
|
55
58
|
updatePlugins,
|