From db6441c51510473c9fee90810baeb8966f7e3ad8 Mon Sep 17 00:00:00 2001 From: Mick McGrath Date: Wed, 27 May 2020 18:28:56 -0500 Subject: [PATCH] initial attempt at a standalone version using docker-compose --- .gitignore | 4 + Dockerfile | 27 +++++ docker-compose.yml | 13 +++ gulpfile.js | 2 +- tasks/browserify.js | 160 +++++++++++++++++++++++++++ tasks/build.js | 19 ++++ tasks/default.js | 19 ++++ tasks/font.js | 24 ++++ tasks/index.js | 23 ++++ tasks/lint.js | 25 +++++ tasks/package.json | 73 ++++++++++++ tasks/production/environment.js | 22 ++++ tasks/production/index.js | 28 +++++ tasks/production/package-metadata.js | 36 ++++++ tasks/production/scripts.js | 38 +++++++ tasks/production/serve.js | 31 ++++++ tasks/production/static.js | 23 ++++ tasks/production/styles.js | 31 ++++++ tasks/production/test.js | 49 ++++++++ tasks/serve.js | 50 +++++++++ tasks/settings.json | 48 ++++++++ tasks/test-functional.js | 50 +++++++++ tasks/test-unit.js | 34 ++++++ tasks/test.js | 22 ++++ tasks/watch.js | 23 ++++ 25 files changed, 873 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 tasks/browserify.js create mode 100644 tasks/build.js create mode 100644 tasks/default.js create mode 100644 tasks/font.js create mode 100644 tasks/index.js create mode 100644 tasks/lint.js create mode 100644 tasks/package.json create mode 100644 tasks/production/environment.js create mode 100644 tasks/production/index.js create mode 100644 tasks/production/package-metadata.js create mode 100644 tasks/production/scripts.js create mode 100644 tasks/production/serve.js create mode 100644 tasks/production/static.js create mode 100644 tasks/production/styles.js create mode 100644 tasks/production/test.js create mode 100644 tasks/serve.js create mode 100644 tasks/settings.json create mode 100644 tasks/test-functional.js create mode 100644 tasks/test-unit.js create mode 100644 tasks/test.js create mode 100644 tasks/watch.js diff --git a/.gitignore b/.gitignore index 9f008e09..0c40cabd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ build # VIM Swap .*.swp + + +# local stuff +config.local.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3e744db5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM node:10.15.3 + +# Create app directory +WORKDIR /opt/stackstorm/static/webui/st2flow + +# get files +COPY . . + +RUN cd /opt/stackstorm/static/webui && git clone https://github.com/StackStorm/st2web.git + +# install dependencies +RUN npm install -g gulp-cli lerna yarn +RUN cd /opt/stackstorm/static/webui/st2web && lerna bootstrap +RUN ls /opt/stackstorm/static/webui/st2web + + +RUN cd /opt/stackstorm/static/webui/st2flow && lerna bootstrap +RUN ls /opt/stackstorm/static/webui/st2flow + + + + +# expose your ports +EXPOSE 3000 + +# start it up +CMD [ "gulp" ] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..79a9733a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.2' +services: + app: + build: . + ports: + - "3000:3000" + expose: + - 3000 + volumes: + - .:/opt/stackstorm/static/webui/st2flow + - ./config.local.js:/opt/stackstorm/static/webui/st2web/config.js + - /opt/stackstorm/static/webui/st2flow/node_modules + - /opt/stackstorm/static/webui/st2web/node_modules diff --git a/gulpfile.js b/gulpfile.js index ab7c978c..462f137b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,4 +7,4 @@ /* jshint node: true */ 'use strict'; -require('@stackstorm/st2-build'); +require('./tasks'); diff --git a/tasks/browserify.js b/tasks/browserify.js new file mode 100644 index 00000000..5c1ad29b --- /dev/null +++ b/tasks/browserify.js @@ -0,0 +1,160 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); +const path = require('path'); +const fs = require('fs'); + +const _ = require('lodash'); +const git = require('git-rev-sync'); +const pkg = require(`${process.cwd()}/package.json`); +const es = require('event-stream'); +const browserify = require('browserify'); +const watchify = require('watchify'); +const source = require('vinyl-source-stream'); +const buffer = require('vinyl-buffer'); +const pathmodify = require('pathmodify'); +const cssExtract = require('css-extract'); +const chalk = require('chalk'); +const fancylog = require('fancy-log'); + +function buildHeader() { + const host = 'https://github.com/'; + const commitURL = `${host + pkg.repository}/commit/${git.long()}`; + + return `Built ${new Date().toISOString()} from ${commitURL}`; +} + +function walk(dir) { + const pkgPath = path.join(dir, 'package.json'); + if (fs.existsSync(pkgPath)) { + return require(pkgPath); + } + + const nextDir = path.dirname(dir); + + if (nextDir === dir) { + return false; + } + + return walk(nextDir); +} + +function overridePackage(overrides) { + return (rec) => { + const from = rec.id; + const to = overrides[from]; + + if (!to) { + return {}; + } + + const pkg = walk(path.dirname(rec.opts.filename)); + if (pkg && pkg.name === to) { + return { + id: from, + }; + } + + return { + id: to, + }; + }; +} + +function bundle(file, name) { + const customOpts = { + fullPaths: true, + entries: [ file ], + debug: true, + }; + const opts = _.assign({}, watchify.args, customOpts); + + const b = !global.watch ? browserify(opts) : watchify(browserify(opts), { poll: 100 }) + .on('update', () => { + bundle(file, name) + .pipe(plugins.size({ + showFiles: true, + })) + .pipe(plugins.size({ + showFiles: true, + gzip: true, + })) + ; + }); + + if (pkg.override) { + b + .plugin(pathmodify, { + mods: overridePackage(pkg.override), + }); + } + + fs.mkdir(settings.styles.dest, () => { /* noop */ }); + + b + .plugin(cssExtract, { out: path.join(settings.styles.dest, 'style.css')}) + .on('log', fancylog) + ; + + return b.bundle() + .on('error', function (error) { + fancylog( + chalk.cyan('Browserify') + chalk.red(' found unhandled error:\n'), + error.toString() + ); + this.emit('end'); + }) + .pipe(source(name)) + .pipe(buffer()) + .pipe(plugins.sourcemaps.init({ loadMaps: true })) + .pipe(plugins.header(`/* ${buildHeader()} */`)) + .pipe(plugins.sourcemaps.write('./')) + .pipe(gulp.dest('js/')) + ; +} + +gulp.task('browserify', () => { + const tasks = _.map(settings.modules, bundle); + + return es.merge.apply(null, tasks) + .pipe(plugins.size({ + showFiles: true, + })) + .pipe(plugins.size({ + showFiles: true, + gzip: true, + })) + ; +}); + +gulp.task('watchify', () => { + global.watch = true; + + const tasks = _.map(settings.modules, bundle); + + return es.merge.apply(null, tasks) + .pipe(plugins.size({ + showFiles: true, + })) + .pipe(plugins.size({ + showFiles: true, + gzip: true, + })) + ; +}); diff --git a/tasks/build.js b/tasks/build.js new file mode 100644 index 00000000..6738c04f --- /dev/null +++ b/tasks/build.js @@ -0,0 +1,19 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); + +gulp.task('build', gulp.series([ 'lint', 'browserify' ])); diff --git a/tasks/default.js b/tasks/default.js new file mode 100644 index 00000000..913e8db6 --- /dev/null +++ b/tasks/default.js @@ -0,0 +1,19 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); + +gulp.task('default', gulp.series([ 'lint', 'watch', 'serve' ])); diff --git a/tasks/font.js b/tasks/font.js new file mode 100644 index 00000000..98e98cde --- /dev/null +++ b/tasks/font.js @@ -0,0 +1,24 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const fontelloUpdate = require('fontello-update'); + +gulp.task('font', () => fontelloUpdate({ + config: 'fontello.json', + fonts: 'font', + css: 'font', +})); diff --git a/tasks/index.js b/tasks/index.js new file mode 100644 index 00000000..30b404c6 --- /dev/null +++ b/tasks/index.js @@ -0,0 +1,23 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const fwdRef = require('undertaker-forward-reference'); + +gulp.registry(fwdRef()); + +const requireDir = require('require-dir'); +module.exports = requireDir('./', { recurse: true }); diff --git a/tasks/lint.js b/tasks/lint.js new file mode 100644 index 00000000..41b578ae --- /dev/null +++ b/tasks/lint.js @@ -0,0 +1,25 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +gulp.task('lint', () => gulp.src(settings.lint, { cwd: settings.dev }) + .pipe(plugins.plumber()) + .pipe(plugins.eslint()) + .pipe(plugins.eslint.format()) +); diff --git a/tasks/package.json b/tasks/package.json new file mode 100644 index 00000000..b527d86f --- /dev/null +++ b/tasks/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stackstorm/st2-build", + "version": "2.4.3", + "description": "", + "main": "index.js", + "directories": { + "test": "tests" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": "stackstorm/st2web", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/stackstorm/st2web/issues" + }, + "homepage": "https://github.com/stackstorm/st2web#readme", + "browserify": { + "transform": [ + "babelify" + ] + }, + "publishConfig": { + "access": "public" + }, + "dependencies": { + "atob": "2.1.2", + "babelify": "10.0.0", + "cached-path-relative": "1.0.2", + "chalk": "2.4.2", + "cryptiles": "4.1.3", + "css-extract": "1.3.0", + "deep-extend": "0.6.0", + "event-stream": "4.0.1", + "express": "4.16.4", + "fancy-log": "1.3.3", + "fontello-update": "0.6.3", + "git-rev-sync": "1.12.0", + "growl": "1.10.5", + "gulp": "4.0.1", + "gulp-concat": "2.6.1", + "gulp-csscomb": "3.0.8", + "gulp-env": "0.4.0", + "gulp-eslint": "5.0.0", + "gulp-header": "2.0.7", + "gulp-load-plugins": "1.5.0", + "gulp-mocha": "6.0.0", + "gulp-plumber": "1.2.1", + "gulp-rename": "1.4.0", + "gulp-size": "3.0.0", + "gulp-sourcemaps": "2.6.5", + "gulp-uglify-es": "1.0.4", + "gulp-util": "3.0.8", + "gulp-webserver": "0.9.1", + "lodash": "4.17.11", + "mocha": "6.1.4", + "pathmodify": "0.5.0", + "react": "16.8.6", + "react-dom": "16.8.6", + "require-dir": "1.2.0", + "undertaker-forward-reference": "1.0.2", + "vinyl-buffer": "1.0.1", + "vinyl-source-stream": "2.0.0", + "watchify": "3.11.1", + "yargs": "13.2.2", + "zombie": "5.0.8" + }, + "peerDependencies": { + "gulp": "4.0.1", + "react": "16.8.6", + "react-dom": "16.8.6" + } +} diff --git a/tasks/production/environment.js b/tasks/production/environment.js new file mode 100644 index 00000000..50250fda --- /dev/null +++ b/tasks/production/environment.js @@ -0,0 +1,22 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); + +gulp.task('production-environment', (done) => { + process.env.NODE_ENV = 'production'; + done(); +}); diff --git a/tasks/production/index.js b/tasks/production/index.js new file mode 100644 index 00000000..ddb425b5 --- /dev/null +++ b/tasks/production/index.js @@ -0,0 +1,28 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const requireDir = require('require-dir'); + +module.exports = requireDir('./', { recurse: true }); + +gulp.task('production', gulp.series([ + 'production-environment', + 'production-scripts', + 'production-styles', + 'production-static', + 'production-package-metadata', +])); diff --git a/tasks/production/package-metadata.js b/tasks/production/package-metadata.js new file mode 100644 index 00000000..44dfd7dd --- /dev/null +++ b/tasks/production/package-metadata.js @@ -0,0 +1,36 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const child_process = require('child_process'); +const fs = require('fs'); +const path = require('path'); + +gulp.task('production-package-metadata', (done) => { + const circle_build_url = process.env.CIRCLE_BUILD_URL; + + const result = child_process.spawnSync('git', [ 'rev-parse', '--short', 'HEAD' ]); + const git_sha = result.stdout.toString().trim(); + + const pkg_version = require(path.resolve('./package.json')).st2_version; + + const data = `[st2web]\nversion = ${pkg_version}\ngit_sha = ${git_sha}\ncircle_build_url = ${circle_build_url}\n`; + + const file_path = path.join(path.resolve('./build'), 'package.meta'); + + fs.writeFileSync(file_path, data); + done(); +}); diff --git a/tasks/production/scripts.js b/tasks/production/scripts.js new file mode 100644 index 00000000..207e0647 --- /dev/null +++ b/tasks/production/scripts.js @@ -0,0 +1,38 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('../settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); +const uglify = require('gulp-uglify-es').default; + +gulp.task('production-scripts', gulp.series([ 'browserify' ], () => + gulp.src(settings.production.scripts, { base: '.' }) + .pipe(uglify({ + mangle: false, + compress: { + keep_fnames: true, + }, + })) + .pipe(gulp.dest(settings.production.dest)) + .pipe(plugins.size({ + showFiles: true, + })) + .pipe(plugins.size({ + showFiles: true, + gzip: true, + })) +)); diff --git a/tasks/production/serve.js b/tasks/production/serve.js new file mode 100644 index 00000000..8989dbd2 --- /dev/null +++ b/tasks/production/serve.js @@ -0,0 +1,31 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('../settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +let server; + +gulp.task('serve-production', gulp.series([ 'production' ], () => { + server = gulp.src('./build') + .pipe(plugins.webserver({ + host: '0.0.0.0', + port: 3000, + })); + + return server; +})); diff --git a/tasks/production/static.js b/tasks/production/static.js new file mode 100644 index 00000000..d82b5033 --- /dev/null +++ b/tasks/production/static.js @@ -0,0 +1,23 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('../settings.json'); + +gulp.task('production-static', () => + gulp.src(settings.production.static, { base: '.' }) + .pipe(gulp.dest(settings.production.dest)) +); diff --git a/tasks/production/styles.js b/tasks/production/styles.js new file mode 100644 index 00000000..79713390 --- /dev/null +++ b/tasks/production/styles.js @@ -0,0 +1,31 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('../settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +gulp.task('production-styles', () => + gulp.src(settings.production.styles, { base: '.' }) + .pipe(gulp.dest(settings.production.dest)) + .pipe(plugins.size({ + showFiles: true, + })) + .pipe(plugins.size({ + showFiles: true, + gzip: true, + })) +); diff --git a/tasks/production/test.js b/tasks/production/test.js new file mode 100644 index 00000000..22d6fb4a --- /dev/null +++ b/tasks/production/test.js @@ -0,0 +1,49 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('../settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +const argv = require('yargs').argv; + +gulp.task('test-production', gulp.series([ 'production' ], (done) => { + const server = gulp.src('.') + .pipe(plugins.webserver({ + host: '0.0.0.0', + port: 3002, + })); + + plugins.env({ + vars: { + PORT: 3002, + }, + }); + + return gulp.src(argv['test-files'] || settings.production.tests, { read: false }) + .pipe(plugins.plumber()) + .pipe(plugins.mocha({ + reporter: 'dot', + require: [ + '@babel/register', + ], + })) + .on('end', () => { + server.emit('kill'); + return done(); + }) + .on('error', (err) => done(err)); +})); diff --git a/tasks/serve.js b/tasks/serve.js new file mode 100644 index 00000000..58be7341 --- /dev/null +++ b/tasks/serve.js @@ -0,0 +1,50 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +let server; + +gulp.task('serve', () => { + const st2host = process.env.ST2_HOST || '127.0.0.1'; + const options = { + rejectUnauthorized: false, + }; + + server = gulp.src('.') + .pipe(plugins.webserver({ + host: '0.0.0.0', + port: process.env.PORT || 3000, + https: true, + proxies: [{ + source: '/api', + target: `https://${st2host}/api`, + options, + }, { + source: '/auth', + target: `https://${st2host}/auth`, + options, + }, { + source: '/stream', + target: `https://${st2host}/stream`, + options, + }], + })); + + return server; +}); diff --git a/tasks/settings.json b/tasks/settings.json new file mode 100644 index 00000000..a3d28698 --- /dev/null +++ b/tasks/settings.json @@ -0,0 +1,48 @@ +{ + "port": 3000, + "dev": ".", + "styles": { + "dest": "css" + }, + "modules": { + "main.js": "main.js" + }, + "html": "index.html", + "production": { + "dest": "build/", + "scripts": [ + "js/*.js" + ], + "static": [ + "index.html", + "img/*", + "font/*", + "static/*", + "config.js", + "favicon.ico" + ], + "styles": [ + "css/*.css" + ], + "tests": [ + "tests/**/test-*.js", + "!**/node_modules/**" + ] + }, + "lint": [ + "*.js", + "modules/**/*.js", + "apps/**/*.js", + "tasks/**/*.js", + "!**/node_modules/**" + ], + "tests": [ + "tests/**/test-*.js", + "!**/node_modules/**" + ], + "units": [ + "apps/**/test-*.js", + "modules/**/test-*.js", + "!**/node_modules/**" + ] +} diff --git a/tasks/test-functional.js b/tasks/test-functional.js new file mode 100644 index 00000000..f3cd827f --- /dev/null +++ b/tasks/test-functional.js @@ -0,0 +1,50 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +const argv = require('yargs').argv; + +gulp.task('test-functional', gulp.series([ 'build' ], (done) => { + const server = gulp.src('.') + .pipe(plugins.webserver({ + host: '0.0.0.0', + port: 3001, + })); + + plugins.env({ + vars: { + PORT: 3001, + }, + }); + + return gulp.src(argv['test-files'] || settings.tests, {read: false}) + .pipe(plugins.plumber()) + .pipe(plugins.mocha({ + reporter: 'spec', + require: [ + '@babel/register', + ], + })) + .on('end', () => { + server.emit('kill'); + return done(); + }) + .on('error', (err) => done(err)) + ; +})); diff --git a/tasks/test-unit.js b/tasks/test-unit.js new file mode 100644 index 00000000..62dee8e0 --- /dev/null +++ b/tasks/test-unit.js @@ -0,0 +1,34 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); +const plugins = require('gulp-load-plugins')(settings.plugins); + +const { argv } = require('yargs'); + +gulp.task('test-unit', (done) => gulp.src(argv['test-files'] || settings.units, {read: false}) + .pipe(plugins.plumber()) + .pipe(plugins.mocha({ + reporter: 'dot', + require: [ + '@babel/register', + 'ignore-styles', + ], + })) + .on('end', () => done()) + .on('error', (err) => done(err)) +); diff --git a/tasks/test.js b/tasks/test.js new file mode 100644 index 00000000..1b08ffa5 --- /dev/null +++ b/tasks/test.js @@ -0,0 +1,22 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); + +gulp.task('test', gulp.series([ + 'test-unit', + 'test-functional', +])); diff --git a/tasks/watch.js b/tasks/watch.js new file mode 100644 index 00000000..d9b76e5c --- /dev/null +++ b/tasks/watch.js @@ -0,0 +1,23 @@ +// Copyright 2019 Extreme Networks, Inc. +// +// 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. + +'use strict'; + +const gulp = require('gulp'); +const settings = require('./settings.json'); + +gulp.task('watch', gulp.series([ 'watchify' ], (done) => { + gulp.watch(settings.lint); + done(); +}));