@automattic/jetpack-cli 0.1.0-beta3 → 1.0.0-beta1
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 +89 -63
- package/package.json +3 -2
package/bin/jp.js
CHANGED
|
@@ -8,11 +8,26 @@ import { fileURLToPath } from 'url';
|
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import dotenv from 'dotenv';
|
|
10
10
|
import prompts from 'prompts';
|
|
11
|
+
import updateNotifier from 'update-notifier';
|
|
11
12
|
|
|
12
13
|
// Get package.json path relative to this file
|
|
13
14
|
const __dirname = dirname( fileURLToPath( import.meta.url ) );
|
|
14
15
|
const packageJson = JSON.parse( readFileSync( resolve( __dirname, '../package.json' ), 'utf8' ) );
|
|
15
16
|
|
|
17
|
+
// Check for updates
|
|
18
|
+
const notifier = updateNotifier( {
|
|
19
|
+
pkg: packageJson,
|
|
20
|
+
updateCheckInterval: 1000 * 60 * 60 * 24, // Check once per day
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
// Show update notification
|
|
24
|
+
notifier.notify( {
|
|
25
|
+
message:
|
|
26
|
+
'Update available for Jetpack CLI: {currentVersion} → {latestVersion}\n' +
|
|
27
|
+
'Run {updateCommand} to update',
|
|
28
|
+
isGlobal: true,
|
|
29
|
+
} );
|
|
30
|
+
|
|
16
31
|
/**
|
|
17
32
|
* Check if a directory is the monorepo root.
|
|
18
33
|
*
|
|
@@ -35,10 +50,13 @@ const isMonorepoRoot = dir => {
|
|
|
35
50
|
*/
|
|
36
51
|
const findMonorepoRoot = startDir => {
|
|
37
52
|
let dir = startDir;
|
|
38
|
-
|
|
53
|
+
let prevDir;
|
|
54
|
+
while ( dir !== prevDir ) {
|
|
55
|
+
// Keep going until dirname() stops changing the path
|
|
39
56
|
if ( isMonorepoRoot( dir ) ) {
|
|
40
57
|
return dir;
|
|
41
58
|
}
|
|
59
|
+
prevDir = dir;
|
|
42
60
|
dir = dirname( dir );
|
|
43
61
|
}
|
|
44
62
|
return null;
|
|
@@ -154,31 +172,6 @@ const main = async () => {
|
|
|
154
172
|
// Create empty .env file
|
|
155
173
|
fs.writeFileSync( resolve( monorepoRoot, 'tools/docker/.env' ), '' );
|
|
156
174
|
|
|
157
|
-
const images = [
|
|
158
|
-
{ name: 'mariadb:lts' },
|
|
159
|
-
{ name: 'automattic/jetpack-wordpress-dev:latest' },
|
|
160
|
-
{ name: 'phpmyadmin/phpmyadmin:latest', platform: 'linux/amd64' },
|
|
161
|
-
{ name: 'maildev/maildev', platform: 'linux/amd64' },
|
|
162
|
-
{ name: 'atmoz/sftp', platform: 'linux/amd64' },
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
for ( const image of images ) {
|
|
166
|
-
const inspect = spawnSync( 'docker', [ 'image', 'inspect', image.name ], {
|
|
167
|
-
stdio: 'ignore',
|
|
168
|
-
} );
|
|
169
|
-
if ( inspect.status !== 0 ) {
|
|
170
|
-
console.log( chalk.blue( `Pulling ${ image.name }...` ) );
|
|
171
|
-
const pullArgs = [ 'pull', image.name ];
|
|
172
|
-
if ( image.platform ) {
|
|
173
|
-
pullArgs.splice( 1, 0, '--platform', image.platform );
|
|
174
|
-
}
|
|
175
|
-
const pull = spawnSync( 'docker', pullArgs, { stdio: 'inherit' } );
|
|
176
|
-
if ( pull.status !== 0 ) {
|
|
177
|
-
throw new Error( `Failed to pull ${ image.name }` );
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
175
|
const configResult = spawnSync(
|
|
183
176
|
resolve( monorepoRoot, 'tools/docker/bin/monorepo' ),
|
|
184
177
|
[ 'pnpm', 'jetpack', 'docker', 'config' ],
|
|
@@ -225,48 +218,81 @@ const main = async () => {
|
|
|
225
218
|
// Get project name (from docker.js)
|
|
226
219
|
const projectName = args.includes( '--type=e2e' ) ? 'jetpack_e2e' : 'jetpack_dev';
|
|
227
220
|
|
|
228
|
-
// Load versions from .github/versions.sh
|
|
229
|
-
const versionsPath = resolve( monorepoRoot, '.github/versions.sh' );
|
|
230
|
-
const versions = fs.readFileSync( versionsPath, 'utf8' );
|
|
231
|
-
const versionVars = {};
|
|
232
|
-
versions.split( '\n' ).forEach( line => {
|
|
233
|
-
const match = line.match( /^([A-Z_]+)=(.+)$/ );
|
|
234
|
-
if ( match ) {
|
|
235
|
-
versionVars[ match[ 1 ] ] = match[ 2 ].replace( /['"]/g, '' );
|
|
236
|
-
}
|
|
237
|
-
} );
|
|
238
|
-
|
|
239
221
|
// Build environment variables (from docker.js)
|
|
240
222
|
const envVars = {
|
|
241
|
-
...process.env,
|
|
242
|
-
// Load from default.env
|
|
243
|
-
...( fs.existsSync( resolve( monorepoRoot, 'tools/docker/default.env' ) )
|
|
244
|
-
? dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/default.env' ) ) )
|
|
245
|
-
: {} ),
|
|
246
|
-
// Load from .env if it exists
|
|
247
|
-
...( fs.existsSync( resolve( monorepoRoot, 'tools/docker/.env' ) )
|
|
248
|
-
? dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/.env' ) ) )
|
|
249
|
-
: {} ),
|
|
250
|
-
HOST_CWD: monorepoRoot,
|
|
251
|
-
PHP_VERSION: versionVars.PHP_VERSION,
|
|
252
|
-
COMPOSER_VERSION: versionVars.COMPOSER_VERSION,
|
|
253
|
-
NODE_VERSION: versionVars.NODE_VERSION,
|
|
254
|
-
PNPM_VERSION: versionVars.PNPM_VERSION,
|
|
255
|
-
COMPOSE_PROJECT_NAME: projectName,
|
|
256
|
-
PORT_WORDPRESS: args.includes( '--type=e2e' ) ? '8889' : '80',
|
|
223
|
+
...process.env, // Start with process.env
|
|
257
224
|
};
|
|
258
225
|
|
|
226
|
+
// Add default env vars if they exist
|
|
227
|
+
if ( fs.existsSync( resolve( monorepoRoot, 'tools/docker/default.env' ) ) ) {
|
|
228
|
+
Object.assign(
|
|
229
|
+
envVars,
|
|
230
|
+
dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/default.env' ) ) )
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Add user overrides from .env if they exist
|
|
235
|
+
if ( fs.existsSync( resolve( monorepoRoot, 'tools/docker/.env' ) ) ) {
|
|
236
|
+
Object.assign(
|
|
237
|
+
envVars,
|
|
238
|
+
dotenv.parse( fs.readFileSync( resolve( monorepoRoot, 'tools/docker/.env' ) ) )
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Only set these specific vars if they're not already set in .env
|
|
243
|
+
if ( ! envVars.COMPOSE_PROJECT_NAME ) {
|
|
244
|
+
envVars.COMPOSE_PROJECT_NAME = projectName;
|
|
245
|
+
}
|
|
246
|
+
if ( ! envVars.PORT_WORDPRESS ) {
|
|
247
|
+
envVars.PORT_WORDPRESS = args.includes( '--type=e2e' ) ? '8889' : '80';
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Load versions from .github/versions.sh if not already set
|
|
251
|
+
if (
|
|
252
|
+
! (
|
|
253
|
+
envVars.PHP_VERSION &&
|
|
254
|
+
envVars.COMPOSER_VERSION &&
|
|
255
|
+
envVars.NODE_VERSION &&
|
|
256
|
+
envVars.PNPM_VERSION
|
|
257
|
+
)
|
|
258
|
+
) {
|
|
259
|
+
const versionsPath = resolve( monorepoRoot, '.github/versions.sh' );
|
|
260
|
+
const versions = fs.readFileSync( versionsPath, 'utf8' );
|
|
261
|
+
const versionVars = {};
|
|
262
|
+
versions.split( '\n' ).forEach( line => {
|
|
263
|
+
const match = line.match( /^([A-Z_]+)=(.+)$/ );
|
|
264
|
+
if ( match ) {
|
|
265
|
+
versionVars[ match[ 1 ] ] = match[ 2 ].replace( /['"]/g, '' );
|
|
266
|
+
}
|
|
267
|
+
} );
|
|
268
|
+
|
|
269
|
+
// Only set version vars if they're not already set
|
|
270
|
+
if ( ! envVars.PHP_VERSION ) envVars.PHP_VERSION = versionVars.PHP_VERSION;
|
|
271
|
+
if ( ! envVars.COMPOSER_VERSION ) envVars.COMPOSER_VERSION = versionVars.COMPOSER_VERSION;
|
|
272
|
+
if ( ! envVars.NODE_VERSION ) envVars.NODE_VERSION = versionVars.NODE_VERSION;
|
|
273
|
+
if ( ! envVars.PNPM_VERSION ) envVars.PNPM_VERSION = versionVars.PNPM_VERSION;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Always set HOST_CWD as it's required for Docker context
|
|
277
|
+
envVars.HOST_CWD = monorepoRoot;
|
|
278
|
+
|
|
259
279
|
// Build the list of compose files to use
|
|
260
|
-
const composeFiles =
|
|
261
|
-
'-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
280
|
+
const composeFiles =
|
|
281
|
+
args[ 0 ] === 'docker' && [ 'build-image', 'install' ].includes( args[ 1 ] )
|
|
282
|
+
? [ '-f', resolve( monorepoRoot, 'tools/docker/docker-compose-monorepo.yml' ) ]
|
|
283
|
+
: [
|
|
284
|
+
'-f',
|
|
285
|
+
resolve( monorepoRoot, 'tools/docker/docker-compose.yml' ),
|
|
286
|
+
'-f',
|
|
287
|
+
resolve( monorepoRoot, 'tools/docker/compose-mappings.built.yml' ),
|
|
288
|
+
'-f',
|
|
289
|
+
resolve( monorepoRoot, 'tools/docker/compose-extras.built.yml' ),
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
// Add dev profile for monorepo service
|
|
293
|
+
const composeArgs = [ 'compose', '--profile', 'dev', ...composeFiles, ...args.slice( 1 ) ];
|
|
294
|
+
|
|
295
|
+
const result = spawnSync( 'docker', composeArgs, {
|
|
270
296
|
stdio: 'inherit',
|
|
271
297
|
shell: true,
|
|
272
298
|
cwd: resolve( monorepoRoot, 'tools/docker' ),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0-beta1",
|
|
4
4
|
"description": "Docker-based CLI for Jetpack development",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jp": "bin/jp.js"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"chalk": "^5.4.1",
|
|
14
14
|
"dotenv": "^16.3.1",
|
|
15
|
-
"prompts": "^2.4.2"
|
|
15
|
+
"prompts": "^2.4.2",
|
|
16
|
+
"update-notifier": "^7.0.0"
|
|
16
17
|
},
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public"
|