Created
February 10, 2017 20:20
-
-
Save bgentry/752c1e722ea81041b35bb1a10021ea0d to your computer and use it in GitHub Desktop.
attempt to make graphql files available as ember imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global require, module */ | |
var EmberApp = require('ember-cli/lib/broccoli/ember-app'); | |
var Filter = require('broccoli-filter'); | |
var Funnel = require('broccoli-funnel'); | |
module.exports = function(defaults) { | |
var env = EmberApp.env(); | |
var isProductionLikeBuild = ['production', 'staging'].indexOf(env) > -1; | |
var ENV = defaults.project.config(env); | |
// necessary to avoid using non-prod builds of redux | |
if (isProductionLikeBuild) { | |
process.env.NODE_ENV = 'production'; | |
} | |
var app = new EmberApp(defaults, {}); | |
var extras = []; | |
if (!isProductionLikeBuild) { | |
GraphqlModule.prototype = Object.create(Filter.prototype) | |
GraphqlModule.prototype.constructor = GraphqlModule | |
function GraphqlModule (inputTree, options) { | |
if (!(this instanceof GraphqlModule)) return new GraphqlModule(inputTree, options) | |
Filter.call(this, inputTree, options) | |
options = options || {}; | |
} | |
GraphqlModule.prototype.extensions = ['graphql'] | |
GraphqlModule.prototype.targetExtension = 'js' | |
GraphqlModule.prototype.processString = function (string) { | |
return "export default `" + string + "`;"; | |
} | |
var graphqlAssets = new Funnel( | |
GraphqlModule('tests/fixtures') | |
); | |
extras.push(graphqlAssets); | |
} | |
return app.toTree(extras); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment