Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tools to import/export content #3354

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vendor/
.svn
.sandbox-config
.wp-env.override.json
export/*

#Ignoring headstart and language files
*/languages/*
Expand Down
1 change: 1 addition & 0 deletions .sandbox-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ package-lock.json
sandbox.sh
vendor
node_modules
export
**/*.zip
9 changes: 8 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "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": "npx wp-env run cli 'wp site empty --uploads --yes'",

"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": "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"

},
"devDependencies": {
"chokidar-cli": "^2.1.0",
Expand Down
25 changes: 24 additions & 1 deletion sandbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this command assumes I have some exported content in /home/wpcom/export already? Is there a way I could specify a specific site of mine to export from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that command will create the file in the /home/wpcom/export folder and then copy it locally.

It's a pretty hacky way to do it I think but I couldn't quite get things to work in another way. And Bash always just seems like a giant roll of duct tape to me anyway...

It would be a simple change to target a particular site defined in the command execution, yea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth be told I have NO idea where there's a mkdir followed by an immediate rm so that's probably something that should change (even if it doesn't not work)

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 ; rm /home/wpcom/export/* ; /home/wpcom/public_html/bin/wp export --dir=/home/wpcom/export --url=theamdemo.wordpress.com"'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably just change to use whatever URL you pass in like:

./sandbox.sh export theamdemo.wordpress.com

instead of

./sandbox.sh export-theam

allowing for

./sandbox.sh export peanutbutterbatter.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