Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Removed grunt helpers
Browse files Browse the repository at this point in the history
refs #5
  • Loading branch information
oncletom committed Nov 14, 2012
1 parent 7928d85 commit 12dde1e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 51 deletions.
22 changes: 22 additions & 0 deletions lib/crx-manifest.js
@@ -0,0 +1,22 @@
"use strict";

var path = require('path');

exports.init = function(grunt){
var exports = {};

exports.build = function build(ChromeExtension, callback) {
if (!ChromeExtension.manifest.update_url || !ChromeExtension.codebase){
return callback();
}

ChromeExtension.generateUpdateXML();
var dest = path.dirname(ChromeExtension.dest);

grunt.file.write(path.join(dest, path.basename(ChromeExtension.manifest.update_url)), ChromeExtension.updateXML);

callback();
};

return exports;
};
40 changes: 40 additions & 0 deletions lib/crx.js
@@ -0,0 +1,40 @@
"use strict";

var exec = require('child_process').exec;
var path = require('path');

exports.init = function(grunt){
var exports = {};

exports.build = function build(ChromeExtension, callback) {
grunt.utils.async.series([
function(done){
ChromeExtension.load(done);
},
function(done){
if (!Array.isArray(ChromeExtension.exclude) || !ChromeExtension.exclude.length){
return done();
}

var files = grunt.file.expand(ChromeExtension.exclude.map(function(pattern){
return path.join(ChromeExtension.path, '/', pattern);
}));

exec('rm -rf '+ files.join(' '), done);
},
function(done){
ChromeExtension.pack(function(err, data){
if (err){
throw new grunt.task.taskError(err);
}

grunt.file.write(this.dest, data);

done();
});
}
], callback);
};

return exports;
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-crx",
"description": "Package your Chrome Extensions in a bliss.",
"version": "0.1.1",
"version": "0.1.2",
"homepage": "https://github.com/oncletom/grunt-crx",
"author": {
"name": "oncletom",
Expand Down
55 changes: 5 additions & 50 deletions tasks/crx.js
Expand Up @@ -9,7 +9,6 @@
var ChromeExtension = require('crx');
var path = require('path');
var fs = require('fs');
var exec = require('child_process').exec;

/**
* Expand the current multitask config key name
Expand Down Expand Up @@ -66,6 +65,9 @@ function configure(defaults){

module.exports = function(grunt) {

var crx = require('./../lib/crx').init(grunt);
var crxManifest = require('./../lib/crx-manifest').init(grunt);

// ==========================================================================
// TASKS
// ==========================================================================
Expand Down Expand Up @@ -101,11 +103,11 @@ module.exports = function(grunt) {
grunt.utils.async.series([
// Building extension
function(callback){
grunt.helper('crx', extension, callback);
crx.build(extension, callback);
},
// Building manifest
function(callback){
grunt.helper('crx-manifest', extension, callback);
crxManifest.build(extension, callback);
},
// Clearing stuff
function(callback){
Expand All @@ -115,51 +117,4 @@ module.exports = function(grunt) {
}
], /* Baking done! */ done);
});

// ==========================================================================
// HELPERS
// ==========================================================================

grunt.registerHelper('crx', function(ChromeExtension, callback) {
grunt.utils.async.series([
function(done){
ChromeExtension.load(done);
},
function(done){
if (!Array.isArray(ChromeExtension.exclude) || !ChromeExtension.exclude.length){
return done();
}

var files = grunt.file.expand(ChromeExtension.exclude.map(function(pattern){
return path.join(ChromeExtension.path, '/', pattern);
}));

exec('rm -rf '+ files.join(' '), done);
},
function(done){
ChromeExtension.pack(function(err, data){
if (err){
throw new grunt.task.taskError(err);
}

grunt.file.write(this.dest, data);

done();
});
}
], callback);
});

grunt.registerHelper('crx-manifest', function(ChromeExtension, callback) {
if (!ChromeExtension.manifest.update_url || !ChromeExtension.codebase){
return callback();
}

ChromeExtension.generateUpdateXML();
var dest = path.dirname(ChromeExtension.dest);

grunt.file.write(path.join(dest, path.basename(ChromeExtension.manifest.update_url)), ChromeExtension.updateXML);

callback();
});
};

0 comments on commit 12dde1e

Please sign in to comment.