From e3e17996838029cebfd5e7d7a0df351997b8ac4a Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Tue, 24 Nov 2015 11:47:56 -0500 Subject: [PATCH 1/8] Refactoring build system --- Transloadit.js | 1 + build.js | 236 ++++++++++++++++++++++++++++++ build/core/.empty | 0 build/plugins/.empty | 0 examples/playground/package.json | 2 +- examples/playground/src/js/app.js | 5 +- lib/core/Transloadit.js | 71 +++++++++ lib/core/index.js | 14 ++ lib/plugins/DragDrop.js | 46 ++++++ lib/plugins/TransloaditBasic.js | 27 ++++ lib/plugins/TransloaditPlugin.js | 35 +++++ lib/plugins/Tus10.js | 52 +++++++ lib/plugins/index.js | 25 ++++ package.json | 6 +- plugins.js | 1 + src/core/index.js | 1 + src/plugins/index.js | 3 + 17 files changed, 519 insertions(+), 6 deletions(-) create mode 100644 Transloadit.js create mode 100644 build.js delete mode 100644 build/core/.empty delete mode 100644 build/plugins/.empty create mode 100644 lib/core/Transloadit.js create mode 100644 lib/core/index.js create mode 100644 lib/plugins/DragDrop.js create mode 100644 lib/plugins/TransloaditBasic.js create mode 100644 lib/plugins/TransloaditPlugin.js create mode 100644 lib/plugins/Tus10.js create mode 100644 lib/plugins/index.js create mode 100644 plugins.js create mode 100644 src/core/index.js create mode 100644 src/plugins/index.js diff --git a/Transloadit.js b/Transloadit.js new file mode 100644 index 000000000..05801e8f1 --- /dev/null +++ b/Transloadit.js @@ -0,0 +1 @@ +module.exports = require('./lib/core'); diff --git a/build.js b/build.js new file mode 100644 index 000000000..07a80848a --- /dev/null +++ b/build.js @@ -0,0 +1,236 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Now running ' + plugin.type + ' plugin ' + plugin.name + ': '); + files = plugin.run(files); + console.dir(files); + console.log(''); + } + } + + // core.run is the final step and retuns the results (vs every other method, returning `this`) + // for chainability + return files; + } + }]); + + return Transloadit; +})(); + +exports['default'] = Transloadit; +module.exports = exports['default']; + +},{}],2:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _pluginsTransloaditPlugin = require('../plugins/TransloaditPlugin'); + +var _pluginsTransloaditPlugin2 = _interopRequireDefault(_pluginsTransloaditPlugin); + +var DragDrop = (function (_TransloaditPlugin) { + _inherits(DragDrop, _TransloaditPlugin); + + function DragDrop(core, opts) { + _classCallCheck(this, DragDrop); + + _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts); + this.type = 'selecter'; + } + + _createClass(DragDrop, [{ + key: 'run', + value: function run(files) { + this.core.setProgress(this, 0); + var selected = [{ name: 'lolcat.jpeg' }]; + this.core.setProgress(this, 100); + + return selected; + } + }]); + + return DragDrop; +})(_pluginsTransloaditPlugin2['default']); + +exports['default'] = DragDrop; +module.exports = exports['default']; + +},{"../plugins/TransloaditPlugin":3}],3:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var TransloaditPlugin = (function () { + // This contains boilerplate that all TransloaditPlugins share - and should not be used + // directly. It also shows which methods final plugins should implement/override, + // this deciding on structure. + + function TransloaditPlugin(core, opts) { + _classCallCheck(this, TransloaditPlugin); + + this.core = core; + this.opts = opts; + this.name = this.constructor.name; + } + + _createClass(TransloaditPlugin, [{ + key: "run", + value: function run(files) { + return files; + } + }]); + + return TransloaditPlugin; +})(); + +exports["default"] = TransloaditPlugin; +module.exports = exports["default"]; + +},{}],4:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _TransloaditPlugin2 = require('./TransloaditPlugin'); + +var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); + +var Tus10 = (function (_TransloaditPlugin) { + _inherits(Tus10, _TransloaditPlugin); + + function Tus10(core, opts) { + _classCallCheck(this, Tus10); + + _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts); + this.type = 'uploader'; + } + + _createClass(Tus10, [{ + key: 'run', + value: function run(files) { + this.core.setProgress(this, 0); + var uploaded = []; + for (var i in files) { + var file = files[i]; + this.core.setProgress(this, i * 1 + 1); + uploaded[i] = file; + uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name; + } + this.core.setProgress(this, 100); + + return uploaded; + } + }]); + + return Tus10; +})(_TransloaditPlugin3['default']); + +exports['default'] = Tus10; +module.exports = exports['default']; + +},{"./TransloaditPlugin":3}],5:[function(require,module,exports){ +'use strict'; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _srcCoreTransloadit = require('./src/core/Transloadit'); + +var _srcCoreTransloadit2 = _interopRequireDefault(_srcCoreTransloadit); + +var _srcPluginsDragDrop = require('./src/plugins/DragDrop'); + +var _srcPluginsDragDrop2 = _interopRequireDefault(_srcPluginsDragDrop); + +var _srcPluginsTus10 = require('./src/plugins/Tus10'); + +var _srcPluginsTus102 = _interopRequireDefault(_srcPluginsTus10); + +var transloadit = new _srcCoreTransloadit2['default']({ wait: false }); +var files = transloadit.use(_srcPluginsDragDrop2['default'], { modal: true }).use(_srcPluginsTus102['default'], { endpoint: 'http://master.tus.io:8080' }).run(); + +console.log('--> Finished transloadit. Final result: '); +console.dir(files); + +},{"./src/core/Transloadit":1,"./src/plugins/DragDrop":2,"./src/plugins/Tus10":4}]},{},[5]); diff --git a/build/core/.empty b/build/core/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/plugins/.empty b/build/plugins/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/playground/package.json b/examples/playground/package.json index 611f20b9c..2c23e3caa 100644 --- a/examples/playground/package.json +++ b/examples/playground/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "build": "../../node_modules/.bin/browserify src/js/app.js -o static/js/app.js", + "build": "../../node_modules/.bin/browserify src/js/app.js -o static/js/app.js -t [ babelify ]", "watch": "../../node_modules/.bin/watchify src/js/app.js -o static/js/app.js", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/examples/playground/src/js/app.js b/examples/playground/src/js/app.js index b80495264..4e4d32d0c 100644 --- a/examples/playground/src/js/app.js +++ b/examples/playground/src/js/app.js @@ -1,6 +1,5 @@ -import Transloadit from '../../../../src/core/Transloadit'; -import DragDrop from '../../../../src/plugins/DragDrop'; -import Tus10 from '../../../../src/plugins/Tus10'; +import Transloadit from '../../../../Transloadit'; +import { DragDrop, Tus10 } from '../../../../plugins'; const transloadit = new Transloadit({wait: false}); const files = transloadit diff --git a/lib/core/Transloadit.js b/lib/core/Transloadit.js new file mode 100644 index 000000000..ccc70776c --- /dev/null +++ b/lib/core/Transloadit.js @@ -0,0 +1,71 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +var Transloadit = (function () { + function Transloadit(opts) { + _classCallCheck(this, Transloadit); + + // Dictates in what order different plugin types are ran: + this.types = ['presetter', 'selecter', 'uploader']; + + // Container for different types of plugins + this.plugins = {}; + } + + _createClass(Transloadit, [{ + key: 'use', + value: function use(Plugin, opts) { + // Instantiate + var plugin = new Plugin(this, opts); + + // Save in plugin container + if (!this.plugins[plugin.type]) { + this.plugins[plugin.type] = []; + } + this.plugins[plugin.type].push(plugin); + + return this; + } + }, { + key: 'setProgress', + value: function setProgress(plugin, percentage) { + // Any plugin can call this via `this.core.setProgress(this, precentage)` + console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage); + + return this; + } + }, { + key: 'run', + value: function run() { + // Walk over plugins in the order as defined by this.types. + var files = []; + for (var j in this.types) { + var type = this.types[j]; + // Walk over all plugins of this type, passing & modifying the files array as we go + for (var i in this.plugins[type]) { + var plugin = this.plugins[type][i]; + console.log('--> Now running ' + plugin.type + ' plugin ' + plugin.name + ': '); + files = plugin.run(files); + console.dir(files); + console.log(''); + } + } + + // core.run is the final step and retuns the results (vs every other method, returning `this`) + // for chainability + return files; + } + }]); + + return Transloadit; +})(); + +exports['default'] = Transloadit; +module.exports = exports['default']; \ No newline at end of file diff --git a/lib/core/index.js b/lib/core/index.js new file mode 100644 index 000000000..39404ca3b --- /dev/null +++ b/lib/core/index.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _TransloaditJs = require('./Transloadit.js'); + +var _TransloaditJs2 = _interopRequireDefault(_TransloaditJs); + +exports['default'] = _TransloaditJs2['default']; +module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/DragDrop.js b/lib/plugins/DragDrop.js new file mode 100644 index 000000000..76cb8168e --- /dev/null +++ b/lib/plugins/DragDrop.js @@ -0,0 +1,46 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _pluginsTransloaditPlugin = require('../plugins/TransloaditPlugin'); + +var _pluginsTransloaditPlugin2 = _interopRequireDefault(_pluginsTransloaditPlugin); + +var DragDrop = (function (_TransloaditPlugin) { + _inherits(DragDrop, _TransloaditPlugin); + + function DragDrop(core, opts) { + _classCallCheck(this, DragDrop); + + _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts); + this.type = 'selecter'; + } + + _createClass(DragDrop, [{ + key: 'run', + value: function run(files) { + this.core.setProgress(this, 0); + var selected = [{ name: 'lolcat.jpeg' }]; + this.core.setProgress(this, 100); + + return selected; + } + }]); + + return DragDrop; +})(_pluginsTransloaditPlugin2['default']); + +exports['default'] = DragDrop; +module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/TransloaditBasic.js b/lib/plugins/TransloaditBasic.js new file mode 100644 index 000000000..0b2274626 --- /dev/null +++ b/lib/plugins/TransloaditBasic.js @@ -0,0 +1,27 @@ +'use strict'; + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _TransloaditPlugin2 = require('./TransloaditPlugin'); + +var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); + +var TransloaditBasic = (function (_TransloaditPlugin) { + _inherits(TransloaditBasic, _TransloaditPlugin); + + function TransloaditBasic(core, opts) { + _classCallCheck(this, TransloaditBasic); + + _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts); + this.type = 'presetter'; + this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' }); + } + + return TransloaditBasic; +})(_TransloaditPlugin3['default']); \ No newline at end of file diff --git a/lib/plugins/TransloaditPlugin.js b/lib/plugins/TransloaditPlugin.js new file mode 100644 index 000000000..1a03a750c --- /dev/null +++ b/lib/plugins/TransloaditPlugin.js @@ -0,0 +1,35 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var TransloaditPlugin = (function () { + // This contains boilerplate that all TransloaditPlugins share - and should not be used + // directly. It also shows which methods final plugins should implement/override, + // this deciding on structure. + + function TransloaditPlugin(core, opts) { + _classCallCheck(this, TransloaditPlugin); + + this.core = core; + this.opts = opts; + this.name = this.constructor.name; + } + + _createClass(TransloaditPlugin, [{ + key: "run", + value: function run(files) { + return files; + } + }]); + + return TransloaditPlugin; +})(); + +exports["default"] = TransloaditPlugin; +module.exports = exports["default"]; \ No newline at end of file diff --git a/lib/plugins/Tus10.js b/lib/plugins/Tus10.js new file mode 100644 index 000000000..e0d55377f --- /dev/null +++ b/lib/plugins/Tus10.js @@ -0,0 +1,52 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _TransloaditPlugin2 = require('./TransloaditPlugin'); + +var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); + +var Tus10 = (function (_TransloaditPlugin) { + _inherits(Tus10, _TransloaditPlugin); + + function Tus10(core, opts) { + _classCallCheck(this, Tus10); + + _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts); + this.type = 'uploader'; + } + + _createClass(Tus10, [{ + key: 'run', + value: function run(files) { + this.core.setProgress(this, 0); + var uploaded = []; + for (var i in files) { + var file = files[i]; + this.core.setProgress(this, i * 1 + 1); + uploaded[i] = file; + uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name; + } + this.core.setProgress(this, 100); + + return uploaded; + } + }]); + + return Tus10; +})(_TransloaditPlugin3['default']); + +exports['default'] = Tus10; +module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/index.js b/lib/plugins/index.js new file mode 100644 index 000000000..948b68555 --- /dev/null +++ b/lib/plugins/index.js @@ -0,0 +1,25 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _DragDrop2 = require('./DragDrop'); + +var _DragDrop3 = _interopRequireDefault(_DragDrop2); + +exports.DragDrop = _DragDrop3['default']; + +var _TransloaditBasic2 = require('./TransloaditBasic'); + +var _TransloaditBasic3 = _interopRequireDefault(_TransloaditBasic2); + +exports.TransloaditBasic = _TransloaditBasic3['default']; + +var _Tus102 = require('./Tus10'); + +var _Tus103 = _interopRequireDefault(_Tus102); + +exports.Tus10 = _Tus103['default']; \ No newline at end of file diff --git a/package.json b/package.json index 845539c40..3f453a1b9 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "build": "npm run build:js && npm run build:css", "build:css": "bin/builder node_modules/.bin/node-sass", "build:js": "bin/builder node_modules/.bin/browserify", + "build:lib": "rm -rf ./lib && babel src -d lib --stage 0", "build:examples": "examples/buildAll node_modules/.bin/browserify", - "clean": "rm -rf build/*.js && rm -rf build/*.css", - "lint": "eslint src/js/lib/**/*.js", + "clean": "rm -rf lib/**/*.js && rm -rf lib/**/*.css", + "lint": "eslint src/**/*.js", "phantom-test": "zuul test/spec/upload.js --phantom", "preview": "npm run watch & npm run browser-sync", "test": "bin/test", @@ -29,6 +30,7 @@ }, "homepage": "https://github.com/transloadit/uppy#readme", "devDependencies": { + "babel": "^5.8.34", "babel-eslint": "^4.1.5", "babelify": "^6.4.0", "browser-sync": "^2.10.0", diff --git a/plugins.js b/plugins.js new file mode 100644 index 000000000..a94e316be --- /dev/null +++ b/plugins.js @@ -0,0 +1 @@ +module.exports = require('./lib/plugins') diff --git a/src/core/index.js b/src/core/index.js new file mode 100644 index 000000000..b0bbca90b --- /dev/null +++ b/src/core/index.js @@ -0,0 +1 @@ +export default from './Transloadit.js' diff --git a/src/plugins/index.js b/src/plugins/index.js new file mode 100644 index 000000000..b1ed1188c --- /dev/null +++ b/src/plugins/index.js @@ -0,0 +1,3 @@ +export DragDrop from './DragDrop' +export TransloaditBasic from './TransloaditBasic' +export Tus10 from './Tus10' From df30cbe1fbdd4660ee6f375f879d070ec43316e2 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Wed, 25 Nov 2015 11:37:15 -0500 Subject: [PATCH 2/8] Add factory function to create new core. --- .gitignore | 1 + lib/core/Transloadit.js | 12 ++++++------ src/core/Transloadit.js | 2 +- src/create.js | 8 ++++++++ src/index.js | 15 +++++++++++++++ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/create.js create mode 100644 src/index.js diff --git a/.gitignore b/.gitignore index 33858b136..bb06bffab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ npm-debug.log node_modules build/ +lib/ examples/playground/static/js/app.js examples/playground/static/uppy/ diff --git a/lib/core/Transloadit.js b/lib/core/Transloadit.js index ccc70776c..93e31c6ca 100644 --- a/lib/core/Transloadit.js +++ b/lib/core/Transloadit.js @@ -8,9 +8,9 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } -var Transloadit = (function () { - function Transloadit(opts) { - _classCallCheck(this, Transloadit); +var _default = (function () { + function _default(opts) { + _classCallCheck(this, _default); // Dictates in what order different plugin types are ran: this.types = ['presetter', 'selecter', 'uploader']; @@ -19,7 +19,7 @@ var Transloadit = (function () { this.plugins = {}; } - _createClass(Transloadit, [{ + _createClass(_default, [{ key: 'use', value: function use(Plugin, opts) { // Instantiate @@ -64,8 +64,8 @@ var Transloadit = (function () { } }]); - return Transloadit; + return _default; })(); -exports['default'] = Transloadit; +exports['default'] = _default; module.exports = exports['default']; \ No newline at end of file diff --git a/src/core/Transloadit.js b/src/core/Transloadit.js index 8a12a9e66..b5de3794b 100644 --- a/src/core/Transloadit.js +++ b/src/core/Transloadit.js @@ -1,4 +1,4 @@ -export default class Transloadit { +export default class { constructor(opts) { // Dictates in what order different plugin types are ran: this.types = [ 'presetter', 'selecter', 'uploader' ]; diff --git a/src/create.js b/src/create.js new file mode 100644 index 000000000..b649b1365 --- /dev/null +++ b/src/create.js @@ -0,0 +1,8 @@ +import Core from './core' + +/** + * Factory function for creating a new + * instance of the core. + * @returns { object } new Core instance + */ +export default () => new Core() diff --git a/src/index.js b/src/index.js new file mode 100644 index 000000000..0e6f493af --- /dev/null +++ b/src/index.js @@ -0,0 +1,15 @@ +import Core from './core' +import { + DragDrop, + UppyBasic, + Tus10 +} from './plugins' + +import createUppy from './create' + +export default { + DragDrop, + TransloaditBasic, + Tus10, + createUppy +} From 3d50677fdd16a55bac2fb79307905a835fe910a0 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Wed, 25 Nov 2015 19:33:39 -0500 Subject: [PATCH 3/8] Removed lib and build file --- build.js | 236 ------------------------------- lib/core/Transloadit.js | 71 ---------- lib/core/index.js | 14 -- lib/plugins/DragDrop.js | 46 ------ lib/plugins/TransloaditBasic.js | 27 ---- lib/plugins/TransloaditPlugin.js | 35 ----- lib/plugins/Tus10.js | 52 ------- lib/plugins/index.js | 25 ---- 8 files changed, 506 deletions(-) delete mode 100644 build.js delete mode 100644 lib/core/Transloadit.js delete mode 100644 lib/core/index.js delete mode 100644 lib/plugins/DragDrop.js delete mode 100644 lib/plugins/TransloaditBasic.js delete mode 100644 lib/plugins/TransloaditPlugin.js delete mode 100644 lib/plugins/Tus10.js delete mode 100644 lib/plugins/index.js diff --git a/build.js b/build.js deleted file mode 100644 index 07a80848a..000000000 --- a/build.js +++ /dev/null @@ -1,236 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o Now running ' + plugin.type + ' plugin ' + plugin.name + ': '); - files = plugin.run(files); - console.dir(files); - console.log(''); - } - } - - // core.run is the final step and retuns the results (vs every other method, returning `this`) - // for chainability - return files; - } - }]); - - return Transloadit; -})(); - -exports['default'] = Transloadit; -module.exports = exports['default']; - -},{}],2:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var _pluginsTransloaditPlugin = require('../plugins/TransloaditPlugin'); - -var _pluginsTransloaditPlugin2 = _interopRequireDefault(_pluginsTransloaditPlugin); - -var DragDrop = (function (_TransloaditPlugin) { - _inherits(DragDrop, _TransloaditPlugin); - - function DragDrop(core, opts) { - _classCallCheck(this, DragDrop); - - _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts); - this.type = 'selecter'; - } - - _createClass(DragDrop, [{ - key: 'run', - value: function run(files) { - this.core.setProgress(this, 0); - var selected = [{ name: 'lolcat.jpeg' }]; - this.core.setProgress(this, 100); - - return selected; - } - }]); - - return DragDrop; -})(_pluginsTransloaditPlugin2['default']); - -exports['default'] = DragDrop; -module.exports = exports['default']; - -},{"../plugins/TransloaditPlugin":3}],3:[function(require,module,exports){ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var TransloaditPlugin = (function () { - // This contains boilerplate that all TransloaditPlugins share - and should not be used - // directly. It also shows which methods final plugins should implement/override, - // this deciding on structure. - - function TransloaditPlugin(core, opts) { - _classCallCheck(this, TransloaditPlugin); - - this.core = core; - this.opts = opts; - this.name = this.constructor.name; - } - - _createClass(TransloaditPlugin, [{ - key: "run", - value: function run(files) { - return files; - } - }]); - - return TransloaditPlugin; -})(); - -exports["default"] = TransloaditPlugin; -module.exports = exports["default"]; - -},{}],4:[function(require,module,exports){ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var _TransloaditPlugin2 = require('./TransloaditPlugin'); - -var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); - -var Tus10 = (function (_TransloaditPlugin) { - _inherits(Tus10, _TransloaditPlugin); - - function Tus10(core, opts) { - _classCallCheck(this, Tus10); - - _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts); - this.type = 'uploader'; - } - - _createClass(Tus10, [{ - key: 'run', - value: function run(files) { - this.core.setProgress(this, 0); - var uploaded = []; - for (var i in files) { - var file = files[i]; - this.core.setProgress(this, i * 1 + 1); - uploaded[i] = file; - uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name; - } - this.core.setProgress(this, 100); - - return uploaded; - } - }]); - - return Tus10; -})(_TransloaditPlugin3['default']); - -exports['default'] = Tus10; -module.exports = exports['default']; - -},{"./TransloaditPlugin":3}],5:[function(require,module,exports){ -'use strict'; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _srcCoreTransloadit = require('./src/core/Transloadit'); - -var _srcCoreTransloadit2 = _interopRequireDefault(_srcCoreTransloadit); - -var _srcPluginsDragDrop = require('./src/plugins/DragDrop'); - -var _srcPluginsDragDrop2 = _interopRequireDefault(_srcPluginsDragDrop); - -var _srcPluginsTus10 = require('./src/plugins/Tus10'); - -var _srcPluginsTus102 = _interopRequireDefault(_srcPluginsTus10); - -var transloadit = new _srcCoreTransloadit2['default']({ wait: false }); -var files = transloadit.use(_srcPluginsDragDrop2['default'], { modal: true }).use(_srcPluginsTus102['default'], { endpoint: 'http://master.tus.io:8080' }).run(); - -console.log('--> Finished transloadit. Final result: '); -console.dir(files); - -},{"./src/core/Transloadit":1,"./src/plugins/DragDrop":2,"./src/plugins/Tus10":4}]},{},[5]); diff --git a/lib/core/Transloadit.js b/lib/core/Transloadit.js deleted file mode 100644 index 93e31c6ca..000000000 --- a/lib/core/Transloadit.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -var _default = (function () { - function _default(opts) { - _classCallCheck(this, _default); - - // Dictates in what order different plugin types are ran: - this.types = ['presetter', 'selecter', 'uploader']; - - // Container for different types of plugins - this.plugins = {}; - } - - _createClass(_default, [{ - key: 'use', - value: function use(Plugin, opts) { - // Instantiate - var plugin = new Plugin(this, opts); - - // Save in plugin container - if (!this.plugins[plugin.type]) { - this.plugins[plugin.type] = []; - } - this.plugins[plugin.type].push(plugin); - - return this; - } - }, { - key: 'setProgress', - value: function setProgress(plugin, percentage) { - // Any plugin can call this via `this.core.setProgress(this, precentage)` - console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage); - - return this; - } - }, { - key: 'run', - value: function run() { - // Walk over plugins in the order as defined by this.types. - var files = []; - for (var j in this.types) { - var type = this.types[j]; - // Walk over all plugins of this type, passing & modifying the files array as we go - for (var i in this.plugins[type]) { - var plugin = this.plugins[type][i]; - console.log('--> Now running ' + plugin.type + ' plugin ' + plugin.name + ': '); - files = plugin.run(files); - console.dir(files); - console.log(''); - } - } - - // core.run is the final step and retuns the results (vs every other method, returning `this`) - // for chainability - return files; - } - }]); - - return _default; -})(); - -exports['default'] = _default; -module.exports = exports['default']; \ No newline at end of file diff --git a/lib/core/index.js b/lib/core/index.js deleted file mode 100644 index 39404ca3b..000000000 --- a/lib/core/index.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _TransloaditJs = require('./Transloadit.js'); - -var _TransloaditJs2 = _interopRequireDefault(_TransloaditJs); - -exports['default'] = _TransloaditJs2['default']; -module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/DragDrop.js b/lib/plugins/DragDrop.js deleted file mode 100644 index 76cb8168e..000000000 --- a/lib/plugins/DragDrop.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var _pluginsTransloaditPlugin = require('../plugins/TransloaditPlugin'); - -var _pluginsTransloaditPlugin2 = _interopRequireDefault(_pluginsTransloaditPlugin); - -var DragDrop = (function (_TransloaditPlugin) { - _inherits(DragDrop, _TransloaditPlugin); - - function DragDrop(core, opts) { - _classCallCheck(this, DragDrop); - - _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts); - this.type = 'selecter'; - } - - _createClass(DragDrop, [{ - key: 'run', - value: function run(files) { - this.core.setProgress(this, 0); - var selected = [{ name: 'lolcat.jpeg' }]; - this.core.setProgress(this, 100); - - return selected; - } - }]); - - return DragDrop; -})(_pluginsTransloaditPlugin2['default']); - -exports['default'] = DragDrop; -module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/TransloaditBasic.js b/lib/plugins/TransloaditBasic.js deleted file mode 100644 index 0b2274626..000000000 --- a/lib/plugins/TransloaditBasic.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var _TransloaditPlugin2 = require('./TransloaditPlugin'); - -var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); - -var TransloaditBasic = (function (_TransloaditPlugin) { - _inherits(TransloaditBasic, _TransloaditPlugin); - - function TransloaditBasic(core, opts) { - _classCallCheck(this, TransloaditBasic); - - _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts); - this.type = 'presetter'; - this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' }); - } - - return TransloaditBasic; -})(_TransloaditPlugin3['default']); \ No newline at end of file diff --git a/lib/plugins/TransloaditPlugin.js b/lib/plugins/TransloaditPlugin.js deleted file mode 100644 index 1a03a750c..000000000 --- a/lib/plugins/TransloaditPlugin.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var TransloaditPlugin = (function () { - // This contains boilerplate that all TransloaditPlugins share - and should not be used - // directly. It also shows which methods final plugins should implement/override, - // this deciding on structure. - - function TransloaditPlugin(core, opts) { - _classCallCheck(this, TransloaditPlugin); - - this.core = core; - this.opts = opts; - this.name = this.constructor.name; - } - - _createClass(TransloaditPlugin, [{ - key: "run", - value: function run(files) { - return files; - } - }]); - - return TransloaditPlugin; -})(); - -exports["default"] = TransloaditPlugin; -module.exports = exports["default"]; \ No newline at end of file diff --git a/lib/plugins/Tus10.js b/lib/plugins/Tus10.js deleted file mode 100644 index e0d55377f..000000000 --- a/lib/plugins/Tus10.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } - -function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var _TransloaditPlugin2 = require('./TransloaditPlugin'); - -var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2); - -var Tus10 = (function (_TransloaditPlugin) { - _inherits(Tus10, _TransloaditPlugin); - - function Tus10(core, opts) { - _classCallCheck(this, Tus10); - - _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts); - this.type = 'uploader'; - } - - _createClass(Tus10, [{ - key: 'run', - value: function run(files) { - this.core.setProgress(this, 0); - var uploaded = []; - for (var i in files) { - var file = files[i]; - this.core.setProgress(this, i * 1 + 1); - uploaded[i] = file; - uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name; - } - this.core.setProgress(this, 100); - - return uploaded; - } - }]); - - return Tus10; -})(_TransloaditPlugin3['default']); - -exports['default'] = Tus10; -module.exports = exports['default']; \ No newline at end of file diff --git a/lib/plugins/index.js b/lib/plugins/index.js deleted file mode 100644 index 948b68555..000000000 --- a/lib/plugins/index.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _DragDrop2 = require('./DragDrop'); - -var _DragDrop3 = _interopRequireDefault(_DragDrop2); - -exports.DragDrop = _DragDrop3['default']; - -var _TransloaditBasic2 = require('./TransloaditBasic'); - -var _TransloaditBasic3 = _interopRequireDefault(_TransloaditBasic2); - -exports.TransloaditBasic = _TransloaditBasic3['default']; - -var _Tus102 = require('./Tus10'); - -var _Tus103 = _interopRequireDefault(_Tus102); - -exports.Tus10 = _Tus103['default']; \ No newline at end of file From 40d50b58ecf20cfae2ae0a81a8a18234f6da3e44 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Wed, 25 Nov 2015 21:17:22 -0500 Subject: [PATCH 4/8] Modified build system. Added dist build script --- .gitignore | 2 +- bin/build | 15 +++++++++++++++ core.js | 1 + examples/playground/src/js/app.js | 2 +- index.js | 4 ++++ src/index.js | 11 ++++------- src/plugins/index.js | 12 +++++++++--- 7 files changed, 35 insertions(+), 12 deletions(-) create mode 100755 bin/build create mode 100644 core.js create mode 100644 index.js diff --git a/.gitignore b/.gitignore index bb06bffab..0a414ad91 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,8 @@ Thumbs.db npm-debug.log node_modules - build/ +dist/ lib/ examples/playground/static/js/app.js examples/playground/static/uppy/ diff --git a/bin/build b/bin/build new file mode 100755 index 000000000..e39fe9b48 --- /dev/null +++ b/bin/build @@ -0,0 +1,15 @@ +CORESRC="src/core/index.js" +COREDIST="dist/uppy.js" + +PLUGINSRC="src/plugins/index.js" +PLUGINDIST="dist/uppy-plugins.js" + +CORENAME="Uppy" +PLUGINNAME="UppyPlugin" + +TRANSFORMS="[ babelify ]" + +rm -rf dist +mkdir dist +browserify $CORESRC -o $COREDIST --standalone $CORENAME -t $TRANSFORMS +browserify $PLUGINSRC -o $PLUGINDIST --standalone $PLUGINNAME -t $TRANSFORMS diff --git a/core.js b/core.js new file mode 100644 index 000000000..bb58f6b3c --- /dev/null +++ b/core.js @@ -0,0 +1 @@ +module.exports = require('./lib/core') diff --git a/examples/playground/src/js/app.js b/examples/playground/src/js/app.js index 4e4d32d0c..cf46d7f1b 100644 --- a/examples/playground/src/js/app.js +++ b/examples/playground/src/js/app.js @@ -1,4 +1,4 @@ -import Transloadit from '../../../../Transloadit'; +import Transloadit from '../../../../core'; import { DragDrop, Tus10 } from '../../../../plugins'; const transloadit = new Transloadit({wait: false}); diff --git a/index.js b/index.js new file mode 100644 index 000000000..720b1bc63 --- /dev/null +++ b/index.js @@ -0,0 +1,4 @@ +module.exports = { + core: require('./core'), + plugins: require('./plugins') +} diff --git a/src/index.js b/src/index.js index 0e6f493af..5d1c82cf2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,12 @@ import Core from './core' import { DragDrop, - UppyBasic, + TransloaditBasic, Tus10 } from './plugins' import createUppy from './create' -export default { - DragDrop, - TransloaditBasic, - Tus10, - createUppy -} +var uppy = createUppy(); + +export default uppy diff --git a/src/plugins/index.js b/src/plugins/index.js index b1ed1188c..9275e9ba5 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -1,3 +1,9 @@ -export DragDrop from './DragDrop' -export TransloaditBasic from './TransloaditBasic' -export Tus10 from './Tus10' +import DragDrop from './DragDrop' +import TransloaditBasic from './TransloaditBasic' +import Tus10 from './Tus10' + +export default { + DragDrop, + TransloaditBasic, + Tus10 +} From 1f8cf50da8060dc915bbb37010c90d90819c0ee4 Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Fri, 27 Nov 2015 05:40:45 -0500 Subject: [PATCH 5/8] Updated build system --- Transloadit.js | 1 - bin/build | 15 ------- bin/build-css | 1 + bin/build-umd | 11 ++++++ bin/builder | 61 ----------------------------- core.js | 1 - index.js | 4 -- package.json | 24 ++++++------ plugins.js | 1 - src/create.js | 8 ---- src/index.js | 15 +++---- build/.empty => src/scss/index.scss | 0 12 files changed, 30 insertions(+), 112 deletions(-) delete mode 100644 Transloadit.js delete mode 100755 bin/build create mode 100755 bin/build-css create mode 100755 bin/build-umd delete mode 100755 bin/builder delete mode 100644 core.js delete mode 100644 index.js delete mode 100644 plugins.js delete mode 100644 src/create.js rename build/.empty => src/scss/index.scss (100%) diff --git a/Transloadit.js b/Transloadit.js deleted file mode 100644 index 05801e8f1..000000000 --- a/Transloadit.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/core'); diff --git a/bin/build b/bin/build deleted file mode 100755 index e39fe9b48..000000000 --- a/bin/build +++ /dev/null @@ -1,15 +0,0 @@ -CORESRC="src/core/index.js" -COREDIST="dist/uppy.js" - -PLUGINSRC="src/plugins/index.js" -PLUGINDIST="dist/uppy-plugins.js" - -CORENAME="Uppy" -PLUGINNAME="UppyPlugin" - -TRANSFORMS="[ babelify ]" - -rm -rf dist -mkdir dist -browserify $CORESRC -o $COREDIST --standalone $CORENAME -t $TRANSFORMS -browserify $PLUGINSRC -o $PLUGINDIST --standalone $PLUGINNAME -t $TRANSFORMS diff --git a/bin/build-css b/bin/build-css new file mode 100755 index 000000000..76368a4f4 --- /dev/null +++ b/bin/build-css @@ -0,0 +1 @@ +node_modules/.bin/node-sass src/scss/index.scss -o dist/uppy.css diff --git a/bin/build-umd b/bin/build-umd new file mode 100755 index 000000000..0fa656a72 --- /dev/null +++ b/bin/build-umd @@ -0,0 +1,11 @@ +SRC="src/index.js" +OUT="uppy.js" + +OUTDIR="dist" +TRANSFORMS="[ babelify ]" +FLAGS="-t [ babelify ] --standalone Uppy" + +rm -rf $OUTDIR +mkdir $OUTDIR + +browserify $SRC $FLAGS > $OUTDIR/$OUT diff --git a/bin/builder b/bin/builder deleted file mode 100755 index c9406138a..000000000 --- a/bin/builder +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -# Setup -####################################################### -transformations="[ babelify ]" -toolpath="${1:-node_modules/.bin/browserify}" -toolname="$(basename "${toolpath}")" - -if [ "${toolname}" = "node-sass" ]; then - srcExtension="scss" - dstExtension="css" -else - srcExtension="js" - dstExtension="js" -fi - -if [ "${toolname}" = "watchify" ]; then - extraArgs="-t ${transformations} --ignore-watch=**/build/** --verbose" -elif [ "${toolname}" = "browserify" ]; then - extraArgs="-t ${transformations} --ignore-watch=**/build/** --verbose" -else - extraArgs="" -fi - - -bundleTarget="build/uppy.${dstExtension}" - -# Individual files, built seperately -####################################################### -allSourceFiles="" -for src in $(find src -name "*.${srcExtension}" -type f); do - allSourceFiles="${allSourceFiles} ${src}" - dst="build/$(basename $(dirname ${src}))/$(basename ${src})" - echo "--> ${src} -> ${dst}" - - # Argument should be `browserify`, or `node-sass` - if [ "${toolname}" = "node-sass" ]; then - "${toolpath}" "${src}" "${dst}" ${extraArgs} - else - "${toolpath}" "${src}" -o "${dst}" ${extraArgs} - fi -done - -# All files in one bundle -####################################################### -echo "--> *.${srcExtension} -> ${bundleTarget}" -if [ "${toolname}" = "node-sass" ]; then - "${toolpath}" ${allSourceFiles} "${bundleTarget}" ${extraArgs} -else - "${toolpath}" ${allSourceFiles} -o "${bundleTarget}" ${extraArgs} -fi - -# Install into examples -for path in $(find examples -maxdepth 1 -mindepth 1 -type d); do - exampleProject="$(basename "${path}")" - rsync \ - -ai \ - --exclude='.DS_Store' \ - --exclude='.empty' \ - build/ "examples/${exampleProject}/static/uppy" -done diff --git a/core.js b/core.js deleted file mode 100644 index bb58f6b3c..000000000 --- a/core.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/core') diff --git a/index.js b/index.js deleted file mode 100644 index 720b1bc63..000000000 --- a/index.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - core: require('./core'), - plugins: require('./plugins') -} diff --git a/package.json b/package.json index 3f453a1b9..8350e9586 100644 --- a/package.json +++ b/package.json @@ -2,22 +2,24 @@ "name": "uppy", "version": "0.0.1", "description": "Almost as cute as a Puppy :dog:", - "main": "index.js", + "main": "src/index.js", "scripts": { - "browser-sync": "browser-sync start --config bs-config.js", - "build": "npm run build:js && npm run build:css", - "build:css": "bin/builder node_modules/.bin/node-sass", - "build:js": "bin/builder node_modules/.bin/browserify", + "build": "npm run build:lib && npm run build:umd && npm run build:umd:min && npm run build:css", + "build:css": "bin/build-css", "build:lib": "rm -rf ./lib && babel src -d lib --stage 0", + "build:umd": "./bin/build-umd", + "build:umd:min": "./bin/build-umd", "build:examples": "examples/buildAll node_modules/.bin/browserify", - "clean": "rm -rf lib/**/*.js && rm -rf lib/**/*.css", + "clean": "rm -rf lib && rm -rf dist", "lint": "eslint src/**/*.js", - "phantom-test": "zuul test/spec/upload.js --phantom", - "preview": "npm run watch & npm run browser-sync", + "preview": "npm run watch & npm run server", + "server": "browser-sync start --config bs-config.js", "test": "bin/test", - "watch": "npm run watch:css && npm run watch:js", - "watch:css": "nodemon -e scss -x \"npm run build:css\"", - "watch:js": "bin/builder node_modules/.bin/watchify" + "test:phantom": "zuul test/spec/upload.js --phantom", + "watch": "npm run watch:css & npm run watch:js", + "watch:css": "nodemon -e src/scss -x \"npm run build:css\"", + "watch:examples": "examples/buildAll node_modules/.bin/watchify & npm run watch:js", + "watch:js": "nodemon --watch src -e js --ignore src/scss -x \"npm run build:lib\"" }, "repository": { "type": "git", diff --git a/plugins.js b/plugins.js deleted file mode 100644 index a94e316be..000000000 --- a/plugins.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/plugins') diff --git a/src/create.js b/src/create.js deleted file mode 100644 index b649b1365..000000000 --- a/src/create.js +++ /dev/null @@ -1,8 +0,0 @@ -import Core from './core' - -/** - * Factory function for creating a new - * instance of the core. - * @returns { object } new Core instance - */ -export default () => new Core() diff --git a/src/index.js b/src/index.js index 5d1c82cf2..f9defadf3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,7 @@ import Core from './core' -import { - DragDrop, - TransloaditBasic, - Tus10 -} from './plugins' +import plugins from './plugins' -import createUppy from './create' - -var uppy = createUppy(); - -export default uppy +export default { + Core, + plugins +} diff --git a/build/.empty b/src/scss/index.scss similarity index 100% rename from build/.empty rename to src/scss/index.scss From afa382bdc9d8040ea32623c4b179918964e2d52c Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Fri, 27 Nov 2015 05:41:29 -0500 Subject: [PATCH 6/8] removed build/ from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0a414ad91..4e98459ee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ Thumbs.db npm-debug.log node_modules -build/ dist/ lib/ examples/playground/static/js/app.js From 5014604589ef803c078e387f7b8acb0e181c4e5f Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Fri, 27 Nov 2015 05:51:00 -0500 Subject: [PATCH 7/8] added root core/plugins indexes --- core.js | 1 + plugins.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 core.js create mode 100644 plugins.js diff --git a/core.js b/core.js new file mode 100644 index 000000000..bb58f6b3c --- /dev/null +++ b/core.js @@ -0,0 +1 @@ +module.exports = require('./lib/core') diff --git a/plugins.js b/plugins.js new file mode 100644 index 000000000..a94e316be --- /dev/null +++ b/plugins.js @@ -0,0 +1 @@ +module.exports = require('./lib/plugins') From 177210957ce634e01ba53b17928689e1096c96ce Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Fri, 27 Nov 2015 05:58:14 -0500 Subject: [PATCH 8/8] Added dev:examples --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8350e9586..c2672723d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "build:examples": "examples/buildAll node_modules/.bin/browserify", "clean": "rm -rf lib && rm -rf dist", "lint": "eslint src/**/*.js", - "preview": "npm run watch & npm run server", + "dev": "npm run watch & npm run server", + "dev:examples": "npm run watch & npm run server", "server": "browser-sync start --config bs-config.js", "test": "bin/test", "test:phantom": "zuul test/spec/upload.js --phantom",