Build refactor to webpack (#2139)

* Move to webpack build
* Use webpack for building openmct.  Move SCSS to one folder and load
all core css up front.  Remove bower, begin removing gulp in favor
of npm run.
* Uses eslint instead of jshint and jscs.  Merge style checking rules
into .eshintrc.js, carrying over core parts of crockford style and
our adaptations.  Current code base fails to pass the linter, want
to separate linter changes from fixes to linting rules.
* Support for Vue SFC with example
* Remove outdated examples
* Use HTML loader for html (supports relative imports of resources e.g.
images) and raw-loader for when javascript must be loaded as text.
This commit is contained in:
Pete Richards
2018-08-07 14:47:50 -07:00
committed by Andrew Henry
parent 9582fb2b06
commit 0d53898af9
355 changed files with 1910 additions and 3693 deletions

View File

@@ -20,10 +20,9 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global window,requirejs*/
/*global window*/
define([
'require',
'./Constants',
'./FrameworkInitializer',
'./LogLevel',
@@ -31,13 +30,11 @@ define([
'./resolve/ImplementationLoader',
'./resolve/ExtensionResolver',
'./resolve/BundleResolver',
'./resolve/RequireConfigurator',
'./register/CustomRegistrars',
'./register/ExtensionRegistrar',
'./register/ExtensionSorter',
'./bootstrap/ApplicationBootstrapper'
], function (
require,
Constants,
FrameworkInitializer,
LogLevel,
@@ -45,7 +42,6 @@ define([
ImplementationLoader,
ExtensionResolver,
BundleResolver,
RequireConfigurator,
CustomRegistrars,
ExtensionRegistrar,
ExtensionSorter,
@@ -68,10 +64,9 @@ define([
loader = new BundleLoader($http, $log, legacyRegistry),
resolver = new BundleResolver(
new ExtensionResolver(
new ImplementationLoader(require),
new ImplementationLoader({}),
$log
),
new RequireConfigurator(requirejs),
$log
),
registrar = new ExtensionRegistrar(

View File

@@ -20,7 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global window,requirejs*/
/*global window*/
/**
* Implements the framework layer, which handles the loading of bundles
@@ -29,15 +29,11 @@
*/
define(
[
'require',
'es6-promise',
'./FrameworkLayer',
'angular',
'angular-route'
],
function (
require,
es6promise,
FrameworkLayer,
angular
) {
@@ -56,12 +52,9 @@ define(
return match ? match[1] : "";
}
// Polyfill Promise, in case browser does not natively provide Promise
window.Promise = window.Promise || es6promise.Promise;
// Reconfigure base url, since bundle paths will all be relative
// to the root now.
requirejs.config({"baseUrl": ""});
injector.instantiate(['$http', '$log', FrameworkLayer])
.initializeApplication(angular, legacyRegistry, logLevel());
};

View File

@@ -147,8 +147,8 @@ define(
}
return Array.isArray(bundles) ? loadBundlesFromArray(bundles) :
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
(typeof bundles === 'string') ? loadBundlesFromFile(bundles) :
Promise.reject(new Error(INVALID_ARGUMENT_MESSAGE));
};
return BundleLoader;

View File

@@ -132,8 +132,8 @@ define(
*/
Extension.prototype.getImplementationPath = function () {
return (this.hasImplementation() && !this.hasImplementationValue()) ?
this.bundle.getSourcePath(this.definition.implementation) :
undefined;
this.bundle.getSourcePath(this.definition.implementation) :
undefined;
};
/**
@@ -143,8 +143,8 @@ define(
*/
Extension.prototype.getImplementationValue = function () {
return typeof this.definition.implementation === 'function' ?
this.definition.implementation :
undefined;
this.definition.implementation :
undefined;
};
/**

View File

@@ -180,8 +180,8 @@ define(
(extension.depends || []).filter(
isExtensionDependency
).forEach(function (dependency) {
needed[dependency] = true;
});
needed[dependency] = true;
});
});
// Remove categories which have been provided

View File

@@ -35,9 +35,8 @@ define(
* @memberof platform/framework
* @constructor
*/
function BundleResolver(extensionResolver, requireConfigurator, $log) {
function BundleResolver(extensionResolver, $log) {
this.extensionResolver = extensionResolver;
this.requireConfigurator = requireConfigurator;
this.$log = $log;
}
@@ -53,7 +52,6 @@ define(
*/
BundleResolver.prototype.resolveBundles = function (bundles) {
var extensionResolver = this.extensionResolver,
requireConfigurator = this.requireConfigurator,
$log = this.$log;
/*
@@ -116,9 +114,6 @@ define(
.then(giveResult);
}
// First, make sure Require is suitably configured
requireConfigurator.configure(bundles);
// Then, resolve all extension implementations.
return Promise.all(bundles.map(resolveBundle))
.then(mergeResolvedBundles);

View File

@@ -60,8 +60,8 @@ define(
function loadImplementation(ext) {
var implPromise = ext.hasImplementationValue() ?
Promise.resolve(ext.getImplementationValue()) :
loader.load(ext.getImplementationPath()),
Promise.resolve(ext.getImplementationValue()) :
loader.load(ext.getImplementationPath()),
definition = ext.getDefinition();
// Wrap a constructor function (to avoid modifying the original)

View File

@@ -1,112 +0,0 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, 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(
[],
function () {
/**
* Handles configuration of RequireJS to expose libraries
* from bundles with module names that can be used from other
* bundles.
* @memberof platform/framework
* @constructor
* @param requirejs an instance of RequireJS
*/
function RequireConfigurator(requirejs) {
this.requirejs = requirejs;
}
// Utility function to clone part of a bundle definition
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
// Look up module configuration from the bundle definition.
// This will adjust paths to libraries as-needed.
function getConfiguration(bundle) {
var configuration = bundle.getConfiguration();
// Adjust paths to point to libraries
if (configuration.paths) {
// Don't modify the actual bundle definition...
configuration = clone(configuration);
// ...replace values in a clone instead.
Object.keys(configuration.paths).forEach(function (path) {
configuration.paths[path] =
bundle.getLibraryPath(configuration.paths[path]);
});
}
return configuration;
}
// Build up paths and shim values from multiple bundles;
// this is sensitive to the value from baseConfiguration
// passed via reduce in buildConfiguration below, insofar
// as it assumes paths and shim will have initial empty values.
function mergeConfigurations(base, next) {
["paths", "shim"].forEach(function (k) {
Object.keys(next[k] || {}).forEach(function (p) {
base[k][p] = next[k][p];
});
});
return base;
}
// Build a configuration object, to pass to requirejs.config,
// based on the defined configurations for all bundles.
// The paths and shim properties from all bundles will be
// merged to allow one requirejs.config call.
function buildConfiguration(bundles) {
// Provide an initial requirejs configuration...
var baseConfiguration = {
baseUrl: "",
paths: {},
shim: {}
},
// ...and pull out all bundle-specific parts
bundleConfigurations = bundles.map(getConfiguration);
// Reduce this into one configuration object.
return bundleConfigurations.reduce(
mergeConfigurations,
baseConfiguration
);
}
/**
* Configure RequireJS to utilize any path/shim definitions
* provided by these bundles.
*
* @param {Bundle[]} the bundles to include in this
* configuration
* @memberof platform/framework.RequireConfigurator#
*/
RequireConfigurator.prototype.configure = function (bundles) {
return this.requirejs.config(buildConfiguration(bundles));
};
return RequireConfigurator;
}
);

View File

@@ -29,7 +29,6 @@ define(
describe("The bundle resolver", function () {
var mockExtensionResolver,
mockRequireConfigurator,
mockLog,
resolver;
@@ -38,10 +37,6 @@ define(
"extensionResolver",
["resolve"]
);
mockRequireConfigurator = jasmine.createSpyObj(
"requireConfigurator",
["configure"]
);
mockLog = jasmine.createSpyObj(
"$log",
["error", "warn", "info", "debug"]
@@ -51,7 +46,6 @@ define(
resolver = new BundleResolver(
mockExtensionResolver,
mockRequireConfigurator,
mockLog
);
});
@@ -67,18 +61,6 @@ define(
});
});
it("configures require before loading implementations", function () {
var bundles = [
new Bundle("x", { extensions: { tests: [{}, {}, {}] } }),
new Bundle("y", { extensions: { tests: [{}, {}], others: [{}, {}] } }),
new Bundle("z", { extensions: { others: [{}] } })
];
resolver.resolveBundles(bundles);
expect(mockRequireConfigurator.configure)
.toHaveBeenCalledWith(bundles);
});
});
}
);

View File

@@ -1,82 +0,0 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2018, 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(
["../../src/resolve/RequireConfigurator", "../../src/load/Bundle"],
function (RequireConfigurator, Bundle) {
describe("The RequireJS configurator", function () {
var mockRequire,
configurator;
beforeEach(function () {
mockRequire = jasmine.createSpyObj(
"requirejs",
["config"]
);
configurator = new RequireConfigurator(mockRequire);
});
it("configures RequireJS when invoked", function () {
// Verify precondition - no config call
expect(mockRequire.config).not.toHaveBeenCalled();
// Configure with an empty set of bundles
configurator.configure([]);
// Should have invoked require.config
expect(mockRequire.config).toHaveBeenCalled();
});
it("assembles configurations from bundles", function () {
configurator.configure([
new Bundle("test/a", { configuration: {
paths: { a: "path/to/a", b: "path/to/b" }
} }),
new Bundle("test/b", { configuration: {
paths: { b: "path/to/b" },
shim: {
b: { "exports": "someExport" },
c: {}
}
} }),
new Bundle("test/c", { configuration: {
shim: {
c: { "exports": "someOtherExport" }
}
} })
]);
expect(mockRequire.config).toHaveBeenCalledWith({
baseUrl: "",
paths: {
a: "test/a/lib/path/to/a",
b: "test/b/lib/path/to/b"
},
shim: {
b: { "exports": "someExport" },
c: { "exports": "someOtherExport" }
}
});
});
});
}
);