开发者社区> 镜像站> NPM> ember-stream-generator
ember-stream-generator
streams!!!!
Last updated 7 years ago by knownasilya .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ember-stream-generator 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.3.8                                ...           latest (7 years ago)

10 Versions

  • 0.3.8                                ...           7 years ago
  • 0.3.7                                ...           7 years ago
  • 0.3.6                                ...           7 years ago
  • 0.3.5                                ...           7 years ago
  • 0.3.4                                ...           7 years ago
  • 0.3.3                                ...           7 years ago
  • 0.3.2                                ...           7 years ago
  • 0.3.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (2)
Dependents (0)
None