1- package.json
2- gulpfile.js
3- lib/myFile.ts
4- spec/myFile.spec.ts
5- index.ts
6- tsconfig.json
1{
2 "name": "my-package",
3 "version": "0.0.0",
4 //...
5 "main": "dist/index.js", // for import from nodejs environments
6 "typings": "definitions/index", // TypeScript definitions
7 "typescript": {
8 "definition": "definitions/index" // TypeScript definitions
9 },
10 //...
11 "devDependencies": {
12 "@types/node": "~6.0.46", // needed for Node.js targeting
13 //...
14 },
15 "scripts": {
16 "test": "gulp test",
17 "release": "standard-version" // amazing package, seriously !
18 },
19 //...
20 "dependencies": {
21 "@types/jasmine": "^2.5.38" // need for using jasmine in TS !
22 }
23}
1{
2 "compilerOptions": {
3 "lib": ["es6"], // we target Node.js(v6)
4 "module": "commonjs", // export compatibility
5 "target": "es5", // we target Node.js(v6)
6 "moduleResolution": "node", // we target Node.js(v6)
7 "declaration": true, // generate TypeScript definitions
8 "rootDir": ".",
9 "outDir": "dist", // transpile JS in this directory
10 "types" : ["node", "jasmine"] // only use needed types
11 },
12 "include": [
13 "index.ts",
14 "lib/**/*",
15 "spec/**/*"
16 ]
17}
1gulp.task('build', function() {
2 const merge = require('merge2');
3 const tsProject = ts.createProject('tsconfig.json');
4
5var tsResult = tsProject.src()
6 .pipe(tsProject());
7
8return merge(\[
9 tsResult.dts.pipe(gulp.dest('./definitions')),
10 tsResult.js.pipe(
11 gulp.dest(tsProject.config.compilerOptions.outDir)
12 )
13 \]);
14});
1import * from 'my-package'
1gulp.task('test:run', function() {
2 return gulp.src('dist/spec/\*\*').pipe(jasmine())
3});
4// ...
5gulp.task('test', \[\], function(cb) {
6 runSequence('clean', 'build', 'test:run', cb);
7});