Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Add subgenerators #36

Merged
merged 6 commits into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const fountain = require('fountain-generator');
const version = require('../../package.json').version;

module.exports = fountain.Base.extend({
prompting: {
Expand Down Expand Up @@ -30,6 +31,8 @@ module.exports = fountain.Base.extend({
},

configuring() {
this.config.set('version', version);
this.config.set('props', this.props);
this.mergeJson('package.json', {
dependencies: {
angular: '^1.5.0'
Expand Down
24 changes: 24 additions & 0 deletions generators/component/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fountain = require('fountain-generator');

module.exports = fountain.Base.extend({
writing() {
const name = this.options.name || 'component';
const titleCase = string => string.charAt(0).toUpperCase() + string.slice(1);
const lowerCase = string => string.charAt(0).toLowerCase() + string.slice(1);
const path = this.options.dir ? `app/${this.options.dir}` : `app`;
const typings = this.options.dir ? this.options.dir.split('/').reduce(prev => `../${prev}`, '../../typings/index.d.ts') : '../../typings/index.d.ts';
const props = {
componentName: lowerCase(name),
className: titleCase(name),
modules: this.config.get('props').modules,
js: this.config.get('props').js,
framework: this.config.get('props').framework,
name,
typings,
templateUrl: this.config.get('props').modules === 'systemjs' ? `src/${path}/${name}.html` : `${path}/${name}.html`
};
this.copyTemplate(`src/app/component.js`, `src/${path}/${name}.js`, props);
this.copyTemplate(`src/app/component.spec.js`, `src/${path}/${name}.spec.js`, props);
this.copyTemplate('src/app/component.html', `src/${path}/${name}.html`, props);
}
});
11 changes: 11 additions & 0 deletions generators/component/templates/src/app/component.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class <%- className %>Controller {
constructor() {
this.text = 'My brand new component!';
}
}

<% if (modules === 'inject') { -%>
<% include inject/component.babel %>
<% } else { -%>
<% include modules/component.babel %>
<% } -%>
3 changes: 3 additions & 0 deletions generators/component/templates/src/app/component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="component">
<h2>{{$ctrl.text}}</h2>
</div>
9 changes: 9 additions & 0 deletions generators/component/templates/src/app/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function <%- componentName %>Controller() {
this.text = 'My brand new component!';
}

<% if (modules === 'inject') { -%>
<% include inject/component.js %>
<% } else { -%>
<% include modules/component.js %>
<% } -%>
15 changes: 15 additions & 0 deletions generators/component/templates/src/app/component.spec.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if (modules !== 'inject') { -%>
<% include modules/component.spec.header.babel %>
<% } -%>
describe('<%- componentName %> component', () => {
<% if (modules === 'inject') { -%>
<% include inject/component.spec.babel %>
<% } else { -%>
<% include modules/component.spec.babel %>
<% } -%>
it('should...', angular.mock.inject(($rootScope, $compile) => {
const element = $compile('<<%- componentName %>></<%- componentName %>>')($rootScope);
$rootScope.$digest();
expect(element).not.toBeNull();
}));
});
15 changes: 15 additions & 0 deletions generators/component/templates/src/app/component.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if (modules !== 'inject') { -%>
<% include modules/component.spec.header.js %>
<% } -%>
describe('<%- componentName %> component', function () {
<% if (modules === 'inject') { -%>
<% include inject/component.spec.js %>
<% } else { -%>
<% include modules/component.spec.js %>
<% } -%>
it('should...', angular.mock.inject(function ($rootScope, $compile) {
var element = $compile('<<%- componentName %>></<%- componentName %>>')($rootScope);
$rootScope.$digest();
expect(element).not.toBeNull();
}));
});
17 changes: 17 additions & 0 deletions generators/component/templates/src/app/component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference path="<%- typings %>" />

<% if (modules !== 'inject') { -%>
<% include modules/component.spec.header.ts %>
<% } -%>
describe('<%- componentName %> component', () => {
<% if (modules === 'inject') { -%>
<% include inject/component.spec.ts %>
<% } else { -%>
<% include modules/component.spec.ts %>
<% } -%>
it('should...', <%- modules === 'webpack' ? 'angular.mock.' : '' %>inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => {
const element = $compile('<<%- componentName %>></<%- componentName %>>')($rootScope);
$rootScope.$digest();
expect(element).not.toBeNull();
}));
});
13 changes: 13 additions & 0 deletions generators/component/templates/src/app/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class <%- className %>Controller {
public text: string;

constructor() {
this.text = 'My brand new component!';
}
}

<% if (modules === 'inject') { -%>
<% include inject/component.babel %>
<% } else { -%>
<% include modules/component.babel %>
<% } -%>
6 changes: 6 additions & 0 deletions generators/component/templates/src/app/inject/component.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular
.module('app')
.component('<%- componentName %>', {
templateUrl: '<%- templateUrl %>',
controller: <%- className %>Controller
});
6 changes: 6 additions & 0 deletions generators/component/templates/src/app/inject/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular
.module('app')
.component('<%- componentName %>', {
templateUrl: '<%- templateUrl %>',
controller: <%- componentName %>Controller
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
beforeEach(module('app', $provide => {
$provide.factory('<%- componentName %>', () => {
return {
templateUrl: 'app/<%- name %>.html'
};
});
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
beforeEach(module('app', function ($provide) {
$provide.factory('<%- componentName %>', function () {
return {
templateUrl: 'app/<%- name %>.html'
};
});
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
beforeEach(module('app', ($provide: ng.auto.IProvideService) => {
$provide.factory('<%- componentName %>', () => {
return {
templateUrl: 'app/<%- name %>.html'
};
});
}));
6 changes: 6 additions & 0 deletions generators/component/templates/src/app/inject/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
angular
.module('app')
.component('<%- componentName %>', {
templateUrl: '<%- templateUrl %>',
controller: <%- className %>Controller
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const <%- componentName %> = {
templateUrl: '<%- templateUrl %>',
controller: <%- className %>Controller
};
4 changes: 4 additions & 0 deletions generators/component/templates/src/app/modules/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
templateUrl: '<%- templateUrl %>',
controller: <%- componentName %>Controller
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
beforeEach(() => {
angular
.module('<%- componentName %>', ['<%- templateUrl %>'])
.component('<%- componentName %>', <%- componentName %>);
angular.mock.module('<%- componentName %>');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import angular from 'angular';
import 'angular-mocks';
import {<%- componentName %>} from './<%- name %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var angular = require('angular');
require('angular-mocks');
var <%- componentName %> = require('./<%- name %>');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as angular from 'angular';
import 'angular-mocks';
import {<%- componentName %>} from './<%- name %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
beforeEach(function () {
angular
.module('<%- componentName %>', ['<%- templateUrl %>'])
.component('<%- componentName %>', <%- componentName %>);
angular.mock.module('<%- componentName %>');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
beforeEach(() => {
angular
.module('<%- componentName %>', ['<%- templateUrl %>'])
.component('<%- componentName %>', <%- componentName %>);
<%- modules === 'webpack' ? 'angular.mock.' : '' %>module('<%- componentName %>');
});
4 changes: 4 additions & 0 deletions generators/component/templates/src/app/modules/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const <%- componentName %> = {
templateUrl: '<%- templateUrl %>',
controller: <%- className %>Controller
};
20 changes: 20 additions & 0 deletions generators/directive/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fountain = require('fountain-generator');

module.exports = fountain.Base.extend({
writing() {
const name = this.options.name || 'directive';
const lowerCase = string => string.charAt(0).toLowerCase() + string.slice(1);
const path = this.options.dir ? `src/app/${this.options.dir}` : `src/app`;
const typings = this.options.dir ? this.options.dir.split('/').reduce(prev => `../${prev}`, '../../typings/index.d.ts') : '../../typings/index.d.ts';
const props = {
directiveName: lowerCase(name),
modules: this.config.get('props').modules,
js: this.config.get('props').js,
framework: this.config.get('props').framework,
name,
typings
};
this.copyTemplate(`src/app/directive.js`, `${path}/${name}.js`, props);
this.copyTemplate(`src/app/directive.spec.js`, `${path}/${name}.spec.js`, props);
}
});
17 changes: 17 additions & 0 deletions generators/directive/templates/src/app/directive.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function <%- directiveName %>() {
return {
restrict: 'E',
scope: {
data: '='
},
link: (scope, element, attrs) => {},
controller: () => {},
controllerAs: 'ctrl'
};
}

<% if (modules === 'inject') { -%>
<% include inject/directive.babel %>
<% } else { -%>
<% include modules/directive.babel %>
<% } -%>
17 changes: 17 additions & 0 deletions generators/directive/templates/src/app/directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function <%- directiveName %>() {
return {
restrict: 'E',
scope: {
data: '='
},
link: function (scope, element, attrs) {},
controller: function () {},
controllerAs: 'ctrl'
};
}

<% if (modules === 'inject') { -%>
<% include inject/directive.js %>
<% } else { -%>
<% include modules/directive.js %>
<% } -%>
7 changes: 7 additions & 0 deletions generators/directive/templates/src/app/directive.spec.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if (modules !== 'inject') { -%>
<% include modules/directive.spec.header.babel %>
<% } -%>
describe('<%- directiveName %> directive', () => {
it('should...', angular.mock.inject(($rootScope, $compile) => {
}));
});
7 changes: 7 additions & 0 deletions generators/directive/templates/src/app/directive.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if (modules !== 'inject') { -%>
<% include modules/directive.spec.header.js %>
<% } -%>
describe('<%- directiveName %> directive', function () {
it('should...', angular.mock.inject(function ($rootScope, $compile) {
}));
});
9 changes: 9 additions & 0 deletions generators/directive/templates/src/app/directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="<%- typings %>" />

<% if (modules !== 'inject') { -%>
<% include modules/directive.spec.header.ts %>
<% } -%>
describe('<%- directiveName %> directive', () => {
it('should...', <%- modules === 'webpack' ? 'angular.mock.' : '' %>inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => {
}));
});
17 changes: 17 additions & 0 deletions generators/directive/templates/src/app/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function <%- directiveName %>() {
return {
restrict: 'E',
scope: {
data: '='
},
link: (scope, element, attrs) => {},
controller: () => {},
controllerAs: 'ctrl'
};
}

<% if (modules === 'inject') { -%>
<% include inject/directive.ts %>
<% } else { -%>
<% include modules/directive.ts %>
<% } -%>
3 changes: 3 additions & 0 deletions generators/directive/templates/src/app/inject/directive.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular
.module('app')
.directive('<%- directiveName %>', <%- directiveName %>);
3 changes: 3 additions & 0 deletions generators/directive/templates/src/app/inject/directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular
.module('app')
.directive('<%- directiveName %>', <%- directiveName %>);
3 changes: 3 additions & 0 deletions generators/directive/templates/src/app/inject/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
angular
.module('app')
.directive('<%- directiveName %>', <%- directiveName %>);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default <%- directiveName %>;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = <%- directiveName %>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import angular from 'angular';
import 'angular-mocks';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var angular = require('angular');
require('angular-mocks');
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as angular from 'angular';
import 'angular-mocks';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default <%- directiveName %>;
20 changes: 20 additions & 0 deletions generators/filter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fountain = require('fountain-generator');

module.exports = fountain.Base.extend({
writing() {
const name = this.options.name || 'filter';
const lowerCase = string => string.charAt(0).toLowerCase() + string.slice(1);
const path = this.options.dir ? `src/app/${this.options.dir}` : `src/app`;
const typings = this.options.dir ? this.options.dir.split('/').reduce(prev => `../${prev}`, '../../typings/index.d.ts') : '../../typings/index.d.ts';
const props = {
filterName: lowerCase(name),
modules: this.config.get('props').modules,
js: this.config.get('props').js,
framework: this.config.get('props').framework,
name,
typings
};
this.copyTemplate(`src/app/filter.js`, `${path}/${name}.js`, props);
this.copyTemplate(`src/app/filter.spec.js`, `${path}/${name}.spec.js`, props);
}
});
11 changes: 11 additions & 0 deletions generators/filter/templates/src/app/filter.babel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function <%- filterName %>() {
return (item, arg1, arg2) => {
// transform the item and return it
};
}

<% if (modules === 'inject') { -%>
<% include inject/filter.babel %>
<% } else { -%>
<% include modules/filter.babel %>
<% } -%>
11 changes: 11 additions & 0 deletions generators/filter/templates/src/app/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function <%- filterName %>() {
return function (item, arg1, arg2) {
// transform the item and return it
};
}

<% if (modules === 'inject') { -%>
<% include inject/filter.babel %>
<% } else { -%>
<% include modules/filter.babel %>
<% } -%>
Loading