From c442a02cb663f1756710ff7113d0b77364f8f69d Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 3 Apr 2016 19:34:34 -0700 Subject: [PATCH] Add build support for expiring old releases Builds expire after 90 days. --- Gruntfile.js | 16 +++++++++++++--- background.html | 1 + js/expire.js | 10 ++++++++++ package.json | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 js/expire.js diff --git a/Gruntfile.js b/Gruntfile.js index 4f970bd9..5ff2f110 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -125,6 +125,14 @@ module.exports = function(grunt) { 'textsecure-service-ca.whispersystems.org:4433').replace( /whispersystems-textsecure-attachments-staging.s3.amazonaws.com/g, 'whispersystems-textsecure-attachments.s3.amazonaws.com'); + } else if (srcpath.match('expire.js')) { + var gitinfo = grunt.config.get('gitinfo'); + var commited = gitinfo.local.branch.current.lastCommitTime; + var time = Date.parse(commited) + 1000 * 60 * 60 * 24 * 90; + return content.replace( + /var BUILD_EXPIRATION = 0/, + "var BUILD_EXPIRATION = " + time + ); } else { return content; } @@ -157,7 +165,7 @@ module.exports = function(grunt) { }, dist: { files: ['<%= dist.src %>', '<%= dist.res %>'], - tasks: ['copy'] + tasks: ['copy_dist'] }, scripts: { files: ['<%= jshint.files %>', './js/**/*.js'], @@ -198,7 +206,8 @@ module.exports = function(grunt) { 'tx-pull': { cmd: 'tx pull' } - } + }, + gitinfo: {} // to be populated by grunt gitinfo }); Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) { @@ -232,6 +241,7 @@ module.exports = function(grunt) { grunt.registerTask('tx', ['exec:tx-pull', 'locale-patch']); grunt.registerTask('dev', ['default', 'connect', 'watch']); grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']); - grunt.registerTask('default', ['concat', 'sass', 'copy']); + grunt.registerTask('copy_dist', ['gitinfo', 'copy']); + grunt.registerTask('default', ['concat', 'sass', 'copy_dist']); }; diff --git a/background.html b/background.html index a3817dce..2f845aea 100644 --- a/background.html +++ b/background.html @@ -382,6 +382,7 @@ + diff --git a/js/expire.js b/js/expire.js new file mode 100644 index 00000000..639aeae8 --- /dev/null +++ b/js/expire.js @@ -0,0 +1,10 @@ +;(function() { + 'use strict'; + var BUILD_EXPIRATION = 0; + + window.extension = window.extension || {}; + + extension.expired = function() { + return (BUILD_EXPIRATION && Date.now() > BUILD_EXPIRATION); + }; +})(); diff --git a/package.json b/package.json index 77e4da7c..a5bf999a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "grunt-contrib-sass": "^0.8.1", "grunt-contrib-watch": "^0.6.1", "grunt-exec": "^0.4.6", + "grunt-gitinfo": "^0.1.7", "grunt-jscs": "^1.1.0", "grunt-preen": "^1.0.0", "grunt-saucelabs": "^8.3.3"