Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] first pass at updating to work with ESM and split into 3 project types #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and Test

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * *' # Runs at 00:00 UTC every day

jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
directory:
- git-submodule
- npm-dependency
- peer-dependency
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies and run tests
run: |
cd ${{ matrix.directory }}
npm install
npm run build
npm test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
package-lock.json
**/node_modules
**/dist/
84 changes: 60 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,91 @@

# OpenMCT as a Dependency

This repository serves as an example to guide users on how to build, develop, and test Open MCT when it's used as a dependency.
This repository serves as a guide for using Open MCT as a dependency in your projects. It demonstrates how to build, develop, and test Open MCT in various scenarios.

Please refer to the following showcases for a comprehensive understanding:
**Note:** This guide is not intended for Open MCT beginners. Newcomers should start with the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial) to learn the basics through step-by-step instructions and common use cases.

## Table of Contents

- [Getting Started](#getting-started)
- [Integration Methods](#integration-methods)
- [Node Module Dependency](#1-node-module-dependency)
- [Git Submodule](#2-git-submodule)
- [Peer Dependency](#3-peer-dependency)
- [Testing](#testing)
- [Unit Tests](#unit-tests)
- [End-to-End (e2e) Tests](#end-to-end-e2e-tests)

- [openmct-yamcs](https://github.com/akhenry/openmct-yamcs)
- [openmct-mcws](https://github.com/NASA-AMMOS/openmct-mcws)

Please note, this is not the starting point for newcomers! To familiarize yourself with Open MCT, refer to the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). These tutorials provide step-by-step instructions to help you get started and also address common developer use cases.
## Getting Started

## Development
- **Development Guide:** For a detailed development guide, refer to [Developing Applications with Open MCT](https://github.com/nasa/openmct/blob/master/API.md#developing-applications-with-open-mct).

A comprehensive development guide is available [here](https://github.com/nasa/openmct/blob/master/API.md#developing-applications-with-open-mct).
## Integration Methods

## Building
This project showcases three methods to integrate OpenMCT into your build process, tailored to different development requirements:

There are two ways to specify OpenMCT in your build process:
### 1. Node Module Dependency

Ideal for scenarios where you wish to use OpenMCT as-is. The [/npm-dependency](./npm-dependency) directory contains an example setup.

- **Using npm:** Source OpenMCT from [npm](https://www.npmjs.com/package/openmct) with the `@stable` npm tag:

1. Node package hosted on npm:
This method is ideal if you do not plan to make any changes to the core OpenMCT project or if you are satisfied with using older/stable builds. Specify it in your package.json as follows:

```json
"dependencies": {
"openmct": "stable",
"openmct": "stable"
}
```
If you want to use a specific version, you can do it like this:

- **Specifying a Version:** To use a specific version of OpenMCT, adjust the dependency as follows:

```json
"dependencies": {
"openmct": "^2.2.5",
"openmct": "^2.2.5"
}
```
GitHub repo alias:
This method is suitable if you plan on using recent builds of OpenMCT or if you want to use pre-production versions.

- **Building from Source (Not Recommended):** This approach is suitable for using recent, untested builds or specific pre-production versions:

```json
"dependencies": {
"openmct": "nasa/openmct#master",
"openmct": "nasa/openmct#master"
}
```
For a comprehensive example, see:
- [openmct-mcws](https://github.com/NASA-AMMOS/openmct-mcws)


### 2. TODO Git Submodule

Useful for working with a specific version of OpenMCT, including forks with custom modifications. The [/git-submodule](./git-submodule) directory provides an example of this method.

### 3. TODO NPM Peer Dependency

If you are creating an openmct plugin which is designed to sit alongside openmct, you should use the peer dependency model. The [/peer-dependency](./peer-dependency) directory demonstrates this approach. For a comprehensive example, see:

- [openmct-yamcs](https://github.com/akhenry/openmct-yamcs)

```mermaid
graph TD;
parent-openmct -- extends --> openmct;
parent-openmct -- extends --> openmct-example-plugin;
openmct-example-plugin -- extends --> openmct;
...

## Testing
There are two approaches to testing with Open MCT as a dependency: unit tests and e2e (end-to-end) tests.

In both cases, it's essential to gather the devDependencies from the OpenMCT project to run the tests. Implement this with a build step to be executed just before your tests are run:
There are two primary approaches to testing when using Open MCT as a dependency: unit tests and end-to-end (e2e) tests. Before running tests, ensure to gather the `devDependencies` from the OpenMCT project with a build step:

```json
"build:example": "npm install openmct@unstable --no-save",
"build:example:master": "npm install nasa/openmct#master --no-save",
```

### Unit Tests as a Dependency
Open MCT unit tests are designed to be run with Karma and Jasmine.
### Unit Tests

As of 2024, the Karma and Jasmine frameworks used for Open MCT unit tests are deprecated.

### End-to-End (e2e) Tests

### e2e Tests as a Dependency
In addition to our unit test pattern, we also have an established e2e test-as-a-dependency model. It is widely used in both open-source and closed-source repositories. For a good open-source example, please refer to [openmct-yamcs](https://github.com/akhenry/openmct-yamcs/blob/master/tests/README.md)
Open MCT supports an e2e test-as-a-dependency model, widely used across both open-source and proprietary projects. For an example, refer to [openmct-yamcs](https://github.com/akhenry/openmct-yamcs/blob/master/tests/README.md).
11 changes: 0 additions & 11 deletions dist/index.html

This file was deleted.

2 changes: 0 additions & 2 deletions dist/main.js

This file was deleted.

105 changes: 0 additions & 105 deletions dist/main.js.LICENSE.txt

This file was deleted.

40 changes: 40 additions & 0 deletions npm-dependency/.webpack/webpack.common.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import path from 'path';
import { VueLoaderPlugin } from "vue-loader";
//import CopyWebpackPlugin from "copy-webpack-plugin";
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

/** @type {import('webpack').Configuration} */
const commonConfig = {
entry: './src/index.js',
devtool: 'source-map',
output: {
clean: true,
filename: '[name].js',
library: {
name: "[name]",
type: "umd",
},
path: path.resolve(new URL('.', import.meta.url).pathname, 'dist')
},
plugins: [
//Only necessary when using a vue open mct plugin
new VueLoaderPlugin()
],
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"]
}
],
}
};

export default commonConfig;
29 changes: 29 additions & 0 deletions npm-dependency/.webpack/webpack.dev.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from 'path';
import { fileURLToPath } from 'url';
import HtmlWebpackPlugin from "html-webpack-plugin";
import { merge } from 'webpack-merge';
import commonConfig from './webpack.common.mjs';

// Replicate __dirname functionality for ES modules
const __dirname = path.dirname(fileURLToPath(import.meta.url));

/** @type {import('webpack').Configuration} */
const devConfig = {
mode: 'development',
devtool: 'eval-source-map',
plugins: [
new HtmlWebpackPlugin({
template: "index.html",
}),
],
devServer: {
static: [
{directory: path.join(__dirname, "dist")},
{directory: path.join(__dirname, "node_modules/openmct/dist")}
],
compress: true,
port: 9000,
}
};

export default merge(commonConfig, devConfig);
31 changes: 31 additions & 0 deletions npm-dependency/.webpack/webpack.prod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2020, 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.
*****************************************************************************/

import { merge } from 'webpack-merge';
import common from './webpack.common.mjs';

/** @type {import('webpack').Configuration} */
const prodConfig = {
mode: 'production',
devtool: 'source-map'
}
export default merge(common, prodConfig);
Loading