-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adding typescript support to generator-angular #539
Changes from 7 commits
c494011
f0806c0
8c062da
acf9cff
c7a37fa
3ba295b
3041dd5
96ab8cb
9008eb8
deaf7bd
c79c9b6
1475034
9c9a7dc
a6535ff
fa454bc
f63d6af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,20 @@ var Generator = module.exports = function Generator() { | |
this.env.options.testPath = this.env.options.testPath || 'test/spec'; | ||
} | ||
|
||
this.env.options.typescript = this.options.typescript; | ||
if (typeof this.env.options.typescript === 'undefined') { | ||
this.option('typescript'); | ||
|
||
// attempt to detect if user is using CS or not | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS |
||
// if cml arg provided, use that; else look for the existence of cs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ts |
||
if (!this.options.typescript && | ||
this.expandFiles(path.join(this.env.options.appPath, '/scripts/**/*.ts'), {}).length > 0) { | ||
this.options.typescript = true; | ||
} | ||
|
||
this.env.options.typescript = this.options.typescript; | ||
} | ||
|
||
this.env.options.coffee = this.options.coffee; | ||
if (typeof this.env.options.coffee === 'undefined') { | ||
this.option('coffee'); | ||
|
@@ -59,6 +73,11 @@ var Generator = module.exports = function Generator() { | |
this.scriptSuffix = '.coffee'; | ||
} | ||
|
||
if (this.env.options.typescript) { | ||
sourceRoot = '/templates/typescript'; | ||
this.scriptSuffix = '.ts'; | ||
} | ||
|
||
if (this.env.options.minsafe) { | ||
sourceRoot += '-min'; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
"dependencies": { | ||
"angular": "1.2.6", | ||
"json3": "~3.2.6", | ||
"es5-shim": "~2.1.0"<% if (bootstrap) { %>, | ||
"es5-shim": "~2.1.0"<% if (typescript) { %>, | ||
"definitivelyTyped": "https://github.com/borisyankov/DefinitelyTyped.git"<% } %><% if (bootstrap) { %>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitively? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I have a pull request up on dt-angular for this, but it's not merged in yet. Currently, you can use |
||
"jquery": "~1.10.2"<% if (compassBootstrap) { %>, | ||
"sass-bootstrap": "~3.0.2"<% } else { %>, | ||
"bootstrap": "~3.0.3"<% } } %><% if (resourceModule) { %>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.coffee | ||
*.coffee | ||
*.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular.d.ts" /> | ||
<% if (ngRoute) { %>/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-route.d.ts" /><% } %> | ||
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-resource.d.ts" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These module references should be conditional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a bunch of extra steps to get the other references to be conditional, though it would probably be a good idea. |
||
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-sanitize.d.ts" /> | ||
/// <reference path="../bower_components/definitivelyTyped/angularjs/angular-resource.d.ts" /> | ||
|
||
'use strict'; | ||
|
||
angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) { %> | ||
.config(function ($routeProvider:ng.route.IRouteProvider) { | ||
$routeProvider | ||
.when('/', { | ||
templateUrl: 'views/main.html', | ||
controller: 'MainCtrl' | ||
}) | ||
.otherwise({ | ||
redirectTo: '/' | ||
}); | ||
})<% } %>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path="../app.ts" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the installed Angular modules. Do they not need to be referenced up here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see what you did there. Since app.ts is referenced, you don't need to re-reference any of the angular modules. Nice! |
||
|
||
'use strict'; | ||
|
||
module <%= scriptAppName %> { | ||
export interface I<%= classedName %>Scope extends ng.IScope { | ||
awesomeThings: any[]; | ||
} | ||
|
||
export class <%= classedName %>Ctrl { | ||
|
||
constructor (private $scope:I<%= classedName %>Scope) { | ||
$scope.awesomeThings = [ | ||
'HTML5 Boilerplate', | ||
'AngularJS', | ||
'Karma' | ||
]; | ||
} | ||
} | ||
} | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller('<%= classedName %>Ctrl', <%= scriptAppName %>.<%= classedName %>Ctrl); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference path="../app.ts" /> | ||
|
||
'use strict'; | ||
|
||
module <%= scriptAppName %>{ | ||
export function <%= cameledName %>DecoratorProvider($provide:ng.auto.IProvideService):void { | ||
//decorate <%= cameledName %> | ||
$provide.decorator('<%= cameledName %>', <%= cameledName %>Decorator); | ||
} | ||
|
||
export function <%= cameledName %>Decorator($delegate) { | ||
// decorate the $delegate | ||
return $delegate; | ||
} | ||
} | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.config(<%= scriptAppName %>.<%= cameledName %>DecoratorProvider); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// <reference path="../app.ts" /> | ||
|
||
'use strict'; | ||
|
||
module <%= scriptAppName %> { | ||
|
||
export class <%= classedName %> implements ng.IDirective { | ||
template = '<div></div>'; | ||
restrict = 'E'; | ||
link = function (scope, element: JQuery, attrs: ng.IAttributes):void { | ||
element.text('this is the <%= cameledName %> directive'); | ||
} | ||
} | ||
|
||
export function <%= cameledName %>Factory() { | ||
return new <%= scriptAppName %>.<%= classedName %>(); | ||
} | ||
|
||
} | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.directive('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>Factory); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference path="../app.ts" /> | ||
|
||
'use strict'; | ||
|
||
module <%= scriptAppName %> { | ||
export function <%= cameledName %>FilterFactory():Function { | ||
return <%= cameledName %>Filter; | ||
} | ||
|
||
function <%= cameledName %>Filter(input, param) { | ||
//usage {{"text" | <%= cameledName %>: "suffix"}} | ||
//returns '<%= cameledName %> filter: text suffix' | ||
return '<%= cameledName %> filter: ' + input + (param ? ' ' + param: ''); | ||
} | ||
} | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.filter('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>FilterFactory); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// <reference path="../app.ts" /> | ||
|
||
'use strict'; | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.constant('<%= cameledName %>', 42); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference path="../app.ts" /> | ||
|
||
'use strict'; | ||
|
||
module <%= scriptAppName %> { | ||
export function <%= cameledName %>Factory() { | ||
return new <%= classedName %>(42); | ||
} | ||
export class <%= classedName %> { | ||
|
||
constructor (private meaningOfLife) { | ||
} | ||
|
||
someMethod(){ | ||
return this.meaningOfLife | ||
} | ||
} | ||
} | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.factory('<%= cameledName %>', <%= scriptAppName %>.<%= cameledName %>Factory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure the splicable section doesn't also need a condition for typescript? Maybe (coffee || typescript)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, because typescript is a superset of javascript, so it has the same syntax as javascript. CoffeeScript has different language syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Just making sure.