Skip to content

Commit

Permalink
convert to task
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmer Bulthuis committed Mar 23, 2015
1 parent 2ff1294 commit fa459af
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 207 deletions.
14 changes: 14 additions & 0 deletions task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* jshint node: true */

var nopt = require('nopt');
var Q = require('q');

var tasks = nopt({}, {}, process.argv).argv.remain;

Q.longStackSupport = true;

Q.all(
tasks.map(function(task) {
return require('./tasks/' + task + '.task');
})
).done();
129 changes: 63 additions & 66 deletions tasks/debug.task.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,71 @@ var vars = require('./vars');
var io = require('./io');
var when_jsdom = when_node.lift(jsdom.env);

module.exports.task = function() {

var app = express();

app.get('/', function (req, res, next) {

when([
io.find(config.scripts),
io.find(config.styles),
io.readText([vars.srcRoot, 'public', 'main.html']).then(when_jsdom)
]).spread(function(scripts, styles, window){

var document = window.document;
var element;

//document.documentElement.setAttribute('ng-app', config.globals.appModule);

element = document.createElement('script');
element.innerHTML = 'window.globals=' + JSON.stringify(config.globals);
document.head.appendChild(element);

styles.forEach(function (style) {
element = document.createElement('link');
if (style.substr(-5, 5).toLowerCase() === '.less') {
element.setAttribute('rel', 'stylesheet/less');
} else {
element.setAttribute('rel', 'stylesheet');
}
element.setAttribute('type', 'text/css');
element.setAttribute('href', style);
document.head.appendChild(element);
});

element = document.createElement('script');
element.innerHTML = 'window.less=' + JSON.stringify({
errorReporting: 'console',
logLevel: 0
});
var app = express();

app.get('/', function(req, res, next) {

when([
io.find(config.scripts),
io.find(config.styles),
io.readText([vars.srcRoot, 'public', 'main.html']).then(when_jsdom)
]).spread(function(scripts, styles, window) {

var document = window.document;
var element;

//document.documentElement.setAttribute('ng-app', config.globals.appModule);

element = document.createElement('script');
element.innerHTML = 'window.globals=' + JSON.stringify(config.globals);
document.head.appendChild(element);

styles.forEach(function(style) {
element = document.createElement('link');
if (style.substr(-5, 5).toLowerCase() === '.less') {
element.setAttribute('rel', 'stylesheet/less');
}
else {
element.setAttribute('rel', 'stylesheet');
}
element.setAttribute('type', 'text/css');
element.setAttribute('href', style);
document.head.appendChild(element);

});

element = document.createElement('script');
element.innerHTML = 'window.less=' + JSON.stringify({
errorReporting: 'console',
logLevel: 0
});
document.head.appendChild(element);

element = document.createElement('script');
element.setAttribute("src", "bower_components/less/dist/less.js");
document.head.appendChild(element);

scripts.forEach(function(script) {
element = document.createElement('script');
element.setAttribute("src", "bower_components/less/dist/less.js");
element.setAttribute('src', script);
document.head.appendChild(element);

scripts.forEach(function (script) {
element = document.createElement('script');
element.setAttribute('src', script);
document.head.appendChild(element);
});

return jsdom.serializeDocument(document);
}).done(function (content) {
res.set('Content-Type', 'text/html');
res.send(content);
}, next);
});

app.use('/public', express.static(vars.srcRoot + '/public'));
app.use('/bower_components', express.static(vars.srcRoot + '/bower_components'));

return when.promise(function(resolve, reject){
var server = app.listen(args.port, function () {
var host = server.address().address;
var port = server.address().port;

console.log('Debug server listening at http://%s:%s', host, port);
resolve(server);
});
});

};
return jsdom.serializeDocument(document);
}).done(function(content) {
res.set('Content-Type', 'text/html');
res.send(content);
}, next);
});

app.use('/public', express.static(vars.srcRoot + '/public'));
app.use('/bower_components', express.static(vars.srcRoot + '/bower_components'));

module.exports = when.promise(function(resolve, reject) {
var server = app.listen(args.port, function() {
var host = server.address().address;
var port = server.address().port;

console.log('Debug server listening at http://%s:%s', host, port);
resolve(server);
});
});
99 changes: 49 additions & 50 deletions tasks/deploy.task.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,142 +19,141 @@ var when_listObjects = when_node.lift(s3bucket.listObjects.bind(s3bucket));
var when_deleteObjects = when_node.lift(s3bucket.deleteObjects.bind(s3bucket));
var when_putObject = when_node.lift(s3bucket.putObject.bind(s3bucket));

module.exports = require('./dist.task').then(function(dist) {

module.exports.task = function(dist) {
return when_listObjects().then(function (objects) {
return when_listObjects().then(function(objects) {
if (objects.Contents.length === 0) return;

return when_deleteObjects({
Delete: {
Quiet: true,
Objects: objects.Contents.map(function (content) {
Objects: objects.Contents.map(function(content) {
return {
Key: content.Key
};
})
}
});
}).then(function () {
}).then(function() {
return io.find('**/*.jpg', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'image/jpeg')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.png', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'image/png')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.gif', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'image/gif')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.ico', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'image/x-icon')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.woff', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'application/font-woff')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.ttf', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadBinary.bind(null, 'application/octet-stream')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.svg', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'image/svg+xml')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.html', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'text/html')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.css', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'text/css')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.js', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'text/javascript')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.map', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'application/json')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.txt', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'text/plain')));
});
}).then(function () {

}).then(function() {
return io.find('**/*.appcache', {
cwd: vars.dstRoot
}).then(function (files) {
}).then(function(files) {
return when.all(files.map(uploadText.bind(null, 'text/cache-manifest')));
});

});


};
});

function uploadText(type, file) {
return io.readText([vars.dstRoot, file]).then(function (content) {
return io.readText([vars.dstRoot, file]).then(function(content) {
return new Buffer(content, 'utf8');
}).then(when_gzip).then(function (content) {
}).then(when_gzip).then(function(content) {
return when_putObject({
Key: file,
ContentType: '' + type + '; charset=utf-8',
ContentEncoding: 'gzip',
Body: content
});
}).then(function () {
}).then(function() {
console.log(' ^ ' + file);
return file;
});

}

function uploadBinary(type, file) {
return io.readBinary([vars.dstRoot, file]).then(function (content) {
return io.readBinary([vars.dstRoot, file]).then(function(content) {
return when_putObject({
Key: file,
ContentType: '' + type + '',
Body: content
});
}).then(function () {
}).then(function() {
console.log(' ^ ' + file);
return file;
});
Expand Down
10 changes: 8 additions & 2 deletions tasks/dist.task.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/* jshint node: true */

module.exports.task = function(script, style, html, robots) {
};
var Q = require('q');

module.exports = Q.all([
require('./script.task'),
require('./style.task'),
require('./html.task'),
require('./robots.task'),
]);
Loading

0 comments on commit fa459af

Please sign in to comment.