Coder Social home page Coder Social logo

ember-cli-build-config-editor's Introduction

Build Status Dependency Status devDependency Status Greenkeeper badge Ember Observer

Ember CLI Build Config Editor

Utility for ember blueprints to use to modify ember-cli-build.js

Installation for Use

For installation in a non-Ember project:

npm install ember-cli-build-config-editor --save-dev

For installation in an Ember project:

ember install ember-cli-build-config-editor

Usage

Note: This package only handles flat configurations at this point.

Querying configuration

var BuildConfigEditor = require('ember-cli-build-config-editor.js');
var fs = require('fs');

// Specify 'utf-8' to force it to be a string instead of a buffer
var source = fs.readFileSync('./ember-cli-build.js', 'utf-8');

var build = new BuildConfigEditor(source);

var config = build.retrieve('some-addon');

// Do something with the config

Adding or editing configuration

Use this from your Ember blueprint to add or update configuration options in your ember-cli-build.js.

var BuildConfigEditor = require('ember-cli-build-config-editor.js');
var fs = require('fs');

// Specify 'utf-8' to force it to be a string instead of a buffer
var source = fs.readFileSync('./ember-cli-build.js', 'utf-8');

var build = new BuildConfigEditor(source);

build.edit('some-addon', {
    booleanProperty: false,
    numericProperty: 17,
    stringProperty: 'wow'
});

fs.writeFileSync('./ember-cli-build.js', build.code());

What It Does

The above example modifies ember-cli-build.js in the following ways

  • Finds the 'some-addon' key in the options object of your EmberApp construction, creating one if it doesn't exist
  • For each of the entries in the passed object, it adds property or updates it if it already exists with the specified value.

Keys that are not specified are preserved untouched. Added object keys are single-quoted for safety.

Troubleshooting

TypeError: this.source.charCodeAt is not a function

You have passed a buffer instead of a string to the constructor. Add the encoding argument when you read the file, e.g., var source = fs.readFileSync('./ember-cli-build.js', 'utf-8').

Development

Installation for Development

  • Fork and clone the repo
  • cd into the project directory
  • npm install

Running tests

npm test

Understanding JavaScript ASTs

The AST for the basic configuration can be found in this SVG for reference. It was generated from Rappid's JavaScript AST Visualizer.

The approach used here is based on that for ember-router-generator.

The DSL for AST types used by esprima provided great insight once I got my head around it.

Contributing

Please fork the project and submit pull requests and issues using GitHub.

ember-cli-build-config-editor's People

Contributors

greenkeeper[bot] avatar srvance avatar synaptiko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.