diff --git a/.gitignore b/.gitignore index 33858b136..4e98459ee 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-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/build/App.js b/build/App.js new file mode 100644 index 000000000..2cf63fcb4 --- /dev/null +++ b/build/App.js @@ -0,0 +1,10 @@ +import Transloadit from './core/Transloadit'; + +const transloadit = new Transloadit({wait: false}); +const files = transloadit + .use(DragDrop, {modal: true}) + .use(Tus10, {endpoint: 'http://master.tus.io:8080'}) + .run(); + +console.log('--> Finished transloadit. Final result: '); +console.dir(files); diff --git a/build/core/.empty b/build/core/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/core/Transloadit.js b/build/core/Transloadit.js new file mode 100644 index 000000000..fd525ffbb --- /dev/null +++ b/build/core/Transloadit.js @@ -0,0 +1,74 @@ +(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']; + +},{}]},{},[1]); diff --git a/build/core/Transloadit.scss b/build/core/Transloadit.scss new file mode 100644 index 000000000..a188fa2e1 --- /dev/null +++ b/build/core/Transloadit.scss @@ -0,0 +1,5 @@ +.transloadit-js-client { + font-family: "Comic Sans MS"; + color: purple; + border: 1px dashed pink; + font-size: 32px; } diff --git a/build/plugins/.empty b/build/plugins/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/plugins/DragDrop.js b/build/plugins/DragDrop.js new file mode 100644 index 000000000..de98fefdc --- /dev/null +++ b/build/plugins/DragDrop.js @@ -0,0 +1,86 @@ +(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":4}],3:[function(require,module,exports){ +'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']); + +},{"./TransloaditPlugin":4}],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; }; })(); + +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"]; + +},{}],5:[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":4}]},{},[1,2,3,4,5]); 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/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 5aceafe16..6d641d93e 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 '../../../../core'; +import { DragDrop, Tus10 } from '../../../../plugins'; const transloadit = new Transloadit({wait: false}); const files = transloadit diff --git a/package.json b/package.json index 5222bab8a..33ca6efa2 100644 --- a/package.json +++ b/package.json @@ -2,22 +2,25 @@ "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 build/*.js && rm -rf build/*.css", - "lint": "eslint src/js/lib/**/*.js", - "phantom-test": "zuul test/spec/upload.js --phantom", - "preview": "npm run watch & npm run browser-sync", + "clean": "rm -rf lib && rm -rf dist", + "lint": "eslint src/**/*.js", + "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", - "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", - "watch:examples": "examples/buildAll 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", @@ -30,6 +33,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/Transloadit.js b/src/core/Transloadit.js index 298387a32..3ee55c3f9 100644 --- a/src/core/Transloadit.js +++ b/src/core/Transloadit.js @@ -1,6 +1,6 @@ import async from 'async'; -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/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/index.js b/src/index.js new file mode 100644 index 000000000..f9defadf3 --- /dev/null +++ b/src/index.js @@ -0,0 +1,7 @@ +import Core from './core' +import plugins from './plugins' + +export default { + Core, + plugins +} diff --git a/src/plugins/index.js b/src/plugins/index.js new file mode 100644 index 000000000..9275e9ba5 --- /dev/null +++ b/src/plugins/index.js @@ -0,0 +1,9 @@ +import DragDrop from './DragDrop' +import TransloaditBasic from './TransloaditBasic' +import Tus10 from './Tus10' + +export default { + DragDrop, + TransloaditBasic, + Tus10 +} diff --git a/build/.empty b/src/scss/index.scss similarity index 100% rename from build/.empty rename to src/scss/index.scss