Created
January 12, 2017 23:10
-
-
Save TheJaredWilcurt/0f1379953c4f0c068f1933aa8ee6a1e0 to your computer and use it in GitHub Desktop.
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
// Building Scout-App for Windows | |
// Prerequisites: Must have Node, NPM, and Bower installed globally. | |
// Variables and Functions | |
var start = Date.now() + ''; | |
var fs = require('fs-extra'); | |
var execSync = require('child_process').execSync; | |
var build = '../scout-app-build/win32/Scout-App/'; | |
var bowerJSON = fs.readJsonSync('bower.json'); | |
var manifest = fs.readJsonSync('package.json'); | |
delete manifest.devDependencies; | |
function timer (finish, begin) { | |
var subtract = finish - begin; | |
var round = Math.round(subtract / 10); | |
var seconds = round / 100; | |
var splitSeconds = seconds.toString().split('.'); | |
if (splitSeconds[0].length < 2) { | |
splitSeconds[0] = ' ' + splitSeconds[0]; | |
} | |
if (splitSeconds.length == 1 || splitSeconds[1].length < 1) { | |
splitSeconds[1] = '00'; | |
} else if (splitSeconds[1].length == 1) { | |
splitSeconds[1] = splitSeconds[1] + '0'; | |
} | |
if (splitSeconds[0].length == 3) { | |
splitSeconds[1] = splitSeconds[1][0]; | |
} | |
var time = splitSeconds.join('.') + ' seconds'; | |
return time; | |
} | |
// Clean build folder | |
fs.removeSync(build + 'License'); | |
fs.removeSync(build + 'bower_components'); | |
fs.removeSync(build + 'node_modules'); | |
fs.removeSync(build + 'scout-files/'); | |
fs.mkdirsSync(build + 'scout-files/'); | |
var timeClean = Date.now() + ''; | |
console.log('Cleaning build folder - ' + timer(timeClean, start)); | |
// Copy files over | |
fs.writeJsonSync(build + 'package.json', manifest); | |
fs.writeJsonSync(build + 'bower.json', bowerJSON); | |
fs.copySync('scout-files/index.html', build + 'scout-files/index.html'); | |
var timeFiles = Date.now() + ''; | |
console.log('Copying files - ' + timer(timeFiles, timeClean)); | |
// Copy folders over | |
fs.copySync('License', build + 'License'); | |
fs.copySync('scout-files/_img', build + 'scout-files/_img'); | |
fs.copySync('scout-files/_scripts', build + 'scout-files/_scripts'); | |
fs.copySync('scout-files/_style', build + 'scout-files/_style'); | |
fs.copySync('scout-files/cultures', build + 'scout-files/cultures'); | |
fs.removeSync(build + 'scout-files/cultures/README.md'); | |
var timeFolder = Date.now() + ''; | |
console.log('Copying folders - ' + timer(timeFolder, timeFiles)); | |
// Run executables | |
process.chdir(build); | |
execSync('npm --loglevel=error install'); | |
if (fs.existsSync('bower_components/sass-css3-mixins/css3-mixins.sass')) { | |
fs.removeSync('bower_components/sass-css3-mixins/css3-mixins.scss'); | |
} | |
process.chdir('../../../scout-app'); | |
var timeExec = Date.now() + ''; | |
console.log('NPM & Bower Installs - ' + timer(timeExec, timeFolder)); | |
// Node-Sass Vendor Bindings | |
fs.removeSync(build + 'node_modules/node-sass/vendor'); | |
fs.copySync('scout-files/_assets/node-sass_v3.8.0/wind32-x64-43', build + 'node_modules/node-sass/vendor/wind32-x64-43'); | |
var timeNS = Date.now() + ''; | |
console.log('Node-Sass bindings - ' + timer(timeNS, timeExec)); | |
// Zip package | |
var zipExe = 'node_modules/7zip-bin-win/' + process.arch + '/7za.exe'; | |
var buildInput = '../scout-app-build/win32/Scout-App'; | |
var outputZip = '../scout-app-build/WIN_Scout-App_' + manifest.version + '.zip'; | |
fs.removeSync(outputZip); | |
execSync(zipExe + ' a -bd -tzip -mx=9 -y ' + outputZip + ' ' + buildInput); | |
var timeZip = Date.now() + ''; | |
console.log('Zipped Package - ' + timer(timeZip, timeNS)); | |
// Total Time | |
var end = Date.now() + ''; | |
console.log('-------------------------------------'); | |
console.log('Total Build Time - ' + timer(end, start) | |
// Run the app | |
if (fs.existsSync(build + 'Scout-App.exe')) { | |
execSync(build + 'Scout-App.exe'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment