Skip to content

Commit 50d32aa

Browse files
committed
Merge pull request #1508 from angular-fullstack/feat/typescript-client
feat(client): Add initial TypeScript support
2 parents 5bc5656 + cfa47bc commit 50d32aa

19 files changed

+446
-103
lines changed

Diff for: app/generator.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ export default class Generator extends Base {
9696

9797
this.log('# Client\n');
9898

99-
this.prompt([/*{
99+
this.prompt([{
100100
type: 'list',
101-
name: 'script',
101+
name: 'transpiler',
102102
message: 'What would you like to write scripts with?',
103103
choices: ['Babel', 'TypeScript'],
104-
filter: function(val) { return val.toLowerCase(); }
105-
}, */{
104+
filter: val => {
105+
return {
106+
'Babel': 'babel',
107+
'TypeScript': 'ts'
108+
}[val];
109+
}
110+
}, {
106111
type: 'list',
107112
name: 'markup',
108113
message: 'What would you like to write markup with?',
@@ -136,14 +141,14 @@ export default class Generator extends Base {
136141
}], function (answers) {
137142

138143
this.filters.js = true;
139-
this.filters.babel = true;
144+
this.filters[answers.transpiler] = true;
140145
this.filters[answers.markup] = true;
141146
this.filters[answers.stylesheet] = true;
142147
this.filters[answers.router] = true;
143148
this.filters.bootstrap = !!answers.bootstrap;
144149
this.filters.uibootstrap = !!answers.uibootstrap;
145150

146-
this.scriptExt = answers.script === 'coffee' ? 'coffee' : 'js';
151+
this.scriptExt = answers.transpiler === 'ts' ? 'ts' : 'js';
147152
this.templateExt = answers.markup;
148153
this.styleExt = answers.stylesheet === 'sass' ? 'scss' : answers.stylesheet;
149154

@@ -359,6 +364,7 @@ export default class Generator extends Base {
359364
if(this.filters.ngroute) filters.push('ngroute');
360365
if(this.filters.uirouter) filters.push('uirouter');
361366
if(this.filters.babel) extensions.push('babel');
367+
if(this.filters.ts) extensions.push('ts');
362368
if(this.filters.js) extensions.push('js');
363369
if(this.filters.html) extensions.push('html');
364370
if(this.filters.jade) extensions.push('jade');
@@ -412,8 +418,15 @@ export default class Generator extends Base {
412418
return {
413419

414420
generateProject: function() {
421+
let self = this;
415422
this.sourceRoot(path.join(__dirname, './templates'));
416-
this.processDirectory('.', '.');
423+
this.processDirectory('.', '.', function(dest) {
424+
if(self.filters.ts && dest.indexOf('client') > -1 && dest.indexOf('.json') === -1) {
425+
dest = dest.replace('.js', '.ts');
426+
}
427+
428+
return dest;
429+
});
417430
},
418431

419432
generateEndpoint: function() {

Diff for: app/templates/Gruntfile(grunt).js

+94-27
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ module.exports = function (grunt) {
6060
babel: {
6161
files: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js'],
6262
tasks: ['newer:babel:client']
63+
},<% } %><% if(filters.ts) { %>
64+
ts: {
65+
files: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).ts'],
66+
tasks: ['ts:client']
6367
},<% } %>
6468
ngconstant: {
6569
files: ['<%%= yeoman.server %>/config/environment/shared.js'],
6670
tasks: ['ngconstant']
6771
},
6872
injectJS: {
6973
files: [
70-
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js',
74+
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',
7175
'!<%%= yeoman.client %>/app/app.js'
7276
],
7377
tasks: ['injector:scripts']
@@ -77,12 +81,12 @@ module.exports = function (grunt) {
7781
tasks: ['injector:css']
7882
},
7983
mochaTest: {
80-
files: ['<%%= yeoman.server %>/**/*.{spec,integration}.js'],
84+
files: ['<%%= yeoman.server %>/**/*.{spec,integration}.<%= scriptExt %>'],
8185
tasks: ['env:test', 'mochaTest']
8286
},
8387
jsTest: {
84-
files: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js'],
85-
tasks: ['newer:jshint:all', 'wiredep:test', 'karma']
88+
files: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.<%= scriptExt %>'],
89+
tasks: [<% if(filters.babel) { %>'newer:jshint:all'<% } if(filters.ts) { %>'newer:tslint:all', 'newer:ts:client_test',<% } %>, 'wiredep:test', 'karma']
8690
},<% if (filters.stylus) { %>
8791
injectStylus: {
8892
files: ['<%%= yeoman.client %>/{app,components}/**/*.styl'],
@@ -118,7 +122,7 @@ module.exports = function (grunt) {
118122
livereload: {
119123
files: [
120124
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.{css,html}',
121-
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',
125+
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',
122126
'<%%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}'
123127
],
124128
options: {
@@ -161,7 +165,16 @@ module.exports = function (grunt) {
161165
test: {
162166
src: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js']
163167
}
164-
},
168+
},<% if(filters.ts) { %>
169+
170+
tslint: {
171+
options: {
172+
configuration: '<%%= yeoman.client %>/tslint.json'
173+
},
174+
all: {
175+
src: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).ts']
176+
}
177+
},<% } %>
165178

166179
jscs: {
167180
options: {
@@ -420,7 +433,13 @@ module.exports = function (grunt) {
420433
cwd: '<%%= yeoman.client %>',
421434
dest: '.tmp/',
422435
src: ['{app,components}/**/*.css']
423-
}
436+
}<% if(filters.ts) { %>,
437+
constant: {
438+
expand: true,
439+
cwd: '<%%= yeoman.client %>',
440+
dest: '.tmp/',
441+
src: ['app/app.constant.js']
442+
}<% } %>
424443
},
425444

426445
buildcontrol: {
@@ -451,17 +470,23 @@ module.exports = function (grunt) {
451470
'injector:stylus',<% } if (filters.less) { %>
452471
'injector:less',<% } if (filters.sass) { %>
453472
'injector:sass',<% } %>
454-
'ngconstant'
473+
'ngconstant'<% if(filters.ts) { %>,
474+
'copy:constant'<% } %>
455475
],
456476
server: [<% if(filters.babel) { %>
457-
'newer:babel:client',<% } if(filters.jade) { %>
477+
'newer:babel:client',<% } if(filters.ts) { %>
478+
'ts:client',
479+
'copy:constant',<% } if(filters.jade) { %>
458480
'jade',<% } if(filters.stylus) { %>
459481
'stylus',<% } if(filters.sass) { %>
460482
'sass',<% } if(filters.less) { %>
461483
'less',<% } %>
462484
],
463485
test: [<% if(filters.babel) { %>
464-
'newer:babel:client',<% } if(filters.jade) { %>
486+
'newer:babel:client',<% } if(filters.ts) { %>
487+
'ts:client',
488+
'copy:constant',<% } if(filters.ts) { %>
489+
'ts:client_test',<% } if(filters.jade) { %>
465490
'jade',<% } if(filters.stylus) { %>
466491
'stylus',<% } if(filters.sass) { %>
467492
'sass',<% } if(filters.less) { %>
@@ -477,7 +502,9 @@ module.exports = function (grunt) {
477502
}
478503
},
479504
dist: [<% if(filters.babel) { %>
480-
'newer:babel:client',<% } if(filters.jade) { %>
505+
'newer:babel:client',<% } if(filters.ts) { %>
506+
'ts:client',
507+
'copy:constant',<% } if(filters.jade) { %>
481508
'jade',<% } if(filters.stylus) { %>
482509
'stylus',<% } if(filters.sass) { %>
483510
'sass',<% } if(filters.less) { %>
@@ -613,7 +640,37 @@ module.exports = function (grunt) {
613640
dest: '<%%= yeoman.dist %>/<%%= yeoman.server %>'
614641
}]
615642
}
616-
},<% if(filters.stylus) { %>
643+
},<% if(filters.ts) { %>
644+
645+
ts: {
646+
options: {
647+
sourceMap: true,
648+
failOnTypeErrors: false
649+
},
650+
client: {
651+
tsconfig: './tsconfig.client.json',
652+
outDir: '.tmp'
653+
},
654+
client_test: {
655+
tsconfig: './tsconfig.client.test.json',
656+
outDir: '.tmp/test'
657+
}
658+
},
659+
660+
tsd: {
661+
install: {
662+
options: {
663+
command: 'reinstall',
664+
config: './tsd.json'
665+
}
666+
},
667+
install_test: {
668+
options: {
669+
command: 'reinstall',
670+
config: './tsd_test.json'
671+
}
672+
}
673+
},<% } %><% if(filters.stylus) { %>
617674

618675
// Compiles Stylus to CSS
619676
stylus: {
@@ -649,16 +706,15 @@ module.exports = function (grunt) {
649706
},<% } %>
650707

651708
injector: {
652-
options: {
653-
654-
},
709+
options: {},
655710
// Inject application script files into index.html (doesn't include bower)
656711
scripts: {
657712
options: {
658713
transform: function(filePath) {
659714
var yoClient = grunt.config.get('yeoman.client');
660715
filePath = filePath.replace('/' + yoClient + '/', '');
661-
filePath = filePath.replace('/.tmp/', '');
716+
filePath = filePath.replace('/.tmp/', '');<% if(filters.ts) { %>
717+
filePath = filePath.replace('.ts', '.js');<% } %>
662718
return '<script src="' + filePath + '"></script>';
663719
},
664720
sort: function(a, b) {
@@ -673,10 +729,10 @@ module.exports = function (grunt) {
673729
},
674730
files: {
675731
'<%%= yeoman.client %>/index.html': [
676-
[<% if(filters.babel) { %>
677-
'.tmp/{app,components}/**/!(*.spec|*.mock).js',<% } else { %>
678-
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',<% } %>
679-
'!{.tmp,<%%= yeoman.client %>}/app/app.js'
732+
[
733+
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',<% if(filters.ts) { %>
734+
'<%%= yeoman.client %>/app/app.constant.js',<% } %>
735+
'!{.tmp,<%%= yeoman.client %>}/app/app.{js,ts}'
680736
]
681737
]
682738
}
@@ -788,7 +844,8 @@ module.exports = function (grunt) {
788844
return grunt.task.run([
789845
'clean:server',
790846
'env:all',
791-
'concurrent:pre',
847+
'concurrent:pre',<% if(filters.ts) { %>
848+
'tsd',<% } %>
792849
'concurrent:server',
793850
'injector',
794851
'wiredep:client',
@@ -800,7 +857,8 @@ module.exports = function (grunt) {
800857
grunt.task.run([
801858
'clean:server',
802859
'env:all',
803-
'concurrent:pre',
860+
'concurrent:pre',<% if(filters.ts) { %>
861+
'tsd',<% } %>
804862
'concurrent:server',
805863
'injector',
806864
'wiredep:client',
@@ -831,7 +889,10 @@ module.exports = function (grunt) {
831889
return grunt.task.run([
832890
'clean:server',
833891
'env:all',
834-
'concurrent:pre',
892+
'concurrent:pre',<% if(filters.ts) { %>
893+
'ts:client',
894+
'ts:client_test',
895+
'tsd',<% } %>
835896
'concurrent:test',
836897
'injector',
837898
'postcss',
@@ -857,7 +918,11 @@ module.exports = function (grunt) {
857918
'clean:server',
858919
'env:all',
859920
'env:test',
860-
'concurrent:pre',
921+
'concurrent:pre',<% if(filters.ts) { %>
922+
'tsd:install',
923+
'tsd:install_test',
924+
'ts:client',
925+
'ts:client_test',<% } %>
861926
'concurrent:test',
862927
'injector',
863928
'wiredep:client',
@@ -911,7 +976,8 @@ module.exports = function (grunt) {
911976

912977
grunt.registerTask('build', [
913978
'clean:dist',
914-
'concurrent:pre',
979+
'concurrent:pre',<% if(filters.ts) { %>
980+
'tsd',<% } %>
915981
'concurrent:dist',
916982
'injector',
917983
'wiredep:client',
@@ -929,8 +995,9 @@ module.exports = function (grunt) {
929995
'usemin'
930996
]);
931997

932-
grunt.registerTask('default', [
933-
'newer:jshint',
998+
grunt.registerTask('default', [<% if(filters.babel) { %>
999+
'newer:tslint',<% } %><% if(filters.ts) { %>
1000+
'newer:jshint',<% } %>
9341001
'test',
9351002
'build'
9361003
]);

Diff for: app/templates/_package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242
"gulp": "^3.9.0",
4343
"gulp-add-src": "^0.2.0",
4444
"gulp-angular-templatecache": "^1.7.0",
45-
"gulp-autoprefixer": "2.3.1",<% if(filters.babel) { %>
46-
"gulp-babel": "^5.1.0",<% } %>
47-
"gulp-babel-istanbul": "^0.11.0",
45+
"gulp-autoprefixer": "2.3.1",
46+
"gulp-babel": "^5.1.0",
47+
"gulp-babel-istanbul": "^0.11.0",<% if(filters.ts) { %>
48+
"gulp-typescript": "~2.10.0",
49+
"gulp-tsd": "~0.0.4",
50+
"gulp-tslint": "~4.2.1",<% } %>
4851
"gulp-cache": "^0.2.10",
4952
"gulp-concat": "^2.6.0",
5053
"gulp-env": "^0.2.0",
@@ -97,7 +100,10 @@
97100
"grunt-contrib-watch": "~0.6.1",<% if (filters.jade) { %>
98101
"grunt-contrib-jade": "^0.15.0",<% } %><% if (filters.less) { %>
99102
"grunt-contrib-less": "^1.0.0",<% } %><% if(filters.babel) { %>
100-
"grunt-babel": "~5.0.0",<% } %>
103+
"grunt-babel": "~5.0.0",<% } %><% if(filters.ts) { %>
104+
"grunt-ts": "~5.2.0",
105+
"grunt-tsd": "~0.1.0",
106+
"grunt-tslint": "~3.0.1",<% } %>
101107
"grunt-google-cdn": "~0.4.0",
102108
"grunt-jscs": "^2.1.0",
103109
"grunt-newer": "^1.1.1",
File renamed without changes.

Diff for: app/templates/client/app/account(auth)/login/login.controller.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
'use strict';
22

33
class LoginController {
4-
//start-non-standard
5-
user = {};
6-
errors = {};
7-
submitted = false;
8-
//end-non-standard
9-
104
constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) {
5+
this.user = {};
6+
this.errors = {};
7+
this.submitted = false;
8+
119
this.Auth = Auth;<% if (filters.ngroute) { %>
1210
this.$location = $location;<% } if (filters.uirouter) { %>
1311
this.$state = $state;<% } %>

Diff for: app/templates/client/app/account(auth)/settings/settings.controller.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict';
22

33
class SettingsController {
4-
//start-non-standard
5-
errors = {};
6-
submitted = false;
7-
//end-non-standard
8-
94
constructor(Auth) {
5+
this.errors = {};
6+
this.submitted = false;
7+
108
this.Auth = Auth;
119
}
1210

Diff for: app/templates/client/components/auth(auth)/auth.service.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
2020
* @param {Function} callback - optional, function(error, user)
2121
* @return {Promise}
2222
*/
23-
login(user, callback) {
23+
login({email, password}, callback) {
2424
return $http.post('/auth/local', {
25-
email: user.email,
26-
password: user.password
25+
email: email,
26+
password: password
2727
})
2828
.then(res => {
2929
$cookies.put('token', res.data.token);

0 commit comments

Comments
 (0)