Skip to content

Commit

Permalink
implement angular feature structure (only one level deep)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinspecker committed Jul 19, 2014
1 parent f0f8991 commit 2e336d3
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 127 deletions.
44 changes: 28 additions & 16 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Generator.prototype.prompting = function prompting() {

this.log(yosay('Welcome to ngPoly!'));

// ask for app name
// get preferred langugaes
this.prompt([{
name: 'appName',
message: 'What is the app\'s name?'
Expand Down Expand Up @@ -79,22 +81,30 @@ Generator.prototype.prompting = function prompting() {

done();
}.bind(this));

};






Generator.prototype.configuring = function configuring() {
// create a directory with appName, unless user is in a directory named appName
if (this.appName !== this._.last(this.destinationRoot().split(path.sep))) {
this.destinationRoot(this.appName);
}

// save config info
this.config.set('markup', this.markup);
this.config.set('appScript', this.appScript);
this.config.set('testScript', this.testScript);
this.config.set('style', this.style);
this.config.save();

this.context = { appName: this.appName };
this.context = { appName: this.appName, moduleName: this.appName };

// copy over common files
this.template('_bower.json', 'bower.json', this.context);
this.template('_package.json', 'package.json', this.context);
this.copy('.editorconfig', '.editorconfig');
Expand All @@ -105,22 +115,17 @@ Generator.prototype.configuring = function configuring() {
Generator.prototype.writing = function writing() {
var markup = this.config.get('markup');

this.mkdir('src/components/');

this.mkdir('src/markup/');
this.template('_index.' + markup, 'src/markup/index.' + markup, this.context);
this.mkdir('src/markup/views/');
this.template('_main.' + markup, 'src/markup/views/main.' + markup, this.context);
// create main module and index.html
this.template('_app.js', 'src/app.js', this.context);
this.template('_index.' + markup, 'src/index.' + markup, this.context);

this.mkdir('src/js/');
this.template('_app.js', 'src/js/app.js');
/* // create a home module
this.mkdir('src/home');
this.template('_app.js', 'src/home/home.js', this.context);
this.mkdir('src/less/');
this.copy('style.less', 'src/less/style.less');
this.mkdir('src/less/includes/');
this.copy('variables.less', 'src/less/includes/variables.less');

this.mkdir('tests/');
// create a home view, controller, and route
this.template('_index.' + markup, 'src/home/home.' + markup, this.context);
this.copy('style.less', 'src/home/home.less');*/
};

Generator.prototype.install = function install() {
Expand All @@ -133,5 +138,12 @@ Generator.prototype.end = function end() {
// force save to guarantee config exists for controller
// tests randomly fail without this
this.config.forceSave();
this.invoke('ng-poly:controller', { args: ['main'] });
this.invoke('ng-poly:module', {
args: ['home'],
options: {
options: {
module: 'home',
}
}
});
};
1 change: 1 addition & 0 deletions app/templates/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"immed": true,
"indent": 2,
"latedef": true,
"laxcomma": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
Expand Down
12 changes: 3 additions & 9 deletions app/templates/_app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
'use strict';

angular.module('<%= appName %>', ['ui.router']);
angular.module('<%= moduleName %>', ['ui.router', 'home']);

angular.module('<%= appName %>').config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('index', {
url: '/',
templateUrl: 'views/main.html',
controller: 'MainCtrl'
});
angular.module('<%= moduleName %>').config(function ($urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
});
47 changes: 23 additions & 24 deletions app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ var componentsBase = 'src/components/'
, componentsMarkup = componentsDir
, componentsJs = componentsDir + '*.js'
, componentsLess = componentsDir + '*.less'
, srcMarkup = 'src/markup/**/'
, srcMarkupTemplates = 'src/markup/templates/' // used for karmaConf
, srcJsFiles = 'src/js/**/*.js'
, srcLessDir = 'src/less/'; // since we need to strictly specify style.less later
, srcMarkup = 'src/**/'
, srcMarkupTemplates = 'src/**/*Directive.{jade,html}' // used for karmaConf
, srcJsFiles = 'src/**/*.js'
, srcLessFiles = 'src/**/*.less'; // since we need to strictly specify style.less later

// test files
var unitTests = 'tests/unit/**/*.spec.{coffee,js}';
var unitTests = 'src/**/*_test.{coffee,js}';

// build files
var build = 'build/'
, buildComponents = build + 'components/'
, buildCss = build + 'css/'
, buildJs = build + 'js/';
, buildCss = build
, buildJs = build;

var bowerDir = 'bower_components/';
function prependBowerDir(file) {
Expand All @@ -65,20 +65,20 @@ var karmaConf = {
'bower_components/angular-mocks/angular-mocks.js',
srcJsFiles,
unitTests,
srcMarkupTemplates + '*.{jade,html}'
srcMarkupTemplates
],
reporters: ['failed', 'coverage'],
preprocessors: {
'src/js/**/*.js': ['coverage'],
'src/markup/templates/*.html': ['ng-html2js'],
'src/markup/templates/*.jade': ['ng-jade2js'],
'tests/unit/**/*.spec.coffee': ['coffee']
'src/**/!(*_test)+(.js)': ['coverage'],
'src/*Directive.html': ['ng-html2js'],
'src/**/*Directive.jade': ['ng-jade2js'],
'src/**/*_test.coffee': ['coffee']
},
ngHtml2JsPreprocessor: {
stripPrefix: 'src/markup/'
stripPrefix: 'src/'
},
ngJade2JsPreprocessor: {
stripPrefix: 'src/markup/'
stripPrefix: 'src/'
},
singleRun: true
};
Expand Down Expand Up @@ -119,7 +119,7 @@ gulp.task('inject', ['js', 'less', 'markup', 'components'], function () {
return gulp.src(build + 'index.html')
.pipe(inject(gulp.src([
buildComponents + '**/*.html',
buildCss + '*.css',
buildCss + '**/*.css',
buildJs + 'angular.js',
buildJs + 'angular-ui-router.js',
buildJs + '**/*.js'
Expand All @@ -133,15 +133,16 @@ gulp.task('inject', ['js', 'less', 'markup', 'components'], function () {

gulp.task('js', ['clean', 'jshint'], function () {
return gulp.src([
srcJsFiles
srcJsFiles,
'!**/*_test.*'
].concat(injectableBowerComponents.map(prependBowerDir)))
.pipe(gulp.dest('build/js'));
.pipe(gulp.dest('build'));
});

gulp.task('coffeelint', function () {
return gulp.src([
unitTests,
'!**/*.spec.js'
'!**/*_test.js'
])
.pipe(coffeelint())
.pipe(coffeelint.reporter())
Expand All @@ -153,7 +154,7 @@ gulp.task('jshint', function () {
componentsJs,
srcJsFiles,
unitTests,
'!**/*.spec.coffee'
'!**/*_test.coffee'
])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
Expand All @@ -162,10 +163,8 @@ gulp.task('jshint', function () {
});

gulp.task('less', ['clean'], function () {
return gulp.src(srcLessDir + 'style.less')
.pipe(less({
paths: [path.join(__dirname, srcLessDir, srcLessDir + 'includes')]
}))
return gulp.src(srcLessFiles)
.pipe(less())
.pipe(gulp.dest(buildCss));
});

Expand Down Expand Up @@ -203,5 +202,5 @@ gulp.task('test', ['jshint', 'coffeelint'], function (done) {

gulp.task('watch', function () {
gulp.watch([unitTests], ['test']);
gulp.watch([srcMarkup + '*.{html,jade}', srcJsFiles, srcLessDir + '**/*.less', componentsDir + '*.{html,jade,js,less}'], ['build']);
gulp.watch([srcMarkup + '*.{html,jade}', srcJsFiles, srcLessFiles, componentsDir + '*.{html,jade,js,less}'], ['build']);
});
2 changes: 1 addition & 1 deletion app/templates/style.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'includes/variables.less';
@bg-color: #E5E5E5;

body {
background-color: @bg-color;
Expand Down
24 changes: 21 additions & 3 deletions constant/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use strict';
var genBase = require('../genBase');
var genBase = require('../genBase')
, path = require('path');


var Generator = module.exports = genBase.extend();

Generator.prototype.prompting = function prompting() {
var done = this.async();

this.prompt([{
name: 'module',
message: 'Which module is this for?',
default: this.name,
when: function () {
return !(this.options && this.options.options && this.options.options.module);
}.bind(this)
}], function (props) {
this.module = props.module || this.options.options.module;

done();
}.bind(this));
};

Generator.prototype.writing = function writing() {
var config = this.getConfig();

this.template('_constant.js', 'src/js/constants/' + config.lowerCamel + '.js', config);
this.template('_constant.js', path.join('src', this.module, config.lowerCamel + 'Constant.js'), config);
this.template('_spec.' + config.testScript,
'tests/unit/constants/' + config.lowerCamel + '.spec.' + config.testScript, config);
path.join('src', this.module, config.lowerCamel + 'Constant_test.' + config.testScript), config);
};
24 changes: 21 additions & 3 deletions controller/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use strict';
var genBase = require('../genBase');
var genBase = require('../genBase')
, path = require('path');


var Generator = module.exports = genBase.extend();

Generator.prototype.prompting = function prompting() {
var done = this.async();

this.prompt([{
name: 'module',
message: 'Which module is this for?',
default: this.name,
when: function () {
return !(this.options && this.options.options && this.options.options.module);
}.bind(this)
}], function (props) {
this.module = props.module || this.options.options.module;

done();
}.bind(this));
};

Generator.prototype.writing = function writing() {
var config = this.getConfig();

this.template('_controller.js', 'src/js/controllers/' + config.ctrlName + '.js', config);
this.template('_controller.js', path.join('src', this.module, config.ctrlName + '.js'), config);
this.template('_spec.' + config.testScript,
'tests/unit/controllers/' + config.ctrlName + '.spec.' + config.testScript, config);
path.join('src', this.module, config.ctrlName + '_test.' + config.testScript), config);
};
27 changes: 23 additions & 4 deletions directive/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
'use strict';
var genBase = require('../genBase');
var genBase = require('../genBase')
, path = require('path');


var Generator = module.exports = genBase.extend();

Generator.prototype.prompting = function prompting() {
var done = this.async();

this.prompt([{
name: 'module',
message: 'Which module is this for?',
default: this.name,
when: function () {
return !(this.options && this.options.options && this.options.options.module);
}.bind(this)
}], function (props) {
this.module = props.module || this.options.options.module;

done();
}.bind(this));
};

Generator.prototype.writing = function writing() {
var config = this.getConfig();
config.moduleName = this.module;

this.template('_directive.js', 'src/js/directives/' + config.lowerCamel + '.js', config);
this.template('_directive.js', path.join('src', this.module, config.lowerCamel + 'Directive.js'), config);
this.template('_directive.' + config.markup,
'src/markup/templates/' + config.lowerCamel + '.' + config.markup, config);
path.join('src', this.module, config.lowerCamel + 'Directive.' + config.markup), config);
this.template('_spec.' + config.testScript,
'tests/unit/directives/' + config.lowerCamel + '.spec.' + config.testScript, config);
path.join('src', this.module, config.lowerCamel + 'Directive_test.' + config.testScript), config);
};
2 changes: 1 addition & 1 deletion directive/templates/_directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('<%= appName %>').directive('<%= lowerCamel %>', function () {
return {
restrict: 'AE',
scope: {},
templateUrl: 'templates/<%= lowerCamel %>.html',
templateUrl: '<%= moduleName %>/<%= lowerCamel %>Directive.html',
replace: false,
link: function (scope, element, attrs) {
element.text('<%= lowerCamel %>\n' + scope + '\n' + attrs);
Expand Down
2 changes: 1 addition & 1 deletion directive/templates/_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe '<%= lowerCamel %>', ->
scope = undefined
element = undefined

beforeEach module('<%= appName %>', 'templates/<%= lowerCamel %>.html')
beforeEach module('<%= appName %>', '<%= moduleName %>/<%= lowerCamel %>Directive.html')

beforeEach inject ($compile, $rootScope) ->
scope = $rootScope.$new()
Expand Down
2 changes: 1 addition & 1 deletion directive/templates/_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('<%= lowerCamel %>', function () {
var scope;
var element;

beforeEach(module('<%= appName %>', 'templates/<%= lowerCamel %>.html'));
beforeEach(module('<%= appName %>', '<%= moduleName %>/<%= lowerCamel %>Directive.html'));

beforeEach(inject(function ($compile, $rootScope) {
scope = $rootScope.$new();
Expand Down
Loading

0 comments on commit 2e336d3

Please sign in to comment.