Skip to content

Commit

Permalink
refactor: Improved Gulp script
Browse files Browse the repository at this point in the history
- upgrade.json is now read from ./upgrade/{win, linux, mac}.json
  • Loading branch information
colin969 committed Dec 29, 2019
1 parent 73b3d9e commit 89dccdd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 101 deletions.
77 changes: 27 additions & 50 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const builder = require('electron-builder');
const { Platform, archFromString } = require('electron-builder');
const { exec } = require('child_process');

const packageJson = JSON.parse(fs.readFileSync('./package.json'));
const config = {
buildVersion: Date.now().toString(),
isRelease: process.env.NODE_ENV === 'production',
isStaticInstall: process.env.STATIC_INSTALL ? true : false,
isStaticInstall: packageJson.config.installed,
static: {
src: './static',
dest: './build',
Expand Down Expand Up @@ -75,11 +76,9 @@ gulp.task('config-version', (done) => {
/* ------ Pack ------ */

gulp.task('pack', (done) => {
if (!fs.existsSync('.installed')) {
fs.createFileSync('.installed');
}
const targets = createBuildTargets(process.env.PACK_PLATFORM, process.env.PACK_ARCH);
const publish = process.env.PUBLISH ? createPublishInfo() : [];
const publish = process.env.PUBLISH ? createPublishInfo() : []; // Uses Git repo for unpublished builds
const copyFiles = getCopyFiles();
console.log(publish);
builder.build({
config: {
Expand All @@ -93,22 +92,8 @@ gulp.task('pack', (done) => {
'./build',
'./static'
],
extraFiles: [
{ // Only copy 7zip execs for packed platform
from: './extern/7zip-bin',
to: './extern/7zip-bin',
filter: ['${os}/**/*']
},
'./lang',
'./licenses',
'.installed',
'upgrade.json',
{
from: './LICENSE',
to: './licenses/LICENSE'
}
],
compression: 'store', // Only used if a compressed target (like 7z, nsis, dmg etc)
extraFiles: copyFiles, // Files to copy to the build folder
compression: 'maximum', // Only used if a compressed target (like 7z, nsis, dmg etc)
target: 'dir', // Keep unpacked versions of every pack
asar: config.isRelease,
publish: publish,
Expand All @@ -120,35 +105,6 @@ gulp.task('pack', (done) => {
}
},
targets: targets
// // "afterCopy" in the docs:
// // "An array of functions to be called after your app directory has been copied to a temporary directory."
// afterCopy: [[
// function(buildPath, electronVersion, platform, arch) {
// // Save file to the temporary folder (that gets moved or packed into the release)
// fs.writeFileSync(path.join(buildPath, 'package.json'), minifyPackage(fs.readFileSync('package.json')));
// // Copy dependencies of the Node processes
// const deps = ['ws', 'async-limiter'];
// for (let dep of deps) {
// const depPath = 'node_modules/'+dep;
// const packagePath = path.join(buildPath, depPath, 'package.json');
// fs.copySync(depPath, path.join(buildPath, depPath));
// fs.writeFileSync(packagePath, minifyPackage(fs.readFileSync(packagePath)));
// }
// /** Copy only some fields (I'm not really sure which are required or serves any purpose - but these have been enough so far) */
// function minifyPackage(package) {
// const p = JSON.parse(package);
// return JSON.stringify({
// name: p.name,
// version: p.version,
// description: p.description,
// main: p.main,
// author: p.author,
// license: p.license,
// dependencies: p.dependencies
// }, undefined, 2);
// }
// },
// ]],
})
.then(() => { console.log('Pack - Done!'); })
.catch((error) => { console.log('Pack - Error!', error); })
Expand Down Expand Up @@ -183,6 +139,27 @@ function createBuildTargets(os, arch) {
}
}

function getCopyFiles() {
return [
{ // Only copy 7zip execs for packed platform
from: './extern/7zip-bin',
to: './extern/7zip-bin',
filter: ['${os}/**/*']
},
'./lang',
'./licenses',
'./.installed',
{
from: './LICENSE',
to: './licenses/LICENSE'
},
{ // Copy the OS specific upgrade file
from: './upgrade/${os}.json',
to: './upgrade.json'
}
];
}

function createPublishInfo() {
return [
{
Expand Down
14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "7.0.0",
"description": "A desktop application used to browse, manage and play games from BlueMaxima's Flashpoint",
"main": "build/main/index.js",
"config": {
"installed": false
},
"scripts": {
"start": "npx electron ./build/main/index.js",
"build": "npx gulp build",
Expand All @@ -19,17 +22,6 @@
"release:win32": "npx cross-env-shell NODE_ENV=production \"npm run build && npm run pack:win32\"",
"release:darwin": "npx cross-env-shell NODE_ENV=production \"npm run build && npm run pack:darwin\"",
"release:all": "npx cross-env-shell NODE_ENV=production \"npm run build && npm run pack:all\"",
"build:static": "npx cross-env STATIC_INSTALL=1 npx gulp build",
"pack:static": "npx cross-env STATIC_INSTALL=1 npx gulp pack",
"pack:linux:static": "npx cross-env STATIC_INSTALL=1 PACK_PLATFORM=linux PACK_ARCH=x64 npx gulp pack",
"pack:win32:static": "npx cross-env STATIC_INSTALL=1 PACK_PLATFORM=win32 PACK_ARCH=ia32 npx gulp pack",
"pack:darwin:static": "npx cross-env STATIC_INSTALL=1 PACK_PLATFORM=darwin PACK_ARCH=x64 npx gulp pack",
"pack:all:static": "npx cross-env STATIC_INSTALL=1 PACK_PLATFORM=all PACK_ARCH=all npx gulp pack",
"release:static": "npx cross-env-shell STATIC_INSTALL=1 NODE_ENV=production \"npm run build && npm run pack\"",
"release:linux:static": "npx cross-env-shell STATIC_INSTALL=1 NODE_ENV=production \"npm run build && npm run pack:linux\"",
"release:win32:static": "npx cross-env-shell STATIC_INSTALL=1 NODE_ENV=production \"npm run build && npm run pack:win32\"",
"release:darwin:static": "npx cross-env-shell STATIC_INSTALL=1 NODE_ENV=production \"npm run build && npm run pack:darwin\"",
"release:all:static": "npx cross-env-shell STATIC_INSTALL=1 NODE_ENV=production \"npm run build && npm run pack:all\"",
"publish": "npx cross-env-shell NODE_ENV=production PUBLISH=true \"npm run build && npm run pack\"",
"publish:linux": "npx cross-env-shell NODE_ENV=production PUBLISH=true \"npm run build && npm run pack:linux\"",
"publish:win32": "npx cross-env-shell NODE_ENV=production PUBLISH=true \"npm run build && npm run pack:win32\"",
Expand Down
40 changes: 0 additions & 40 deletions upgrade/FPL-Updater.bat

This file was deleted.

12 changes: 12 additions & 0 deletions upgrade/win.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"infinity": {
"title": "infinity",
"description": "infinityDesc",
"verify_files": [ "readme.txt" ],
"verify_sha256": [ "9DCB49CAC9FF515881158534BFEFFC1EA1B5DFA35B1FFEDEDFFAFF885DEAE33A" ],
"deletePaths": [ "Data\\Platforms\\", "Data\\Images\\", "FPSoftware\\BrowserPlugins\\", "FPSoftware\\Basilisk-Portable\\Bin\\" ],
"keepPaths": [ "Data\\Playlists\\favorites.json" ],
"sources": [ "https://download.unstable.life/upgrades/FP70-Infinity.7z" ],
"sources_sha256": "31DFFDB248D5292598131B4F547C8ECA0A921F24765E4AB0FA86BE99BBEC84A9"
}
}

0 comments on commit 89dccdd

Please sign in to comment.