diff --git a/.gitignore b/.gitignore index eb03e3e1..ca038566 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules *.log +ssl/*.pem diff --git a/Gulpfile.js b/Gulpfile.js index 385ee9ca..ddccbcb0 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -2,11 +2,21 @@ const babel = require('rollup-plugin-babel'); const eslint = require('gulp-eslint'); const gulp = require('gulp'); +const header = require('gulp-header'); const minify = require('uglify-js').minify; const rollup = require('rollup-stream'); const source = require('vinyl-source-stream'); const uglify = require('rollup-plugin-uglify'); +const pkg = require('./package.json'); +const banner = ['/**', + ' * <%= pkg.name %> - <%= pkg.description %>', + ' * @version v<%= pkg.version %>', + ' * @link <%= pkg.homepage %>', + ' * @license <%= pkg.license %>', + ' */', + ''].join('\n'); + gulp.task('build', () => rollup({ entry: './lib/postmate.js', @@ -20,6 +30,7 @@ gulp.task('build', () => ], }) .pipe(source('postmate.min.js')) + .pipe(header(banner, { pkg })) .pipe(gulp.dest('./build')) ); diff --git a/build/postmate.min.js b/build/postmate.min.js index 663e08b2..0cdbaad2 100644 --- a/build/postmate.min.js +++ b/build/postmate.min.js @@ -1 +1,7 @@ -!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.Postmate=n()}(this,function(){"use strict";function e(){var e;(e=console).log.apply(e,arguments)}function n(e){var n=document.createElement("a");return n.href=e,n.origin}function t(e,n){return e.origin===n&&("object"===r(e.data)&&("postmate"in e.data&&e.data.type===d))}function a(e,n,t){var a="function"==typeof e[n]?e[n](t):e[n];return Promise.resolve(a)}function i(n){var i=n.id,r=n.context,o=n.parent,s=n.parentOrigin,u=n.frame,c=n.child,h=n.childOrigin;return e('Registering consumer: "'+i+'"'),"parent"===i?(e("Parent awaiting messages..."),{frame:u,get:function(e,n){return new Promise(function(t){var a=(new Date).getTime(),i=function e(n){n.data.uid===a&&(o.removeEventListener("message",e,!1),t(n.data.value))};o.addEventListener("message",i,!1),c.postMessage({data:n,postmate:"request",type:d,key:e,uid:a},h)})}}):void("child"===i&&(e("Child awaiting messages..."),c.addEventListener("message",function(n){if(t(n,s)){e("Child received message",n.data);var i=n.data,o=i.data,u=i.key,c=i.uid;a(r,u,o).then(function(e){return n.source.postMessage({key:u,postmate:"reply",type:d,uid:c,value:e},n.origin)})}})))}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},o=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},s=function(){function e(e,n){for(var t=0;t express.static(path.join(__dirname, folder)); + +// Routes +app.use('/sandbox', staticPath('sandbox')); +app.use('/build', staticPath('build')); + +// http://blog.mgechev.com/2014/02/19/create-https-tls-ssl-application-with-express-nodejs/ +if (useSSL) { + https.createServer({ + key: fs.readFileSync(path.join(__dirname, 'ssl', 'key.pem')), + cert: fs.readFileSync(path.join(__dirname, 'ssl', 'cert.pem')), + }, app).listen(port, () => console.log(`Sandbox served at https://localhost:${port}`)); +} else { + app.listen(port, () => console.log(`Sandbox served at http://localhost:${port}`)); +} diff --git a/ssl/.gitkeep b/ssl/.gitkeep new file mode 100644 index 00000000..e69de29b