This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.ts
199 lines (174 loc) · 4.48 KB
/
gulpfile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/// <reference path="src/typings/tsd.d.ts" />
import * as gulp from "gulp";
import * as babel from "gulp-babel";
import * as plumber from "gulp-plumber";
import * as sass from "gulp-sass";
import * as typescript from "gulp-typescript";
import * as useref from "gulp-useref";
import * as watch from "gulp-watch";
import * as browserify from "browserify";
import * as buffer from "vinyl-buffer";
import * as childProcess from "child_process";
import * as runSequence from "run-sequence";
import * as source from "vinyl-source-stream";
/* tslint:disable - typings is not defined. */
const del = require("del");
const stringify = require("stringify");
const electron = require("electron-connect").server.create();
const packager = require("electron-packager");
const config = require("./package.json");
const tsfiles = require("./tsfiles.json");
/* tslint:enable */
const gitHash: string = childProcess.execSync("git rev-parse HEAD").toString().trim();
const tsMainProject: any = typescript.createProject("./src/tsconfig.json");
const tsTestProject: any = typescript.createProject("./test/tsconfig.json");
const appDir: string = "./app";
const srcDir: string = "./src";
const testDir: string = "./test";
const tsFiles: string = srcDir + "/**/*.{ts,tsx}"; // TypeScript(*.ts) + TypeScript React(*.tsx)
const ssFiles: string = srcDir + "/**/*.{sass,scss}"; // SASS(*.sass, *.scss)
const htFiles: string = srcDir + "/**/*.html"; // HTML Files
const rsFiles: string = srcDir + "/**/*.json"; // Resource Files
const ttFiles: string = testDir + "/**/*.ts"; // TypeScript Test
let served: boolean = false;
// Clean project
gulp.task("clean", (done) => {
del(["app", "dist", "coverage", "test/**/*.js"]);
done();
});
// TypeScript Compile (Main)
gulp.task("ts:compile:main", () => {
return gulp.src(tsFiles)
.pipe(plumber())
.pipe(typescript(tsMainProject))
.pipe(babel())
.pipe(gulp.dest(appDir));
});
// TypeScript Compile (Test)
gulp.task("ts:compile:test", () => {
return gulp.src(ttFiles)
.pipe(plumber())
.pipe(typescript(tsTestProject))
.pipe(babel())
.pipe(gulp.dest(testDir));
});
// SASS Compile
gulp.task("sass:compile", () => {
return gulp.src(ssFiles)
.pipe(plumber())
.pipe(sass())
.pipe(gulp.dest(appDir));
});
// HTML Compile
gulp.task("html:compile", () => {
return gulp.src(htFiles, {base: "src"})
.pipe(useref())
.pipe(gulp.dest(appDir));
});
gulp.task("browserify:browser", (done) => {
browserify({
builtins: [],
debug: true,
detectGlobals: false,
entries: ["app/browser/Application.js"],
extensions: [".js"],
ignoreMissing: true
})
.transform("envify", {
GIT_HASH: gitHash,
NAME: config.name,
NODE_ENV: "production",
ROOT: __dirname,
VERSION: config.version
})
.bundle()
.pipe(source("Application.js"))
.pipe(buffer())
.pipe(gulp.dest("app/browser"));
done();
});
gulp.task("browserify:renderer", (done) => {
browserify({
builtins: [],
debug: true,
detectGlobals: false,
entries: tsfiles,
ignoreMissing: true,
transform: stringify({
extensions: [".html"],
minify: true
})
})
.bundle()
.pipe(source("Application.js"))
.pipe(buffer())
.pipe(gulp.dest("app/renderer"));
done();
});
// Copy assets
gulp.task("html:copy", () => {
return gulp.src(htFiles, {base: "src"})
.pipe(gulp.dest(appDir));
});
gulp.task("assets:copy", () => {
return gulp.src(rsFiles, {base: "src"})
.pipe(gulp.dest(appDir));
});
gulp.task("watch", () => {
watch(tsFiles, () => {
return runSequence(
"ts:compile:main",
"serve:reload"
);
});
watch(ssFiles, () => {
return runSequence(
"sass:compile",
"serve:reload"
);
});
watch(rsFiles, () => {
gulp.start(["assets:copy"]);
});
});
gulp.task("serve", () => {
electron.start();
served = true;
});
gulp.task("serve:reload", () => {
if (served) {
electron.reload();
}
});
gulp.task("build:main", (done) => {
return runSequence(
"clean",
"ts:compile:main",
"sass:compile",
"html:compile",
"assets:copy",
"browserify:browser",
"browserify:renderer",
done
);
});
gulp.task("build:test", (done) => {
return runSequence(
"clean",
"ts:compile:main",
"ts:compile:test",
done
);
});
gulp.task("default", (done) => {
return runSequence(
"clean",
"ts:compile:main",
"sass:compile",
"html:copy",
"assets:copy",
"watch",
"serve",
done
);
});