Last active
August 29, 2015 14:16
-
-
Save YurySolovyov/d56ba1128a8f83a0c70f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
var path = require('path'); | |
var Promise = require('bluebird'); | |
var asar = Promise.promisifyAll(require('asar')); | |
var globAsync = Promise.promisify(require('glob')); | |
var stylus = Promise.promisifyAll(require('stylus')); | |
var fs = Promise.promisifyAll(require('fs-extra')); | |
var readFiles = function(files) { | |
return Promise.map(files, function(file) { | |
return Promise.props({ | |
path: path.basename(file), | |
content: fs.readFileAsync(file, 'utf8') | |
}); | |
}); | |
}; | |
var writeFiles = function(files, outputDir) { | |
return Promise.map(files, function(file) { | |
var filePath = path.join(outputDir, file.path); | |
return fs.outputFileAsync(filePath, file.content); | |
}).all(); | |
}; | |
var complieStyles = function() { | |
var outputDir = 'out/resources/app/frontend/static/styles'; | |
return globAsync('static/styles/*.styl').then(function(files) { | |
return readFiles(files); | |
}).then(function(files) { | |
return Promise.map(files, function(file) { | |
var fileName = file.path.replace(/\.styl/, '.css'); | |
return Promise.props({ | |
path: fileName, | |
content: stylus.renderAsync(file.content, { | |
filename: fileName, | |
lineNumbers: true | |
}) | |
}); | |
}); | |
}).then(function(files) { | |
return writeFiles(files, outputDir); | |
}); | |
}; | |
var copyStatic = function() { | |
var from = [ | |
'src/frontend', | |
'src/backend', | |
'src/package.json', | |
'src/index.html', | |
'static/js', | |
'static/img', | |
'static/fonts', | |
]; | |
var to = [ | |
'out/resources/app/frontend', | |
'out/resources/app/backend', | |
'out/resources/app/package.json', | |
'out/resources/app/index.html', | |
'out/resources/app/frontend/static/js', | |
'out/resources/app/frontend/static/img', | |
'out/resources/app/frontend/static/fonts', | |
]; | |
return Promise.each(from, function(fromItem, index) { | |
return fs.copyAsync(fromItem, to[index]); | |
}).all(); | |
}; | |
var createAsar = function() { | |
return asar.createPackageAsync('out/resources/app', 'runtime/resources/app.asar'); | |
}; | |
var cleanOutDirectory = function() { | |
return fs.removeAsync('out'); | |
}; | |
var cleanAsar = function() { | |
return fs.removeAsync('runtime/resources/app.asar'); | |
}; | |
var cleanUp = function() { | |
return Promise.join(cleanOutDirectory(), cleanAsar()); | |
}; | |
cleanUp().then(function() { | |
console.log('cleaned up'); | |
return complieStyles(); | |
}).then(function() { | |
console.log('styles ready'); | |
return copyStatic(); | |
}).then(function() { | |
console.log('static ready'); | |
return createAsar(); | |
}).then(function() { | |
console.log('asar ready'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment