Skip to content

Commit

Permalink
Move some parameters around, update command
Browse files Browse the repository at this point in the history
  • Loading branch information
lithrel committed Mar 10, 2023
1 parent d0a3b04 commit 97e7ea9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 13 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"ecmaVersion": "latest"
},
"rules": {
"operator-linebreak": ["error", "before"]
}
}
10 changes: 10 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@
"development": {
"port": 80
}
},
"planet4": {
"content": {
"db": "v0.2.13",
"images": "1-25"
},
"repos": {
"planet4-master-theme": "main",
"planet4-plugin-gutenberg-blocks": "main"
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ npm run
- env:config Show generated configuration
- env:fix-permissions [all] Fix files permissions to current user as owner
- env:clean-repos Remove main repos if they are not git repositories
- env:update Update installer, base and main repos
- nro:install <?nro> Install NRO theme and database, if declared in .p4-env.json
- nro:enable Enable installed NRO theme and database
- nro:disable Switch back to default theme and database
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"env:config": "node ./scripts/config.js",
"env:fix-permissions": "node ./scripts/fix-permissions.js",
"env:clean-repos": "node ./scripts/clean-repos.js",
"env:update": "node ./scripts/update.js",
"nro:install": "node ./scripts/nro-install.js",
"nro:enable": "node ./scripts/nro-enable.js",
"nro:disable": "node ./scripts/nro-disable.js",
Expand Down
4 changes: 2 additions & 2 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ run('wp-env run cli plugin activate --all')
/**
* Images
*/
const imagesDump = 'planet4-default-content-1-25-images.zip'
const imagesDump = `planet4-default-content-${config.planet4.content.images}-images.zip`
download(
`https://storage.googleapis.com/planet4-default-content/${imagesDump}`,
`content/${imagesDump}`
Expand All @@ -72,7 +72,7 @@ if (!existsSync('content')) {
mkdirSync('content')
}
const dbName = 'planet4_dev'
const dbDump = 'planet4-defaultcontent_wordpress-v0.2.13.sql.gz'
const dbDump = `planet4-defaultcontent_wordpress-${config.planet4.content.db}.sql.gz`
download(
`https://storage.googleapis.com/planet4-default-content/${dbDump}`,
`content/${dbDump}`
Expand Down
24 changes: 17 additions & 7 deletions scripts/lib/main-repos.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
const { run } = require('./run')
const { isDir, isRepo } = require('./utils')

function getMainReposFromGit ({ themesDir, pluginsDir }) {
function getMainReposFromGit ({ themesDir, pluginsDir, planet4 }) {
run(`mkdir -p ${themesDir} && mkdir -p ${pluginsDir}`)

isRepo(`${themesDir}/planet4-master-theme`)
? run('git status', { cwd: `${themesDir}/planet4-master-theme` })
: run(`git clone [email protected]:greenpeace/planet4-master-theme.git ${themesDir}/planet4-master-theme`)

run(
`git checkout ${planet4.repos['planet4-master-theme'] || 'main'} || true`,
{ cwd: `${themesDir}/planet4-master-theme` }
)

isRepo(`${pluginsDir}/planet4-plugin-gutenberg-blocks`)
? run('git status', { cwd: `${pluginsDir}/planet4-plugin-gutenberg-blocks` })
: run(`git clone --recurse-submodules --shallow-submodule [email protected]:greenpeace/planet4-plugin-gutenberg-blocks.git ${pluginsDir}/planet4-plugin-gutenberg-blocks`)

run(
`git checkout ${planet4.repos['planet4-plugin-gutenberg-blocks'] || 'main'} || true`,
{ cwd: `${pluginsDir}/planet4-plugin-gutenberg-blocks` }
)
};

function getMainReposFromRelease (config, force = false) {
if (!force &&
isDir(`${config.themesDir}/planet4-master-theme`) &&
isDir(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks`)
if (!force
&& isDir(`${config.themesDir}/planet4-master-theme`)
&& isDir(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks`)
) {
return
}
Expand Down Expand Up @@ -47,9 +57,9 @@ function installNpmDependencies (config) {
}

function buildAssets (config, force = false) {
if (!force &&
isDir(`${config.themesDir}/planet4-master-theme/assets/build`) &&
isDir(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks/assets/build`)
if (!force
&& isDir(`${config.themesDir}/planet4-master-theme/assets/build`)
&& isDir(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks/assets/build`)
) {
return
}
Expand Down
9 changes: 5 additions & 4 deletions scripts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ function makeDirStructure ({ themesDir, pluginsDir, uploadsDir }) {
}

function installPluginsDependencies ({ pluginsDir }) {
const excluded = ['cmb2']
const files = readdirSync(pluginsDir)

files.forEach((file) => {
const path = `${pluginsDir}/${file}`
if (!isDir(path) ||
!existsSync(`${path}/composer.json`) ||
isDir(`${path}/vendor`) ||
file === 'cmb2'
if (excluded.includes(file)
|| !isDir(path)
|| !existsSync(`${path}/composer.json`)
|| isDir(`${path}/vendor`)
) {
return
}
Expand Down
44 changes: 44 additions & 0 deletions scripts/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { nodeCheck } = require('./lib/node-check')
const { getConfig } = require('./lib/config')
const { run } = require('./lib/run')
const { getMainReposFromRelease, installRepos } = require('./lib/main-repos')
const { isRepo, isDir } = require('./lib/utils')

/**
* Node version control
*/
console.log('Node version: ' + process.version)
nodeCheck()

/**
* Config
*/
const config = getConfig()
console.log(process.cwd(), '\n', config)

// self ? and rerun
// base dir
// main repos
// default DB
// default images

if (isRepo(process.cwd())) {
run('git pull || true', { cwd: `${process.cwd()}` })
}

if (isRepo(config.baseDir)) {
run('git pull || true', { cwd: `${config.baseDir}` })
}

if (isRepo(`${config.themesDir}/planet4-master-theme`)
&& isRepo(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks`)
) {
run('git pull || true', { cwd: `${config.themesDir}/planet4-master-theme` })
run('git pull || true', { cwd: `${config.pluginsDir}/planet4-plugin-gutenberg-blocks` })
installRepos(config)
} else if (isDir(`${config.themesDir}/planet4-master-theme`)
&& isDir(`${config.pluginsDir}/planet4-plugin-gutenberg-blocks`)
) {
getMainReposFromRelease(config, true)
installRepos(config)
}

0 comments on commit 97e7ea9

Please sign in to comment.