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

Plugins do tests work #11

Open
wants to merge 19 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
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Hello world!
= Spinnaker UI

image::https://api.travis-ci.org/spinnaker/deck.svg?branch=master["Build Status", link="https://travis-ci.org/spinnaker/deck"]
Expand Down
2 changes: 1 addition & 1 deletion app/index.deck
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html class="no-js" ng-app="netflix.spinnaker">
<html class="no-js" >
<head>
<title>Spinnaker</title>
<meta charset="utf-8">
Expand Down
39 changes: 23 additions & 16 deletions app/scripts/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'jquery'; // ensures jQuery is loaded before Angular so Angular does not use jqlite
import { module } from 'angular';
import { initPlugins } from './plugin-loader';

import { CORE_MODULE } from '@spinnaker/core';
import { DOCKER_MODULE } from '@spinnaker/docker';
Expand All @@ -15,19 +16,25 @@ import { ECS_MODULE } from '@spinnaker/ecs';
import '@spinnaker/cloudfoundry';
import { AZURE_MODULE } from '@spinnaker/azure';

module('netflix.spinnaker', [
CORE_MODULE,
AMAZON_MODULE,
GOOGLE_MODULE,
ECS_MODULE,
AZURE_MODULE,
KUBERNETES_V1_MODULE,
DOCKER_MODULE,
ORACLE_MODULE,
require('./modules/dcos/dcos.module').name,
APPENGINE_MODULE,
CANARY_MODULE,
KUBERNETES_V2_MODULE,
KAYENTA_MODULE,
TITUS_MODULE,
]);
initPlugins()
.catch(() => {
//TODO use CustomBanner to tell the user that plugin(s) have not been loaded
})
.finally(() => {
module('netflix.spinnaker', [
CORE_MODULE,
AMAZON_MODULE,
GOOGLE_MODULE,
ECS_MODULE,
AZURE_MODULE,
KUBERNETES_V1_MODULE,
DOCKER_MODULE,
ORACLE_MODULE,
require('./modules/dcos/dcos.module').name,
APPENGINE_MODULE,
CANARY_MODULE,
KUBERNETES_V2_MODULE,
KAYENTA_MODULE,
TITUS_MODULE,
]);
});
5 changes: 5 additions & 0 deletions app/scripts/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { bootstrap, element } from 'angular';

element(document.documentElement).ready(() => {
bootstrap(document.documentElement, ['netflix.spinnaker']);
});
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface ISpinnakerSettings {
providers?: {
[key: string]: IProviderSettings; // allows custom providers not typed in here (good for testing too)
};
plugins: Array<{ name: string; location: string }>;
pubsubProviders: string[];
quietPeriod: [string | number, string | number];
resetProvider: (provider: string) => () => void;
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/modules/plugins/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions app/scripts/modules/plugins/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@spinnaker/plugins",
"version": "0.0.1",
"main": "lib/lib.js",
"types": "lib/plugins.d.ts",
"scripts": {
"clean": "../../../../node_modules/rimraf/bin.js lib",
"lib": "npm run clean && ../../../../node_modules/typescript/bin/tsc && node ../../../../node_modules/webpack/bin/webpack.js",
"prepublishOnly": "npm run lib"
}
}
2 changes: 2 additions & 0 deletions app/scripts/modules/plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-ignore
export * from './plugins';
1 change: 1 addition & 0 deletions app/scripts/modules/plugins/src/plugins.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@spinnaker/plugins';
13 changes: 13 additions & 0 deletions app/scripts/modules/plugins/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PipelineRegistry } from '@spinnaker/core';

export type IPluginInitialize = (registry: IStageRegistry) => void;

export interface IStageRegistry {
pipeline: PipelineRegistry;
}

declare global {
interface Window {
spinnakerSettings: any;
}
}
38 changes: 38 additions & 0 deletions app/scripts/modules/plugins/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"buildOnSave": false,
"compileOnSave": true,
"compilerOptions": {
"allowJs": false,
"baseUrl": "./src",
"declaration": true,
"declarationDir": "lib",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"jsx": "react",
"lib": ["es2016", "dom"],
"moduleResolution": "node",
"module": "esnext",
"noEmitHelpers": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": false, // should really get to a place where we can turn this on
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "lib",
"pretty": true,
"removeComments": false,
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": true,
"inlineSources": true,
"strictNullChecks": false, // should really get to a place where we can turn this on
"target": "es6",
"typeRoots": ["../../../../node_modules/@types"],
"paths": {
"@spinnaker/core": ["../../core/lib"],
"core/*": ["core/src/*"]
}
},
"files": ["src/index.ts"],
"exclude": ["./lib", "**/*.spec.*"]
}
114 changes: 114 additions & 0 deletions app/scripts/modules/plugins/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

const path = require('path');
const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

const WATCH = process.env.WATCH === 'true';
const WEBPACK_MODE = WATCH ? 'development' : 'production';
const IS_PRODUCTION = WEBPACK_MODE === 'production';

module.exports = {
context: basePath,
mode: WEBPACK_MODE,
stats: 'minimal',
watch: WATCH,
entry: {
lib: path.join(__dirname, 'src', 'index.ts'),
},
output: {
path: path.join(__dirname, 'lib'),
filename: '[name].js',
library: '@spinnaker/plugins',
libraryTarget: 'umd',
umdNamedDefine: true,
},
devtool: 'source-map',
optimization: {
minimizer: IS_PRODUCTION
? [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
},
resolve: {
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.css', '.less', '.html'],
modules: [NODE_MODULE_PATH, path.resolve('.')],
alias: {
'@spinnaker/plugins': path.join(__dirname, 'src'),
plugins: path.join(__dirname, 'src'),
},
},
module: {
rules: [
{
test: /\.js$/,
use: [
{ loader: 'cache-loader' },
{ loader: 'thread-loader', options: { workers: WEBPACK_THREADS } },
{ loader: 'babel-loader' },
{ loader: 'envify-loader' },
{ loader: 'eslint-loader' },
],
exclude: exclusionPattern,
},
{
test: /\.tsx?$/,
use: [
{ loader: 'cache-loader' },
{ loader: 'thread-loader', options: { workers: WEBPACK_THREADS } },
{ loader: 'ts-loader', options: { happyPackMode: true } },
{ loader: 'tslint-loader' },
],
exclude: exclusionPattern,
},
{
test: /\.less$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'less-loader' },
],
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'postcss-loader' }],
},
{
test: /\.html$/,
exclude: exclusionPattern,
use: [
{ loader: 'ngtemplate-loader?relativeTo=' + path.resolve(__dirname) + '&prefix=plugins' },
{ loader: 'html-loader' },
],
},
{
test: /\.(woff|woff2|otf|ttf|eot|png|gif|ico|svg)$/,
use: [{ loader: 'file-loader', options: { name: '[name].[hash:5].[ext]' } }],
},
{
test: require.resolve('jquery'),
use: [{ loader: 'expose-loader?$' }, { loader: 'expose-loader?jQuery' }],
},
],
},
plugins: [new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true })],
externals: ['@spinnaker/core', nodeExternals({ modulesDir: '../../../../node_modules' })],
};
8 changes: 8 additions & 0 deletions app/scripts/modules/plugins/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@spinnaker/core@^0.0.406":
version "0.0.406"
resolved "https://registry.yarnpkg.com/@spinnaker/core/-/core-0.0.406.tgz#898f555a43b401f44561e8a742a92e51f128a476"
integrity sha512-NTqryXCEpYL8feO4hMZyBH70gVBfVabyJ4nChgmIC8PlZ/TMCN8rpGOtr9Q9g/tqgMUXRYiGWnNqxRS/g2Zs4g==
25 changes: 25 additions & 0 deletions app/scripts/plugin-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Registry } from '@spinnaker/core';

// This method appends the plugin script location to the bottom of
// the page to load the plugin
function loadPluginScript(plugin) {
return new Promise((resolve, reject) => {
var scriptTag = document.createElement('script');
scriptTag.src = plugin.location;
scriptTag.onload = () => resolve();
scriptTag.onreadystatechange = () => resolve();
scriptTag.onerror = () => reject();
document.body.appendChild(scriptTag);
});
}

// This method grabs all plugins that are defined in Spinnaker settings
// and then loops through all of them. It then calls the function above to
// appends a script tag to the page from where the plugin location and then
// initializes the plugin by passing in the registry for plugins to register
// themselves as stages
export function initPlugins() {
const plugins = window.spinnakerSettings.plugins;
window.spinnakerSettings.onPluginLoaded = plugin => plugin.initialize(Registry);
return Promise.all(plugins.map(p => loadPluginScript(p)));
}
1 change: 1 addition & 0 deletions halconfig/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ window.spinnakerSettings = {
},
},
pubsubProviders: ['google'], // TODO(joonlim): Add amazon once it is confirmed that amazon pub/sub works.
plugins: '{{%plugins%}}',
triggerTypes: [
'artifactory',
'nexus',
Expand Down
1 change: 1 addition & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ window.spinnakerSettings = {
required: false,
},
pubsubProviders: ['google'], // TODO(joonlim): Add amazon once it is confirmed that amazon pub/sub works.
plugins: [],
searchVersion: 1,
triggerTypes: [
'artifactory',
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"titus "
],
"indent": [true, "spaces"],
"interface-name": [false],
"jsx-no-lambda": false,
"jsx-no-multiline-js": false,
"label-position": true,
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function configure(env, webpackOpts) {
settings: SETTINGS_PATH,
'settings-local': './settings-local.js',
app: './app/scripts/app.ts',
bootstrap: './app/scripts/bootstrap.js',
},
output: {
path: path.join(__dirname, 'build', 'webpack', process.env.SPINNAKER_ENV || ''),
Expand Down