#62 and #61 added build-for-browser tasks

This commit is contained in:
Umed Khudoiberdiev 2016-12-04 00:07:42 +05:00
parent 3c5c5f672f
commit 3e9b7a4a94
3 changed files with 95 additions and 13 deletions

View File

@ -4,14 +4,16 @@ const gulp = require("gulp");
const del = require("del");
const shell = require("gulp-shell");
const replace = require("gulp-replace");
const rename = require("gulp-rename");
const file = require("gulp-file");
const mocha = require("gulp-mocha");
const chai = require("chai");
const tslint = require("gulp-tslint");
const stylish = require("tslint-stylish");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const istanbul = require("gulp-istanbul");
const remapIstanbul = require("remap-istanbul/lib/gulpRemapIstanbul");
const ts = require("gulp-typescript");
@Gulpclass()
export class Gulpfile {
@ -37,6 +39,66 @@ export class Gulpfile {
.pipe(shell(["tsc"]));
}
/**
*/
@Task()
browserCopySources() {
return gulp.src([
"./src/**/*.ts",
"!./src/commands/*.ts",
"!./src/cli.ts",
"!./src/typeorm.ts",
"!./src/decorators-shim.ts",
"!./src/platform/PlatformTools.ts",
"!./src/platform/BrowserPlatformTools.ts"
])
.pipe(gulp.dest("./build/browser/typeorm"));
}
@Task()
browserCopyMainBrowserFile() {
return gulp.src("./package.json", { read: false })
.pipe(file("typeorm.ts", `export * from "./typeorm/index";`))
.pipe(gulp.dest("./build/browser"));
}
@Task()
browserCopyPlatformTools() {
return gulp.src("./src/platform/BrowserPlatformTools.ts")
.pipe(rename("PlatformTools.ts"))
.pipe(gulp.dest("./build/browser/typeorm/platform"));
}
/**
* Runs typescript files compilation.
*/
@MergedTask()
browserCompile() {
const tsProject = ts.createProject("tsconfig.json", {
outFile: "typeorm-browser.js",
module: "system",
target: "es6",
typescript: require("typescript")
});
const tsResult = gulp.src(["./build/browser/**/*.ts", "./node_modules/@types/**/*.ts"])
.pipe(sourcemaps.init())
.pipe(tsProject());
return [
tsResult.dts.pipe(gulp.dest("./build/package")),
tsResult.js
.pipe(sourcemaps.write(".", { sourceRoot: "", includeContent: true }))
.pipe(gulp.dest("./build/package"))
];
}
/**
*/
@SequenceTask()
browser() {
return [["browserCopySources", "browserCopyMainBrowserFile", "browserCopyPlatformTools"], "browserCompile"];
}
// -------------------------------------------------------------------------
// Packaging and Publishing tasks
// -------------------------------------------------------------------------

View File

@ -33,8 +33,10 @@
"chai-as-promised": "^6.0.0",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-file": "^0.3.0",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.1",
"gulp-sourcemaps": "^1.9.1",
@ -42,7 +44,7 @@
"gulp-typescript": "^3.1.3",
"gulpclass": "0.1.1",
"mariasql": "^0.2.6",
"mocha": "^3.1.2",
"mocha": "^3.2.0",
"mssql": "^3.3.0",
"mysql": "^2.12.0",
"mysql2": "^1.1.2",
@ -53,17 +55,17 @@
"sinon-chai": "^2.8.0",
"sqlite3": "^3.1.8",
"ts-node": "^1.7.0",
"tslint": "^4.0.1",
"tslint": "^4.0.2",
"tslint-stylish": "^2.1.0-beta",
"typescript": "^2.1.1"
},
"dependencies": {
"@types/node": "^6.0.50",
"@types/node": "^6.0.51",
"app-root-path": "^2.0.1",
"glob": "^7.1.1",
"reflect-metadata": "^0.1.8",
"yargonaut": "^1.1.2",
"yargs": "^6.4.0"
"yargs": "^6.5.0"
},
"scripts": {
"test": "node_modules/.bin/gulp tests"

View File

@ -5,7 +5,7 @@
* For node.js environment this class is not getting packaged.
* Don't use methods of this class in the code, use PlatformTools methods instead.
*/
export class BrowserPlatformTools {
export class PlatformTools {
/**
* Type of the currently running platform.
@ -16,43 +16,61 @@ export class BrowserPlatformTools {
* Loads ("require"-s) given file or package.
* This operation only supports on node platform
*/
static load(name: string) {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: require("${name}").`);
static load(name: string): any {
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: require("${name}").`);
return "";
}
/**
* Normalizes given path. Does "path.normalize".
*/
static pathNormilize(pathStr: string): string {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize("${pathStr}").`);
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.normalize("${pathStr}").`);
return "";
}
/**
* Gets file extension. Does "path.extname".
*/
static pathExtname(pathStr: string): string {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname("${pathStr}").`);
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.extname("${pathStr}").`);
return "";
}
/**
* Resolved given path. Does "path.resolve".
*/
static pathResolve(pathStr: string): string {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve("${pathStr}").`);
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: path.resolve("${pathStr}").`);
return "";
}
/**
* Synchronously checks if file exist. Does "fs.existsSync".
*/
static fileExist(pathStr: string): boolean {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync("${pathStr}").`);
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: fs.existsSync("${pathStr}").`);
return false;
}
/**
* Gets environment variable.
*/
static getEnvVariable(name: string): any {
throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env["${name}"].`);
if (this.type === "browser")
throw new Error(`This option/function is not supported in the browser environment. Failed operation: process.env["${name}"].`);
return "";
}
}