Pārlūkot izejas kodu

Add theme zips to deploy script (#4924)

* Quadrat: remove title spacers from templates

* Quadrat: add margin to post-title

* Quadrat: increase post title bottom margin

* Quadrat: increase post title margin again

* Quadrat: add GB comment for context

* Quadrat: reduce spacing above featured image

* Quadrat: increase featured image spacing slightly

* Quadrat: add spacing below featured image

* Remove :empty title styling

* Move post title spacing to theme.json

* Tweak featured image spacing

* Remove title spacer from index template

* Remove title spacer from page template

* Reduce post title spacing

* Move post title spacing from theme.json to css

* Add spacer back to index template

* Reduce featured image spacing

* Make it possible to build theme zips from the deploy script

* Add dynamic values for theme version and wp version compat

Only updated Videomaker package so far

* Reset Quadrat files

Not part of this PR

* Get data from style.css instead of package.json

* Remove wpversioncompat from package.json

* Replace Requires at least: with Tested up to:

* Add zip function to deploy process; add extra error message details

* Remove unnecessary try/catch

* Add some brackets

* Add await to buildComZip call

Co-authored-by: Sarah Norris <sarah@sekai.co.uk>
Ben Dwyer 3 gadi atpakaļ
vecāks
revīzija
f6579eacb5
2 mainītis faili ar 42 papildinājumiem un 5 dzēšanām
  1. 2 1
      package.json
  2. 40 4
      theme-utils.mjs

+ 2 - 1
package.json

@@ -23,7 +23,8 @@
 		"deploy:push:changes": "node ./theme-utils.mjs push-changes-to-sandbox",
 		"deploy:push:changes": "node ./theme-utils.mjs push-changes-to-sandbox",
 		"deploy:git": "node ./theme-utils.mjs push-button-deploy-git",
 		"deploy:git": "node ./theme-utils.mjs push-button-deploy-git",
 		"deploy:svn": "node ./theme-utils.mjs push-button-deploy-svn",
 		"deploy:svn": "node ./theme-utils.mjs push-button-deploy-svn",
-		"deploy:preview": "node ./theme-utils.mjs deploy-preview"
+		"deploy:preview": "node ./theme-utils.mjs deploy-preview",
+		"build:zip": "node ./theme-utils.mjs build-com-zip"
 	},
 	},
 	"devDependencies": {
 	"devDependencies": {
 		"@octokit/rest": "^18.11.1",
 		"@octokit/rest": "^18.11.1",

+ 40 - 4
theme-utils.mjs

@@ -25,6 +25,7 @@ const isWin = process.platform === 'win32';
 		case "land-diff-svn": return landChangesSvn(args?.[1]);
 		case "land-diff-svn": return landChangesSvn(args?.[1]);
 		case "deploy-preview": return deployPreview();
 		case "deploy-preview": return deployPreview();
 		case "deploy-theme": return deployThemes([args?.[1]]);
 		case "deploy-theme": return deployThemes([args?.[1]]);
+		case "build-com-zip": return buildComZip([args?.[1]]);
 	}
 	}
 	return showHelp();
 	return showHelp();
 })();
 })();
@@ -161,10 +162,45 @@ async function pushButtonDeploy(repoType) {
 		console.log("ERROR with deply script: ", err);
 		console.log("ERROR with deply script: ", err);
 	}
 	}
 }
 }
+
+/*
+ Build .zip file for .com
+*/
+async function buildComZip(themeSlug) {
+	let response;
+
+	console.log( `Building ${themeSlug} .zip` );
+
+	let themeVersion;
+	let wpVersionCompat;
+	let styleCss = fs.readFileSync(`${themeSlug}/style.css`, 'utf8');
+
+	// Gets the theme version (Version:) and minimum WP version (Tested up to:) from the theme's style.css
+	if (styleCss) {
+		const themeVersionFromCss = styleCss.match(/(?<=Version:\s*).*?(?=\s*\r?\n|\rg)/gs);
+		themeVersion = themeVersionFromCss[0].trim().replace('-wpcom', '');
+		wpVersionCompat = styleCss.match(/(?<=Tested up to:\s*).*?(?=\s*\r?\n|\rg)/gs);
+	}
+
+	if (themeVersion && wpVersionCompat) {
+		await executeOnSandbox(`php ${sandboxRootFolder}bin/themes/theme-downloads/build-theme-zip.php --stylesheet=pub/${themeSlug} --themeversion=${themeVersion} --wpversioncompat=${wpVersionCompat}`, true);
+	} else {
+		console.log('Unable to build theme .zip.');
+		if (!themeVersion) {
+			console.log('Could not find theme version (Version:) in the theme style.css.');
+		}
+		if (!wpVersionCompat) {
+			console.log('Could not find WP compat version (Tested up to:) in the theme style.css.');
+		}
+		console.log('Please build the .zip file for the theme manually.', themeSlug);
+		open('https://mc.a8c.com/themes/downloads/');
+	}
+}
+
 async function buildComZips(themes) {
 async function buildComZips(themes) {
-	//TODO: Figure out how to create these zip files automatically.
-	console.log('Please build the .zip files for the themes manually.', themes);
-	open('https://mc.a8c.com/themes/downloads/');
+	for ( let theme of themes ) {
+		await buildComZip(theme);
+	}
 }
 }
 
 
 /*
 /*
@@ -252,7 +288,7 @@ async function deployThemes( themes ) {
 			if( ! deploySuccess ) {
 			if( ! deploySuccess ) {
 				console.log( 'Deploy was not successful.  Trying again in 10 seconds...' );
 				console.log( 'Deploy was not successful.  Trying again in 10 seconds...' );
 				await new Promise(resolve => setTimeout(resolve, 10000));
 				await new Promise(resolve => setTimeout(resolve, 10000));
-			} 
+			}
 			else {
 			else {
 				console.log( "Deploy successful." );
 				console.log( "Deploy successful." );
 			}
 			}