| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  | const path = require("path"); | 
					
						
							|  |  |  | const fs = require("fs"); | 
					
						
							|  |  |  | const buildUtils = require("./buildutils"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  | function gulptasksCordova($, gulp, buildFolder) { | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |     const cdvRes = path.join("..", "..", "res"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Cleans up the app assets
 | 
					
						
							|  |  |  |     // Removes all temporary folders used while optimizing the assets
 | 
					
						
							|  |  |  |     gulp.task("cleanupAppAssetsBuiltFolder", () => { | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |         return gulp | 
					
						
							|  |  |  |             .src(path.join(cdvRes, "built"), { read: false, allowEmpty: true }) | 
					
						
							|  |  |  |             .pipe($.clean({ force: true })); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Optimizes all built assets
 | 
					
						
							|  |  |  |     gulp.task("optimizeBuiltAppAssets", () => { | 
					
						
							|  |  |  |         return gulp | 
					
						
							|  |  |  |             .src(path.join(cdvRes, "built", "**", "*.png")) | 
					
						
							|  |  |  |             .pipe($.flatten()) | 
					
						
							|  |  |  |             .pipe($.imagemin([$.imagemin.optipng({ optimizationLevel: 1 })])) | 
					
						
							|  |  |  |             .pipe(gulp.dest(path.join(cdvRes, "built"))); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Scales the icon resources
 | 
					
						
							|  |  |  |     gulp.task("scaleIconIos", async () => { | 
					
						
							|  |  |  |         const sizes = [ | 
					
						
							|  |  |  |             180, | 
					
						
							|  |  |  |             60, | 
					
						
							|  |  |  |             120, | 
					
						
							|  |  |  |             76, | 
					
						
							|  |  |  |             152, | 
					
						
							|  |  |  |             40, | 
					
						
							|  |  |  |             80, | 
					
						
							|  |  |  |             57, | 
					
						
							|  |  |  |             114, | 
					
						
							|  |  |  |             72, | 
					
						
							|  |  |  |             144, | 
					
						
							|  |  |  |             167, | 
					
						
							|  |  |  |             29, | 
					
						
							|  |  |  |             58, | 
					
						
							|  |  |  |             87, | 
					
						
							|  |  |  |             50, | 
					
						
							|  |  |  |             100, | 
					
						
							|  |  |  |             167, | 
					
						
							|  |  |  |             20, | 
					
						
							|  |  |  |             1024, | 
					
						
							|  |  |  |             24, | 
					
						
							|  |  |  |             48, | 
					
						
							|  |  |  |             55, | 
					
						
							|  |  |  |             172, | 
					
						
							|  |  |  |             196, | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         for (let i = 0; i < sizes.length; ++i) { | 
					
						
							|  |  |  |             const size = sizes[i]; | 
					
						
							|  |  |  |             console.log("Scaling icon to", size, "x", size); | 
					
						
							|  |  |  |             const img = await $.jimp.read(path.join(cdvRes, "ios", "icon-prefab.png")); | 
					
						
							|  |  |  |             await img.resize(size, size).write(path.join(cdvRes, "built", "ios", "icon@" + size + ".png")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gulp.task("copyOtherIosResources", () => { | 
					
						
							|  |  |  |         return gulp | 
					
						
							|  |  |  |             .src(path.join(cdvRes, "ios", "splash-prefab.png")) | 
					
						
							|  |  |  |             .pipe($.rename("Default@2x~universal~anyany.png")) | 
					
						
							|  |  |  |             .pipe(gulp.dest(path.join(cdvRes, "built", "ios"))); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |     gulp.task("prepareIosRes", gulp.series("scaleIconIos", "copyOtherIosResources")); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     gulp.task("copyAndroidResources", () => { | 
					
						
							|  |  |  |         return gulp | 
					
						
							|  |  |  |             .src(path.join(cdvRes, "android", "**", "*.*")) | 
					
						
							|  |  |  |             .pipe(gulp.dest(path.join(cdvRes, "built", "android"))); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |     gulp.task("prepareAndroidRes", gulp.series("copyAndroidResources")); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |     gulp.task( | 
					
						
							|  |  |  |         "prepareCordovaAssets", | 
					
						
							|  |  |  |         gulp.series( | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |             "cleanupAppAssetsBuiltFolder", | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |             gulp.parallel("prepareIosRes", "prepareAndroidRes"), | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |             "optimizeBuiltAppAssets" | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |         ) | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Patches the config.xml by replacing the app id to app_beta
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |     gulp.task("patchConfigXML", cb => { | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |         const configUrl = path.join("..", "..", "config.xml"); | 
					
						
							|  |  |  |         let configContent = fs.readFileSync(configUrl).toString(); | 
					
						
							|  |  |  |         const version = buildUtils.getVersion(); | 
					
						
							|  |  |  |         configContent = configContent.replace("%VERSION%", version); | 
					
						
							|  |  |  |         configContent = configContent.replace(' id="io.shapez.app" ', ' id="io.shapez.app_beta" '); | 
					
						
							|  |  |  |         configContent = configContent.replace("<name>Shapez.io</name>", "<name>Shapez.io BETA</name>"); | 
					
						
							|  |  |  |         fs.writeFileSync(configUrl, configContent); | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |         cb(); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |     gulp.task("patchConfigXMLChangeStagingToProd", cb => { | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |         const configUrl = path.join("..", "..", "config.xml"); | 
					
						
							|  |  |  |         let configContent = fs.readFileSync(configUrl).toString(); | 
					
						
							|  |  |  |         configContent = configContent.replace(' id="io.shapez.app_beta" ', ' id="io.shapez.app" '); | 
					
						
							|  |  |  |         configContent = configContent.replace("<name>Shapez.io BETA</name>", "<name>Shapez.io</name>"); | 
					
						
							|  |  |  |         fs.writeFileSync(configUrl, configContent); | 
					
						
							| 
									
										
										
										
											2020-06-13 15:59:25 +00:00
										 |  |  |         cb(); | 
					
						
							| 
									
										
										
										
											2020-05-09 14:45:23 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Triggers a new build on phonegap
 | 
					
						
							|  |  |  |     gulp.task("triggerPhonegapBuild", () => { | 
					
						
							|  |  |  |         return gulp | 
					
						
							|  |  |  |             .src("src/html/", { dot: false }) | 
					
						
							|  |  |  |             .pipe( | 
					
						
							|  |  |  |                 $.phonegapBuild({ | 
					
						
							|  |  |  |                     isRepository: true, | 
					
						
							|  |  |  |                     appId: "3339820", | 
					
						
							|  |  |  |                     platforms: ["android", "ios"], | 
					
						
							|  |  |  |                     user: { | 
					
						
							|  |  |  |                         token: process.env.SHAPEZ_CLI_PHONEGAP_KEY, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |             .pipe( | 
					
						
							|  |  |  |                 $.phonegapBuild({ | 
					
						
							|  |  |  |                     isRepository: true, | 
					
						
							|  |  |  |                     appId: "3537816", | 
					
						
							|  |  |  |                     platforms: ["android", "ios"], | 
					
						
							|  |  |  |                     user: { | 
					
						
							|  |  |  |                         token: process.env.SHAPEZ_CLI_PHONEGAP_KEY, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // gulp.task("pushToStagingRepo", (cb) => {
 | 
					
						
							|  |  |  |     //     var cmd = spawn('../push-pgb.sh', ['https://TOKEN@github.com/tobspr/shapezapp-cordova-buildslave.git'],
 | 
					
						
							|  |  |  |     //         { stdio: 'inherit', stdout: 'inherit', stderr: 'inherit', shell: true });
 | 
					
						
							|  |  |  |     //     cmd.on('close', function (code) {
 | 
					
						
							|  |  |  |     //         console.log('push staging exited with code ' + code + " / " + cmd.stdout + " / " + cmd.stderr);
 | 
					
						
							|  |  |  |     //         cb(code);
 | 
					
						
							|  |  |  |     //     });
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // });
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // gulp.task("pushToProdRepo", (cb) => {
 | 
					
						
							|  |  |  |     //     var cmd = spawn('../push-pgb.sh', ['https://TOKEN@github.com/tobspr/shapezapp-cordova-buildslave-release.git'],
 | 
					
						
							|  |  |  |     //         { stdio: 'inherit', stdout: 'inherit', stderr: 'inherit', shell: true });
 | 
					
						
							|  |  |  |     //     cmd.on('close', function (code) {
 | 
					
						
							|  |  |  |     //         console.log('push prod exited with code ' + code + " / " + cmd.stdout + " / " + cmd.stderr);
 | 
					
						
							|  |  |  |     //         cb(code);
 | 
					
						
							|  |  |  |     //     });
 | 
					
						
							|  |  |  |     // });
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |     gulptasksCordova, | 
					
						
							|  |  |  | }; |