@caweb/cli 1.11.2 → 1.12.1

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.
@@ -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
@@ -26,11 +25,12 @@ import {
26
25
  configureCAWeb,
27
26
  downloadSources,
28
27
  configureWordPress,
29
- runCmd
28
+ runCmd,
29
+ runCLICmds
30
30
  } from '../../lib/index.js';
31
- import wpEnvConfig from '../../configs/wp-env.js';
32
- import dockerConfig from '../../configs/docker-compose.js';
33
31
 
32
+ import { wpEnvConfig, wpEnvOverrideConfig } from '../../configs/wp-env.js';
33
+ import {default as SyncProcess} from '../sync/index.js';
34
34
 
35
35
  /**
36
36
  * Starts the development server.
@@ -41,6 +41,7 @@ import dockerConfig from '../../configs/docker-compose.js';
41
41
  * @param {string} options.xdebug The Xdebug mode to set.
42
42
  * @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
43
43
  * @param {boolean} options.debug True if debug mode is enabled.
44
+ * @param {boolean} options.sync Will attempt to sync changes from a CAWebPublishing static site to this WordPress instance..
44
45
  * @param {boolean} options.bare True if excluding any CAWeb Configurations.
45
46
  * @param {boolean} options.plugin True if root directory is a plugin.
46
47
  * @param {boolean} options.theme True if root directory is a theme.
@@ -54,6 +55,7 @@ export default async function start({
54
55
  xdebug,
55
56
  scripts,
56
57
  debug,
58
+ sync,
57
59
  bare,
58
60
  plugin,
59
61
  theme,
@@ -61,23 +63,51 @@ export default async function start({
61
63
  subdomain
62
64
  }) {
63
65
 
64
- spinner.text = 'Writing configuration file...';
66
+
67
+
68
+ // Write CAWeb .wp-env.override.json file.
69
+ if( ! fs.existsSync( path.join(appPath, '.wp-env.override.json')) ){
70
+ spinner.stop()
71
+
72
+ // Keys should not be saved in the repository so we store them in the override.json file.
73
+ fs.writeFileSync(
74
+ path.join(appPath, '.wp-env.override.json'),
75
+ JSON.stringify( await wpEnvOverrideConfig(bare, multisite, subdomain, plugin, theme), null, 4 )
76
+ );
77
+
78
+ spinner.start('Writing .wp-env.override.json file...');
79
+
80
+ }
65
81
 
66
82
  // Write CAWeb .wp-env.json file.
67
- fs.writeFileSync(
68
- path.join(appPath, '.wp-env.json'),
69
- JSON.stringify( wpEnvConfig(bare, multisite, plugin, theme), null, 4 )
70
- );
83
+ if( ! fs.existsSync( path.join(appPath, '.wp-env.json')) || update ){
84
+ spinner.stop()
85
+
86
+ fs.writeFileSync(
87
+ path.join(appPath, '.wp-env.json'),
88
+ JSON.stringify( wpEnvConfig(bare, multisite, subdomain, plugin, theme), null, 4 )
89
+ );
90
+
91
+ spinner.start('Writing .wp-env.json file...');
92
+ }
71
93
 
72
94
  // Get current wp-env cache key
73
95
  const config = await loadConfig(path.resolve('.'));
74
96
  const { workDirectoryPath } = config;
75
97
  const cacheKey = await getCache(CONFIG_CACHE_KEY, {workDirectoryPath});
76
-
77
- // Set extra congiguration for WordPress.
98
+
99
+ // Set extra configuration for WordPress.
78
100
  // Increase max execution time to 300 seconds.
79
101
  process.env.WORDPRESS_CONFIG_EXTRA = 'set_time_limit(300);';
80
102
 
103
+ // we can enable phpMyAdmin since @wordpress/env:10.14.0
104
+ if( config.env.development.config.WP_ENV_PHPMYADMIN_PORT ){
105
+ process.env.WP_ENV_PHPMYADMIN_PORT = config.env.development.config.WP_ENV_PHPMYADMIN_PORT;
106
+ }
107
+ if( config.env.tests.config.WP_ENV_TESTS_PHPMYADMIN_PORT ){
108
+ process.env.WP_ENV_TESTS_PHPMYADMIN_PORT = config.env.tests.config.WP_ENV_TESTS_PHPMYADMIN_PORT;
109
+ }
110
+
81
111
  // wp-env launch.
82
112
  await wpEnvStart({
83
113
  spinner,
@@ -87,6 +117,13 @@ export default async function start({
87
117
  debug,
88
118
  })
89
119
 
120
+ // Save pretext from wp-env if it exists for later.
121
+ let preText = undefined !== spinner.prefixText ? spinner.prefixText.slice(0, -1) : '';
122
+
123
+ // We aren't done lets clear the default WordPress text.
124
+ spinner.prefixText = '';
125
+ spinner.text = '';
126
+
90
127
  // Check if we should configure settings.
91
128
  const shouldConfigureWp = ( update ||
92
129
  ( await didCacheChange( CONFIG_CACHE_KEY, cacheKey, {
@@ -96,40 +133,18 @@ export default async function start({
96
133
  // the majority of update tasks involve connecting to the internet. (Such
97
134
  // as downloading sources and pulling docker images.)
98
135
  ( 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
136
 
119
137
  // Only run configurations when config has changed.
120
138
  if( shouldConfigureWp ){
121
-
122
- // We need to bring the WordPress and CLI instances up again so they pick up
123
- // any config changes that may have been added to the docker-compose.override.yml.
124
- await dockerCompose.upMany(
125
- [
126
- 'wordpress', 'tests-wordpress',
127
- 'cli', 'tests-cli'
128
- ], {
129
- cwd: workDirectoryPath,
130
- commandOptions: ['--build', '--force-recreate'],
131
- log: debug
132
- })
139
+ // Download any resources required for CAWeb.
140
+ if( ! bare ){
141
+ spinner.text = 'Downloading CAWeb resources...';
142
+ // Download sources for development and tests.
143
+ await Promise.all( [
144
+ downloadSources('development', {spinner, config}),
145
+ downloadSources('tests', {spinner, config})
146
+ ] );
147
+ }
133
148
 
134
149
  // Make additional WordPress Configurations.
135
150
  await Promise.all( [
@@ -140,7 +155,7 @@ export default async function start({
140
155
  times: 2,
141
156
  } )
142
157
  ] );
143
-
158
+
144
159
  // Make CAWeb WordPress Configurations.
145
160
  await Promise.all( [
146
161
  retry( () => configureCAWeb( 'development', config, spinner ), {
@@ -151,35 +166,18 @@ export default async function start({
151
166
  } ),
152
167
  ] );
153
168
 
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
169
 
165
- }
166
-
167
- // Start phpMyAdmin Service.
168
- spinner.text = 'Starting phpMyAdmin Service';
169
-
170
- await dockerCompose.upOne(
171
- 'phpmyadmin',
172
- {
173
- cwd: workDirectoryPath,
174
- commandOptions: ['--build', '--force-recreate'],
175
- log: debug
170
+ if( sync ){
171
+ // sync any static information.
172
+ spinner.text = `Syncing CAWebPublishing development Environment...`;
173
+ // Sync the static site to the local WordPress instance.
174
+ await SyncProcess({spinner, debug, target: 'static', dest: 'local'})
176
175
  }
177
- )
176
+
177
+ }
178
178
 
179
- spinner.prefixText = preText +
180
- `phpMyAdmin site started at http://localhost:8080\n\n`;
179
+ spinner.prefixText = preText;
181
180
 
182
181
 
183
182
  spinner.text = 'Done!';
184
-
185
183
  };
@@ -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 default wp-env commands, we overwrite these commands so we can run additional steps.
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 destroy from './env/destroy.js';
38
- import stop from './env/stop.js';
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
- logs,
49
- run,
50
- installPath,
51
+ logs,
52
+ run,
53
+ installPath,
51
54
  start,
52
- stop,
55
+ stop,
53
56
  destroy,
54
57
  sync,
55
58
  updatePlugins,