Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ember-stream-generator with all npm packages installed. Try it out:

var emberStreamGenerator = require("ember-stream-generator")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ember-stream-generator v0.3.8

streams!!!!

Ember Stream Generator Build Status

NPM

This generator set is used to create an CJS require hierarchy for an EmberJS project structure. The main use-case, is for use with Browserify.
For example, given the following structure:

app
  |_controllers/
    |_user.js
    |_user/
      |_new.js
  |_views/
    |_user.js
  |_routes/
    |_user.js
    |_user/
      |_new.js
  |_...

This generator set can be used to generate a file, along the lines of .index.js, with the following contents:

// Start template code: Generated from template
require('ember'); // get Ember global around for the templates
require('./.templates');

var routes = require('./config/routes');
var App = require('./config/application');

App.Router.map(routes);
// End template code

// Start generated code
App.UserController = require('./controllers/user');
App.UserNewController = require('./controllers/user/new');
App.UserView = require('./views/user');
App.UserRoute = require('./routes/user');
App.UserNewRoute = require('./routes/user/new');
// more ...

Note: The config directory is required, with the application definition in config/application.js and the router definition in config/routes.js. This also requires a .templates.js file in the root directory (this is a precompiled templates file, see ember-template-compiler).

Usage

Install:

npm install ember-stream-generator --save

Available Options:

This stream takes three options stream(path, appName, customTemplatePath).

  • path - The path to the root of you client directory.
  • appName - Name of your Ember.Application instance, e.g. App.UserRoute.
  • customTemplatePath - Path to custom template, the default template is below.

Basic Example:

This stream should be used with other streams:

var esg = require('ember-stream-generator');
var fs = require('fs');

esg('./client/app').pipe(fs.createReadStream('./tmp/.index.js'));

Default Template:

If no template path is given, this is the default:

// this file is auto-generated, do not edit

require('ember'); // get Ember global around for the templates
require('./.templates');

var routes = require('./config/routes');
var {{appName}} = require('./config/application');

{{appName}}.Router.map(routes);

{{#each helpers}}
require('{{path}}');{{/each}}

{{#each modules}}
{{../appName}}.{{name}} = require('{{path}}');{{/each}}

module.exports = {{appName}};

Via Grunt

  // creates a file with requires for App.* for ember
  grunt.registerTask('pre-browserify', function () {
    var done = this.async();
    var emberStream = require('ember-stream-generator');
    var fs = require('fs');
    var inStream = emberStream('./client');
    var outStream = fs.createWriteStream('./client/.index.js');

    outStream.on('finish', done);
    inStream.pipe(outStream);
  });

Via Gulp

// creates a file with requires for App.* for ember
gulp.task('pre-browserify', function () {
  var emberStream = require('ember-stream-generator');
  var rename = require('gulp-rename');
  var source = require('vinyl-source-stream');
  var clientPath = './client/';
  
  emberStream(clientPath)
    .pipe(source(clientPath))
    .pipe(rename('.index.js'))
    .pipe(gulp.dest(clientPath));
});

Acknowledgment

The concept and some of the code comes from Ryan Florence's loom-ember.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free