Skip to content

Download supported extensions at build time #17

Open
@La0

Description

@La0

It's tricky to do in a plugin, using hooks.
Here is the farther i got, the extensions.json file is created as an asset, bur require('extensions.json') does not work...

const fs = require('fs');
const download = require('download');

// Plugin downloading the supported extensions from production backend
const pluginName = 'ExtensionsPlugin';
class ExtensionsPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap(pluginName, compilation => {
      compilation.hooks.additionalAssets.tapAsync(pluginName, callback => {

        console.debug('Downloading coverage extensions...');
        download('https://coverage.moz.tools/v2/extensions').then(data => {

          // Setup downloaded file as asset
          let extensions = data.toString('utf-8');
          compilation.assets['extensions.json'] = {
            source: () => {
              return extensions;
            },
            size: () => {
              return extensions.length;
            }
          };

          callback();
        });
      });
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    addonWebExtension

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions