Skip to content

Commit 749a5e8

Browse files
author
Umed Khudoiberdiev
committed
added gulpfile and all required dependencies
1 parent 5cfef54 commit 749a5e8

File tree

2 files changed

+160
-2
lines changed

2 files changed

+160
-2
lines changed

gulpfile.ts

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import {Gulpclass, Task, SequenceTask} from "gulpclass/Decorators";
2+
3+
const gulp = require("gulp");
4+
const del = require("del");
5+
const shell = require("gulp-shell");
6+
const replace = require("gulp-replace");
7+
const mocha = require("gulp-mocha");
8+
const chai = require("chai");
9+
const tslint = require("gulp-tslint");
10+
const stylish = require("tslint-stylish");
11+
12+
@Gulpclass()
13+
export class Gulpfile {
14+
15+
// -------------------------------------------------------------------------
16+
// General tasks
17+
// -------------------------------------------------------------------------
18+
19+
/**
20+
* Cleans build folder.
21+
*/
22+
@Task()
23+
clean(cb: Function) {
24+
return del(["./build/**"], cb);
25+
}
26+
27+
/**
28+
* Runs typescript files compilation.
29+
*/
30+
@Task()
31+
compile() {
32+
return gulp.src("*.js", { read: false })
33+
.pipe(shell(["tsc"]));
34+
}
35+
36+
// -------------------------------------------------------------------------
37+
// Packaging and Publishing tasks
38+
// -------------------------------------------------------------------------
39+
40+
/**
41+
* Publishes a package to npm from ./build/package directory.
42+
*/
43+
@Task()
44+
npmPublish() {
45+
return gulp.src("*.js", { read: false })
46+
.pipe(shell([
47+
"cd ./build/package && npm publish"
48+
]));
49+
}
50+
51+
/**
52+
* Copies all files that will be in a package.
53+
*/
54+
@Task()
55+
packageFiles() {
56+
return gulp.src("./build/es5/src/**/*")
57+
.pipe(gulp.dest("./build/package"));
58+
}
59+
60+
/**
61+
* Change the "private" state of the packaged package.json file to public.
62+
*/
63+
@Task()
64+
packagePreparePackageFile() {
65+
return gulp.src("./package.json")
66+
.pipe(replace("\"private\": true,", "\"private\": false,"))
67+
.pipe(gulp.dest("./build/package"));
68+
}
69+
70+
/**
71+
* This task will replace all typescript code blocks in the README (since npm does not support typescript syntax
72+
* highlighting) and copy this README file into the package folder.
73+
*/
74+
@Task()
75+
packageReadmeFile() {
76+
return gulp.src("./README.md")
77+
.pipe(replace(/```typescript([\s\S]*?)```/g, "```javascript$1```"))
78+
.pipe(gulp.dest("./build/package"));
79+
}
80+
81+
/**
82+
* This task will copy typings.json file to the build package.
83+
*/
84+
@Task()
85+
copyTypingsFile() {
86+
return gulp.src("./typings.json")
87+
.pipe(gulp.dest("./build/package"));
88+
}
89+
90+
/**
91+
* Creates a package that can be published to npm.
92+
*/
93+
@SequenceTask()
94+
package() {
95+
return [
96+
"clean",
97+
"compile",
98+
["packageFiles", "packagePreparePackageFile", "packageReadmeFile", "copyTypingsFile"]
99+
];
100+
}
101+
102+
/**
103+
* Creates a package and publishes it to npm.
104+
*/
105+
@SequenceTask()
106+
publish() {
107+
return ["package", "npmPublish"];
108+
}
109+
110+
// -------------------------------------------------------------------------
111+
// Run tests tasks
112+
// -------------------------------------------------------------------------
113+
114+
/**
115+
* Runs ts linting to validate source code.
116+
*/
117+
@Task()
118+
tslint() {
119+
return gulp.src(["./src/**/*.ts", "./test/**/*.ts", "./sample/**/*.ts"])
120+
.pipe(tslint())
121+
.pipe(tslint.report(stylish, {
122+
emitError: true,
123+
sort: true,
124+
bell: true
125+
}));
126+
}
127+
128+
/**
129+
* Runs unit-tests.
130+
*/
131+
@Task()
132+
unit() {
133+
chai.should();
134+
chai.use(require("sinon-chai"));
135+
return gulp.src("./build/es5/test/unit/**/*.js")
136+
.pipe(mocha());
137+
}
138+
139+
/**
140+
* Compiles the code and runs tests.
141+
*/
142+
@SequenceTask()
143+
tests() {
144+
return ["compile", "tslint", "unit"];
145+
}
146+
147+
}

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@
2323
"typeorm-typedi"
2424
],
2525
"devDependencies": {
26+
"chai": "^3.5.0",
27+
"del": "^2.2.2",
28+
"gulp": "^3.9.1",
29+
"gulp-mocha": "^3.0.1",
30+
"gulp-replace": "^0.5.4",
31+
"gulp-shell": "^0.5.2",
32+
"gulp-tslint": "^6.1.2",
33+
"gulpclass": "^0.1.1",
2634
"pg": "^6.1.0",
2735
"reflect-metadata": "^0.1.8",
36+
"ts-node": "^1.3.0",
37+
"tslint": "^3.15.1",
38+
"tslint-stylish": "^2.1.0-beta",
2839
"typedi": "^0.4.2",
29-
"typeorm": "^0.0.2-alpha.63",
40+
"typeorm": "^0.0.2-alpha.66",
3041
"typescript": "^2.0.2"
3142
},
3243
"peerDependencies": {
33-
"typeorm": "^0.0.2-alpha.63",
44+
"typeorm": "^0.0.2-alpha.66",
3445
"typedi": "^0.4.2"
3546
}
3647
}

0 commit comments

Comments
 (0)