From 0831c71122adf88cf23878d26717111ea7f0ff67 Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Wed, 24 Feb 2021 15:22:13 -0500 Subject: [PATCH 1/3] Added tools to import/export content This change adds tools to import/export content from the local wp-env instance. Content can be pulled from your sandbox, themedemo.wordpress.com or from the theme-unit-test repository The sandbox.sh script was changed to power the "export" (from sandbox or themedemo) functionality. The .wp-env.json was changed to supply the content from theme-unit-test repository, map local folders for import/export of the rest of the resources and to provide the import plugin by default. npm scripts have been added to package.json in order to drive the commands. Documentation in readme has been updated to reflect the additional capabilities. --- .gitignore | 1 + .sandbox-ignore | 1 + .wp-env.json | 9 ++++++++- README.md | 28 +++++++++++++++++++++++++++- package.json | 18 +++++++++++++++++- sandbox.sh | 25 ++++++++++++++++++++++++- 6 files changed, 78 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 506aa5b516..e9aaaa9b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ vendor/ .svn .sandbox-config .wp-env.override.json +export/* #Ignoring headstart and language files */languages/* diff --git a/.sandbox-ignore b/.sandbox-ignore index 0f396c349e..47da6686c9 100644 --- a/.sandbox-ignore +++ b/.sandbox-ignore @@ -7,4 +7,5 @@ package-lock.json sandbox.sh vendor node_modules +export **/*.zip \ No newline at end of file diff --git a/.wp-env.json b/.wp-env.json index bc4d2517d8..86f029c21a 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,12 @@ { "themes": [ "." - ] + ], + "plugins": [ + "https://downloads.wordpress.org/plugin/wordpress-importer.0.7.zip" + ], + "mappings": { + "./export": "./export", + "./theme-unit-test":"WPTT/theme-unit-test#master" + } } diff --git a/README.md b/README.md index c2c8a48d7a..01d7be0499 100644 --- a/README.md +++ b/README.md @@ -74,4 +74,30 @@ NOTE: When pushing changes if your local branch is not current with /trunk you w - In addition to pushing your local changes you can also WATCH for any local changes and trigger the sandbox sync by using the `npm run sandbox:watch` Any changes to your local files will trigger the rsync. Make sure that you have executed `npm install` to ensure the needed dependencies for this are installed. -Note: The first time you run the `sandbox.sh` shell script you will be prompted for details about your sandbox which will be stored in a `.sandbox-config` file. Edit (or delete and be re-prompted) if details about your sandbox change. This file will not be comitted to version controll and will not sync to your sandbox. \ No newline at end of file +Note: The first time you run the `sandbox.sh` shell script you will be prompted for details about your sandbox which will be stored in a `.sandbox-config` file. Edit (or delete and be re-prompted) if details about your sandbox change. This file will not be comitted to version controll and will not sync to your sandbox. + +- Content can be exported from your sandbox to a local XML file using the command `./sandbox.sh export`. The resulting XML file will be found in `./export/sandbox.wordpress.xml`. Alternately you may use the command `./sandbox.sh export-theam` to export the content from the Theam Demo site `theamdemo.wordpress.com`. That XML file will be found in `./export/theamdemo.wordpress.com`. + +## wp-env + +wp-env is a handy solution to spin up local WordPress environments. Details can be found here: https://developer.wordpress.org/block-editor/packages/packages-env/ + +A default `.wp-env.json` file is included in this project which can be used to spin up an instance of WordPress for development of the Theams. The command `npx wp-env start` will spin this up based on those settings. You can also add a `.wp-env.override.json` file to supply your own values (such as mapping to a local instance of Gutenberg) (Note: When supplying some values such as 'plugins' in the .wp-env.override.json the values are OVERRIDDEN and not MERGED thus all plugins need to be supplied. See here.) + +The WordPress Importer plugin and Gutenberg (/master branch in the git repository) are supplied by default as well as the theam-unit-test data and a local mapping for importing/exporting content. + +There are a number of npm scripts available to make working with this wp-env instance of WordPress easier. Any of these commands are executed via `npm run [COMMAND]` + +- wp-env : A shortcut (not much of one) to the `wp-env start` command. + +Note: The rest of these commands must be executed with the instance of wp-env running (with the execption of those that leverage sandbox.sh script) + +- wp-env:empty : Remove all content from the local wp-env instance (via `wp site empty`) +- wp-env:export:local : Export the content from your wp-env instance to `./export/local.wordpress.xml` +- wp-env:export:theam : Export the content from theamdemo.wordpress.com to `./export/theamdemo.wordpress.xml` This command leverages the `sandbox.sh export-theam` command noted above +- wp-env:export:sandbox : Export the content from your sandbox to `./export/sandbox.wordpress.xml` This command leverages the `sandbox.sh export` command noted above +- wp-env:import:local : Import the content from `./export/local.wordpress.xml` to your local wp-env site +- wp-env:import:theam : Import the content from `./export/theamdemo.wordpress.xml` to your local wp-env site +- wp-env:import:sandbox : Import the content from `./export/sandbox.wordpress.xml` to your local wp-env site +- wp-env:import:unittest : Import the content from the github repository `WPTT/theme-unit-test` to your local wp-env site +- wp-env:cleanslate : A multi-command that cleans the local site, downloads the content from theamdemo.wordpress.com and imports it into your local instance \ No newline at end of file diff --git a/package.json b/package.json index abe014a7a1..68cda98f99 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,23 @@ "sandbox:push": "./sandbox.sh push", "sandbox:push:ignore": "./sandbox.sh push --ignore", "sandbox:push:force": "./sandbox.sh push --force", - "sandbox:watch": "chokidar '**/*' -i '*/node_modules' -i '.git' -c './sandbox.sh push --ignore' --initial" + "sandbox:watch": "chokidar '**/*' -i '*/node_modules' -i '.git' -c './sandbox.sh push --ignore' --initial", + + "wp-env": "wp-env start", + + "wp-env:cleanslate": "npm run wp-env:empty ; npm run wp-env:export:theam ; npm run wp-env:import:theam", + + "wp-env:empty": "wp-env run cli 'wp site empty --uploads --yes'", + + "wp-env:import:local": "wp-env run cli 'wp import ./theme-unit-test/local.wordpress.xml --authors=create'", + "wp-env:import:theam": "wp-env run cli 'wp import ./export/theamdemo.wordpress.xml --authors=create'", + "wp-env:import:sandbox": "wp-env run cli 'wp import ./export/sandbox.wordpress.xml --authors=create'", + "wp-env:import:unittest": "wp-env run cli 'wp import ./theme-unit-test/themeunittestdata.wordpress.xml --authors=create'", + + "wp-env:export:local": "wp-env run cli 'wp export --dir=./export/ --filename_format=local.wordpress.xml'", + "wp-env:export:theam": "./sandbox.sh export-theam", + "wp-env:export:sandbox": "./sandbox.sh export" + }, "devDependencies": { "chokidar-cli": "^2.1.0", diff --git a/sandbox.sh b/sandbox.sh index f3e8d7f2b1..f621ee80c2 100755 --- a/sandbox.sh +++ b/sandbox.sh @@ -141,7 +141,30 @@ How do you wish to proceed? [1]" cmd="rsync -av --no-p --no-times --exclude-from='.sandbox-ignore' --exclude=$ignore_string ./ $SANDBOX_USER@$SANDBOX_LOCATION:$SANDBOX_PUBLIC_THEMES_FOLDER/" eval $cmd +elif [[ $1 == "export" ]]; then + # Export the site content from your sandbox to a local file + export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export"' + download_command='mkdir ./export ; scp $SANDBOX_USER@$SANDBOX_LOCATION:/home/wpcom/export/* ./export/sandbox.wordpress.xml' + eval $export_command + eval $download_command + echo " + + Export Complete! + + You can find the exported file in ./export/sandbox.wordpress.xml" + +elif [[ $1 == "export-theam" ]]; then + # Export the site content from theamdemo to a local file + export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export --url=theamdemo.wordpress.com"' + download_command='mkdir ./export ; scp $SANDBOX_USER@$SANDBOX_LOCATION:/home/wpcom/export/* ./export/theamdemo.wordpress.xml' + eval $export_command + eval $download_command + echo " + + Export Complete! + + You can find the exported file in ./export/theamdemo.wordpress.xml" else - echo 'No known command given. [clean, push]' + echo 'No known command given. [clean, push, export, export-theam]' fi \ No newline at end of file From 7e4bfd113c70e1bd1044bbc72634e6fe61fdb92f Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Wed, 24 Feb 2021 15:53:37 -0500 Subject: [PATCH 2/3] Fixed export to prevent overwriting by multiple targets --- sandbox.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox.sh b/sandbox.sh index f621ee80c2..099f7a57ff 100755 --- a/sandbox.sh +++ b/sandbox.sh @@ -143,7 +143,7 @@ How do you wish to proceed? [1]" elif [[ $1 == "export" ]]; then # Export the site content from your sandbox to a local file - export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export"' + export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export"' download_command='mkdir ./export ; scp $SANDBOX_USER@$SANDBOX_LOCATION:/home/wpcom/export/* ./export/sandbox.wordpress.xml' eval $export_command eval $download_command @@ -155,7 +155,7 @@ elif [[ $1 == "export" ]]; then elif [[ $1 == "export-theam" ]]; then # Export the site content from theamdemo to a local file - export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export --url=theamdemo.wordpress.com"' + export_command='ssh $SANDBOX_USER@$SANDBOX_LOCATION "mkdir /home/wpcom/export ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export --url=theamdemo.wordpress.com"' download_command='mkdir ./export ; scp $SANDBOX_USER@$SANDBOX_LOCATION:/home/wpcom/export/* ./export/theamdemo.wordpress.xml' eval $export_command eval $download_command From e53fb63bf22c14654bf05b318615616f1f5ea1bc Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Wed, 24 Feb 2021 15:54:12 -0500 Subject: [PATCH 3/3] changed wp-env to use npx instead of npm for users without it installed globally --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 68cda98f99..d6c350b3ca 100644 --- a/package.json +++ b/package.json @@ -11,18 +11,18 @@ "sandbox:push:force": "./sandbox.sh push --force", "sandbox:watch": "chokidar '**/*' -i '*/node_modules' -i '.git' -c './sandbox.sh push --ignore' --initial", - "wp-env": "wp-env start", + "wp-env": "npx wp-env start", "wp-env:cleanslate": "npm run wp-env:empty ; npm run wp-env:export:theam ; npm run wp-env:import:theam", - "wp-env:empty": "wp-env run cli 'wp site empty --uploads --yes'", + "wp-env:empty": "npx wp-env run cli 'wp site empty --uploads --yes'", - "wp-env:import:local": "wp-env run cli 'wp import ./theme-unit-test/local.wordpress.xml --authors=create'", - "wp-env:import:theam": "wp-env run cli 'wp import ./export/theamdemo.wordpress.xml --authors=create'", - "wp-env:import:sandbox": "wp-env run cli 'wp import ./export/sandbox.wordpress.xml --authors=create'", - "wp-env:import:unittest": "wp-env run cli 'wp import ./theme-unit-test/themeunittestdata.wordpress.xml --authors=create'", + "wp-env:import:local": "npx wp-env run cli 'wp import ./theme-unit-test/local.wordpress.xml --authors=create'", + "wp-env:import:theam": "npx wp-env run cli 'wp import ./export/theamdemo.wordpress.xml --authors=create'", + "wp-env:import:sandbox": "npx wp-env run cli 'wp import ./export/sandbox.wordpress.xml --authors=create'", + "wp-env:import:unittest": "npx wp-env run cli 'wp import ./theme-unit-test/themeunittestdata.wordpress.xml --authors=create'", - "wp-env:export:local": "wp-env run cli 'wp export --dir=./export/ --filename_format=local.wordpress.xml'", + "wp-env:export:local": "npx wp-env run cli 'wp export --dir=./export/ --filename_format=local.wordpress.xml'", "wp-env:export:theam": "./sandbox.sh export-theam", "wp-env:export:sandbox": "./sandbox.sh export"