Skip to content

Commit

Permalink
Add release task that would commit (for bower) a checked javascript a…
Browse files Browse the repository at this point in the history
…s main file
  • Loading branch information
martinpaljak committed Mar 25, 2015
1 parent 6ea0b60 commit f66b64f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/node_modules
/gh-pages
/dist
/build
42 changes: 33 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@ module.exports = function(grunt) {
options: {
banner: '/*! This is hwcrypto.js <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
},
build: {
src: 'hwcrypto.js',
minify: {
src: 'build/hwcrypto.js',
dest: 'dist/<%= pkg.name %>.min.js'
},
dist: {
beautify: {
options: {
beautify: true,
mangle: false,
compress: false
},
src: 'hwcrypto.js',
src: 'build/hwcrypto.js',
dest: 'dist/hwcrypto.js'
},
release: {
options: {
beautify: true,
mangle: false,
compress: false
},
src: 'build/hwcrypto.js',
dest: 'hwcrypto.js'
}
},
jshint: {
app: {
src: ['hwcrypto.js', 'test/*.js'],
src: {
src: ['src/hwcrypto.js', 'test/*.js'],
},
release: {
src: ['hwcrypto.js']
}
},
includereplace: {
build: {
options: {
globals: {
hwcryptoversion: '<%= pkg.version %>'
}
},
files: [
{src: 'hwcrypto.js', dest: 'build/', expand: true, cwd: 'src'}
]
},
dist: {
options: {
prefix: '<!-- @@',
Expand Down Expand Up @@ -63,7 +85,7 @@ module.exports = function(grunt) {
css_dest: 'dist/css'
}
},
clean: ['dist']
clean: ['build', 'dist']
});
// Minification
grunt.loadNpmTasks('grunt-contrib-uglify');
Expand All @@ -83,6 +105,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');

// Default task(s).
grunt.registerTask('build', ['jshint', 'clean', 'bower', 'includereplace', 'uglify']);
grunt.registerTask('default', ['build', 'mocha']);
grunt.registerTask('build', ['clean', 'jshint:src', 'includereplace', 'uglify:minify', 'uglify:beautify']);
grunt.registerTask('dist', ['build', 'bower']);
grunt.registerTask('default', ['dist', 'mocha']);
grunt.registerTask('release', ['sync', 'build', 'includereplace:build', 'uglify:release', 'jshint:release'])
};
23 changes: 10 additions & 13 deletions hwcrypto.js → src/hwcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ var hwcrypto = (function hwcrypto() {
probe();
});
// Backend for DigiDoc plugin
function digidoc_plugin() {
/* jshint validthis: true */
function DigiDocPlugin() {
this._name = "NPAPI/BHO for application/x-digidoc";
var p = loadPluginFor(digidoc_mime);
// keeps track of detected certificates and their ID-s
Expand Down Expand Up @@ -167,8 +166,7 @@ var hwcrypto = (function hwcrypto() {
};
}
// Backend for Digidoc Chrome Extension
function digidoc_ext() {
/* jshint validthis: true */
function DigiDocExtension() {
this._name = "Chrome native messaging extension";
var p = null;
this.check = function() {
Expand All @@ -193,8 +191,7 @@ var hwcrypto = (function hwcrypto() {
}

// Dummy
function no_backend() {
/* jshint validthis: true */
function NoBackend() {
this._name = "No implementation";
this.check = function() {
return true;
Expand Down Expand Up @@ -231,26 +228,26 @@ var hwcrypto = (function hwcrypto() {
// MSIE
if(navigator.userAgent.indexOf('MSIE') != -1 || navigator.userAgent.indexOf('Trident') != -1) {
console.log("Assuming IE BHO, testing");
if (_testAndUse(digidoc_plugin)) return true;
if (_testAndUse(DigiDocPlugin)) return true;
}
// First try Chrome extensions
if(navigator.userAgent.indexOf('Chrome') != -1 && hasExtensionFor(digidoc_chrome)) {
if(_testAndUse(digidoc_ext)) return true;
if(_testAndUse(DigiDocExtension)) return true;
}
if(hasPluginFor(digidoc_mime)) {
if(_testAndUse(digidoc_plugin)) return true;
if(_testAndUse(DigiDocPlugin)) return true;
}
return _testAndUse(no_backend);
return _testAndUse(NoBackend);
}
// Use a specific backend or autodetect
fields.use = function(backend) {
if(typeof backend === undefined || backend === 'auto') {
return _autodetect();
} else {
if(backend === "chrome") {
return _testAndUse(digidoc_ext);
return _testAndUse(DigiDocExtension);
} else if(backend === "npapi") {
return _testAndUse(digidoc_plugin);
return _testAndUse(DigiDocPlugin);
} else {
return false; // unknown backend
}
Expand All @@ -259,7 +256,7 @@ var hwcrypto = (function hwcrypto() {
// Give debugging information.
fields.debug = function() {
return new Promise(function(resolve, reject) {
var hwversion = "hwcrypto.js v0.1.0";
var hwversion = "hwcrypto.js @@hwcryptoversion";
if(!_backend) _autodetect();
_backend.getVersion().then(function(version) {
resolve(hwversion + " with " + _backend._name + " " + version);
Expand Down

0 comments on commit f66b64f

Please sign in to comment.