@caweb/cli 1.0.4 → 1.0.5

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.
@@ -115,16 +115,6 @@ module.exports = async function start({
115
115
  await sleep( 4000 );
116
116
  }
117
117
 
118
- // Make additional WordPress Configurations.
119
- await Promise.all( [
120
- retry( () => configureWordPress( 'development', config, spinner, multisite, subdomain ), {
121
- times: 2,
122
- } ),
123
- retry( () => configureWordPress( 'tests', config, spinner, multisite, subdomain ), {
124
- times: 2,
125
- } )
126
- ] );
127
-
128
118
  // Download any resources required for CAWeb.
129
119
  if( ! bare ){
130
120
  await downloadSources({spinner, config});
@@ -136,6 +126,28 @@ module.exports = async function start({
136
126
  yaml.dump( buildDockerComposeConfig(workDirectoryPath) )
137
127
  );
138
128
 
129
+ // We need to bring the WordPress and CLI instances up again so they pick up
130
+ // any config changes that may have been added to the docker-compose.override.yml.
131
+ await dockerCompose.upMany(
132
+ [
133
+ 'wordpress', 'tests-wordpress',
134
+ 'cli', 'tests-cli'
135
+ ], {
136
+ cwd: workDirectoryPath,
137
+ commandOptions: ['--build', '--force-recreate'],
138
+ log: debug
139
+ })
140
+
141
+ // Make additional WordPress Configurations.
142
+ await Promise.all( [
143
+ retry( () => configureWordPress( 'development', config, spinner, multisite, subdomain ), {
144
+ times: 2,
145
+ } ),
146
+ retry( () => configureWordPress( 'tests', config, spinner, multisite, subdomain ), {
147
+ times: 2,
148
+ } )
149
+ ] );
150
+
139
151
  // Make CAWeb WordPress Configurations.
140
152
  await Promise.all( [
141
153
  retry( () => configureCAWeb( 'development', config, spinner ), {
@@ -149,13 +161,9 @@ module.exports = async function start({
149
161
  // Start phpMyAdmin Service.
150
162
  spinner.text = 'Starting phpMyAdmin Service';
151
163
 
152
- // We need to bring the WordPress instances up again so they pick up
153
- // any config changes that may have been added to the docker-compose.override.yml.
154
164
  await dockerCompose.upMany(
155
165
  [
156
166
  'phpmyadmin','tests-phpmyadmin',
157
- 'wordpress', 'tests-wordpress',
158
- 'cli', 'tests-cli'
159
167
  ], {
160
168
  cwd: workDirectoryPath,
161
169
  commandOptions: ['--build', '--force-recreate'],
@@ -10,6 +10,7 @@ const dockerCompose = require( 'docker-compose' );
10
10
  const loadConfig = require( '@wordpress/env/lib/config/load-config' );
11
11
  const run = require('@wordpress/env/lib/commands/run');
12
12
  const getHostUser = require( '@wordpress/env/lib/get-host-user' );
13
+ const yaml = require( 'js-yaml' );
13
14
 
14
15
  /**
15
16
  * Internal dependencies
@@ -17,7 +18,7 @@ const getHostUser = require( '@wordpress/env/lib/get-host-user' );
17
18
  const {
18
19
  runDockerCmds,
19
20
  } = require('../docker');
20
-
21
+
21
22
  const {
22
23
  buildWPEnvConfig,
23
24
  buildDockerComposeConfig
@@ -66,9 +67,14 @@ module.exports = async function test({
66
67
  const {WP_PERMALINK} = config.env[ environment ].config
67
68
  const { workDirectoryPath} = config;
68
69
  const {name} = getHostUser();
69
-
70
+ const containerName = path.basename(workDirectoryPath) + ('tests' === environment ? '-tests' : '') + '-cli';
71
+ //const containerID = await execSync(`docker ps -qf "name=${containerName}"`).toString().trim();
72
+
70
73
  spinner.text = "Testing code...";
71
-
74
+
75
+
76
+ spinner.text = 'Completed Testing code...'
77
+
72
78
  /*
73
79
  let result = await runDockerCmds(
74
80
  environment,
@@ -83,7 +89,6 @@ module.exports = async function test({
83
89
  }
84
90
  */
85
91
 
86
- spinner.text = 'Completed Testing code...'
87
92
 
88
93
  } catch(error) {
89
94
  console.log(error)
package/lib/configs.js CHANGED
@@ -4,8 +4,15 @@
4
4
  const path = require( 'path' );
5
5
  const fs = require('fs-extra');
6
6
  const pkg = require( '../package.json' );
7
+ const yaml = require( 'js-yaml' );
8
+ const getHostUser = require( '@wordpress/env/lib/get-host-user' );
7
9
 
8
10
 
11
+ /**
12
+ * Promisified dependencies
13
+ */
14
+ const { writeFile } = fs.promises;
15
+
9
16
  /**
10
17
  * Build .wp-env.json
11
18
  *
@@ -44,6 +51,11 @@ const buildWPEnvConfig = (bare, multisite) => {
44
51
  * @returns object
45
52
  */
46
53
  const buildDockerComposeConfig = (workDirectoryPath) => {
54
+ const {name} = getHostUser();
55
+
56
+ // generate cli config file for cli containers.
57
+ generateCLIConfig(workDirectoryPath);
58
+
47
59
  let dockerConfig = {
48
60
  version: '3.7',
49
61
  services: {
@@ -68,6 +80,32 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
68
80
  MEMORY_LIMIT: '5G',
69
81
  MAX_EXECUTION_TIME: 7200
70
82
  }
83
+ },
84
+ cli: {
85
+ build: {
86
+ context: '.',
87
+ dockerfile: 'CLI.Dockerfile'
88
+ },
89
+ volumes: [ path.join(workDirectoryPath, 'config.yml') + `:/home/${name}/.wp-cli/config.yml` ]
90
+ },
91
+ "tests-cli": {
92
+ build: {
93
+ context: '.',
94
+ dockerfile: 'Tests-CLI.Dockerfile'
95
+ },
96
+ volumes: [ path.join(workDirectoryPath, 'config.yml') + `:/home/${name}/.wp-cli/config.yml`]
97
+ },
98
+ wordpress: {
99
+ build: {
100
+ context: '.',
101
+ dockerfile: 'WordPress.Dockerfile'
102
+ }
103
+ },
104
+ "tests-wordpress": {
105
+ build: {
106
+ context: '.',
107
+ dockerfile: 'Tests-WordPress.Dockerfile'
108
+ }
71
109
  }
72
110
  }
73
111
 
@@ -87,40 +125,56 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
87
125
 
88
126
  // Add extra volumes to WordPress instances.
89
127
  if( extraVolumes.length ){
90
-
91
128
  dockerConfig.services.wordpress = {
92
- build: {
93
- context: '.',
94
- dockerfile: 'WordPress.Dockerfile'
95
- },
96
- volumes: extraVolumes,
129
+ ...dockerConfig.services.wordpress,
130
+ volumes: [
131
+ ...extraVolumes
132
+ ],
97
133
  };
98
134
  dockerConfig.services.cli = {
99
- build: {
100
- context: '.',
101
- dockerfile: 'CLI.Dockerfile'
102
- },
103
- volumes: extraVolumes,
135
+ ...dockerConfig.services.cli,
136
+ volumes: [
137
+ ...dockerConfig.services.cli.volumes,
138
+ ...extraVolumes
139
+ ],
104
140
  };
105
141
  dockerConfig.services['tests-wordpress'] = {
106
- build: {
107
- context: '.',
108
- dockerfile: 'Tests-WordPress.Dockerfile'
109
- },
110
- volumes: extraVolumes,
142
+ ...dockerConfig.services['tests-wordpress'],
143
+ volumes: [
144
+ ...extraVolumes
145
+ ],
111
146
  };
112
147
  dockerConfig.services['tests-cli'] = {
113
- build: {
114
- context: '.',
115
- dockerfile: 'Tests-CLI.Dockerfile'
116
- },
117
- volumes: extraVolumes,
148
+ ...dockerConfig.services['tests-cli'],
149
+ volumes: [
150
+ ...dockerConfig.services['tests-cli'].volumes,
151
+ ...extraVolumes
152
+ ],
118
153
  };
154
+
119
155
  }
120
156
 
121
157
  return dockerConfig;
122
158
  }
123
159
 
160
+ /**
161
+ * Generate config.yml
162
+ *
163
+ * @param {string} workDirectoryPath Path to the work directory located in ~/.wp-env.
164
+ *
165
+ * @returns void
166
+ */
167
+ async function generateCLIConfig(workDirectoryPath){
168
+ const yml = {
169
+ path: '/var/www/html',
170
+ apache_modules: ['mod_rewrite']
171
+ };
172
+
173
+ await writeFile(
174
+ path.join(workDirectoryPath, 'config.yml'),
175
+ yaml.dump(yml));
176
+ }
177
+
124
178
  module.exports = {
125
179
  buildWPEnvConfig,
126
180
  buildDockerComposeConfig
package/lib/wordpress.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
  const { writeFile } = require('fs-extra');
3
3
  const path = require( 'path' );
4
- const getHostUser = require( '@wordpress/env/lib/get-host-user' );
5
4
  const { execSync } = require( 'child_process' );
6
5
 
7
6
  /**
@@ -133,13 +132,6 @@ async function configureWordPress(environment, config, spinner, multisite, subdo
133
132
  WP_PERMALINK
134
133
  } = config.env[ environment ].config
135
134
 
136
- const {name} = getHostUser();
137
-
138
- const containerName = path.basename(workDirectoryPath) + ('tests' === environment ? '-tests' : '') + '-cli';
139
- const containerID = await execSync(`docker ps -qf "name=${containerName}"`).toString().trim();
140
-
141
- // Add cli config.yml to cli container.
142
- await execSync(`docker exec ${containerID} mkdir -p /home/${name}/.wp-cli/ && docker cp ./lib/config.yml ${containerID}:/home/${name}/.wp-cli/config.yml`);
143
135
 
144
136
  // Convert to multisite if flag was passed.
145
137
  if( multisite ){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "main": "lib/env.js",
6
6
  "files": [
package/lib/config.yml DELETED
@@ -1,3 +0,0 @@
1
- path: /var/www/html
2
- apache_modules:
3
- - mod_rewrite