mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
tutorials: support arbitrary hosting directory (#1097)
* Include all bundles in artifact change bundle registry such that all bundles are immediately registered, but must be specifically enabled. A default registry class enables bundles that make sense for demonstration purposes. Added methods to the registry to allow enabling and disabling of bundles without having to load additional files. * support alternate asset/worker paths Change the gulp glob for assets to copy over a more minimal set of files-- only css, fonts, and images. Results in a smaller distributable archive. Update stylesheet loader to use a constant for the assets path. This can be customized at run time via MCT.setAssetPath() to allow MCT to be hosted in various locations. Update worker loader to support loading workers from blobs to support packaging as standalone file. * Load templates via requirejs * [gulp] lazy-require where reasonable Require things right before starting tasks to reduce gulp start up time. * document setAssetPath
This commit is contained in:
parent
719f9f45e8
commit
1147f3aa47
6
API.md
6
API.md
@ -106,3 +106,9 @@ Install a plugin in MCT. Must be called before calling `run`. Plugins are func
|
||||
|
||||
For an example of writing a plugin, check out [plugin-example.html](plugin-example.html)
|
||||
|
||||
### `MCT.setAssetPath(path)`
|
||||
|
||||
Sets the path (absolute or relative) at which the Open MCT static files are being hosted. The default value is '.'.
|
||||
|
||||
Note that this API is transitional and will be removed in a future version.
|
||||
|
||||
|
@ -36,7 +36,7 @@ define([
|
||||
legacyRegistry
|
||||
) {
|
||||
"use strict";
|
||||
legacyRegistry.register("example/notifications", {
|
||||
legacyRegistry.register("example/msl-adapter", {
|
||||
"name" : "Mars Science Laboratory Data Adapter",
|
||||
"extensions" : {
|
||||
"types": [
|
||||
|
46
gulpfile.js
46
gulpfile.js
@ -21,36 +21,24 @@
|
||||
*****************************************************************************/
|
||||
|
||||
/*global require,__dirname*/
|
||||
|
||||
var gulp = require('gulp'),
|
||||
requirejsOptimize = require('gulp-requirejs-optimize'),
|
||||
sourcemaps = require('gulp-sourcemaps'),
|
||||
rename = require('gulp-rename'),
|
||||
sass = require('gulp-sass'),
|
||||
bourbon = require('node-bourbon'),
|
||||
jshint = require('gulp-jshint'),
|
||||
jscs = require('gulp-jscs'),
|
||||
replace = require('gulp-replace-task'),
|
||||
karma = require('karma'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
git = require('git-rev-sync'),
|
||||
moment = require('moment'),
|
||||
merge = require('merge-stream'),
|
||||
project = require('./package.json'),
|
||||
_ = require('lodash'),
|
||||
paths = {
|
||||
main: 'main.js',
|
||||
dist: 'dist',
|
||||
assets: 'dist/assets',
|
||||
scss: ['./platform/**/*.scss', './example/**/*.scss'],
|
||||
assets: [
|
||||
'./{example,platform}/**/*.{css,css.map,png,svg,ico,woff,eot,ttf}'
|
||||
],
|
||||
scripts: [ 'main.js', 'platform/**/*.js', 'src/**/*.js' ],
|
||||
specs: [ 'platform/**/*Spec.js', 'src/**/*Spec.js' ],
|
||||
static: [
|
||||
'index.html',
|
||||
'platform/**/*',
|
||||
'example/**/*',
|
||||
'bower_components/**/*'
|
||||
]
|
||||
},
|
||||
options = {
|
||||
requirejsOptimize: {
|
||||
@ -68,7 +56,6 @@ var gulp = require('gulp'),
|
||||
singleRun: true
|
||||
},
|
||||
sass: {
|
||||
includePaths: bourbon.includePaths,
|
||||
sourceComments: true
|
||||
},
|
||||
replace: {
|
||||
@ -82,6 +69,8 @@ var gulp = require('gulp'),
|
||||
};
|
||||
|
||||
gulp.task('scripts', function () {
|
||||
var requirejsOptimize = require('gulp-requirejs-optimize');
|
||||
var replace = require('gulp-replace-task');
|
||||
return gulp.src(paths.main)
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(requirejsOptimize(options.requirejsOptimize))
|
||||
@ -91,10 +80,16 @@ gulp.task('scripts', function () {
|
||||
});
|
||||
|
||||
gulp.task('test', function (done) {
|
||||
var karma = require('karma');
|
||||
new karma.Server(options.karma, done).start();
|
||||
});
|
||||
|
||||
gulp.task('stylesheets', function () {
|
||||
var sass = require('gulp-sass');
|
||||
var rename = require('gulp-rename');
|
||||
var bourbon = require('node-bourbon');
|
||||
options.sass.includePaths = bourbon.includePaths;
|
||||
|
||||
return gulp.src(paths.scss, {base: '.'})
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(sass(options.sass).on('error', sass.logError))
|
||||
@ -108,6 +103,9 @@ gulp.task('stylesheets', function () {
|
||||
});
|
||||
|
||||
gulp.task('lint', function () {
|
||||
var jshint = require('gulp-jshint');
|
||||
var merge = require('merge-stream');
|
||||
|
||||
var nonspecs = paths.specs.map(function (glob) {
|
||||
return "!" + glob;
|
||||
}),
|
||||
@ -122,6 +120,8 @@ gulp.task('lint', function () {
|
||||
});
|
||||
|
||||
gulp.task('checkstyle', function () {
|
||||
var jscs = require('gulp-jscs');
|
||||
|
||||
return gulp.src(paths.scripts)
|
||||
.pipe(jscs())
|
||||
.pipe(jscs.reporter())
|
||||
@ -129,18 +129,20 @@ gulp.task('checkstyle', function () {
|
||||
});
|
||||
|
||||
gulp.task('fixstyle', function () {
|
||||
var jscs = require('gulp-jscs');
|
||||
|
||||
return gulp.src(paths.scripts, { base: '.' })
|
||||
.pipe(jscs({ fix: true }))
|
||||
.pipe(gulp.dest('.'));
|
||||
});
|
||||
|
||||
gulp.task('static', ['stylesheets'], function () {
|
||||
return gulp.src(paths.static, { base: '.' })
|
||||
gulp.task('assets', ['stylesheets'], function () {
|
||||
return gulp.src(paths.assets)
|
||||
.pipe(gulp.dest(paths.dist));
|
||||
});
|
||||
|
||||
gulp.task('watch', function () {
|
||||
gulp.watch(paths.scss, ['stylesheets']);
|
||||
return gulp.watch(paths.scss, ['stylesheets', 'assets']);
|
||||
});
|
||||
|
||||
gulp.task('serve', function () {
|
||||
@ -148,9 +150,9 @@ gulp.task('serve', function () {
|
||||
var app = require('./app.js');
|
||||
});
|
||||
|
||||
gulp.task('develop', ['serve', 'stylesheets', 'watch']);
|
||||
gulp.task('develop', ['serve', 'install', 'watch']);
|
||||
|
||||
gulp.task('install', [ 'static', 'scripts' ]);
|
||||
gulp.task('install', [ 'assets', 'scripts' ]);
|
||||
|
||||
gulp.task('verify', [ 'lint', 'test', 'checkstyle' ]);
|
||||
|
||||
|
47
main.js
47
main.js
@ -65,49 +65,12 @@ requirejs.config({
|
||||
|
||||
define([
|
||||
'./platform/framework/src/Main',
|
||||
'legacyRegistry',
|
||||
'./src/MCT',
|
||||
|
||||
'./src/adapter/bundle',
|
||||
|
||||
'./platform/framework/bundle',
|
||||
'./platform/core/bundle',
|
||||
'./platform/representation/bundle',
|
||||
'./platform/commonUI/about/bundle',
|
||||
'./platform/commonUI/browse/bundle',
|
||||
'./platform/commonUI/edit/bundle',
|
||||
'./platform/commonUI/dialog/bundle',
|
||||
'./platform/commonUI/formats/bundle',
|
||||
'./platform/commonUI/general/bundle',
|
||||
'./platform/commonUI/inspect/bundle',
|
||||
'./platform/commonUI/mobile/bundle',
|
||||
'./platform/commonUI/themes/espresso/bundle',
|
||||
'./platform/commonUI/notification/bundle',
|
||||
'./platform/containment/bundle',
|
||||
'./platform/execution/bundle',
|
||||
'./platform/exporters/bundle',
|
||||
'./platform/telemetry/bundle',
|
||||
'./platform/features/clock/bundle',
|
||||
'./platform/features/imagery/bundle',
|
||||
'./platform/features/layout/bundle',
|
||||
'./platform/features/pages/bundle',
|
||||
'./platform/features/plot/bundle',
|
||||
'./platform/features/timeline/bundle',
|
||||
'./platform/features/table/bundle',
|
||||
'./platform/forms/bundle',
|
||||
'./platform/identity/bundle',
|
||||
'./platform/persistence/aggregator/bundle',
|
||||
'./platform/persistence/local/bundle',
|
||||
'./platform/persistence/queue/bundle',
|
||||
'./platform/policy/bundle',
|
||||
'./platform/entanglement/bundle',
|
||||
'./platform/search/bundle',
|
||||
'./platform/status/bundle',
|
||||
'./platform/commonUI/regions/bundle'
|
||||
], function (Main, legacyRegistry, MCT) {
|
||||
'./src/defaultRegistry',
|
||||
'./src/MCT'
|
||||
], function (Main, defaultRegistry, MCT) {
|
||||
var mct = new MCT();
|
||||
|
||||
mct.legacyRegistry = legacyRegistry;
|
||||
mct.legacyRegistry = defaultRegistry;
|
||||
mct.run = function (domElement) {
|
||||
if (!domElement) { domElement = document.body; }
|
||||
var appDiv = document.createElement('div');
|
||||
@ -117,7 +80,7 @@ define([
|
||||
mct.start();
|
||||
};
|
||||
mct.on('start', function () {
|
||||
return new Main().run(legacyRegistry);
|
||||
return new Main().run(defaultRegistry);
|
||||
});
|
||||
|
||||
return mct;
|
||||
|
@ -39,6 +39,7 @@ define([
|
||||
"text!./res/templates/items/items.html",
|
||||
"text!./res/templates/browse/object-properties.html",
|
||||
"text!./res/templates/browse/inspector-region.html",
|
||||
"text!./res/templates/view-object.html",
|
||||
'legacyRegistry'
|
||||
], function (
|
||||
BrowseController,
|
||||
@ -59,6 +60,7 @@ define([
|
||||
itemsTemplate,
|
||||
objectPropertiesTemplate,
|
||||
inspectorRegionTemplate,
|
||||
viewObjectTemplate,
|
||||
legacyRegistry
|
||||
) {
|
||||
|
||||
@ -129,7 +131,7 @@ define([
|
||||
"representations": [
|
||||
{
|
||||
"key": "view-object",
|
||||
"templateUrl": "templates/view-object.html"
|
||||
"template": viewObjectTemplate
|
||||
},
|
||||
{
|
||||
"key": "browse-object",
|
||||
|
@ -148,7 +148,8 @@ define([
|
||||
"depends": [
|
||||
"stylesheets[]",
|
||||
"$document",
|
||||
"THEME"
|
||||
"THEME",
|
||||
"ASSETS_PATH"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -406,6 +407,11 @@ define([
|
||||
"key": "THEME",
|
||||
"value": "unspecified",
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"key": "ASSETS_PATH",
|
||||
"value": ".",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"containers": [
|
||||
|
@ -38,7 +38,7 @@ define(
|
||||
* @param $document Angular's jqLite-wrapped document element
|
||||
* @param {string} activeTheme the theme in use
|
||||
*/
|
||||
function StyleSheetLoader(stylesheets, $document, activeTheme) {
|
||||
function StyleSheetLoader(stylesheets, $document, activeTheme, assetPath) {
|
||||
var head = $document.find('head'),
|
||||
document = $document[0];
|
||||
|
||||
@ -47,6 +47,7 @@ define(
|
||||
// Create a link element, and construct full path
|
||||
var link = document.createElement('link'),
|
||||
path = [
|
||||
assetPath,
|
||||
stylesheet.bundle.path,
|
||||
stylesheet.bundle.resources,
|
||||
stylesheet.stylesheetUrl
|
||||
|
@ -42,11 +42,19 @@ define(
|
||||
function addWorker(worker) {
|
||||
var key = worker.key;
|
||||
if (!workerUrls[key]) {
|
||||
workerUrls[key] = [
|
||||
worker.bundle.path,
|
||||
worker.bundle.sources,
|
||||
worker.scriptUrl
|
||||
].join("/");
|
||||
if (worker.scriptUrl) {
|
||||
workerUrls[key] = [
|
||||
worker.bundle.path,
|
||||
worker.bundle.sources,
|
||||
worker.scriptUrl
|
||||
].join("/");
|
||||
} else if (worker.scriptText) {
|
||||
var blob = new Blob(
|
||||
[worker.scriptText],
|
||||
{type: 'application/javascript'}
|
||||
);
|
||||
workerUrls[key] = URL.createObjectURL(blob);
|
||||
}
|
||||
sharedWorkers[key] = worker.shared;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ define([
|
||||
"./src/controllers/TableOptionsController",
|
||||
'../../commonUI/regions/src/Region',
|
||||
'../../commonUI/browse/src/InspectorRegion',
|
||||
"text!./res/templates/table-options-edit.html",
|
||||
"text!./res/templates/rt-table.html",
|
||||
"text!./res/templates/historical-table.html",
|
||||
"legacyRegistry"
|
||||
], function (
|
||||
MCTTable,
|
||||
@ -35,6 +38,9 @@ define([
|
||||
TableOptionsController,
|
||||
Region,
|
||||
InspectorRegion,
|
||||
tableOptionsEditTemplate,
|
||||
rtTableTemplate,
|
||||
historicalTableTemplate,
|
||||
legacyRegistry
|
||||
) {
|
||||
/**
|
||||
@ -128,7 +134,7 @@ define([
|
||||
"name": "Historical Table",
|
||||
"key": "table",
|
||||
"glyph": "\ue604",
|
||||
"templateUrl": "templates/historical-table.html",
|
||||
"template": historicalTableTemplate,
|
||||
"needs": [
|
||||
"telemetry"
|
||||
],
|
||||
@ -139,7 +145,7 @@ define([
|
||||
"name": "Real-time Table",
|
||||
"key": "rt-table",
|
||||
"glyph": "\ue620",
|
||||
"templateUrl": "templates/rt-table.html",
|
||||
"template": rtTableTemplate,
|
||||
"needs": [
|
||||
"telemetry"
|
||||
],
|
||||
@ -157,7 +163,7 @@ define([
|
||||
"representations": [
|
||||
{
|
||||
"key": "table-options-edit",
|
||||
"templateUrl": "templates/table-options-edit.html"
|
||||
"template": tableOptionsEditTemplate
|
||||
}
|
||||
],
|
||||
"stylesheets": [
|
||||
|
@ -28,6 +28,7 @@ define([
|
||||
"text!./res/templates/search-item.html",
|
||||
"text!./res/templates/search.html",
|
||||
"text!./res/templates/search-menu.html",
|
||||
"text!./src/services/GenericSearchWorker.js",
|
||||
'legacyRegistry'
|
||||
], function (
|
||||
SearchController,
|
||||
@ -37,6 +38,7 @@ define([
|
||||
searchItemTemplate,
|
||||
searchTemplate,
|
||||
searchMenuTemplate,
|
||||
searchWorkerText,
|
||||
legacyRegistry
|
||||
) {
|
||||
|
||||
@ -114,7 +116,7 @@ define([
|
||||
"workers": [
|
||||
{
|
||||
"key": "genericSearchWorker",
|
||||
"scriptUrl": "services/GenericSearchWorker.js"
|
||||
"scriptText": searchWorkerText
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -24,10 +24,27 @@ define(function () {
|
||||
|
||||
function BundleRegistry() {
|
||||
this.bundles = {};
|
||||
this.knownBundles = {};
|
||||
}
|
||||
|
||||
BundleRegistry.prototype.register = function (path, definition) {
|
||||
this.bundles[path] = definition;
|
||||
if (this.knownBundles.hasOwnProperty(path)) {
|
||||
throw new Error('Cannot register bundle with duplicate path', path);
|
||||
}
|
||||
this.knownBundles[path] = definition;
|
||||
};
|
||||
|
||||
BundleRegistry.prototype.enable = function (path) {
|
||||
if (!this.knownBundles[path]) {
|
||||
throw new Error('Unknown bundle ' + path);
|
||||
}
|
||||
this.bundles[path] = this.knownBundles[path];
|
||||
};
|
||||
|
||||
BundleRegistry.prototype.disable = function (path) {
|
||||
if (!this.bundles[path]) {
|
||||
throw new Error('Tried to disable inactive bundle ' + path);
|
||||
}
|
||||
};
|
||||
|
||||
BundleRegistry.prototype.contains = function (path) {
|
||||
@ -42,8 +59,14 @@ define(function () {
|
||||
return Object.keys(this.bundles);
|
||||
};
|
||||
|
||||
BundleRegistry.prototype.remove = function (path) {
|
||||
BundleRegistry.prototype.remove = BundleRegistry.prototype.disable;
|
||||
|
||||
BundleRegistry.prototype.delete = function (path) {
|
||||
if (!this.knownBundles[path]) {
|
||||
throw new Error('Cannot remove Unknown Bundle ' + path);
|
||||
}
|
||||
delete this.bundles[path];
|
||||
delete this.knownBundles[path];
|
||||
};
|
||||
|
||||
return BundleRegistry;
|
||||
|
13
src/MCT.js
13
src/MCT.js
@ -6,7 +6,6 @@ define([
|
||||
'text!./adapter/templates/edit-object-replacement.html',
|
||||
'./ui/Dialog',
|
||||
'./Selection',
|
||||
'./api/objects/bundle',
|
||||
'./api/objects/object-utils'
|
||||
], function (
|
||||
EventEmitter,
|
||||
@ -16,7 +15,6 @@ define([
|
||||
editObjectTemplate,
|
||||
Dialog,
|
||||
Selection,
|
||||
objectAPIBundle,
|
||||
objectUtils
|
||||
) {
|
||||
function MCT() {
|
||||
@ -40,6 +38,16 @@ define([
|
||||
this.legacyBundle.extensions[category].push(extension);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set path to where assets are hosted. This should be the path to main.js.
|
||||
*/
|
||||
MCT.prototype.setAssetPath = function (path) {
|
||||
this.legacyExtension('constants', {
|
||||
key: "ASSETS_PATH",
|
||||
value: path
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new type of view.
|
||||
*
|
||||
@ -123,6 +131,7 @@ define([
|
||||
});
|
||||
|
||||
legacyRegistry.register('adapter', this.legacyBundle);
|
||||
legacyRegistry.enable('adapter');
|
||||
this.emit('start');
|
||||
};
|
||||
|
||||
|
113
src/defaultRegistry.js
Normal file
113
src/defaultRegistry.js
Normal file
@ -0,0 +1,113 @@
|
||||
define([
|
||||
'legacyRegistry',
|
||||
|
||||
'../src/adapter/bundle',
|
||||
'../src/api/objects/bundle',
|
||||
|
||||
'../example/builtins/bundle',
|
||||
'../example/composite/bundle',
|
||||
'../example/eventGenerator/bundle',
|
||||
'../example/export/bundle',
|
||||
'../example/extensions/bundle',
|
||||
'../example/forms/bundle',
|
||||
'../example/generator/bundle',
|
||||
'../example/identity/bundle',
|
||||
'../example/imagery/bundle',
|
||||
'../example/mobile/bundle',
|
||||
'../example/msl/bundle',
|
||||
'../example/notifications/bundle',
|
||||
'../example/persistence/bundle',
|
||||
'../example/plotOptions/bundle',
|
||||
'../example/policy/bundle',
|
||||
'../example/profiling/bundle',
|
||||
'../example/scratchpad/bundle',
|
||||
'../example/taxonomy/bundle',
|
||||
'../example/worker/bundle',
|
||||
|
||||
'../platform/commonUI/about/bundle',
|
||||
'../platform/commonUI/browse/bundle',
|
||||
'../platform/commonUI/dialog/bundle',
|
||||
'../platform/commonUI/edit/bundle',
|
||||
'../platform/commonUI/formats/bundle',
|
||||
'../platform/commonUI/general/bundle',
|
||||
'../platform/commonUI/inspect/bundle',
|
||||
'../platform/commonUI/mobile/bundle',
|
||||
'../platform/commonUI/notification/bundle',
|
||||
'../platform/commonUI/regions/bundle',
|
||||
'../platform/commonUI/themes/espresso/bundle',
|
||||
'../platform/commonUI/themes/snow/bundle',
|
||||
'../platform/containment/bundle',
|
||||
'../platform/core/bundle',
|
||||
'../platform/entanglement/bundle',
|
||||
'../platform/execution/bundle',
|
||||
'../platform/exporters/bundle',
|
||||
'../platform/features/clock/bundle',
|
||||
'../platform/features/conductor/bundle',
|
||||
'../platform/features/imagery/bundle',
|
||||
'../platform/features/layout/bundle',
|
||||
'../platform/features/pages/bundle',
|
||||
'../platform/features/plot/bundle',
|
||||
'../platform/features/static-markup/bundle',
|
||||
'../platform/features/table/bundle',
|
||||
'../platform/features/timeline/bundle',
|
||||
'../platform/forms/bundle',
|
||||
'../platform/framework/bundle',
|
||||
'../platform/framework/src/load/Bundle',
|
||||
'../platform/identity/bundle',
|
||||
'../platform/persistence/aggregator/bundle',
|
||||
'../platform/persistence/couch/bundle',
|
||||
'../platform/persistence/elastic/bundle',
|
||||
'../platform/persistence/local/bundle',
|
||||
'../platform/persistence/queue/bundle',
|
||||
'../platform/policy/bundle',
|
||||
'../platform/representation/bundle',
|
||||
'../platform/search/bundle',
|
||||
'../platform/status/bundle',
|
||||
'../platform/telemetry/bundle',
|
||||
], function (legacyRegistry) {
|
||||
|
||||
var DEFAULTS = [
|
||||
'src/adapter',
|
||||
'src/api/objects',
|
||||
'platform/framework',
|
||||
'platform/core',
|
||||
'platform/representation',
|
||||
'platform/commonUI/about',
|
||||
'platform/commonUI/browse',
|
||||
'platform/commonUI/edit',
|
||||
'platform/commonUI/dialog',
|
||||
'platform/commonUI/formats',
|
||||
'platform/commonUI/general',
|
||||
'platform/commonUI/inspect',
|
||||
'platform/commonUI/mobile',
|
||||
'platform/commonUI/themes/espresso',
|
||||
'platform/commonUI/notification',
|
||||
'platform/containment',
|
||||
'platform/execution',
|
||||
'platform/exporters',
|
||||
'platform/telemetry',
|
||||
'platform/features/clock',
|
||||
'platform/features/imagery',
|
||||
'platform/features/layout',
|
||||
'platform/features/pages',
|
||||
'platform/features/plot',
|
||||
'platform/features/timeline',
|
||||
'platform/features/table',
|
||||
'platform/forms',
|
||||
'platform/identity',
|
||||
'platform/persistence/aggregator',
|
||||
'platform/persistence/local',
|
||||
'platform/persistence/queue',
|
||||
'platform/policy',
|
||||
'platform/entanglement',
|
||||
'platform/search',
|
||||
'platform/status',
|
||||
'platform/commonUI/regions'
|
||||
];
|
||||
|
||||
DEFAULTS.forEach(function (bundlePath) {
|
||||
legacyRegistry.enable(bundlePath);
|
||||
});
|
||||
|
||||
return legacyRegistry;
|
||||
});
|
Loading…
Reference in New Issue
Block a user