This repository has been archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
624734d
commit 688cbf1
Showing
20 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 componentName = titleCase(name); | ||
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 = { | ||
componentName, | ||
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`, `${path}/${name}.js`, props); | ||
this.copyTemplate(`src/app/component.spec.js`, `${path}/${name}.spec.js`, props); | ||
this.copyTemplate('src/app/component.html', `${path}/${name}.html`, props); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class <%- componentName %>Controller { | ||
constructor() { | ||
this.text = 'My brand new component!'; | ||
} | ||
} | ||
|
||
<% if (modules === 'inject') { -%> | ||
<% include inject/component.babel %> | ||
<% } else { -%> | ||
<% include modules/component.babel %> | ||
<% } -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="component"> | ||
<h2>{{$ctrl.text}}</h2> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
generators/component/templates/src/app/component.spec.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
expect(element).not.toBeNull(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
expect(element).not.toBeNull(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class <%- componentName %>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
6
generators/component/templates/src/app/inject/component.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
angular | ||
.module('app') | ||
.component('<%- componentName %>', { | ||
templateUrl: 'app/<%- name %>.html', | ||
controller: <%- componentName %> | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
angular | ||
.module('app') | ||
.component('<%- componentName %>', { | ||
templateUrl: 'app/<%- name %>.html', | ||
controller: <%- componentName %> | ||
}); |
7 changes: 7 additions & 0 deletions
7
generators/component/templates/src/app/inject/component.spec.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}; | ||
}); | ||
})); |
7 changes: 7 additions & 0 deletions
7
generators/component/templates/src/app/inject/component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}; | ||
}); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
angular | ||
.module('app') | ||
.component('<%- componentName %>', { | ||
templateUrl: 'app/<%- name %>.html', | ||
controller: <%- componentName %> | ||
}); |
4 changes: 4 additions & 0 deletions
4
generators/component/templates/src/app/modules/component.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const <%- componentName %> = { | ||
templateUrl: 'app/<%- name %>.html', | ||
controller: <%- componentName %>Controller | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
templateUrl: 'app/<%- componentName %>.html', | ||
controller: <%- componentName %>Controller | ||
}; |
6 changes: 6 additions & 0 deletions
6
generators/component/templates/src/app/modules/component.spec.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>'); | ||
}); |
3 changes: 3 additions & 0 deletions
3
generators/component/templates/src/app/modules/component.spec.header.babel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>'; |
3 changes: 3 additions & 0 deletions
3
generators/component/templates/src/app/modules/component.spec.header.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>'; |
6 changes: 6 additions & 0 deletions
6
generators/component/templates/src/app/modules/component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const <%- componentName %> = { | ||
templateUrl: 'app/<%- name %>.html', | ||
controller: <%- componentName %>Controller | ||
}; |