Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit c1e8b4e

Browse files
author
Kahlil Lechelt
committed
Add sub-generator for JavaScript modules.
1 parent 6823771 commit c1e8b4e

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

module/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
var util = require('util');
3+
var yeoman = require('yeoman-generator');
4+
5+
var ModuleGenerator = module.exports = function ModuleGenerator() {
6+
yeoman.generators.NamedBase.apply(this, arguments);
7+
};
8+
9+
util.inherits(ModuleGenerator, yeoman.generators.NamedBase);
10+
11+
ModuleGenerator.prototype.module = function module() {
12+
this.copy('module.js', 'js/modules/' + this.name + '.js');
13+
};

module/templates/module.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* An example module
3+
*
4+
* @author Author name
5+
* @date 2013-08-18
6+
*/
7+
8+
define([
9+
// Dependencies of the module
10+
'jquery'
11+
], function ($) {
12+
13+
// Strict mode to prevent sloppy JS
14+
'use strict';
15+
16+
// Private variables
17+
var _eventName = '_test';
18+
19+
// Public API
20+
return {
21+
22+
// Getter for private variable
23+
getEventName: function () {
24+
return _eventName;
25+
},
26+
27+
// File an event on initialisation
28+
init: function () {
29+
$(document).trigger(_eventName);
30+
}
31+
};
32+
33+
});

0 commit comments

Comments
 (0)