Last active
November 26, 2022 08:57
-
-
Save n-at/cc2a401a221a475966c3 to your computer and use it in GitHub Desktop.
nw.js project build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nw.js project building script | |
//////////////////////////////////////////////////////////////////////////////////// | |
var BUILD_DIR = './build'; | |
var BUILD_CACHE_DIR = './build_cache'; | |
var PLATFORMS = ['osx64', 'win32', 'linux32', 'linux64']; | |
var NW_VERSION = 'latest'; | |
var BUILD_TYPE = 'versioned'; | |
//////////////////////////////////////////////////////////////////////////////////// | |
var path = require('path'); | |
var everythingFilePrefix = '/**/**'; | |
/** | |
* Creates list of development dependencies to exclude from build | |
*/ | |
function devDependencies() { | |
var project_package = require('./package.json'); | |
if(!project_package['devDependencies']) return []; | |
var dependencies = []; | |
var project_dependencies = project_package['devDependencies']; | |
for(var dependency in project_dependencies) { | |
if(project_dependencies.hasOwnProperty(dependency)) { | |
dependencies.push('!./node_modules/' + dependency + everythingFilePrefix); | |
} | |
} | |
return dependencies; | |
} | |
/** | |
* Created list of files to include to or exclude from build | |
*/ | |
function listBuildFiles() { | |
return [ | |
'.' + everythingFilePrefix, | |
'!./' + path.basename(__filename), | |
'!' + BUILD_DIR + everythingFilePrefix, | |
'!' + BUILD_CACHE_DIR + everythingFilePrefix | |
].concat(devDependencies()); | |
} | |
//////////////////////////////////////////////////////////////////////////////////// | |
var NwBuilder = require('node-webkit-builder'); | |
var nw = new NwBuilder({ | |
files: listBuildFiles(), | |
platforms: PLATFORMS, | |
version: NW_VERSION, | |
buildType: BUILD_TYPE, | |
buildDir: BUILD_DIR, | |
cacheDir: BUILD_CACHE_DIR | |
}); | |
nw.on('log', console.log); | |
nw.build().then(function () { | |
console.log('build complete'); | |
}).catch(function (error) { | |
console.log('En error occurred while building the project:'); | |
console.error(error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment