From e7e79f41a73a4527f2e1a00c8b669efa4a750e3a Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 21 Jul 2015 14:24:17 -0700 Subject: [PATCH] [Packaging] Create NPM Package Create NPM package for OpenMCTWeb. Includes scripts for hosting, running tests, and building documentation. --- .gitignore | 1 - jsdoc.json | 10 +++++++++ karma.conf.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 33 ++++++++++++++++++++++++++++++ test-main.js | 40 ++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 jsdoc.json create mode 100644 karma.conf.js create mode 100644 package.json create mode 100644 test-main.js diff --git a/.gitignore b/.gitignore index 4c2c6ce8a0..3188d5fa38 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ closed-lib # Node dependencies node_modules - diff --git a/jsdoc.json b/jsdoc.json new file mode 100644 index 0000000000..ed0fddcf31 --- /dev/null +++ b/jsdoc.json @@ -0,0 +1,10 @@ +{ + "source": { + "include": [ + "example/", + "platform/" + ], + "includePattern": "(example|platform)/.+\\.js$", + "excludePattern": ".+\\Spec\\.js$|lib/.+" + } +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000000..b47841019e --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,56 @@ +module.exports = function(config) { + config.set({ + + // Base path that will be used to resolve all file patterns. + basePath: '', + + // Frameworks to use + // Available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine', 'requirejs'], + + // List of files / patterns to load in the browser. + // By default, files are also included in a script tag. + files: [ + '**/moment*', + {pattern: 'example/**/*.js', included: false}, + {pattern: 'platform/**/*.js', included: false}, + {pattern: 'warp/**/*.js', included: false}, + 'test-main.js' + ], + + // List of files to exclude. + exclude: [ + 'platform/framework/src/Main.js' + ], + + // Preprocess matching files before serving them to the browser. + // https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: {}, + + // Test results reporter to use + // Possible values: 'dots', 'progress' + // Available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // Web server port. + port: 9876, + + // Wnable / disable colors in the output (reporters and logs). + colors: true, + + logLevel: config.LOG_INFO, + + // Rerun tests when any file changes. + autoWatch: true, + + // Specify browsers to run tests in. + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [ + 'Chrome' + ], + + // Continuous Integration mode. + // If true, Karma captures browsers, runs the tests and exits. + singleRun: false + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000000..1216935f21 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "open-mct-web", + "version": "0.7.2", + "description": "The OpenMCTWeb core platform", + "dependencies": { + "express": "^4.13.1", + "minimist": "^1.1.1" + }, + "devDependencies": { + "jasmine-core": "^2.3.0", + "jsdoc": "^3.3.2", + "jshint": "^2.7.0", + "karma": "^0.12.31", + "karma-chrome-launcher": "^0.1.8", + "karma-cli": "0.0.4", + "karma-jasmine": "^0.1.5", + "karma-phantomjs-launcher": "^0.1.4", + "karma-requirejs": "^0.2.2", + "requirejs": "^2.1.17" + }, + "scripts": { + "start": "node app.js", + "test": "karma start --single-run", + "jshint": "jshint platform example || exit 0", + "jsdoc": "jsdoc -c jsdoc.json -r -d docs" + }, + "repository": { + "type": "git", + "url": "https://github.com/nasa/openmctweb.git" + }, + "author": "", + "license": "Apache-2.0" +} diff --git a/test-main.js b/test-main.js new file mode 100644 index 0000000000..d687656e68 --- /dev/null +++ b/test-main.js @@ -0,0 +1,40 @@ +var allTestFiles = []; +var TEST_REGEXP = /(Spec)\.js$/; + +var pathToModule = function(path) { + return path.replace(/^\/base\//, '').replace(/\.js$/, ''); +}; + +Object.keys(window.__karma__.files).forEach(function(file) { + if (TEST_REGEXP.test(file)) { + // Normalize paths to RequireJS module names. + allTestFiles.push(pathToModule(file)); + } +}); + +// We will be handling es6-promise loading with a shim. +allTestFiles.unshift('es6-promise'); + +require.config({ + // Karma serves files from the basePath defined in karma.conf.js + baseUrl: '/base', + + paths: { + 'es6-promise': 'platform/framework/lib/es6-promise-2.0.0.min', + 'moment-duration-format': 'warp/clock/lib/moment-duration-format' + }, + shim: { + 'es6-promise': { + init: function () { + console.log('I was inited!'); + window.Promise = window.Promise || ES6Promise.Promise; + } + } + }, + + // dynamically load all test files + deps: allTestFiles, + + // we have to kickoff jasmine, as it is asynchronous + callback: window.__karma__.start +});