diff --git a/blueprints/pace/index.js b/blueprints/pace/index.js new file mode 100644 index 0000000..666a0e1 --- /dev/null +++ b/blueprints/pace/index.js @@ -0,0 +1,11 @@ +var RSVP = require('rsvp'); + +module.exports = { + normalizeEntityName: function() {}, + + afterInstall: function() { + return RSVP.all([ + this.addPackageToProject('pace-progress'), + ]); + } +}; \ No newline at end of file diff --git a/index.js b/index.js index c90416d..c72abd4 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,103 @@ +/* jshint node: true */ 'use strict'; +var fs = require('fs'); +var path = require('path'); +var UglifyJS = require("uglify-js"); +var PACE_DIR = 'pace-progress'; + +var _paceConfig = {}; +var _defaultPaceConfig = { + color: 'blue', + theme: 'minimal', + catchupTime: 50, + initialRate: 0.01, + minTime: 100, + ghostTime: 50, + maxProgressPerFrame: 20, + easeFactor: 1.25, + startOnPageLoad: true, + restartOnPushState: true, + restartOnRequestAfter: 500, + target: 'body', + elements: { + checkInterval: 100, + selectors: ['body', '.ember-view'] + }, + eventLag: { + minSamples: 10, + sampleCount: 3, + lagThreshold: 3 + }, + ajax: { + trackMethods: ['GET', 'POST', 'DELETE', 'OPTIONS'], + trackWebSockets: true, + ignoreURLs: [] + } +}; + + module.exports = { - name: 'ember-cli-pace' + name: 'ember-cli-pace', + + config: function (environment, baseConfig) { + if ('pace' in baseConfig) { + if (!baseConfig.pace) { + _paceConfig = false; + } else { + Object.keys(_defaultPaceConfig).forEach(function (key) { + _paceConfig[key] = baseConfig.pace.hasOwnProperty(key) ? baseConfig.pace[key] : _defaultPaceConfig[key]; + }); + } + } else { + _paceConfig = _defaultPaceConfig; + } + + if (environment === 'development') { + return { + pace: _paceConfig, + contentSecurityPolicy: { + 'script-src': "'self' 'unsafe-eval' 'unsafe-inline'" + } + }; + } + + return { + pace: _paceConfig + }; + }, + + treeFor: function (name) { + if (_paceConfig && name === 'styles') { + var paceThemeName = path.join(_paceConfig.color, 'pace-theme-' + _paceConfig.theme + '.css'), + originalPaceThemePath = path.join('node_modules', PACE_DIR, 'themes', paceThemeName), + addonPaceThemePath = path.join('vendor', 'ember-cli-pace', 'themes', paceThemeName); + + if (fs.existsSync(originalPaceThemePath)) { + this.app.import(originalPaceThemePath); + } else if (fs.existsSync(addonPaceThemePath)) { + this.app.import(addonPaceThemePath); + } else { + throw new Error('Pace theme CSS file was not found: ' + paceThemeName); + } + } + }, + + contentFor: function (name) { + if (_paceConfig && name === 'head') { + var paceScriptPath = path.join('node_modules', PACE_DIR, 'pace.js'), + addonScriptPath = path.resolve(__dirname, 'vendor', 'ember-cli-pace', 'script-loader.js'), + paceScript, addonScript; + + if (this.app.env === 'production') { + paceScript = UglifyJS.minify(paceScriptPath).code; + addonScript = UglifyJS.minify(addonScriptPath).code; + } else { + paceScript = fs.readFileSync(paceScriptPath, 'utf8'); + addonScript = fs.readFileSync(addonScriptPath, 'utf8'); + } + + return ''; + } + } }; diff --git a/package.json b/package.json index f174507..8934f22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "ember-cli-pace", - "version": "0.0.0", + "name": "ember-cli-pace-gs", + "version": "1.1.4", "description": "The default blueprint for ember-cli addons.", "keywords": [ "ember-addon" @@ -19,7 +19,9 @@ "test": "ember try:each" }, "dependencies": { - "ember-cli-babel": "^6.6.0" + "ember-cli-babel": "^6.6.0", + "jquery": "^3.3.1", + "pace-progress": "^1.0.2" }, "devDependencies": { "broccoli-asset-rev": "^2.4.5", diff --git a/tests/.jshintrc b/tests/.jshintrc new file mode 100644 index 0000000..ea8b88f --- /dev/null +++ b/tests/.jshintrc @@ -0,0 +1,51 @@ +{ + "predef": [ + "document", + "window", + "location", + "setTimeout", + "$", + "-Promise", + "define", + "console", + "visit", + "exists", + "fillIn", + "click", + "keyEvent", + "triggerEvent", + "find", + "findWithAssert", + "wait", + "DS", + "andThen", + "currentURL", + "currentPath", + "currentRouteName" + ], + "node": false, + "browser": false, + "boss": true, + "curly": false, + "debug": false, + "devel": false, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true +} diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index b3b2bd6..757df38 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -1,12 +1,14 @@ -import Application from '@ember/application'; -import Resolver from './resolver'; -import loadInitializers from 'ember-load-initializers'; +import Ember from 'ember'; +import Resolver from 'ember/resolver'; +import loadInitializers from 'ember/load-initializers'; import config from './config/environment'; -const App = Application.extend({ +Ember.MODEL_FACTORY_INJECTIONS = true; + +var App = Ember.Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, - Resolver + Resolver: Resolver }); loadInitializers(App, config.modulePrefix); diff --git a/tests/dummy/app/controllers/application.js b/tests/dummy/app/controllers/application.js new file mode 100644 index 0000000..e7008fe --- /dev/null +++ b/tests/dummy/app/controllers/application.js @@ -0,0 +1,22 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend(Ember.PromiseProxyMixin, { + page: 0, + + actions: { + load: function () { + var promise = $.ajax({ + url: "https://andruxnet-random-famous-quotes.p.mashape.com/cat=movies", + type: 'post', + dataType: 'json', + headers: { + "X-Mashape-Key": "NmMfD3pY9dmshv8ZpOelB8xlmiOPp1JDlGtjsnwdRZKZ1cLgJn", + "Content-Type": "application/x-www-form-urlencoded", + "Accept": "application/json" + } + }); + + this.set('promise', promise); + } + } +}); diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html index 61400b2..1d5ece8 100644 --- a/tests/dummy/app/index.html +++ b/tests/dummy/app/index.html @@ -3,23 +3,25 @@
-