Skip to content

feat(client): Add initial TypeScript support #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2015
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
27 changes: 20 additions & 7 deletions app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ export default class Generator extends Base {

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

this.prompt([/*{
this.prompt([{
type: 'list',
name: 'script',
name: 'transpiler',
message: 'What would you like to write scripts with?',
choices: ['Babel', 'TypeScript'],
filter: function(val) { return val.toLowerCase(); }
}, */{
filter: val => {
return {
'Babel': 'babel',
'TypeScript': 'ts'
}[val];
}
}, {
type: 'list',
name: 'markup',
message: 'What would you like to write markup with?',
Expand Down Expand Up @@ -136,14 +141,14 @@ export default class Generator extends Base {
}], function (answers) {

this.filters.js = true;
this.filters.babel = true;
this.filters[answers.transpiler] = true;
this.filters[answers.markup] = true;
this.filters[answers.stylesheet] = true;
this.filters[answers.router] = true;
this.filters.bootstrap = !!answers.bootstrap;
this.filters.uibootstrap = !!answers.uibootstrap;

this.scriptExt = answers.script === 'coffee' ? 'coffee' : 'js';
this.scriptExt = answers.transpiler === 'ts' ? 'ts' : 'js';
this.templateExt = answers.markup;
this.styleExt = answers.stylesheet === 'sass' ? 'scss' : answers.stylesheet;

Expand Down Expand Up @@ -359,6 +364,7 @@ export default class Generator extends Base {
if(this.filters.ngroute) filters.push('ngroute');
if(this.filters.uirouter) filters.push('uirouter');
if(this.filters.babel) extensions.push('babel');
if(this.filters.ts) extensions.push('ts');
if(this.filters.js) extensions.push('js');
if(this.filters.html) extensions.push('html');
if(this.filters.jade) extensions.push('jade');
Expand Down Expand Up @@ -412,8 +418,15 @@ export default class Generator extends Base {
return {

generateProject: function() {
let self = this;
this.sourceRoot(path.join(__dirname, './templates'));
this.processDirectory('.', '.');
this.processDirectory('.', '.', function(dest) {
if(self.filters.ts && dest.indexOf('client') > -1 && dest.indexOf('.json') === -1) {
dest = dest.replace('.js', '.ts');
}

return dest;
});
},

generateEndpoint: function() {
Expand Down
121 changes: 94 additions & 27 deletions app/templates/Gruntfile(grunt).js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ module.exports = function (grunt) {
babel: {
files: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js'],
tasks: ['newer:babel:client']
},<% } %><% if(filters.ts) { %>
ts: {
files: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).ts'],
tasks: ['ts:client']
},<% } %>
ngconstant: {
files: ['<%%= yeoman.server %>/config/environment/shared.js'],
tasks: ['ngconstant']
},
injectJS: {
files: [
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js',
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',
'!<%%= yeoman.client %>/app/app.js'
],
tasks: ['injector:scripts']
Expand All @@ -77,12 +81,12 @@ module.exports = function (grunt) {
tasks: ['injector:css']
},
mochaTest: {
files: ['<%%= yeoman.server %>/**/*.{spec,integration}.js'],
files: ['<%%= yeoman.server %>/**/*.{spec,integration}.<%= scriptExt %>'],
tasks: ['env:test', 'mochaTest']
},
jsTest: {
files: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js'],
tasks: ['newer:jshint:all', 'wiredep:test', 'karma']
files: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.<%= scriptExt %>'],
tasks: [<% if(filters.babel) { %>'newer:jshint:all'<% } if(filters.ts) { %>'newer:tslint:all', 'newer:ts:client_test',<% } %>, 'wiredep:test', 'karma']
},<% if (filters.stylus) { %>
injectStylus: {
files: ['<%%= yeoman.client %>/{app,components}/**/*.styl'],
Expand Down Expand Up @@ -118,7 +122,7 @@ module.exports = function (grunt) {
livereload: {
files: [
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/*.{css,html}',
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',
'<%%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}'
],
options: {
Expand Down Expand Up @@ -161,7 +165,16 @@ module.exports = function (grunt) {
test: {
src: ['<%%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js']
}
},
},<% if(filters.ts) { %>

tslint: {
options: {
configuration: '<%%= yeoman.client %>/tslint.json'
},
all: {
src: ['<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).ts']
}
},<% } %>

jscs: {
options: {
Expand Down Expand Up @@ -420,7 +433,13 @@ module.exports = function (grunt) {
cwd: '<%%= yeoman.client %>',
dest: '.tmp/',
src: ['{app,components}/**/*.css']
}
}<% if(filters.ts) { %>,
constant: {
expand: true,
cwd: '<%%= yeoman.client %>',
dest: '.tmp/',
src: ['app/app.constant.js']
}<% } %>
},

buildcontrol: {
Expand Down Expand Up @@ -451,17 +470,23 @@ module.exports = function (grunt) {
'injector:stylus',<% } if (filters.less) { %>
'injector:less',<% } if (filters.sass) { %>
'injector:sass',<% } %>
'ngconstant'
'ngconstant'<% if(filters.ts) { %>,
'copy:constant'<% } %>
],
server: [<% if(filters.babel) { %>
'newer:babel:client',<% } if(filters.jade) { %>
'newer:babel:client',<% } if(filters.ts) { %>
'ts:client',
'copy:constant',<% } if(filters.jade) { %>
'jade',<% } if(filters.stylus) { %>
'stylus',<% } if(filters.sass) { %>
'sass',<% } if(filters.less) { %>
'less',<% } %>
],
test: [<% if(filters.babel) { %>
'newer:babel:client',<% } if(filters.jade) { %>
'newer:babel:client',<% } if(filters.ts) { %>
'ts:client',
'copy:constant',<% } if(filters.ts) { %>
'ts:client_test',<% } if(filters.jade) { %>
'jade',<% } if(filters.stylus) { %>
'stylus',<% } if(filters.sass) { %>
'sass',<% } if(filters.less) { %>
Expand All @@ -477,7 +502,9 @@ module.exports = function (grunt) {
}
},
dist: [<% if(filters.babel) { %>
'newer:babel:client',<% } if(filters.jade) { %>
'newer:babel:client',<% } if(filters.ts) { %>
'ts:client',
'copy:constant',<% } if(filters.jade) { %>
'jade',<% } if(filters.stylus) { %>
'stylus',<% } if(filters.sass) { %>
'sass',<% } if(filters.less) { %>
Expand Down Expand Up @@ -613,7 +640,37 @@ module.exports = function (grunt) {
dest: '<%%= yeoman.dist %>/<%%= yeoman.server %>'
}]
}
},<% if(filters.stylus) { %>
},<% if(filters.ts) { %>

ts: {
options: {
sourceMap: true,
failOnTypeErrors: false
},
client: {
tsconfig: './tsconfig.client.json',
outDir: '.tmp'
},
client_test: {
tsconfig: './tsconfig.client.test.json',
outDir: '.tmp/test'
}
},

tsd: {
install: {
options: {
command: 'reinstall',
config: './tsd.json'
}
},
install_test: {
options: {
command: 'reinstall',
config: './tsd_test.json'
}
}
},<% } %><% if(filters.stylus) { %>

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

injector: {
options: {

},
options: {},
// Inject application script files into index.html (doesn't include bower)
scripts: {
options: {
transform: function(filePath) {
var yoClient = grunt.config.get('yeoman.client');
filePath = filePath.replace('/' + yoClient + '/', '');
filePath = filePath.replace('/.tmp/', '');
filePath = filePath.replace('/.tmp/', '');<% if(filters.ts) { %>
filePath = filePath.replace('.ts', '.js');<% } %>
return '<script src="' + filePath + '"></script>';
},
sort: function(a, b) {
Expand All @@ -673,10 +729,10 @@ module.exports = function (grunt) {
},
files: {
'<%%= yeoman.client %>/index.html': [
[<% if(filters.babel) { %>
'.tmp/{app,components}/**/!(*.spec|*.mock).js',<% } else { %>
'{.tmp,<%%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',<% } %>
'!{.tmp,<%%= yeoman.client %>}/app/app.js'
[
'<%%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).<%= scriptExt %>',<% if(filters.ts) { %>
'<%%= yeoman.client %>/app/app.constant.js',<% } %>
'!{.tmp,<%%= yeoman.client %>}/app/app.{js,ts}'
]
]
}
Expand Down Expand Up @@ -788,7 +844,8 @@ module.exports = function (grunt) {
return grunt.task.run([
'clean:server',
'env:all',
'concurrent:pre',
'concurrent:pre',<% if(filters.ts) { %>
'tsd',<% } %>
'concurrent:server',
'injector',
'wiredep:client',
Expand All @@ -800,7 +857,8 @@ module.exports = function (grunt) {
grunt.task.run([
'clean:server',
'env:all',
'concurrent:pre',
'concurrent:pre',<% if(filters.ts) { %>
'tsd',<% } %>
'concurrent:server',
'injector',
'wiredep:client',
Expand Down Expand Up @@ -831,7 +889,10 @@ module.exports = function (grunt) {
return grunt.task.run([
'clean:server',
'env:all',
'concurrent:pre',
'concurrent:pre',<% if(filters.ts) { %>
'ts:client',
'ts:client_test',
'tsd',<% } %>
'concurrent:test',
'injector',
'postcss',
Expand All @@ -857,7 +918,11 @@ module.exports = function (grunt) {
'clean:server',
'env:all',
'env:test',
'concurrent:pre',
'concurrent:pre',<% if(filters.ts) { %>
'tsd:install',
'tsd:install_test',
'ts:client',
'ts:client_test',<% } %>
'concurrent:test',
'injector',
'wiredep:client',
Expand Down Expand Up @@ -911,7 +976,8 @@ module.exports = function (grunt) {

grunt.registerTask('build', [
'clean:dist',
'concurrent:pre',
'concurrent:pre',<% if(filters.ts) { %>
'tsd',<% } %>
'concurrent:dist',
'injector',
'wiredep:client',
Expand All @@ -929,8 +995,9 @@ module.exports = function (grunt) {
'usemin'
]);

grunt.registerTask('default', [
'newer:jshint',
grunt.registerTask('default', [<% if(filters.babel) { %>
'newer:tslint',<% } %><% if(filters.ts) { %>
'newer:jshint',<% } %>
'test',
'build'
]);
Expand Down
14 changes: 10 additions & 4 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
"gulp": "^3.9.0",
"gulp-add-src": "^0.2.0",
"gulp-angular-templatecache": "^1.7.0",
"gulp-autoprefixer": "2.3.1",<% if(filters.babel) { %>
"gulp-babel": "^5.1.0",<% } %>
"gulp-babel-istanbul": "^0.11.0",
"gulp-autoprefixer": "2.3.1",
"gulp-babel": "^5.1.0",
"gulp-babel-istanbul": "^0.11.0",<% if(filters.ts) { %>
"gulp-typescript": "~2.10.0",
"gulp-tsd": "~0.0.4",
"gulp-tslint": "~4.2.1",<% } %>
"gulp-cache": "^0.2.10",
"gulp-concat": "^2.6.0",
"gulp-env": "^0.2.0",
Expand Down Expand Up @@ -97,7 +100,10 @@
"grunt-contrib-watch": "~0.6.1",<% if (filters.jade) { %>
"grunt-contrib-jade": "^0.15.0",<% } %><% if (filters.less) { %>
"grunt-contrib-less": "^1.0.0",<% } %><% if(filters.babel) { %>
"grunt-babel": "~5.0.0",<% } %>
"grunt-babel": "~5.0.0",<% } %><% if(filters.ts) { %>
"grunt-ts": "~5.2.0",
"grunt-tsd": "~0.1.0",
"grunt-tslint": "~3.0.1",<% } %>
"grunt-google-cdn": "~0.4.0",
"grunt-jscs": "^2.1.0",
"grunt-newer": "^1.1.1",
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions app/templates/client/app/account(auth)/login/login.controller.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
'use strict';

class LoginController {
//start-non-standard
user = {};
errors = {};
submitted = false;
//end-non-standard

constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) {
this.user = {};
this.errors = {};
this.submitted = false;

this.Auth = Auth;<% if (filters.ngroute) { %>
this.$location = $location;<% } if (filters.uirouter) { %>
this.$state = $state;<% } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';

class SettingsController {
//start-non-standard
errors = {};
submitted = false;
//end-non-standard

constructor(Auth) {
this.errors = {};
this.submitted = false;

this.Auth = Auth;
}

Expand Down
6 changes: 3 additions & 3 deletions app/templates/client/components/auth(auth)/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function AuthService($location, $http, $cookies, $q, appConfig, Util, User) {
* @param {Function} callback - optional, function(error, user)
* @return {Promise}
*/
login(user, callback) {
login({email, password}, callback) {
return $http.post('/auth/local', {
email: user.email,
password: user.password
email: email,
password: password
})
.then(res => {
$cookies.put('token', res.data.token);
Expand Down
Loading