mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
158 lines
4.0 KiB
TypeScript
158 lines
4.0 KiB
TypeScript
import {Gulpclass, Task, SequenceTask} from "gulpclass/Decorators";
|
|
|
|
const gulp = require("gulp");
|
|
const del = require("del");
|
|
const shell = require("gulp-shell");
|
|
const replace = require("gulp-replace");
|
|
const mocha = require("gulp-mocha");
|
|
const chai = require("chai");
|
|
const tslint = require("gulp-tslint");
|
|
const stylish = require("tslint-stylish");
|
|
|
|
@Gulpclass()
|
|
export class Gulpfile {
|
|
|
|
// -------------------------------------------------------------------------
|
|
// General tasks
|
|
// -------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Cleans build folder.
|
|
*/
|
|
@Task()
|
|
clean(cb: Function) {
|
|
return del(["./build/**"], cb);
|
|
}
|
|
|
|
/**
|
|
* Runs typescript files compilation.
|
|
*/
|
|
@Task()
|
|
compile() {
|
|
return gulp.src("*.js", { read: false })
|
|
.pipe(shell(["tsc"]));
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Packaging and Publishing tasks
|
|
// -------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Publishes a package to npm from ./build/package directory.
|
|
*/
|
|
@Task()
|
|
npmPublish() {
|
|
return gulp.src("*.js", { read: false })
|
|
.pipe(shell([
|
|
"cd ./build/package && npm publish"
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* Copies all files that will be in a package.
|
|
*/
|
|
@Task()
|
|
packageFiles() {
|
|
return gulp.src("./build/es5/src/**/*")
|
|
.pipe(gulp.dest("./build/package"));
|
|
}
|
|
|
|
/**
|
|
* Change the "private" state of the packaged package.json file to public.
|
|
*/
|
|
@Task()
|
|
packagePreparePackageFile() {
|
|
return gulp.src("./package.json")
|
|
.pipe(replace("\"private\": true,", "\"private\": false,"))
|
|
.pipe(gulp.dest("./build/package"));
|
|
}
|
|
|
|
/**
|
|
* This task will replace all typescript code blocks in the README (since npm does not support typescript syntax
|
|
* highlighting) and copy this README file into the package folder.
|
|
*/
|
|
@Task()
|
|
packageReadmeFile() {
|
|
return gulp.src("./README.md")
|
|
.pipe(replace(/```typescript([\s\S]*?)```/g, "```javascript$1```"))
|
|
.pipe(gulp.dest("./build/package"));
|
|
}
|
|
|
|
/**
|
|
* This task will copy typings.json file to the build package.
|
|
*/
|
|
@Task()
|
|
copyTypingsFile() {
|
|
return gulp.src("./typings.json")
|
|
.pipe(gulp.dest("./build/package"));
|
|
}
|
|
|
|
/**
|
|
* Creates a package that can be published to npm.
|
|
*/
|
|
@SequenceTask()
|
|
package() {
|
|
return [
|
|
"clean",
|
|
"compile",
|
|
["packageFiles", "packagePreparePackageFile", "packageReadmeFile", "copyTypingsFile"]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Creates a package and publishes it to npm.
|
|
*/
|
|
@SequenceTask()
|
|
publish() {
|
|
return ["package", "npmPublish"];
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Run tests tasks
|
|
// -------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Runs ts linting to validate source code.
|
|
*/
|
|
@Task()
|
|
tslint() {
|
|
return gulp.src(["./src/**/*.ts", "./test/**/*.ts", "./sample/**/*.ts"])
|
|
.pipe(tslint())
|
|
.pipe(tslint.report(stylish, {
|
|
emitError: true,
|
|
sort: true,
|
|
bell: true
|
|
}));
|
|
}
|
|
|
|
/**
|
|
* Runs integration tests.
|
|
*/
|
|
@Task()
|
|
integration() {
|
|
chai.should();
|
|
chai.use(require("sinon-chai"));
|
|
return gulp.src("./build/es5/test/integration/**/*.js")
|
|
.pipe(mocha());
|
|
}
|
|
|
|
/**
|
|
* Runs unit-tests.
|
|
*/
|
|
@Task()
|
|
unit() {
|
|
chai.should();
|
|
chai.use(require("sinon-chai"));
|
|
return gulp.src("./build/es5/test/unit/**/*.js")
|
|
.pipe(mocha());
|
|
}
|
|
|
|
/**
|
|
* Compiles the code and runs tests.
|
|
*/
|
|
@SequenceTask()
|
|
tests() {
|
|
return ["compile", "tslint", "unit", "integration"];
|
|
}
|
|
|
|
} |