@automattic/jetpack-cli 0.1.0-beta.1 → 0.1.0-beta.2
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/bin/jp.js +128 -0
- package/package.json +2 -1
package/bin/jp.js
CHANGED
|
@@ -5,6 +5,7 @@ import fs from 'fs';
|
|
|
5
5
|
import { dirname, resolve } from 'path';
|
|
6
6
|
import process from 'process';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
+
import dotenv from 'dotenv';
|
|
8
9
|
import prompts from 'prompts';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -126,6 +127,133 @@ const main = async () => {
|
|
|
126
127
|
throw new Error( 'Monorepo not found' );
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
// Handle docker commands on the host
|
|
131
|
+
if ( args[ 0 ] === 'docker' ) {
|
|
132
|
+
// Commands that should run in the container
|
|
133
|
+
const containerCommands = [ 'build-image', 'install' ];
|
|
134
|
+
if ( containerCommands.includes( args[ 1 ] ) ) {
|
|
135
|
+
const result = spawnSync(
|
|
136
|
+
resolve( monorepoRoot, 'tools/docker/bin/monorepo' ),
|
|
137
|
+
[ 'pnpm', 'jetpack', ...args ],
|
|
138
|
+
{
|
|
139
|
+
stdio: 'inherit',
|
|
140
|
+
shell: true,
|
|
141
|
+
cwd: monorepoRoot,
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if ( result.status !== 0 ) {
|
|
146
|
+
throw new Error( `Command failed with status ${ result.status }` );
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Run config generation first if this is an 'up' command
|
|
152
|
+
if ( args[ 1 ] === 'up' ) {
|
|
153
|
+
// Create required directories
|
|
154
|
+
fs.mkdirSync( resolve( monorepoRoot, 'tools/docker/data/jetpack_dev_mysql' ), {
|
|
155
|
+
recursive: true,
|
|
156
|
+
} );
|
|
157
|
+
fs.mkdirSync( resolve( monorepoRoot, 'tools/docker/data/ssh.keys' ), { recursive: true } );
|
|
158
|
+
fs.mkdirSync( resolve( monorepoRoot, 'tools/docker/wordpress' ), { recursive: true } );
|
|
159
|
+
|
|
160
|
+
const images = [
|
|
161
|
+
{ name: 'mariadb:lts' },
|
|
162
|
+
{ name: 'automattic/jetpack-wordpress-dev:latest' },
|
|
163
|
+
{ name: 'phpmyadmin/phpmyadmin:latest', platform: 'linux/amd64' },
|
|
164
|
+
{ name: 'maildev/maildev', platform: 'linux/amd64' },
|
|
165
|
+
{ name: 'atmoz/sftp', platform: 'linux/amd64' },
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
for ( const image of images ) {
|
|
169
|
+
const inspect = spawnSync( 'docker', [ 'image', 'inspect', image.name ], {
|
|
170
|
+
stdio: 'ignore',
|
|
171
|
+
} );
|
|
172
|
+
if ( inspect.status !== 0 ) {
|
|
173
|
+
console.log( `Pulling ${ image.name }...` );
|
|
174
|
+
const args = [ 'pull', image.name ];
|
|
175
|
+
if ( image.platform ) {
|
|
176
|
+
args.splice( 1, 0, '--platform', image.platform );
|
|
177
|
+
}
|
|
178
|
+
const pull = spawnSync( 'docker', args, { stdio: 'inherit' } );
|
|
179
|
+
if ( pull.status !== 0 ) {
|
|
180
|
+
throw new Error( `Failed to pull ${ image.name }` );
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const configResult = spawnSync(
|
|
186
|
+
resolve( monorepoRoot, 'tools/docker/bin/monorepo' ),
|
|
187
|
+
[ 'pnpm', 'jetpack', 'docker', 'config' ],
|
|
188
|
+
{
|
|
189
|
+
stdio: 'inherit',
|
|
190
|
+
shell: true,
|
|
191
|
+
cwd: monorepoRoot,
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if ( configResult.status !== 0 ) {
|
|
196
|
+
throw new Error( 'Failed to generate Docker config' );
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Get project name (from docker.js)
|
|
201
|
+
const projectName = args.includes( '--type=e2e' ) ? 'jetpack_e2e' : 'jetpack_dev';
|
|
202
|
+
|
|
203
|
+
// Load versions from .github/versions.sh
|
|
204
|
+
const versionsPath = resolve( monorepoRoot, '.github/versions.sh' );
|
|
205
|
+
const versions = fs.readFileSync( versionsPath, 'utf8' );
|
|
206
|
+
const versionVars = {};
|
|
207
|
+
versions.split( '\n' ).forEach( line => {
|
|
208
|
+
const match = line.match( /^([A-Z_]+)=(.+)$/ );
|
|
209
|
+
if ( match ) {
|
|
210
|
+
versionVars[ match[ 1 ] ] = match[ 2 ].replace( /['"]/g, '' );
|
|
211
|
+
}
|
|
212
|
+
} );
|
|
213
|
+
|
|
214
|
+
// Build environment variables (from docker.js)
|
|
215
|
+
const envVars = {
|
|
216
|
+
...process.env,
|
|
217
|
+
// Load from default.env
|
|
218
|
+
...( fs.existsSync( resolve( monorepoRoot, 'tools/docker/default.env' ) )
|
|
219
|
+
? dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/default.env' ) ) )
|
|
220
|
+
: {} ),
|
|
221
|
+
// Load from .env if it exists
|
|
222
|
+
...( fs.existsSync( resolve( monorepoRoot, 'tools/docker/.env' ) )
|
|
223
|
+
? dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/.env' ) ) )
|
|
224
|
+
: {} ),
|
|
225
|
+
HOST_CWD: monorepoRoot,
|
|
226
|
+
PHP_VERSION: versionVars.PHP_VERSION,
|
|
227
|
+
COMPOSER_VERSION: versionVars.COMPOSER_VERSION,
|
|
228
|
+
NODE_VERSION: versionVars.NODE_VERSION,
|
|
229
|
+
PNPM_VERSION: versionVars.PNPM_VERSION,
|
|
230
|
+
COMPOSE_PROJECT_NAME: projectName,
|
|
231
|
+
PORT_WORDPRESS: args.includes( '--type=e2e' ) ? '8889' : '80',
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Build the list of compose files to use
|
|
235
|
+
const composeFiles = [
|
|
236
|
+
'-f',
|
|
237
|
+
resolve( monorepoRoot, 'tools/docker/docker-compose.yml' ),
|
|
238
|
+
'-f',
|
|
239
|
+
resolve( monorepoRoot, 'tools/docker/compose-mappings.built.yml' ),
|
|
240
|
+
'-f',
|
|
241
|
+
resolve( monorepoRoot, 'tools/docker/compose-extras.built.yml' ),
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
const result = spawnSync( 'docker', [ 'compose', ...composeFiles, ...args.slice( 1 ) ], {
|
|
245
|
+
stdio: 'inherit',
|
|
246
|
+
shell: true,
|
|
247
|
+
cwd: resolve( monorepoRoot, 'tools/docker' ),
|
|
248
|
+
env: envVars,
|
|
249
|
+
} );
|
|
250
|
+
|
|
251
|
+
if ( result.status !== 0 ) {
|
|
252
|
+
throw new Error( `Docker command failed with status ${ result.status }` );
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
129
257
|
// Run the monorepo script with the original arguments
|
|
130
258
|
const result = spawnSync(
|
|
131
259
|
resolve( monorepoRoot, 'tools/docker/bin/monorepo' ),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "Docker-based CLI for Jetpack development",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jp": "bin/jp.js"
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"chalk": "^4.1.2",
|
|
14
|
+
"dotenv": "^16.3.1",
|
|
14
15
|
"prompts": "^2.4.2"
|
|
15
16
|
},
|
|
16
17
|
"publishConfig": {
|