Skip to content

Commit 8d1471a

Browse files
committed
Ts improve (#1867)
* fix(gen:endpoint): return promise * chore(app): tsd -> typings (fix webdriver-update for diff npm versions) closes #1803 [2a46b5d] b * refactor(client): fix some type errors * fix(build): don't include postinstall on CI * test(gen): replace expected tsd files with expected typings file * fix(gen:app): only include `typings.json` with TS
1 parent 55c9a18 commit 8d1471a

File tree

12 files changed

+77
-124
lines changed

12 files changed

+77
-124
lines changed

gulpfile.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ var processJson = function(src, dest, opt) {
8484

8585
var json = JSON.parse(data.replace(/<%(.*)%>/g, ''));
8686

87+
if(/package.json/g.test(src) && opt.test) {
88+
delete json.scripts.postinstall;
89+
}
90+
8791
// set properties
8892
json.name = opt.appName;
8993
json.description = opt.private
@@ -103,13 +107,14 @@ var processJson = function(src, dest, opt) {
103107

104108
function updateFixtures(target) {
105109
const deps = target === 'deps';
110+
const test = target === 'test';
106111
const genVer = require('./package.json').version;
107112
const dest = __dirname + (deps ? '/angular-fullstack-deps/' : '/test/fixtures/');
108113
const appName = deps ? 'angular-fullstack-deps' : 'tempApp';
109114

110115
return Promise.all([
111-
processJson('templates/app/_package.json', dest + 'package.json', {appName, genVer, private: !deps}),
112-
processJson('templates/app/_bower.json', dest + 'bower.json', {appName, genVer, private: !deps})
116+
processJson('templates/app/_package.json', dest + 'package.json', {appName, genVer, private: !deps, test: test}),
117+
processJson('templates/app/_bower.json', dest + 'bower.json', {appName, genVer, private: !deps, test: test})
113118
]);
114119
}
115120

src/generators/endpoint/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Generator extends Base {
2929

3030
initializing() {
3131
// init shared generator properies and methods
32-
genNamedBase(this);
32+
return genNamedBase(this);
3333
}
3434

3535
prompting() {

src/test/get-expected-files.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ export function app(options) {
111111
files = files.concat([
112112
'tsconfig.client.test.json',
113113
'tsconfig.client.json',
114-
'tsd.json',
115-
'tsd_test.json',
114+
'typings.json',
116115
'client/tslint.json'
117116
]);
118117
} else {

templates/app/Gruntfile(grunt).js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -664,19 +664,8 @@ module.exports = function(grunt) {
664664
}
665665
},
666666

667-
tsd: {
668-
install: {
669-
options: {
670-
command: 'reinstall',
671-
config: './tsd.json'
672-
}
673-
},
674-
install_test: {
675-
options: {
676-
command: 'reinstall',
677-
config: './tsd_test.json'
678-
}
679-
}
667+
typings: {
668+
install: {}
680669
},<% } %><% if(filters.stylus) { %>
681670

682671
// Compiles Stylus to CSS
@@ -856,7 +845,7 @@ module.exports = function(grunt) {
856845
'clean:server',
857846
'env:all',
858847
'concurrent:pre',<% if(filters.ts) { %>
859-
'tsd',<% } %>
848+
'typings',<% } %>
860849
'concurrent:server',
861850
'injector',
862851
'wiredep:client',
@@ -869,7 +858,7 @@ module.exports = function(grunt) {
869858
'clean:server',
870859
'env:all',
871860
'concurrent:pre',<% if(filters.ts) { %>
872-
'tsd',<% } %>
861+
'typings',<% } %>
873862
'concurrent:server',
874863
'injector',
875864
'wiredep:client',
@@ -901,7 +890,7 @@ module.exports = function(grunt) {
901890
'concurrent:pre',<% if(filters.ts) { %>
902891
'ts:client',
903892
'ts:client_test',
904-
'tsd',<% } %>
893+
'typings',<% } %>
905894
'concurrent:test',
906895
'injector',
907896
'postcss',
@@ -923,8 +912,7 @@ module.exports = function(grunt) {
923912
'env:all',
924913
'env:test',
925914
'concurrent:pre',<% if(filters.ts) { %>
926-
'tsd:install',
927-
'tsd:install_test',
915+
'typings',
928916
'ts:client',
929917
'ts:client_test',<% } %>
930918
'concurrent:test',
@@ -971,7 +959,7 @@ module.exports = function(grunt) {
971959
grunt.registerTask('build', [
972960
'clean:dist',
973961
'concurrent:pre',<% if(filters.ts) { %>
974-
'tsd',<% } %>
962+
'typings',<% } %>
975963
'concurrent:dist',
976964
'injector',
977965
'wiredep:client',

templates/app/_package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"gulp-autoprefixer": "^3.1.0",
5151
"gulp-babel": "^6.1.2",<% if(filters.ts) { %>
5252
"gulp-typescript": "~2.13.0",
53-
"gulp-tsd": "~0.1.0",
53+
"gulp-typings": "^1.3.6",
5454
"gulp-tslint": "^5.0.0",<% } %>
5555
"gulp-cache": "^0.4.2",
5656
"gulp-concat": "^2.6.0",
@@ -113,7 +113,7 @@
113113
"grunt-contrib-less": "^1.2.0",<% } %>
114114
"grunt-babel": "~6.0.0",<% if(filters.ts) { %>
115115
"grunt-ts": "^5.3.2",
116-
"grunt-tsd": "~0.1.0",
116+
"grunt-typings": "~0.1.4",
117117
"grunt-tslint": "~3.1.0",<% } %>
118118
"grunt-google-cdn": "~0.4.0",
119119
"grunt-jscs": "^2.1.0",
@@ -168,17 +168,23 @@
168168
"phantomjs-prebuilt": "^2.1.4",
169169
"proxyquire": "^1.0.1",
170170
"supertest": "^1.1.0"<% if(filters.ts) { %>,
171-
"tslint": "^3.5.0"<% } %>
171+
"tslint": "^3.5.0",
172+
"typings": "^0.8.1"<% } %>
172173
},
173174
"engines": {
174175
"node": "^4.4.0",
175176
"npm": "^2.14.20"
176177
},
177-
"scripts": {
178-
"start": "node server",<% if(filters.gulp) { %>
178+
"scripts": {<% if(filters.gulp) { %>
179179
"test": "gulp test",<% } else { %>
180180
"test": "grunt test",<% } %>
181-
"update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update"
181+
<%_ if(filters.ts) { _%>
182+
"postinstall": "./node_modules/.bin/typings install",<% } %>
183+
<%_ if(semver.satisfies(npmVersion, '>= 3')) { _%>
184+
"update-webdriver": "node node_modules/protractor/bin/webdriver-manager update",
185+
<%_ } else { _%>
186+
"update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update",<% } %>
187+
"start": "node server"
182188
},
183189
"private": true
184190
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

33
class SettingsController {
4-
constructor(Auth) {
5-
this.errors = {};
6-
this.submitted = false;
4+
errors = {};
5+
submitted = false;
76

7+
constructor(Auth) {
88
this.Auth = Auth;
99
}
1010

templates/app/client/app/admin(auth)/admin.controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
(function() {
44

55
class AdminController {
6+
<%_ if(filters.ts || filters.flow) { _%>
7+
users: Object[];
8+
9+
<%_ } _%>
610
constructor(User) {
711
// Use the User $resource to fetch all users
812
this.users = User.query();

templates/app/gulpfile.babel(gulp).js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,8 @@ function injectTsConfig(filesGlob, tsconfigPath){
245245
gulp.task('inject:tsconfig', () => {
246246
return injectTsConfig([
247247
`${clientPath}/**/!(*.spec|*.mock).ts`,
248-
`!${clientPath}/bower_components/**/*`,
249-
`${clientPath}/typings/**/*.d.ts`,
250-
`!${clientPath}/test_typings/**/*.d.ts`
248+
`!${clientPath}/bower_components/**/*`,
249+
`typings/main.d.ts`
251250
],
252251
'./tsconfig.client.json');
253252
});
@@ -256,8 +255,7 @@ gulp.task('inject:tsconfigTest', () => {
256255
return injectTsConfig([
257256
`${clientPath}/**/+(*.spec|*.mock).ts`,
258257
`!${clientPath}/bower_components/**/*`,
259-
`!${clientPath}/typings/**/*.d.ts`,
260-
`${clientPath}/test_typings/**/*.d.ts`
258+
`typings/main.d.ts`
261259
],
262260
'./tsconfig.client.test.json');
263261
});<% } %>
@@ -298,25 +296,17 @@ gulp.task('inject:<%= styleExt %>', () => {
298296
});<% } %><% if(filters.ts) { %>
299297

300298
// Install DefinitelyTyped TypeScript definition files
301-
gulp.task('tsd', cb => {
302-
plugins.tsd({
303-
command: 'reinstall',
304-
config: './tsd.json'
305-
}, cb);
306-
});
307-
308-
gulp.task('tsd:test', cb => {
309-
plugins.tsd({
310-
command: 'reinstall',
311-
config: './tsd_test.json'
312-
}, cb);
299+
gulp.task('typings', () => {
300+
return gulp.src("./typings.json")
301+
.pipe(plugins.typings());
313302
});<% } %>
314303

315304
gulp.task('styles', () => {
316305
<%_ if(!filters.css) { _%>
317306
return gulp.src(paths.client.mainStyle)
318307
<%_ } else { _%>
319-
return gulp.src(paths.client.styles)<% } %>
308+
return gulp.src(paths.client.styles)
309+
<%_ } _%>
320310
.pipe(styles())
321311
.pipe(gulp.dest('.tmp/app'));
322312
});<% if(filters.ts) { %>
@@ -326,20 +316,18 @@ gulp.task('copy:constant', ['constant'], () => {
326316
.pipe(gulp.dest('.tmp/app'));
327317
})
328318

329-
gulp.task('transpile:client', ['tsd', 'copy:constant'], () => {
330-
let tsProject = plugins.typescript.createProject('./tsconfig.client.json');
331-
return tsProject.src()
319+
gulp.task('transpile:client', ['typings', 'copy:constant'], () => {
320+
return gulp.src(['client/{app,components}/**/!(*.spec|*.mock).ts', 'typings/main.d.ts'])
332321
.pipe(plugins.sourcemaps.init())
333-
.pipe(plugins.typescript(tsProject)).js
322+
.pipe(plugins.typescript()).js
334323
.pipe(plugins.sourcemaps.write('.'))
335324
.pipe(gulp.dest('.tmp'));
336325
});
337326

338-
gulp.task('transpile:client:test', ['tsd:test'], () => {
339-
let tsTestProject = plugins.typescript.createProject('./tsconfig.client.test.json');
340-
return tsTestProject.src()
327+
gulp.task('transpile:client:test', ['typings'], () => {
328+
return gulp.src(['client/{app,components}/**/+(*.spec|*.mock).ts', 'typings/main.d.ts'])
341329
.pipe(plugins.sourcemaps.init())
342-
.pipe(plugins.typescript(tsTestProject)).js
330+
.pipe(plugins.typescript()).js
343331
.pipe(plugins.sourcemaps.write('.'))
344332
.pipe(gulp.dest('.tmp/test'));
345333
});<% } %><% if(filters.babel) { %>
@@ -448,7 +436,7 @@ gulp.task('watch', () => {
448436
.pipe(gulp.dest('.tmp'))
449437
.pipe(plugins.livereload());<% } %><% if(filters.ts) { %>
450438

451-
gulp.watch(paths.client.scripts, ['inject:tsconfig', 'lint:scripts:client', 'transpile:client']);<% } %>
439+
gulp.watch(paths.client.scripts, ['lint:scripts:client', 'transpile:client']);<% } %>
452440

453441
plugins.watch(_.union(paths.server.scripts, testFiles))
454442
.pipe(plugins.plumber())
@@ -459,7 +447,7 @@ gulp.task('watch', () => {
459447
});
460448

461449
gulp.task('serve', cb => {
462-
runSequence(['clean:tmp', 'constant', 'env:all'<% if(filters.ts) { %>, 'tsd'<% } %>],
450+
runSequence(['clean:tmp', 'constant', 'env:all'<% if(filters.ts) { %>, 'typings'<% } %>],
463451
['lint:scripts', 'inject'<% if(filters.jade) { %>, 'jade'<% } %>],
464452
['wiredep:client'],
465453
['transpile:client', 'styles'],
@@ -478,7 +466,7 @@ gulp.task('serve:dist', cb => {
478466
});
479467

480468
gulp.task('serve:debug', cb => {
481-
runSequence(['clean:tmp', 'constant'<% if(filters.ts) { %>, 'tsd'<% } %>],
469+
runSequence(['clean:tmp', 'constant'<% if(filters.ts) { %>, 'typings'<% } %>],
482470
['lint:scripts', 'inject'<% if(filters.jade) { %>, 'jade'<% } %>],
483471
['wiredep:client'],
484472
['transpile:client', 'styles'],
@@ -568,7 +556,7 @@ gulp.task('build', cb => {
568556
'jade',<% } %>
569557
'inject',
570558
'wiredep:client',<% if(filters.ts) { %>
571-
'tsd',<% } %>
559+
'typings',<% } %>
572560
[
573561
'build:images',
574562
'copy:extras',

templates/app/tsconfig.client(ts).json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"compilerOptions": {
33
"sourceMap": true,
44
"rootDir": "./client",
5-
"outDir": ".tmp"
5+
"outDir": ".tmp",
6+
"target": "ES5"
67
},
78
"filesGlob": [
89
"client/{app,components}/**/!(*.spec).ts",
9-
"client/typings/**/*.d.ts"
10+
"typings/main.d.ts"
1011
],
1112
"files": [
1213
"client/app/account/account.ts",
@@ -36,10 +37,6 @@
3637
"client/components/ui-router/ui-router.mock.ts",
3738
"client/components/util/util.module.ts",
3839
"client/components/util/util.service.ts",
39-
"client/typings/angularjs/angular.d.ts",
40-
"client/typings/jquery/jquery.d.ts",
41-
"client/typings/lodash/lodash.d.ts",
42-
"client/typings/socket.io-client/socket.io-client.d.ts",
43-
"client/typings/tsd.d.ts"
40+
"typings/main.d.ts"
4441
]
4542
}

templates/app/tsd(ts).json

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)