Forráskód Böngészése

Premium: Update blockbase references when we push to the premium repo (#5396)

* Premium: Update blockbase references when we push to the premium repo

* Added sandbox:clean-premium:git/svn.  Refactored the -premium change to be more targeted.  Modified rsync command to also delete removed files.

* Exclude /sass files from rsyncing to premium

* Used the 'premium themes' folder as the 'ignore' folder

* Fixed a log

Co-authored-by: Jason Crist <jcrist@pbking.com>
Ben Dwyer 3 éve
szülő
commit
6a3bc5a4a4
2 módosított fájl, 72 hozzáadás és 9 törlés
  1. 2 0
      package.json
  2. 70 9
      theme-utils.mjs

+ 2 - 0
package.json

@@ -13,6 +13,8 @@
 		"sandbox:watch": "chokidar '**/*' -i '*/node_modules' -i '.git' -c './sandbox.sh push --ignore' --initial",
 		"sandbox:clean:git": "node ./theme-utils.mjs clean-sandbox-git",
 		"sandbox:clean:svn": "node ./theme-utils.mjs clean-sandbox-svn",
+		"sandbox:clean-premium:git": "node ./theme-utils.mjs clean-premium-sandbox-git",
+		"sandbox:clean-premium:svn": "node ./theme-utils.mjs clean-premium-sandbox-svn",
 		"sandbox:clean-all:git": "node ./theme-utils.mjs clean-all-sandbox-git",
 		"sandbox:clean-all:svn": "node ./theme-utils.mjs clean-all-sandbox-svn",
 		"local:clean": "git reset --hard HEAD; git clean -fd",

+ 70 - 9
theme-utils.mjs

@@ -5,9 +5,10 @@ import inquirer from 'inquirer';
 
 const remoteSSH = 'wpcom-sandbox';
 const sandboxPublicThemesFolder = '/home/wpdev/public_html/wp-content/themes/pub';
+const sandboxPremiumThemesFolder = '/home/wpdev/public_html/wp-content/themes/premium';
 const sandboxRootFolder = '/home/wpdev/public_html/';
 const isWin = process.platform === 'win32';
-const directoriesToIgnore = [ 'variations', 'videomaker', 'videomaker-white' ];
+const premiumThemes = [ 'videomaker', 'videomaker-white' ];
 
 (async function start() {
 	let args = process.argv.slice(2);
@@ -17,6 +18,8 @@ const directoriesToIgnore = [ 'variations', 'videomaker', 'videomaker-white' ];
 		case "push-button-deploy-svn": return pushButtonDeploy('svn');
 		case "clean-sandbox-git": return cleanSandboxGit();
 		case "clean-sandbox-svn": return cleanSandboxSvn();
+		case "clean-premium-sandbox-git": return cleanPremiumSandboxGit();
+		case "clean-premium-sandbox-svn": return cleanPremiumSandboxSvn();
 		case "clean-all-sandbox-git": return cleanAllSandboxGit();
 		case "clean-all-sandbox-svn": return cleanAllSandboxSvn();
 		case "push-to-sandbox": return pushToSandbox();
@@ -511,6 +514,25 @@ async function cleanSandboxGit() {
 	console.log('All done cleaning.');
 }
 
+/*
+ Clean the premium theme sandbox.
+ Assumes sandbox is in 'git' mode
+ checkout origin/develop and ensure it's up-to-date.
+ Remove any other changes.
+*/
+async function cleanPremiumSandboxGit() {
+	console.log('Cleaning the Themes Sandbox');
+	await executeOnSandbox(`
+		cd ${sandboxPremiumThemesFolder};
+		git reset --hard HEAD;
+		git clean -fd;
+		git checkout develop;
+		git pull;
+		echo;
+		git status
+	`, true);
+	console.log('All done cleaning.');
+}
 /*
  Clean the entire sandbox.
  Assumes sandbox is in 'git' mode
@@ -548,6 +570,22 @@ async function cleanSandboxSvn() {
 	console.log('All done cleaning.');
 }
 
+/*
+ Clean the premium theme sandbox.
+ Assumes sandbox is in 'svn' mode
+ ensure trunk is up-to-date
+ Remove any other changes
+*/
+async function cleanPremiumSandboxSvn() {
+	console.log('Cleaning the premium theme sandbox');
+	await executeOnSandbox(`
+		cd ${sandboxPremiumThemesFolder};
+  		svn revert -R .;
+  		svn cleanup --remove-unversioned;
+  		svn up;
+	`, true);
+	console.log('All done cleaning.');
+}
 /*
  Clean the entire sandbox.
  Assumes sandbox is in 'svn' mode
@@ -584,14 +622,37 @@ function pushToSandbox() {
    * Deploying the theme
    * Triggering the .zip builds
 */
-function pushPremiumToSandbox() {
-	const premiumThemes = [
-		'videomaker',
-		'videomaker-white'
-	]
-	executeCommand(`
-		rsync -av --no-p --no-times --exclude-from='.sandbox-ignore' --exclude='sass/' ./${premiumThemes.join(' ./')} wpcom-sandbox:${sandboxRootFolder}/wp-content/themes/premium/
+async function pushPremiumToSandbox() {
+
+	//TODO: It would be nice to determine this list programatically
+	const filesToModify = [
+		'style.css',
+		'block-templates/404.html',
+		'block-template-parts/header.html',
+		'block-template-parts/footer.html'
+	];
+
+	// Change 'blockbase' to 'blockbase-premium' in the files noted
+	for ( let theme of premiumThemes ) {
+		for ( let file of filesToModify ) {
+			await executeCommand(`perl -pi -e 's/blockbase/blockbase-premium/' ${theme}/${file}`, true);
+		}
+	}
+
+	// Push the changes in the premium themes to the sandbox
+	await executeCommand(`
+		rsync -avR --no-p --no-times --delete -m --exclude-from='.sandbox-ignore' --exclude='sass' ./${premiumThemes.join(' ./')} wpcom-sandbox:${sandboxPremiumThemesFolder}/
 	`, true);
+
+	// revert the local blockbase-premium changes
+	for ( let theme of premiumThemes ) {
+		for ( let file of filesToModify ) {
+			await executeCommand(`
+				git restore --source=HEAD --staged --worktree ./${theme}/${file}
+			`);
+		}
+	}
+
 }
 
 /*
@@ -603,7 +664,7 @@ async function pushChangesToSandbox() {
 	console.log("Pushing Changes to Sandbox.");
 	let hash = await getLastDeployedHash();
 	let changedThemes = await getChangedThemes(hash);
-	changedThemes = changedThemes.filter( item=> ! directoriesToIgnore.includes( item ) );
+	changedThemes = changedThemes.filter( item=> ! premiumThemes.includes( item ) );
 	console.log(`Syncing ${changedThemes.length} themes`);
 
 	for ( let theme of changedThemes ) {