Skip to content
35 changes: 1 addition & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ branches:
env:
global:
- PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- WP_DEVELOP_DIR: ./wordpress
- LOCAL_SCRIPT_DEBUG: false
- INSTALL_COMPOSER: false
- INSTALL_WORDPRESS: true
Expand All @@ -46,39 +45,7 @@ install:
- npm run build
- |
if [[ "$INSTALL_WORDPRESS" = "true" ]]; then
# Download and unpack WordPress.
curl -sL https://wordpress.org/nightly-builds/wordpress-latest.zip -o /tmp/wordpress-latest.zip
unzip -q /tmp/wordpress-latest.zip -d /tmp
mkdir -p wordpress/src
mv /tmp/wordpress/* wordpress/src

# Create the upload directory with permissions that Travis can handle.
mkdir -p wordpress/src/wp-content/uploads
chmod 767 wordpress/src/wp-content/uploads

# Grab the tools we need for WordPress' local-env.
curl -sL https://github.com/WordPress/wordpress-develop/archive/master.zip -o /tmp/wordpress-develop.zip
unzip -q /tmp/wordpress-develop.zip -d /tmp
mv \
/tmp/wordpress-develop-master/tools \
/tmp/wordpress-develop-master/tests \
/tmp/wordpress-develop-master/.env \
/tmp/wordpress-develop-master/docker-compose.yml \
/tmp/wordpress-develop-master/wp-cli.yml \
/tmp/wordpress-develop-master/*config-sample.php \
/tmp/wordpress-develop-master/package.json wordpress

# Install WordPress.
cd wordpress
npm install dotenv wait-on
npm run env:start
sleep 10
npm run env:install
cd ..

# Connect Gutenberg to WordPress.
npm run env connect
npm run env cli plugin activate gutenberg
npm run env install
fi
- |
if [[ "$INSTALL_COMPOSER" = "true" ]]; then
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"@wordpress/eslint-plugin": "file:../eslint-plugin",
"@wordpress/jest-preset-default": "file:../jest-preset-default",
"@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config",
"appdata-path": "^1.0.0",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.5",
"chalk": "^2.4.1",
"check-node-version": "^3.1.1",
"command-exists": "1.2.8",
"cross-spawn": "^5.1.0",
"decompress-zip": "0.2.2",
"eslint": "^6.1.0",
Expand Down
34 changes: 21 additions & 13 deletions packages/scripts/scripts/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ const chalk = require( 'chalk' );
/**
* Node dependencies.
*/
const { env, exit, stdout, cwd } = require( 'process' );
const { env, exit, stdout } = require( 'process' );
const { normalize } = require( 'path' );
const { existsSync } = require( 'fs' );
const { userInfo } = require( 'os' );

/**
* Internal dependencies
*/
const {
getArgsFromCLI,
getManagedWordPressPath,
spawnScript,
} = require( '../utils' );

Expand All @@ -23,38 +25,44 @@ const args = getArgsFromCLI();
if ( ! args.length ) {
const scripts = {
install: "If you don't have a check out of the WordPress repository that you want to work with, this will automatically download, configure, and connect to WordPress.",
connect: 'If you have a WordPress respository already, define the ' + chalk.magenta( 'WP_DEVELOP_DIR' ) + ' environment variable with the path to your repository, then run this command to add this plugin to it.',
connect: chalk`If you have a WordPress respository already, define the {magenta WP_DEVELOP_DIR} environment variable with the path to your repository, then run this command to add this plugin to it.`,
start: "This will start a container that you've already installed and connected to.",
stop: "And this will stop it when you're done!",
update: 'If you used ' + chalk.blue( 'npm run env install' ) + ' to setup WordPress, run this command to update it.',
update: chalk`If you used {blue npm run env install} to setup WordPress, run this command to update it.`,
reinstall: 'Resets the database and re-configures WordPress again.',
cli: 'Run WP-CLI commands against the WordPress install.',
'lint-php': 'Run PHPCS linting on the plugin.',
'test-php': "Run the plugin's PHPUnit tests.",
'docker-run': 'For more advanced debugging, you may sometimes need to run commands in the Docker containers. This is the equivalent of running ' + chalk.blue( 'docker-compose run' ) + '.',
'docker-run': chalk`For more advanced debugging, you may sometimes need to run commands in the Docker containers. This is the equivalent of running {blue docker-compose run}.`,
};

stdout.write( chalk.white( 'Welcome to the WordPress Local Environment! There are several commands available to help you get up and running. Each of these commands should be run after ' ) );
stdout.write( chalk.blue( 'npm run env' ) );
stdout.write( chalk.white( '. For example, ' ) );
stdout.write( chalk.blue( 'npm run env install' ) );
stdout.write( chalk.white( '.\n\n' ) );
stdout.write( chalk`{white Welcome to the WordPress Local Environment! There are several commands available to help you get up and running. Each of these commands should be run after {blue npm run env}. For example, {blue npm run env install}.}\n\n` );

Object.keys( scripts ).forEach( ( script ) => {
stdout.write( chalk.green( script ) + '\n ' + chalk.white( scripts[ script ] ) + '\n\n' );
} );
exit( 0 );
}

const user = userInfo();

if ( ! env.PHP_FPM_UID && user.uid > 0 ) {
env.PHP_FPM_UID = user.uid;
}

if ( ! env.PHP_FPM_GID && user.gid > 0 ) {
env.PHP_FPM_GID = user.gid;
}

const command = args.shift();

if ( ! env.WP_DEVELOP_DIR && command !== 'install' ) {
if ( existsSync( normalize( cwd() + '/wordpress/wp-config-sample.php' ) ) ) {
env.WP_DEVELOP_DIR = normalize( cwd() + '/wordpress' );
if ( existsSync( normalize( getManagedWordPressPath() + '/wp-config.php' ) ) ) {
env.WP_DEVELOP_DIR = getManagedWordPressPath();
env.MANAGED_WP = true;
} else {
stdout.write( chalk.white( 'Please ensure the WP_DEVELOP_DIR environment variable is set to your WordPress Development directory before running this script.\n\n' ) );
stdout.write( chalk.white( "If you don't have a WordPress Development directory to use, run `npm run env install` to automatically configure one!\n" ) );
stdout.write( chalk`{white Please ensure the {magenta WP_DEVELOP_DIR} environment variable is set to your WordPress Development directory before running this script.}\n\n` );
stdout.write( chalk`{white If you don't have a WordPress Development directory to use, run {blue npm run env install} to automatically configure one!}\n` );
exit( 1 );
}
}
Expand Down
9 changes: 6 additions & 3 deletions packages/scripts/scripts/env/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { execSync } = require( 'child_process' );
*/
const {
fromConfigRoot,
hasArgInCLI,
mergeYAMLConfigs,
} = require( '../../utils' );

Expand Down Expand Up @@ -71,7 +72,9 @@ const mergedCompose = mergeYAMLConfigs( compose, pluginCompose, pluginMountDir )

writeFileSync( composeFile, yaml.safeDump( mergedCompose, { lineWidth: -1 } ) );

stdout.write( 'Restarting the WordPress environment...\n' );
if ( ! hasArgInCLI( '--no-restart' ) ) {
stdout.write( 'Restarting the WordPress environment...\n' );

execSync( 'npm run env:stop', { cwd: env.WP_DEVELOP_DIR, stdio: 'inherit' } );
execSync( 'npm run env:start', { cwd: env.WP_DEVELOP_DIR, stdio: 'inherit' } );
execSync( 'npm run env:stop', { cwd: env.WP_DEVELOP_DIR, stdio: 'inherit' } );
execSync( 'npm run env:start', { cwd: env.WP_DEVELOP_DIR, stdio: 'inherit' } );
}
32 changes: 13 additions & 19 deletions packages/scripts/scripts/env/install.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* External dependencies
*/
const { sync: commandExistsSync } = require( 'command-exists' );
const chalk = require( 'chalk' );

/**
* Node dependencies.
* Node dependencies
*/
const { execSync } = require( 'child_process' );
const { env, exit, cwd, stdout } = require( 'process' );
const { env, exit, stdout } = require( 'process' );
const { normalize } = require( 'path' );
const { existsSync } = require( 'fs' );

Expand All @@ -16,29 +15,24 @@ const { existsSync } = require( 'fs' );
*/
const {
buildWordPress,
downloadWordPressZip,
getManagedWordPressPath,
hasArgInCLI,
installManagedWordPress,
} = require( '../../utils' );
const { hasArgInCLI } = require( '../../utils' );

env.WP_DEVELOP_DIR = normalize( cwd() + '/wordpress' );
env.WP_DEVELOP_DIR = getManagedWordPressPath();

if ( hasArgInCLI( '--fast' ) ) {
buildWordPress( true, true );
return;
}

if ( existsSync( normalize( cwd() + '/wordpress/wp-config-sample.php' ) ) ) {
stdout.write( 'It looks like WordPress is already installed, please delete the `wordpress` directory for a fresh install, or run `npm run env start` to start the existing environment.\n' );
if ( existsSync( normalize( env.WP_DEVELOP_DIR + '/wp-config.php' ) ) ) {
stdout.write( chalk`{white It looks like WordPress is already installed, please run {blue npm run env clean} for a fresh install, or run {blue npm run env start} to start the existing environment.}\n` );
exit( 1 );
}

if ( commandExistsSync( 'git' ) ) {
execSync( 'git clone --depth=1 git://develop.git.wordpress.org/ wordpress', { stdio: 'inherit' } );
buildWordPress( true, false );
} else {
stdout.write( "Git isn't available. Switching to downloading a zip version.\n" );
downloadWordPressZip()
.then( () => {
buildWordPress( true, false );
} );
}
installManagedWordPress()
.then( () => {
buildWordPress( true, false );
} );
18 changes: 7 additions & 11 deletions packages/scripts/scripts/env/start.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
/**
* External dependencies
*/
const { sync: commandExistsSync } = require( 'command-exists' );

/**
* Node dependencies.
* Node dependencies
*/
const { execSync } = require( 'child_process' );
const { env, stdout } = require( 'process' );
const { normalize } = require( 'path' );
const { statSync } = require( 'fs' );

/**
* Internal dependencies
*/
const { getManagedWordPressPath } = require( '../../utils' );

if ( env.MANAGED_WP ) {
// We're running in our managed WordPress environment, so check if we need to update.
let stat;
if ( false && commandExistsSync( 'git' ) ) {
stat = statSync( normalize( env.WP_DEVELOP_DIR + '/.git' ) );
} else {
stat = statSync( normalize( env.WP_DEVELOP_DIR + '/wp-config-sample.php' ) );
}
const stat = statSync( normalize( getManagedWordPressPath() + '/src/wp-config-sample.php' ) );

const lastUpdated = new Date( stat.mtimeMs );
if ( Date.now() - lastUpdated.getTime() > 7 * 24 * 60 * 60 * 1000 ) {
Expand Down
24 changes: 6 additions & 18 deletions packages/scripts/scripts/env/update.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
/**
* External dependencies
*/
const { sync: commandExistsSync } = require( 'command-exists' );

/**
* Node dependencies.
*/
const { execSync } = require( 'child_process' );
const { env, cwd, stdout } = require( 'process' );
const { env, cwd } = require( 'process' );
const { normalize } = require( 'path' );

/**
* Internal dependencies
*/
const {
buildWordPress,
downloadWordPressZip,
installManagedWordPress,
} = require( '../../utils' );

env.WP_DEVELOP_DIR = normalize( cwd() + '/wordpress' );

if ( commandExistsSync( 'git' ) ) {
execSync( 'git pull', { cwd: env.WP_DEVELOP_DIR, stdio: 'inherit' } );
buildWordPress( false, false );
} else {
stdout.write( "Git isn't available. Switching to downloading a zip version.\n" );
downloadWordPressZip()
.then( () => {
buildWordPress( false, false );
} );
}
installManagedWordPress()
.then( () => {
buildWordPress( false, false );
} );
Loading