From 907fa6f287bfa6ffca807730ac2d68eee40d1a13 Mon Sep 17 00:00:00 2001 From: Vinicius Fortuna Date: Tue, 30 Aug 2016 11:06:18 -0400 Subject: [PATCH] Run tasks only once --- Gruntfile.js | 76 ++++++++++++++++++++++++++++++---------------------- package.json | 1 + 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 025994892e..b00411abe7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1029,7 +1029,18 @@ module.exports = function(grunt) { return tasks; } - grunt.registerTask('base', [ + // Returns a task name that will run the input task only once if + // called multiple times. + function makeRunOnce(taskName) { + return 'run-once:' + taskName; + } + + // Register a task, making sure subtasks only run once. + function registerTask(grunt, taskName, subTasks) { + return grunt.registerTask(taskName, subTasks.map(makeRunOnce)); + } + + registerTask(grunt, 'base', [ 'copy:resources', 'copy:devGenericCore', 'ts', @@ -1043,14 +1054,14 @@ module.exports = function(grunt) { 'browserify:cloudSocialProviderFreedomModule', 'browserify:digitalOceanFreedomModule' ]); - grunt.registerTask('echoServer', [ + registerTask(grunt, 'echoServer', [ 'base', 'browserify:echoServerFreedomModule', 'copy:libsForEchoServerChromeApp', 'copy:libsForEchoServerFirefoxApp', 'copy:libsForEchoServerNode' ]); - grunt.registerTask('copypasteChat', [ + registerTask(grunt, 'copypasteChat', [ 'base', 'browserify:copypasteChatFreedomModule', 'browserify:copypasteChatMain', @@ -1058,7 +1069,7 @@ module.exports = function(grunt) { 'copy:libsForCopypasteChatFirefoxApp', 'copy:libsForCopypasteChatWebApp' ]); - grunt.registerTask('copypasteSocks', [ + registerTask(grunt, 'copypasteSocks', [ 'base', 'browserify:copypasteSocksFreedomModule', 'browserify:copypasteSocksMain', @@ -1066,13 +1077,13 @@ module.exports = function(grunt) { 'copy:libsForCopyPasteSocksChromeApp', 'copy:libsForCopyPasteSocksFirefoxApp' ]); - grunt.registerTask('deployer', [ + registerTask(grunt, 'deployer', [ 'base', 'browserify:deployerFreedomModule', 'copy:libsForDeployerChromeApp', 'copy:libsForDeployerFirefoxApp' ]); - grunt.registerTask('simpleChat', [ + registerTask(grunt, 'simpleChat', [ 'base', 'browserify:simpleChatFreedomModule', 'browserify:simpleChatMain', @@ -1080,20 +1091,20 @@ module.exports = function(grunt) { 'copy:libsForSimpleChatFirefoxApp', 'copy:libsForSimpleChatWebApp' ]); - grunt.registerTask('simpleSocks', [ + registerTask(grunt, 'simpleSocks', [ 'base', 'browserify:simpleSocksFreedomModule', 'copy:libsForSimpleSocksChromeApp', 'copy:libsForSimpleSocksFirefoxApp', 'copy:libsForSimpleSocksNode' ]); - grunt.registerTask('uprobe', [ + registerTask(grunt, 'uprobe', [ 'base', 'browserify:uprobeFreedomModule', 'copy:libsForUprobeChromeApp', 'copy:libsForUprobeFirefoxApp' ]); - grunt.registerTask('zork', [ + registerTask(grunt, 'zork', [ 'base', 'browserify:zorkFreedomModule', 'copy:libsForZorkChromeApp', @@ -1101,15 +1112,15 @@ module.exports = function(grunt) { 'copy:libsForZorkNode', 'exec:installFreedomForNodeForZork' ]); - grunt.registerTask('version_file', [ + registerTask(grunt, 'version_file', [ 'gitinfo', 'string-replace:version' ]); - grunt.registerTask('build_chrome_app', [ + registerTask(grunt, 'build_chrome_app', [ 'base', 'copy:chrome_app' ].concat(fullyVulcanize('chrome/app/polymer', 'ext-missing', 'vulcanized'))); - grunt.registerTask('build_chrome_ext', [ + registerTask(grunt, 'build_chrome_ext', [ 'base', 'copy:chrome_extension', 'copy:chrome_extension_additional', @@ -1117,13 +1128,13 @@ module.exports = function(grunt) { 'browserify:chromeContext' ].concat(fullyVulcanize('chrome/extension/generic_ui/polymer', 'root', 'vulcanized', true))); - grunt.registerTask('build_chrome', [ + registerTask(grunt, 'build_chrome', [ 'build_chrome_app', 'build_chrome_ext' ]); // Firefox build tasks. - grunt.registerTask('build_firefox', [ + registerTask(grunt, 'build_firefox', [ 'base', 'copy:firefox', 'copy:firefox_additional', @@ -1131,7 +1142,7 @@ module.exports = function(grunt) { ].concat(fullyVulcanize('firefox/data/generic_ui/polymer', 'root', 'vulcanized', true))); // CCA build tasks - grunt.registerTask('build_cca', [ + registerTask(grunt, 'build_cca', [ 'base', 'copy:cca', 'copy:cca_additional', @@ -1140,7 +1151,7 @@ module.exports = function(grunt) { ].concat(fullyVulcanize('cca/app/generic_ui/polymer', 'root', 'vulcanized', true))); // Mobile OS build tasks - grunt.registerTask('build_android', [ + registerTask(grunt, 'build_android', [ 'exec:cleanAndroid', 'build_cca', 'exec:ccaCreateDev', @@ -1150,7 +1161,7 @@ module.exports = function(grunt) { 'exec:ccaBuildAndroid', 'exec:androidReplaceXwalkDev' ]); - grunt.registerTask('release_android', [ + registerTask(grunt, 'release_android', [ 'build_cca', 'copy:dist', 'exec:ccaCreateDist', @@ -1163,12 +1174,12 @@ module.exports = function(grunt) { ]); // Emulate the mobile client for android - grunt.registerTask('emulate_android', [ + registerTask(grunt, 'emulate_android', [ 'build_android', 'exec:ccaEmulateAndroid' ]); - grunt.registerTask('build_ios', [ + registerTask(grunt, 'build_ios', [ 'exec:cleanIos', 'build_cca', 'exec:ccaCreateIosDev', @@ -1176,22 +1187,22 @@ module.exports = function(grunt) { 'exec:addIosrtcHook', 'exec:ccaPrepareIosDev' ]); - grunt.registerTask('test_chrome', [ + registerTask(grunt, 'test_chrome', [ 'build_chrome', 'browserify:chromeExtensionCoreConnectorSpec', 'jasmine:chrome_core_connector' ]); - grunt.registerTask('tcpIntegrationTestModule', [ + registerTask(grunt, 'tcpIntegrationTestModule', [ 'base', 'copy:libsForIntegrationTcp', 'browserify:integrationTcpFreedomModule', 'browserify:integrationTcpSpec' ]); - grunt.registerTask('tcpIntegrationTest', [ + registerTask(grunt, 'tcpIntegrationTest', [ 'tcpIntegrationTestModule', 'jasmine_chromeapp:tcp' ]); - grunt.registerTask('socksEchoIntegrationTestModule', [ + registerTask(grunt, 'socksEchoIntegrationTestModule', [ 'base', 'copy:libsForIntegrationSocksEcho', 'browserify:integrationSocksEchoFreedomModule', @@ -1199,11 +1210,11 @@ module.exports = function(grunt) { 'browserify:integrationSocksEchoNochurnSpec', 'browserify:integrationSocksEchoSlowSpec' ]); - grunt.registerTask('socksEchoIntegrationTest', [ + registerTask(grunt, 'socksEchoIntegrationTest', [ 'socksEchoIntegrationTestModule', 'jasmine_chromeapp:socksEcho' ]); - grunt.registerTask('unit_test_nobuild', _.flatten([].concat( + registerTask(grunt, 'unit_test_nobuild', _.flatten([].concat( Rule.getTests('src', 'lib', ['build-tools', 'integration-tests']), Rule.getTests('src', 'generic_core'), Rule.getTests('src', 'generic_ui/scripts') @@ -1212,16 +1223,16 @@ module.exports = function(grunt) { }) )); - grunt.registerTask('unit_test', [ + registerTask(grunt, 'unit_test', [ 'base', 'unit_test_nobuild' ]); // TODO: add test_chrome once it passes reliably - grunt.registerTask('integration_test', [ + registerTask(grunt, 'integration_test', [ 'tcpIntegrationTest', 'socksEchoIntegrationTest' ]); - grunt.registerTask('test', [ + registerTask(grunt, 'test', [ 'unit_test', 'integration_test' ]); @@ -1229,7 +1240,7 @@ module.exports = function(grunt) { // iOS and Android as well as // ts-linting and testing which can be annoying and slow. // We added jshint here because catches hard syntax errors, etc. - grunt.registerTask('build', [ + registerTask(grunt, 'build', [ 'build_chrome', 'build_firefox', 'build_cca', @@ -1237,15 +1248,15 @@ module.exports = function(grunt) { 'copy:dist', 'jpm:xpi' ]); - grunt.registerTask('lint', ['tslint']); + registerTask(grunt, 'lint', ['tslint']); // This is run prior to releasing uProxy and, in addition to // building, tests and lints all code. - grunt.registerTask('dist', [ + registerTask(grunt, 'dist', [ 'build', 'lint', 'test' ]); - grunt.registerTask('default', ['build']); + registerTask(grunt, 'default', ['build']); //------------------------------------------------------------------------- grunt.loadNpmTasks('grunt-browserify'); @@ -1259,6 +1270,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-gitinfo'); grunt.loadNpmTasks('grunt-jasmine-chromeapp'); grunt.loadNpmTasks('grunt-jpm'); + grunt.loadNpmTasks('grunt-run-once'); grunt.loadNpmTasks('grunt-string-replace'); grunt.loadNpmTasks('grunt-ts'); grunt.loadNpmTasks('grunt-tslint'); diff --git a/package.json b/package.json index 71a34373de..19454a4653 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "grunt-gitinfo": "^0.1.7", "grunt-jasmine-chromeapp": "git://github.com/uproxy/grunt-jasmine-chromeapp", "grunt-jpm": "^0.1.3", + "grunt-run-once": "^0.2.0", "grunt-string-replace": "^1.0.0", "grunt-subgrunt": "^1.2.0", "grunt-template-jasmine-istanbul": "^0.3.0",