From 01330b0b780c092d7ff8b38d0c311387bd01d3ec Mon Sep 17 00:00:00 2001 From: Brian Runnells Date: Mon, 18 Jun 2018 08:35:43 -0500 Subject: [PATCH] Correctly export addon files (#179) --- README.md | 37 +++++++++++++++--------- addon/components.js | 2 -- addon/components/file-field.js | 8 +++-- addon/core.js | 29 ------------------- addon/index.js | 21 -------------- addon/uploaders.js | 7 ----- addon/uploaders/s3.js | 20 ++++++------- addon/uploaders/{base.js => uploader.js} | 25 ++++++++-------- app/components/file-field.js | 3 +- app/uploaders/s3.js | 1 + app/uploaders/uploader.js | 1 + generators/license.js | 6 ---- index.js | 8 +---- lib/version.js | 8 ----- package.json | 2 -- tests/unit/s3-test.js | 2 +- tests/unit/uploader-test.js | 4 +-- yarn.lock | 2 +- 18 files changed, 57 insertions(+), 129 deletions(-) delete mode 100644 addon/components.js delete mode 100644 addon/core.js delete mode 100644 addon/index.js delete mode 100644 addon/uploaders.js rename addon/uploaders/{base.js => uploader.js} (92%) create mode 100644 app/uploaders/s3.js create mode 100644 app/uploaders/uploader.js delete mode 100644 generators/license.js delete mode 100644 lib/version.js diff --git a/README.md b/README.md index da675d5..72369d1 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,12 @@ automatically give you an input field, and will set `files` property when you choose a file. ```js -import EmberUploader from 'ember-uploader'; +import FileField from 'ember-uploader/components/file-field'; +import Uploader from 'ember-uploader/uploaders/uploader'; -export default EmberUploader.FileField.extend({ +export default FileField.extend({ filesDidChange(files) { - const uploader = EmberUploader.Uploader.create({ + const uploader = Uploader.create({ url: this.get('url') }); @@ -44,7 +45,9 @@ By default, the request will be sent as `POST`. To override that, set `method` w creating the object: ```js -const uploader = EmberUploader.Uploader.create({ +import Uploader from 'ember-uploader/uploaders/uploader'; + +const uploader = Uploader.create({ url: '/upload', method: 'PUT' }); @@ -53,7 +56,9 @@ const uploader = EmberUploader.Uploader.create({ #### Change Namespace ```js -const uploader = EmberUploader.Uploader.create({ +import Uploader from 'ember-uploader/uploaders/uploader'; + +const uploader = Uploader.create({ paramNamespace: 'post' }); @@ -64,7 +69,9 @@ const uploader = EmberUploader.Uploader.create({ By default parameter will be `file` ```js -const upload = EmberUploader.Uploader.create({ +import Uploader from 'ember-uploader/uploaders/uploader'; + +const upload = Uploader.create({ paramName: 'upload' }); @@ -109,14 +116,15 @@ uploader.upload(file).then(data => { #### Multiple files ```js -import EmberUploader from 'ember-uploader'; +import FileField from 'ember-uploader/components/file-field'; +import Uploader from 'ember-uploader/uploaders/uploader'; -export default EmberUploader.FileField.extend({ +export default FileField.extend({ multiple: true, url: 'http://example.com/upload', filesDidChange(files) { - const uploader = EmberUploader.Uploader.create({ + const uploader = Uploader.create({ url: this.get('url') }); @@ -135,9 +143,9 @@ settings required by Ember Uploader. Here we modify the headers sent with the request. ```js -import EmberUploader from 'ember-uploader'; +import Uploader from 'ember-uploader/uploaders/uploader'; -export default EmberUploader.Uploader.extend({ +export default Uploader.extend({ ajaxSettings: { headers: { 'X-Application-Name': 'Uploader Test' @@ -156,13 +164,14 @@ able to make an authenticated request to S3. This step is required to avoid saving secret token on your client. ```js -import EmberUploader from 'ember-uploader'; +import FileField from 'ember-uploader/components/file-field'; +import Uploader from 'ember-uploader/uploaders/uploader'; -export default EmberUploader.FileField.extend({ +export default FileField.extend({ signingUrl: '', filesDidChange(files) { - const uploader = EmberUploader.S3Uploader.create({ + const uploader = S3Uploader.create({ signingUrl: this.get('signingUrl') }); diff --git a/addon/components.js b/addon/components.js deleted file mode 100644 index fc77393..0000000 --- a/addon/components.js +++ /dev/null @@ -1,2 +0,0 @@ -import FileField from 'ember-uploader/components/file-field'; -export { FileField }; diff --git a/addon/components/file-field.js b/addon/components/file-field.js index 2dd76a3..db4ef6c 100644 --- a/addon/components/file-field.js +++ b/addon/components/file-field.js @@ -1,6 +1,8 @@ -import Ember from 'ember'; +import { isEmpty } from '@ember/utils'; +import Evented from '@ember/object/evented'; +import Component from '@ember/component'; -export default Ember.Component.extend(Ember.Evented, { +export default Component.extend(Evented, { tagName: 'input', type: 'file', attributeBindings: [ @@ -16,7 +18,7 @@ export default Ember.Component.extend(Ember.Evented, { multiple: false, change (event) { const input = event.target; - if (!Ember.isEmpty(input.files)) { + if (!isEmpty(input.files)) { this.trigger('filesDidChange', input.files); } } diff --git a/addon/core.js b/addon/core.js deleted file mode 100644 index 67de89d..0000000 --- a/addon/core.js +++ /dev/null @@ -1,29 +0,0 @@ -import Ember from 'ember'; -import VERSION from 'ember-uploader/version'; - -/** - * @module ember-uploader - */ - -/** - * All Ember Uploader methods and functions are defined inside of this namespace. - * - * @class EmberUploader - * @static - */ - -/** - * @property VERSION - * @type string - * @static - */ - -const EmberUploader = Ember.Namespace.create({ - VERSION -}); - -if (Ember.libraries) { - Ember.libraries.registerCoreLibrary('Ember Uploader', EmberUploader.VERSION); -} - -export default EmberUploader; diff --git a/addon/index.js b/addon/index.js deleted file mode 100644 index 90c3b76..0000000 --- a/addon/index.js +++ /dev/null @@ -1,21 +0,0 @@ -import Ember from 'ember'; - -/** - Ember Uploader - @module ember-uploader - @main ember-uploader -*/ - -import EmberUploader from 'ember-uploader/core'; -import { Uploader, S3Uploader } from 'ember-uploader/uploaders'; - -EmberUploader.Uploader = Uploader; -EmberUploader.S3Uploader = S3Uploader; - -import { FileField } from 'ember-uploader/components'; - -EmberUploader.FileField = FileField; - -Ember.lookup.EmberUploader = EmberUploader; - -export default EmberUploader; diff --git a/addon/uploaders.js b/addon/uploaders.js deleted file mode 100644 index efb111c..0000000 --- a/addon/uploaders.js +++ /dev/null @@ -1,7 +0,0 @@ -import Uploader from 'ember-uploader/uploaders/base'; -import S3Uploader from 'ember-uploader/uploaders/s3'; - -export { - Uploader, - S3Uploader -}; diff --git a/addon/uploaders/s3.js b/addon/uploaders/s3.js index 3956c92..1ee63fe 100644 --- a/addon/uploaders/s3.js +++ b/addon/uploaders/s3.js @@ -1,11 +1,9 @@ -import Ember from 'ember'; -import Uploader from 'ember-uploader/uploaders/base'; - -const { - get, - set, - run -} = Ember; +import $ from 'jquery'; +import { Promise } from 'rsvp'; +import { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; +import Uploader from 'ember-uploader/uploaders/uploader'; +import { assign } from '@ember/polyfills'; export default Uploader.extend({ /** @@ -75,7 +73,7 @@ export default Uploader.extend({ extra.type = file.type; extra.size = file.size; - const settings = Ember.assign( + const settings = assign( {}, { contentType: 'application/json', @@ -89,7 +87,7 @@ export default Uploader.extend({ set(this, 'isSigning', true); - return new Ember.RSVP.Promise((resolve, reject) => { + return new Promise((resolve, reject) => { settings.success = (json) => { run(null, resolve, this.didSign(json)); }; @@ -98,7 +96,7 @@ export default Uploader.extend({ run(null, reject, this.didErrorOnSign(jqXHR, responseText, errorThrown)); }; - Ember.$.ajax(settings); + $.ajax(settings); }); }, diff --git a/addon/uploaders/base.js b/addon/uploaders/uploader.js similarity index 92% rename from addon/uploaders/base.js rename to addon/uploaders/uploader.js index 7e166cf..932062d 100644 --- a/addon/uploaders/base.js +++ b/addon/uploaders/uploader.js @@ -1,12 +1,11 @@ -import Ember from 'ember'; - -const { - get, - set, - run -} = Ember; - -export default Ember.Object.extend(Ember.Evented, { +import { Promise } from 'rsvp'; +import $ from 'jquery'; +import { assign } from '@ember/polyfills'; +import Evented from '@ember/object/evented'; +import EmberObject, { set, get } from '@ember/object'; +import { run } from '@ember/runloop'; + +export default EmberObject.extend(Evented, { /** * Target url to upload to * @@ -179,13 +178,13 @@ export default Ember.Object.extend(Ember.Evented, { * object */ ajax (url, data = {}, method = this.method) { - const ajaxSettings = Ember.assign( + const ajaxSettings = assign( {}, { contentType: false, processData: false, xhr: () => { - const xhr = Ember.$.ajaxSettings.xhr(); + const xhr = $.ajaxSettings.xhr(); xhr.upload.onprogress = (event) => { this.didProgress(event); }; @@ -210,7 +209,7 @@ export default Ember.Object.extend(Ember.Evented, { * @return {object} Returns a Ember.RSVP.Promise wrapping the ajax request */ ajaxPromise (settings) { - return new Ember.RSVP.Promise((resolve, reject) => { + return new Promise((resolve, reject) => { settings.success = (data) => { run(null, resolve, this.didUpload(data)); }; @@ -219,7 +218,7 @@ export default Ember.Object.extend(Ember.Evented, { run(null, reject, this.didError(jqXHR, responseText, errorThrown)); }; - Ember.$.ajax(settings); + $.ajax(settings); }); } }); diff --git a/app/components/file-field.js b/app/components/file-field.js index ce873e1..7fdd65d 100644 --- a/app/components/file-field.js +++ b/app/components/file-field.js @@ -1,2 +1 @@ -import FileField from 'ember-uploader/components/file-field'; -export default FileField; +export { default } from 'ember-uploader/components/file-field'; \ No newline at end of file diff --git a/app/uploaders/s3.js b/app/uploaders/s3.js new file mode 100644 index 0000000..ffea01b --- /dev/null +++ b/app/uploaders/s3.js @@ -0,0 +1 @@ +export { default } from 'ember-uploader/uploaders/s3'; diff --git a/app/uploaders/uploader.js b/app/uploaders/uploader.js new file mode 100644 index 0000000..be8e24f --- /dev/null +++ b/app/uploaders/uploader.js @@ -0,0 +1 @@ +export { default } from 'ember-uploader/uploaders/uploader'; diff --git a/generators/license.js b/generators/license.js deleted file mode 100644 index c140680..0000000 --- a/generators/license.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * @overview Ember Uploader - * @copyright Copyright 2013-2015 Benefitcloud and contributors. - * @license Licensed under MIT license (see license.js) - * @version VERSION_STRING_PLACEHOLDER - */ diff --git a/index.js b/index.js index 1afedb8..992e355 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,5 @@ 'use strict'; module.exports = { - name: 'ember-uploader', - treeForAddon: function(dir) { - let version = require('./lib/version'); - let merge = require('broccoli-merge-trees'); - - return this._super.treeForAddon.call(this, merge([version(), dir])); - } + name: 'ember-uploader' }; diff --git a/lib/version.js b/lib/version.js deleted file mode 100644 index 4d4f5fc..0000000 --- a/lib/version.js +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint-disable */ -var createFile = require('broccoli-file-creator'); -var version = require('../package.json').version; - -module.exports = function () { - return createFile('version.js', 'export default "' + version + '";'); -} -/* eslint-enable */ diff --git a/package.json b/package.json index d688736..9d20e5a 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ "node": "^4.5 || 6.* || >= 7.*" }, "dependencies": { - "broccoli-file-creator": "^1.0.1", - "broccoli-merge-trees": "^1.0.0", "ember-cli-babel": "^6.6.0" }, "devDependencies": { diff --git a/tests/unit/s3-test.js b/tests/unit/s3-test.js index 3037123..7df20b0 100644 --- a/tests/unit/s3-test.js +++ b/tests/unit/s3-test.js @@ -2,7 +2,7 @@ import { module } from 'qunit'; import { setupTest } from 'ember-qunit'; import { computed } from '@ember/object'; import $ from 'jquery'; -import { S3Uploader } from 'ember-uploader/uploaders'; +import S3Uploader from 'ember-uploader/uploaders/s3'; import test from 'ember-sinon-qunit/test-support/test'; import { startMirage } from 'dummy/initializers/ember-cli-mirage'; diff --git a/tests/unit/uploader-test.js b/tests/unit/uploader-test.js index 935bd02..ce88daa 100644 --- a/tests/unit/uploader-test.js +++ b/tests/unit/uploader-test.js @@ -2,14 +2,14 @@ import { module } from 'qunit'; import { setupTest } from 'ember-qunit'; import { computed } from '@ember/object'; import $ from 'jquery'; -import { Uploader } from 'ember-uploader/uploaders'; +import Uploader from 'ember-uploader/uploaders/uploader'; import test from 'ember-sinon-qunit/test-support/test'; import TestableFormData from '../helpers/form-data'; import { startMirage } from 'dummy/initializers/ember-cli-mirage'; let file; -module("EmberUploader.Uploader", function(hooks) { +module('EmberUploader.Uploader', function(hooks) { setupTest(hooks); hooks.beforeEach(function() { diff --git a/yarn.lock b/yarn.lock index 060f733..b349367 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1018,7 +1018,7 @@ broccoli-debug@^0.6.1, broccoli-debug@^0.6.3, broccoli-debug@^0.6.4: symlink-or-copy "^1.1.8" tree-sync "^1.2.2" -broccoli-file-creator@^1.0.1, broccoli-file-creator@^1.1.1: +broccoli-file-creator@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.2.0.tgz#27f1b25b1b00e7bb7bf3d5d7abed5f4d5388df4d" dependencies: