Skip to content

Commit e79c49d

Browse files
committed
Merge branch 'develop'
2 parents cf68c96 + b69b03d commit e79c49d

File tree

9 files changed

+67
-76
lines changed

9 files changed

+67
-76
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
.DS_Store

README.md

+15-42
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
I'm a [Yeoman](http://yeoman.io) generator that allows you to create NodeJS modules using TypeScript. I let you quickly setup a project with latest available tools and best practices.
66
Tools and libraries I use -
77
- _tsc_ - for compiling TypeScript.
8-
- _tsd_ - for TypeScript definition files management.
8+
- _typings_ - for management of TypeScript definitions.
99
- _tsconfig.json_ - for providing compiler options.
1010
- _tslint_ - for linting TypeScript source files.
1111
- [_gulp_](http://gulpjs.com/) - as a build system. You can carry out above tasks through gulp.
1212
- [_Jasmine 2_](http://jasmine.github.io/2.3/introduction.html) - for writing tests.
1313

14-
>You want to know if you can change any of these? Of course, why not? It is your module after all. I simply get down to business of generating, no questions asked. Once done, I get out of the way as if I were not there at all and you can do as you please!
14+
>You want to know if you can change any of these? Of course, why not? It is your module after all. I simply get down to business of generating, no questions asked. Once done, I get out of the way and you can do as you please!
1515
1616
## Usage
1717

18-
Install `typescript tsd tslint generator-node-typescript` globally.
18+
Install `generator-node-typescript`, `gulp-cli` and `typings` globally.
1919

2020
```
21-
npm install -g typescript tsd tslint generator-node-typescript
21+
npm install -g generator-node-typescript gulp-cli typings
2222
```
2323

2424
Create a new directory and `cd` into it.
@@ -39,50 +39,23 @@ Here is the list of tasks available out of the box -
3939
_build INTERNAL TASK - Compiles all TypeScript source files
4040
build Compiles all TypeScript source files and updates module references
4141
clean Cleans the generated js files from lib directory
42-
gen_tsrefs Generates the app.d.ts references file dynamically for all application *.ts files
42+
gen-def Generate a single .d.ts bundle containing external module declarations exported from TypeScript module files
4343
help Display this help text.
4444
test Runs the Jasmine test specs [build]
45-
tsconfig_files Update files section in tsconfig.json
4645
tslint Lints all TypeScript source files
46+
update-tsconfig Update files section in tsconfig.json using filesGlob entries
47+
watch Watches ts source files and runs build on change
4748
```
4849

49-
## Additional notes
50-
- I provide nice integration with [VSCode editor](https://code.visualstudio.com/). I configure the `gulp build` task as the default VSCode build task.
51-
- The `gulp build` task also updates _tsconfig/files_ section using _tsconfig/filesGlob_ and generates _typings/app.d.ts_ references file dynamically
52-
for all the application *.ts files before build so you don't have to do it manually.
53-
54-
## Development tips
55-
- The _tsd_ tool dynamically updates _typings/tsd.d.ts_ file for all type definitions you install through it. Also, the gulp *gen_tsrefs* task dynamically
56-
updates _typings/app.d.ts_ references file for all application *.ts. Therefore you just need to add references to these two files in any _.ts_ file and you
57-
are good to go with *tsc* compiler.
58-
- To keep on using the typical CommonJS exports and imports use the `export` and `inport` systax mentioned in the example below.
59-
60-
```ts
61-
class Greeter {
62-
greeting: string;
63-
constructor(message: string) {
64-
this.greeting = message;
65-
}
66-
greet() {
67-
return 'Bonjour, ' + this.greeting + '!';
68-
}
69-
}
70-
//The following line is important, export like this allows you to use the old-style CommonJS export/import.
71-
export = Greeter;
72-
73-
```
74-
This is how the above class can be used in some other file.
50+
## What's new in the latest release?
51+
- Use of latest version of TypeScript(`^1.8`).
52+
- Switch to _typings_ as manager for TypeScript definitions. The TSD team has deprecated _tsd_ in favour of _typings_. You can find more information about _typings_ on [Github](https://github.com/typings/typings).
53+
- Integration of _dts-generator_ tool to generate a single _.d.ts_ bundle containing external module declarations exported from TypeScript source files in the module. The package.json now declares _typings_ field that points to the single _.d.ts_ bundle. You can find more information about _typings_ field on [TypeScript Wiki](https://github.com/Microsoft/TypeScript/wiki/Typings-for-npm-packages).
54+
- Less global dependencies. `typescript` and `tslint` are now installed as local dev dependencies allowing you to freely use different versions of these for different modules.
55+
- Addition of _gulp watch_ task that watches ts source files and runs build on change.
7556

76-
```ts
77-
/// <reference path="../typings/tsd.d.ts" />
78-
/// <reference path="../typings/app.d.ts" />
79-
80-
import Greeter = require('./greeter');
81-
82-
const greeter = new Greeter('friend');
83-
greeter.greet();
84-
85-
```
57+
## Additional notes
58+
- I provide nice integration with [VS Code editor](https://code.visualstudio.com/). I configure the `gulp build` task as the default VS Code build task.
8659

8760
## License
8861

generators/app/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module.exports = yeoman.generators.Base.extend({
3030
this.directory('src', 'src');
3131
this.directory('test', 'test');
3232
this.directory('_vscode', '.vscode');
33-
this.directory('typings', 'typings');
3433
},
3534

3635
app: function () {
@@ -44,7 +43,8 @@ module.exports = yeoman.generators.Base.extend({
4443
projectfiles: function () {
4544
this.fs.copy(
4645
this.templatePath('_gulpfile.js'),
47-
this.destinationPath('gulpfile.js')
46+
this.destinationPath('gulpfile.js'),
47+
{ appname: _.kebabCase(path.basename(process.cwd())) }
4848
);
4949
this.fs.copy(
5050
this.templatePath('_tsconfig.json'),
@@ -73,8 +73,8 @@ module.exports = yeoman.generators.Base.extend({
7373
npmInstall: function () {
7474
var generator = this;
7575
generator.npmInstall(null, { skipInstall: this.options['skip-install'] }, function () {
76-
generator.spawnCommandSync('tsd', ['init']); //tsd init
77-
generator.spawnCommandSync('tsd', ['install', 'node', '--save']) //tsd install --save node
76+
generator.spawnCommandSync('typings', ['init']); //typings init
77+
generator.spawnCommandSync('typings', ['install', 'node', '--save', '--ambient']) //typings install --save node --ambient
7878
});
7979
}
8080
}

generators/app/templates/_gulpfile.js

+33-21
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,19 @@ var path = require('path');
88
var inject = require('gulp-inject');
99
var gulpSequence = require('gulp-sequence');
1010
var del = require('del');
11-
12-
var typeDefsPath = (function (tsd) {
13-
return tsd.path || 'typings';
14-
})(require('./tsd.json'));
11+
var dtsGenerator = require('dts-generator');
12+
require('dotbin');
1513

1614
var tsFilesGlob = (function (c) {
1715
return c.filesGlob || c.files || '**/*.ts';
1816
})(require('./tsconfig.json'));
1917

20-
gulp.task('tsconfig_files', 'Update files section in tsconfig.json', function () {
21-
gulp.src(tsFilesGlob).pipe(tsconfig());
22-
});
18+
var appName = (function (p) {
19+
return p.name;
20+
})(require('./package.json'));
2321

24-
gulp.task('gen_tsrefs', 'Generates the app.d.ts references file dynamically for all application *.ts files', function () {
25-
var target = gulp.src(path.join('.', typeDefsPath, 'app.d.ts'));
26-
var sources = gulp.src([path.join('.', 'src', '**', '*.ts')], { read: false });
27-
return target.pipe(inject(sources, {
28-
starttag: '//{',
29-
endtag: '//}',
30-
transform: function (filepath) {
31-
return '/// <reference path="..' + filepath + '" />';
32-
}
33-
})).pipe(gulp.dest(path.join('.', typeDefsPath)));
22+
gulp.task('update-tsconfig', 'Update files section in tsconfig.json', function () {
23+
gulp.src(tsFilesGlob).pipe(tsconfig());
3424
});
3525

3626
gulp.task('clean', 'Cleans the generated js files from lib directory', function () {
@@ -45,18 +35,40 @@ gulp.task('tslint', 'Lints all TypeScript source files', function () {
4535
.pipe(tslint.report('verbose'));
4636
});
4737

38+
gulp.task('gen-def', 'Generate a single .d.ts bundle containing external module declarations exported from TypeScript module files', function (cb) {
39+
return dtsGenerator.default({
40+
name: appName,
41+
project: '.',
42+
out: './lib/' + appName + '.d.ts',
43+
exclude: ['node_modules/**/*.d.ts', 'typings/**/*.d.ts']
44+
});
45+
});
46+
4847
gulp.task('_build', 'INTERNAL TASK - Compiles all TypeScript source files', function (cb) {
49-
exec('tsc', function (err, stdout, stderr) {
48+
exec('tsc --version', function (err, stdout, stderr) {
49+
console.log('TypeScript ', stdout);
50+
if (stderr) {
51+
console.log(stderr);
52+
}
53+
});
54+
55+
return exec('tsc', function (err, stdout, stderr) {
5056
console.log(stdout);
51-
console.log(stderr);
57+
if (stderr) {
58+
console.log(stderr);
59+
}
5260
cb(err);
5361
});
5462
});
5563

56-
//run tslint task, then run _tsconfig_files and _gen_tsrefs in parallel, then run _build
57-
gulp.task('build', 'Compiles all TypeScript source files and updates module references', gulpSequence('tslint', ['tsconfig_files', 'gen_tsrefs'], '_build'));
64+
//run tslint task, then run update-tsconfig and gen-def in parallel, then run _build
65+
gulp.task('build', 'Compiles all TypeScript source files and updates module references', gulpSequence('tslint', ['update-tsconfig', 'gen-def'], '_build'));
5866

5967
gulp.task('test', 'Runs the Jasmine test specs', ['build'], function () {
6068
return gulp.src('test/*.js')
6169
.pipe(jasmine());
6270
});
71+
72+
gulp.task('watch', 'Watches ts source files and runs build on change', function () {
73+
gulp.watch('src/**/*.ts', ['build']);
74+
});

generators/app/templates/_package.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "<%= appname %>",
33
"version": "0.0.0",
4-
"description": "",
5-
"license": "",
4+
"description": "<%= appname %>",
5+
"license": "MIT",
66
"repository": "",
77
"author": "",
88
"keywords": [
@@ -17,16 +17,21 @@
1717
"dependencies": {},
1818
"devDependencies": {
1919
"del": "2.0.2",
20+
"dotbin": "^1.0",
21+
"dts-generator": "^1.7",
2022
"gulp": "^3.9.0",
2123
"gulp-help": "^1.6.0",
2224
"gulp-inject": "3.0.0",
2325
"gulp-jasmine": "^2.0.1",
2426
"gulp-sequence": "0.4.1",
2527
"gulp-tsconfig-files": "0.0.2",
2628
"gulp-tslint": "^3.1",
27-
"jasmine": "^2.3.1"
29+
"jasmine": "^2.3.1",
30+
"tslint": "^3.5",
31+
"typescript": "^1.8"
2832
},
2933
"engines": {
30-
"node": ">=0.12.0"
31-
}
34+
"node": ">=2.0.0"
35+
},
36+
"typings": "./lib/<%= appname %>.d.ts"
3237
}

generators/app/templates/_tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"removeComments": true
1010
},
1111
"filesGlob": [
12+
"typings/main.d.ts",
1213
"src/**/*.ts"
1314
],
1415
"files": [

generators/app/templates/typings/app.d.ts

-2
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-node-typescript",
3-
"version": "0.10.0",
3+
"version": "0.11.0-rc",
44
"description": "Yeoman generator for Node modules using typescript and gulp",
55
"license": "MIT",
66
"main": "app/index.js",

test/test-app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var helpers = require('yeoman-generator').test;
66
var os = require('os');
77

88
describe('node-ts:app', function () {
9+
this.timeout(5000); //5 second timeout
10+
911
before(function (done) {
1012
helpers.run(path.join(__dirname, '../generators/app'))
1113
.withOptions({ skipInstall: true })
@@ -33,7 +35,6 @@ describe('node-ts:app', function () {
3335
it('creates project files', function () {
3436
assert.file([
3537
'.vscode/tasks.json',
36-
'typings/app.d.ts',
3738
'gulpfile.js',
3839
'tsconfig.json',
3940
'tslint.json',

0 commit comments

Comments
 (0)