|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 | 3 | const fs = require( 'fs' );
|
4 |
| -const { exit } = require( 'process' ); |
5 | 4 |
|
6 |
| -const path = `${ process.cwd() }/.wp-env.override.json`; |
| 5 | +const path = `${ process.cwd() }/.wp-env.json`; |
7 | 6 |
|
8 |
| -// eslint-disable-next-line import/no-dynamic-require |
9 |
| -const config = fs.existsSync( path ) ? require( path ) : {}; |
| 7 | +let config = fs.existsSync( path ) ? require( path ) : { plugins: [ '.' ] }; |
10 | 8 |
|
11 |
| -const args = process.argv.slice( 2 ); |
| 9 | +const args = {}; |
| 10 | +process.argv |
| 11 | + .slice(2, process.argv.length) |
| 12 | + .forEach( arg => { |
| 13 | + if (arg.slice(0,2) === '--') { |
| 14 | + const param = arg.split('='); |
| 15 | + const paramName = param[0].slice(2,param[0].length); |
| 16 | + const paramValue = param.length > 1 ? param[1] : true; |
| 17 | + args[paramName] = paramValue; |
| 18 | + } |
| 19 | + }); |
12 | 20 |
|
13 |
| -if ( args.length === 0 ) exit( 0 ); |
| 21 | +if ( ! args.core && ! args.plugins ) { |
| 22 | + return; |
| 23 | +} |
| 24 | + |
| 25 | +if ( 'latest' === args.core ) { |
| 26 | + delete args.core; |
| 27 | +} |
14 | 28 |
|
15 |
| -if ( args[ 0 ] === 'latest' ) { |
16 |
| - if ( fs.existsSync( path ) ) { |
17 |
| - fs.unlinkSync( path ); |
18 |
| - } |
19 |
| - exit( 0 ); |
| 29 | +if( Object.keys(args).length === 0 ) { |
| 30 | + return; |
20 | 31 | }
|
21 | 32 |
|
22 |
| -config.core = args[ 0 ]; |
| 33 | +if ( args.plugins ) { |
| 34 | + args.plugins = args.plugins.split(','); |
| 35 | +} |
23 | 36 |
|
24 |
| -// eslint-disable-next-line no-useless-escape |
25 |
| -if ( ! config.core.match( /^WordPress\/WordPress\#/ ) ) { |
26 |
| - config.core = `WordPress/WordPress#${ config.core }`; |
| 37 | +config = { |
| 38 | + ...config, |
| 39 | + ...args, |
27 | 40 | }
|
28 | 41 |
|
29 | 42 | try {
|
30 |
| - fs.writeFileSync( path, JSON.stringify( config ) ); |
| 43 | + fs.writeFileSync( path, JSON.stringify( config ) ); |
31 | 44 | } catch ( err ) {
|
32 |
| - // eslint-disable-next-line no-console |
33 |
| - console.error( err ); |
| 45 | + console.error( err ); |
34 | 46 | }
|
0 commit comments