From a3a55d3b48d193c0043d48e561bac5a8a62b53a0 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 20 Sep 2017 11:50:17 -0700 Subject: [PATCH] [Build] Modify version info injection to fix sourcemaps (#1708) * [Build] Preserve comments instead of adding header ...to avoid disrupting sourcemaps. Fixes #1707 [Build] Remove extraneous horizontal rule from header [Build] Remove obsolete header-handling ...as this is handled by the replace task after fix for #1707 [Build] Move version headers into start.frag ...so that UMD boilerplate does not wrap it. [Build] Handle version info entirely in start.frag [Build] Replace build variables in start.frag explicitly [Build] Inject build info dynamically [Build] Test MCT.specifyBuildInfo [Build] Mark BUILD_CONSTANTS as global for jshint [Build] Give names to version line items [Build] Fix specifyBuildInfo test case * [Build] Update fix to sourcemaps for code review feedback https://github.com/nasa/openmct/pull/1708 [Build] Move build info registration to plugin https://github.com/nasa/openmct/pull/1708#discussion_r138999027 [Build] Use build info plugin ...instead of specifyBuildInfo [Build] Revert changes to MCT, per code review --- gulpfile.js | 28 ++++++++-------- openmct.js | 11 +++++-- package.json | 2 -- platform/core/bundle.js | 25 --------------- src/about.frag | 7 ---- src/plugins/buildInfo/plugin.js | 45 ++++++++++++++++++++++++++ src/plugins/buildInfo/pluginSpec.js | 50 +++++++++++++++++++++++++++++ src/start.frag | 14 ++++++++ 8 files changed, 131 insertions(+), 51 deletions(-) delete mode 100644 src/about.frag create mode 100644 src/plugins/buildInfo/plugin.js create mode 100644 src/plugins/buildInfo/pluginSpec.js diff --git a/gulpfile.js b/gulpfile.js index 8456323bdb..2dbd2c7c90 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -46,9 +46,22 @@ var gulp = require('gulp'), name: 'bower_components/almond/almond.js', include: paths.main.replace('.js', ''), wrap: { - startFile: "src/start.frag", + start: (function () { + var buildVariables = { + version: project.version, + timestamp: moment.utc(Date.now()).format(), + revision: fs.existsSync('.git') ? git.long() : 'Unknown', + branch: fs.existsSync('.git') ? git.branch() : 'Unknown' + }; + return fs.readFileSync("src/start.frag", 'utf-8') + .replace(/@@(\w+)/g, function (match, key) { + return buildVariables[key]; + });; + }()), endFile: "src/end.frag" }, + optimize: 'uglify2', + uglify2: { output: { comments: /@preserve/ } }, mainConfigFile: paths.main, wrapShim: true }, @@ -58,14 +71,6 @@ var gulp = require('gulp'), }, sass: { sourceComments: true - }, - replace: { - variables: { - version: project.version, - timestamp: moment.utc(Date.now()).format(), - revision: fs.existsSync('.git') ? git.long() : 'Unknown', - branch: fs.existsSync('.git') ? git.branch() : 'Unknown' - } } }; @@ -76,16 +81,11 @@ if (process.env.NODE_ENV === 'development') { gulp.task('scripts', function () { var requirejsOptimize = require('gulp-requirejs-optimize'); - var replace = require('gulp-replace-task'); - var header = require('gulp-header'); - var comment = fs.readFileSync('src/about.frag'); return gulp.src(paths.main) .pipe(sourcemaps.init()) .pipe(requirejsOptimize(options.requirejsOptimize)) .pipe(sourcemaps.write('.')) - .pipe(replace(options.replace)) - .pipe(header(comment, options.replace.variables)) .pipe(gulp.dest(paths.dist)); }); diff --git a/openmct.js b/openmct.js index 8f116ea1a6..788535cf5e 100644 --- a/openmct.js +++ b/openmct.js @@ -19,7 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ -/*global requirejs*/ +/*global requirejs,BUILD_CONSTANTS*/ requirejs.config({ "paths": { @@ -91,12 +91,17 @@ requirejs.config({ define([ './platform/framework/src/Main', './src/defaultRegistry', - './src/MCT' -], function (Main, defaultRegistry, MCT) { + './src/MCT', + './src/plugins/buildInfo/plugin' +], function (Main, defaultRegistry, MCT, buildInfo) { var openmct = new MCT(); openmct.legacyRegistry = defaultRegistry; + if (typeof BUILD_CONSTANTS !== 'undefined') { + openmct.install(buildInfo(BUILD_CONSTANTS)); + } + openmct.on('start', function () { return new Main().run(defaultRegistry); }); diff --git a/package.json b/package.json index c238c3e008..35f2a42261 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,10 @@ "git-rev-sync": "^1.4.0", "glob": ">= 3.0.0", "gulp": "^3.9.1", - "gulp-header": "^1.8.8", "gulp-jscs": "^3.0.2", "gulp-jshint": "^2.0.0", "gulp-jshint-html-reporter": "^0.1.3", "gulp-rename": "^1.2.2", - "gulp-replace-task": "^0.11.0", "gulp-requirejs-optimize": "^0.3.1", "gulp-sass": "^2.2.0", "gulp-sourcemaps": "^1.6.0", diff --git a/platform/core/bundle.js b/platform/core/bundle.js index 63d01e7334..1b8806bb72 100644 --- a/platform/core/bundle.js +++ b/platform/core/bundle.js @@ -94,31 +94,6 @@ define([ } }, "extensions": { - "versions": [ - { - "name": "Version", - "value": "@@version", - "priority": 999 - }, - { - "name": "Built", - "value": "@@timestamp", - "description": "The date on which this version of the client was built.", - "priority": 990 - }, - { - "name": "Revision", - "value": "@@revision", - "description": "A unique revision identifier for the client sources.", - "priority": 995 - }, - { - "name": "Branch", - "value": "@@branch", - "description": "The name of the branch that was used during the build.", - "priority": 994 - } - ], "components": [ { "provides": "objectService", diff --git a/src/about.frag b/src/about.frag deleted file mode 100644 index 54a1961159..0000000000 --- a/src/about.frag +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Open MCT https://nasa.github.io/openmct/ - * Version: ${version} - * Built: ${timestamp} - * Revision: ${revision} - * Branch: ${branch} - */ diff --git a/src/plugins/buildInfo/plugin.js b/src/plugins/buildInfo/plugin.js new file mode 100644 index 0000000000..d9b699c0e6 --- /dev/null +++ b/src/plugins/buildInfo/plugin.js @@ -0,0 +1,45 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define([ +], function ( +) { + return function (buildInfo) { + return function (openmct) { + var aliases = { timestamp: "Built" }; + var descriptions = { + timestamp: "The date on which this version of Open MCT was built.", + revision: "A unique revision identifier for the client sources.", + branch: "The name of the branch that was used during the build." + }; + + Object.keys(buildInfo).forEach(function (key) { + openmct.legacyExtension("versions", { + key: key, + name: aliases[key] || (key.charAt(0).toUpperCase() + key.substring(1)), + value: buildInfo[key], + description: descriptions[key] + }); + }); + }; + }; +}); diff --git a/src/plugins/buildInfo/pluginSpec.js b/src/plugins/buildInfo/pluginSpec.js new file mode 100644 index 0000000000..1a8e689a13 --- /dev/null +++ b/src/plugins/buildInfo/pluginSpec.js @@ -0,0 +1,50 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2017, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define([ + './plugin' +], function (plugin) { + describe("The buildInfo plugin", function () { + var mockmct; + var testInfo; + + beforeEach(function () { + mockmct = jasmine.createSpyObj('openmct', ['legacyExtension']); + testInfo = { foo: 123, bar: "baz" }; + plugin(testInfo)(mockmct); + }); + + it("registers versions extensions", function () { + Object.keys(testInfo).forEach(function (key) { + expect(mockmct.legacyExtension).toHaveBeenCalledWith( + "versions", + { + key: key, + name: jasmine.any(String), + value: testInfo[key], + description: undefined + } + ); + }); + }); + }); +}); diff --git a/src/start.frag b/src/start.frag index 34af917564..0b74abff6a 100644 --- a/src/start.frag +++ b/src/start.frag @@ -18,6 +18,14 @@ * licenses. See the Open Source Licenses file (LICENSES.md) included with * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. + * + * Open MCT https://nasa.github.io/openmct/ + * Version: @@version + * Built: @@timestamp + * Revision: @@revision + * Branch: @@branch + * + * @preserve *****************************************************************************/ (function (root, factory) { @@ -29,3 +37,9 @@ root.openmct = factory(); } }(this, function() { + var BUILD_CONSTANTS = { + version: "@@version", + timestamp: "@@timestamp", + revision: "@@revision", + branch: "@@branch" + };