Skip to content

Commit

Permalink
Annotate JS for minification
Browse files Browse the repository at this point in the history
  • Loading branch information
Hector Virgen committed Oct 21, 2014
1 parent 00731cd commit 86dd866
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bower_components
node_modules
coverage
tmp
19 changes: 17 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-karma-coveralls');
grunt.loadNpmTasks('grunt-ng-annotate');

grunt.initConfig({
pkg: grunt.file.readJSON('bower.json'),

clean: {
tmp: ["tmp"]
},

concat: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
},
build: {
src: ['src/taggedClientStorage.js'],
dest: 'taggedClientStorage.js'
dest: 'tmp/taggedClientStorage.js'
},
},

Expand Down Expand Up @@ -59,6 +65,15 @@ module.exports = function(grunt) {
}
},

ngAnnotate: {
options: {
singleQuotes: true,
},
main: {
files: { 'taggedClientStorage.js': 'tmp/taggedClientStorage.js' }
}
},

uglify: {
build: {
files: {
Expand All @@ -78,7 +93,7 @@ module.exports = function(grunt) {
grunt.registerTask('cobertura', 'Generate Cobertura coverage report', ['karma:cobertura']);

// Build files for production
grunt.registerTask('build', 'Builds files for production', ['concat:build', 'uglify:build']);
grunt.registerTask('build', 'Builds files for production', ['concat:build', 'ngAnnotate:main', 'uglify:build', 'clean:tmp']);

// Travis CI task
grunt.registerTask('travis', 'Travis CI task', ['karma:travis', 'coveralls']);
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tagged-client-storage",
"version": "1.0.1",
"version": "1.0.2",
"authors": [
"Hector Virgen <hvirgen@tagged.com>"
],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"karma-sinon-chai": "*",
"karma-story-reporter": "*",
"mocha": "*",
"requirejs": "*"
"requirejs": "*",
"grunt-ng-annotate": "^0.4.0",
"grunt-contrib-clean": "^0.6.0"
}
}
20 changes: 10 additions & 10 deletions taggedClientStorage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! tagged-client-storage - v0.0.0 - 2014-10-11 */
/*! tagged-client-storage - v1.0.2 - 2014-10-21 */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
Expand All @@ -25,7 +25,7 @@
// storage.get('other'); // returns undefined
// storage.getAll(); // returns object { foo: 'bar' }
var module = angular.module('tagged.services.client-storage', []);
module.factory('taggedClientStorage', function($window, $document) {
module.factory('taggedClientStorage', ['$window', '$document', function($window, $document) {
// Cookie fallback implements the same interface as `localStorage`,
// allowing us to drop it in when `localStorage` is not available.
// Cookies are hard-coded to be stored domain-wide,
Expand All @@ -35,39 +35,39 @@
// Returns the value of the specified cookie,
// otherwise `null` if not found.
getItem: function(name) {
if (!$document.cookie.length) {
if (!$document[0].cookie.length) {
return null;
}

var start = $document.cookie.indexOf(name + "=");
var start = $document[0].cookie.indexOf(name + "=");

if (-1 == start) {
return null;
}

start = start + name.length + 1;
var end = $document.cookie.indexOf(";", start);
var end = $document[0].cookie.indexOf(";", start);

if (-1 == end) {
end = $document.cookie.length;
end = $document[0].cookie.length;
}

return unescape($document.cookie.substring(start, end));
return unescape($document[0].cookie.substring(start, end));
},

// Stores the cookie site-wide for one year.
setItem: function(name, value) {
var date = new Date();
date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 365)); // 1 year
$document.cookie = escape(name) + '=' + escape(value) + '; path=/; expires=' + date.toGMTString();
$document[0].cookie = escape(name) + '=' + escape(value) + '; path=/; expires=' + date.toGMTString();
},

// Removes the cookie by removing its value
// and updating the expiration to a date in the past.
removeItem: function(name) {
var date = new Date();
date.setTime(date.getTime() + (1000 * -1000)); // something in the past
$document.cookie = escape(name) + '=; path=/; expires=' + date.toGMTString();
$document[0].cookie = escape(name) + '=; path=/; expires=' + date.toGMTString();
}
};

Expand Down Expand Up @@ -156,7 +156,7 @@
storages[namespace] = new Storage(namespace);
return storages[namespace];
};
});
}]);

return module;
}));
2 changes: 1 addition & 1 deletion taggedClientStorage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 86dd866

Please sign in to comment.