@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.
@@ -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
- spinner.text = 'Writing configuration file...';
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.writeFileSync(
68
- path.join(appPath, '.wp-env.json'),
69
- JSON.stringify( wpEnvConfig(bare, multisite, plugin, theme), null, 4 )
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 congiguration for WordPress.
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
- // 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
- })
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
- // 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
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 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,