-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
14 | ||
14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { execSync } = require('child_process'); | ||
const { renameSync, readFileSync, writeFileSync, existsSync, lstatSync, mkdirSync, copyFileSync } = require('fs'); | ||
const { run } = require('./lib/run'); | ||
const { getMainReposFromGit } = require('./lib/get-main-repos'); | ||
const { mysqlRootExec, mysqlRootExecNoTTY, mysqlRootCommand, mysqlRootCommandNoTTY } = require('./lib/mysql'); | ||
|
||
const wpEnvConfig = JSON.parse(readFileSync('./.wp-env.json')); | ||
const nodeVersionRequired = parseInt(readFileSync('.nvmrc')); | ||
const config = { | ||
appDir: 'planet4', | ||
nodeVersion: nodeVersionRequired, | ||
...wpEnvConfig | ||
}; | ||
console.log(process.cwd(), config); | ||
const baseDir = `${config.appDir}/planet4-base`; | ||
const themeDir = config.mappings['wp-content/themes']; | ||
const pluginDir = config.mappings['wp-content/plugins']; | ||
|
||
/** | ||
* Node version control | ||
*/ | ||
console.log('Node version: ' + process.version); | ||
const nodeVersionRunning = parseInt(process.version.split('.')[0].substr(1)); // <string> "vX.Y.Z" => <int> X | ||
if (nodeVersionRunning !== nodeVersionRequired) { | ||
console.error(`This install requires Node version ${nodeVersionRequired}. You can run <nvm use> to switch version.`); | ||
process.exit(1); | ||
} | ||
|
||
/** | ||
* Install main repos | ||
*/ | ||
console.log('Cloning base repo ...'); | ||
console.log(`>>> ${baseDir}`); | ||
if (existsSync(`${baseDir}`) && lstatSync(`${baseDir}`).isDirectory()) { | ||
run('git status', {cwd: `${baseDir}`}); | ||
} else { | ||
run(`git clone [email protected]:greenpeace/planet4-base.git ${baseDir}`); | ||
} | ||
|
||
console.log('Cloning main repos ...'); | ||
getMainReposFromGit({themeDir, pluginDir}); | ||
|
||
/** | ||
* Start WP | ||
*/ | ||
run('wp-env start --update'); | ||
|
||
/** | ||
* Merge composer requirements | ||
*/ | ||
console.log('Merging composer requirements ...'); | ||
copyFileSync(`${baseDir}/composer.json`, `${config.appDir}/composer.json`); | ||
run(`wp-env run composer -d /app/${config.appDir}/ config --unset repositories.0`); | ||
run(`wp-env run composer -d /app/${config.appDir}/ config --unset extra.merge-plugin`); | ||
run(`wp-env run composer -d /app/${config.appDir}/ config --json extra.installer-paths '"{\\"plugins/{\\$name}/\\": [\\"type:wordpress-plugin\\"],\\"themes/{\\$name}/\\": [\\"type:wordpress-theme\\"]}"'`); | ||
run(`wp-env run composer -d /app/${config.appDir}/ config platform.php "${config.phpVersion}"`); | ||
if (existsSync(`${themeDir}/planet4-master-theme`) | ||
&& lstatSync(`${themeDir}/planet4-master-theme`).isDirectory() | ||
) { | ||
run('wp-env run composer -d /app/planet4/ remove --no-update greenpeace/planet4-master-theme'); | ||
} | ||
if (existsSync(`${pluginDir}/planet4-plugin-gutenberg-blocks`) | ||
&& lstatSync(`${pluginDir}/planet4-plugin-gutenberg-blocks`).isDirectory() | ||
) { | ||
run('wp-env run composer -d /app/planet4/ remove --no-update greenpeace/planet4-plugin-gutenberg-blocks'); | ||
} | ||
|
||
/** | ||
* Install themes/plugins | ||
*/ | ||
console.log('Installing themes and plugins ...'); | ||
run(`wp-env run composer -d /app/${config.appDir}/ install --ignore-platform-reqs`); | ||
run(`wp-env run composer -d /app/${themeDir}/planet4-master-theme config platform.php "${config.phpVersion}"`); | ||
run(`wp-env run composer -d /app/${themeDir}/planet4-master-theme install --ignore-platform-reqs`); | ||
run(`wp-env run composer -d /app/${pluginDir}/planet4-plugin-gutenberg-blocks config platform.php "${config.phpVersion}"`); | ||
run(`wp-env run composer -d /app/${pluginDir}/planet4-plugin-gutenberg-blocks install --ignore-platform-reqs`); | ||
|
||
if (!existsSync(`${themeDir}/planet4-master-theme/assets/build`)) { | ||
console.log('Generating assets ...'); | ||
process.env.PUPPETEER_SKIP_DOWNLOAD = true; | ||
process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true; | ||
run('npm install && npm run build', {cwd: `${themeDir}/planet4-master-theme`}); | ||
run('npm install && npm run build', {cwd: `${pluginDir}/planet4-plugin-gutenberg-blocks`}); | ||
} | ||
|
||
run('wp-env run cli plugin activate --all'); | ||
|
||
/** | ||
* Database | ||
*/ | ||
if (!existsSync('content')) { | ||
mkdirSync('content'); | ||
} | ||
run('curl --fail https://storage.googleapis.com/planet4-default-content/planet4-defaultcontent_wordpress-v0.2.13.sql.gz > content/planet4-defaultcontent_wordpress-v0.2.13.sql.gz'); | ||
|
||
const dbName = 'planet4_dev'; | ||
mysqlRootExec(`-e \\ | ||
"CREATE DATABASE IF NOT EXISTS planet4_dev; \\ | ||
GRANT all privileges on ${dbName}.* to 'root'@'%'; \\ | ||
USE ${dbName};"`); | ||
|
||
mysqlRootExec('-e \'SET GLOBAL max_allowed_packet=16777216\''); | ||
run(`zcat < "content/planet4-defaultcontent_wordpress-v0.2.13.sql.gz" | ${mysqlRootCommandNoTTY(dbName)}`); | ||
// Fix GTID_PURGED value issue | ||
// mysql_root_exec -D planet4_dev -e 'RESET MASTER' | ||
|
||
run(`wp-env run cli config set DB_NAME ${dbName}`); | ||
run('wp-env run cli user update admin --user_pass=admin --role=administrator'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
const { execSync } = require( 'child_process' ); | ||
const { renameSync, existsSync, lstatSync } = require('fs'); | ||
|
||
function getMainReposFromGit({themeDir, pluginDir}) { | ||
console.log(); | ||
console.log(`>>> ${themeDir}/planet4-master-theme`); | ||
if (existsSync(`${themeDir}/planet4-master-theme`) && lstatSync(`${themeDir}/planet4-master-theme`).isDirectory()) { | ||
execSync('git status', {cwd: `${themeDir}/planet4-master-theme`, stdio: 'inherit'}); | ||
} else { | ||
execSync(`git clone [email protected]:greenpeace/planet4-master-theme.git ${themeDir}/planet4-master-theme`, {stdio: 'inherit'}); | ||
} | ||
|
||
console.log(); | ||
console.log(`>>> ${pluginDir}/planet4-plugin-gutenberg-blocks`); | ||
if (existsSync(`${pluginDir}/planet4-plugin-gutenberg-blocks`) && lstatSync(`${pluginDir}/planet4-plugin-gutenberg-blocks`).isDirectory()) { | ||
execSync('git status', {cwd: `${pluginDir}/planet4-plugin-gutenberg-blocks`, stdio: 'inherit'}); | ||
} else { | ||
execSync(`git clone --recurse-submodules --shallow-submodule [email protected]:greenpeace/planet4-plugin-gutenberg-blocks.git ${pluginDir}/planet4-plugin-gutenberg-blocks`, {stdio: 'inherit'}); | ||
} | ||
}; | ||
|
||
function getMainReposFromRelease({themeDir, pluginDir}) { | ||
console.error('@todo implement'); | ||
} | ||
|
||
module.exports = { | ||
getMainReposFromGit, | ||
getMainReposFromRelease, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
function mysqlRootExec(cmd) { | ||
const dcCommand = mysqlRootCommand(cmd); | ||
console.log(dcCommand); | ||
return execSync(dcCommand, {stdio: 'inherit'}); | ||
}; | ||
|
||
function mysqlRootExecNoTTY(cmd) { | ||
const dcCommand = mysqlRootCommandNoTTY(cmd); | ||
console.log(dcCommand); | ||
return execSync(dcCommand, {stdio: 'inherit'}); | ||
}; | ||
|
||
function mysqlRootCommand(cmd) { | ||
return `docker-compose -f \$(wp-env install-path)/docker-compose.yml exec mysql mysql -uroot -ppassword ${cmd}`; | ||
}; | ||
|
||
function mysqlRootCommandNoTTY(cmd) { | ||
return `docker-compose -f \$(wp-env install-path)/docker-compose.yml exec -T mysql mysql -uroot -ppassword ${cmd}`; | ||
}; | ||
|
||
module.exports = { | ||
mysqlRootExec, | ||
mysqlRootExecNoTTY, | ||
mysqlRootCommand, | ||
mysqlRootCommandNoTTY | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { execSync } = require('child_process'); | ||
|
||
function run(cmd, opts) { | ||
return execSync(cmd, {stdio: 'inherit', ...opts}); | ||
} | ||
|
||
module.exports = { run }; |