UNPKG

ember-cli-openpgp-shim

Version:

Brings OpenPGP.js into your Ember application!

80 lines (63 loc) 1.84 kB
/* jshint node: true */ 'use strict'; const defaults = require('lodash.defaults'); const Funnel = require('broccoli-funnel'); const mergeTrees = require('broccoli-merge-trees'); const path = require('path'); module.exports = { name: 'openpgp', included: function (app) { this._super.included(app); while (typeof app.import !== 'function' && app.app) { app = app.app; } this.app = app; this.openpgpOptions = this.getConfig(); this.importDependencies(app); return app; }, importDependencies: function (app) { app.import('vendor/openpgp.js'); app.import('vendor/shims/openpgp.js', { exports: { openpgp: ['default'] } }); }, treeForVendor: function (vendorTree) { const options = this.openpgpOptions; const trees = []; if (vendorTree) { trees.push(vendorTree); } trees.push(new Funnel(options.openpgpPath, { include: ['openpgp.js'] })); return this._super.treeForVendor(mergeTrees(trees)); }, treeForPublic: function (publicTree) { const options = this.openpgpOptions; const trees = []; if (publicTree) { trees.push(publicTree); } if (options.assetsOutputPath) { trees.push(new Funnel(options.openpgpPath, { include: [ 'openpgp.min.js', 'openpgp.worker.min.js' ], destDir: options.assetsOutputPath })); } return this._super.treeForPublic(mergeTrees(trees)); }, getConfig: function () { const projectConfig = ((this.project.config(process.env.EMBER_ENV) || {}).openpgp || {}); const openpgpPath = path.dirname(require.resolve('openpgp')); return defaults(projectConfig, { openpgpPath: openpgpPath, assetsOutputPath: 'assets' }); } };