Repository: kaliber5/ember-responsive-image
Pull request #136 (2021-02-06 22:26:25)

Move addon options into ember-cli-build.js


Patch:
diff --git a/ember-cli-build.js b/ember-cli-build.js
index e1315cf6..8e9bb81f 100644
--- a/ember-cli-build.js
+++ b/ember-cli-build.js
@@ -11,6 +11,43 @@ module.exports = function (defaults) {
       exclude: ['testem.js'],
       customHash: '00e24234f1b58e32b935b1041432916f',
     },
+    'responsive-image': [
+      {
+        include: 'assets/images/**/*',
+        exclude: ['assets/images/small.png', 'assets/images/lqip/**/*'],
+        quality: 50,
+        supportedWidths: [50, 100, 640],
+        lqip: {
+          type: 'color',
+        },
+        removeSource: true,
+      },
+      {
+        include: 'assets/images/small.png',
+        quality: 10,
+        removeSource: false,
+        supportedWidths: [10, 25],
+      },
+      {
+        include: 'assets/images/lqip/inline.jpg',
+        quality: 50,
+        supportedWidths: [100, 640],
+        lqip: {
+          type: 'inline',
+        },
+        removeSource: true,
+      },
+      {
+        include: 'assets/images/lqip/color.jpg',
+        quality: 50,
+        supportedWidths: [100, 640],
+        lqip: {
+          type: 'color',
+        },
+        removeSource: true,
+        justCopy: false,
+      },
+    ],
   });
 
   /*
diff --git a/index.js b/index.js
index 09f6dca2..35252b15 100644
--- a/index.js
+++ b/index.js
@@ -9,21 +9,14 @@ const SilentError = require('silent-error');
 const minimatch = require('minimatch');
 const walk = require('walk-sync');
 
-function defaultConfig() {
-  let defaultConfig = {
-    exclude: [],
-    quality: 80,
-    supportedWidths: [2048, 1536, 1080, 750, 640],
-    removeSource: true,
-    justCopy: false,
-    destinationDir: '/',
-  };
-
-  //if (env !== 'production') {
-  //  defaultConfig.justCopy = true;
-  //}
-  return defaultConfig;
-}
+const defaultConfig = {
+  exclude: [],
+  quality: 80,
+  supportedWidths: [2048, 1536, 1080, 750, 640],
+  removeSource: true,
+  justCopy: false,
+  destinationDir: '/',
+};
 
 /**
  * Ember Addon, generate resized images on build time
@@ -150,28 +143,32 @@ module.exports = {
     return this.extendedMetaData;
   },
 
-  included(app, parentAddon) {
+  included(parent) {
     this._super.included.apply(this, arguments);
-    this.app = parentAddon || app;
-    this.processingTree = this.createProcessingTree();
+    this.initConfig(parent);
     this.initPlugins();
+    this.processingTree = this.createProcessingTree();
   },
 
-  config(env, baseConfig) {
-    if (!env) {
+  initConfig(app) {
+    let config = app.options['responsive-image'];
+
+    if (!config) {
+      this.ui.writeWarnLine(
+        'Could not find config for ember-responsive-image, skipping image processing...'
+      );
+      this.addonOptions = [];
       return;
     }
-    let config = baseConfig['responsive-image'];
-    let url = baseConfig.rootURL || baseConfig.baseURL || '';
-    this.addonOptions = [];
 
     if (!Array.isArray(config)) {
       config = [config];
     }
-    config.forEach((item) => {
+
+    this.addonOptions = config.map((item) => {
       this.validateConfigItem(item);
-      let extendedConfig = Object.assign({}, defaultConfig(env), item);
-      extendedConfig.rootURL = url;
+      let extendedConfig = { ...defaultConfig, ...item };
+      // extendedConfig.rootURL = url;
       if (!Array.isArray(extendedConfig.include)) {
         extendedConfig.include = [extendedConfig.include];
       }
@@ -180,7 +177,7 @@ module.exports = {
         extendedConfig.exclude = [extendedConfig.exclude];
       }
 
-      this.addonOptions.push(extendedConfig);
+      return extendedConfig;
     });
   },
 
@@ -254,10 +251,6 @@ module.exports = {
 
   createProcessingTree() {
     const tree = this._findHost().trees.public;
-    this.metaData.prepend = '';
-    if (this.app && this.app.options && this.app.options.fingerprint) {
-      this.metaData.prepend = this.app.options.fingerprint.prepend;
-    }
     const trees = this.addonOptions.map((options) => {
       return this.resizeImages(tree, options);
     });
diff --git a/lib/image-writer.js b/lib/image-writer.js
index ea194c26..62d84f14 100644
--- a/lib/image-writer.js
+++ b/lib/image-writer.js
@@ -282,11 +282,7 @@ class ImageResizer extends CachingWriter {
   }
 
   insertMetadata(filename, imagename, format, width, meta) {
-    let image = path.join(
-      this.image_options.rootURL,
-      this.image_options.destinationDir,
-      imagename
-    );
+    let image = path.join(this.image_options.destinationDir, imagename);
     if (process.platform === 'win32') {
       image = image.replace(/\\/g, '/');
     }


Test patch:
diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js
index e6085fd7..ba4e8cb7 100644
--- a/tests/dummy/config/environment.js
+++ b/tests/dummy/config/environment.js
@@ -21,43 +21,6 @@ module.exports = function (environment) {
       // Here you can pass flags/options to your application instance
       // when it is created
     },
-    'responsive-image': [
-      {
-        include: 'assets/images/**/*',
-        exclude: ['assets/images/small.png', 'assets/images/lqip/**/*'],
-        quality: 50,
-        supportedWidths: [50, 100, 640],
-        lqip: {
-          type: 'color',
-        },
-        removeSource: true,
-      },
-      {
-        include: 'assets/images/small.png',
-        quality: 10,
-        removeSource: false,
-        supportedWidths: [10, 25],
-      },
-      {
-        include: 'assets/images/lqip/inline.jpg',
-        quality: 50,
-        supportedWidths: [100, 640],
-        lqip: {
-          type: 'inline',
-        },
-        removeSource: true,
-      },
-      {
-        include: 'assets/images/lqip/color.jpg',
-        quality: 50,
-        supportedWidths: [100, 640],
-        lqip: {
-          type: 'color',
-        },
-        removeSource: true,
-        justCopy: false,
-      },
-    ],
   };
 
   if (environment === 'development') {