generated from AndreyBelym/nodejs-stub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.js
110 lines (97 loc) · 3.04 KB
/
Gulpfile.js
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
const { dest, series, parallel, src } = require('gulp');
const del = require('del');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const testcafe = require('gulp-testcafe');
const paths = {
BUILD_DIR: 'lib',
CLIENT_DIR: 'client',
SERVER_DIR: 'server',
SHARED_DIR: 'shared',
TESTS_DIR: 'test',
MOCK_GITHUB: 'mock-github',
E2E_TESTS: 'test/e2e'
};
const serverTs = ts.createProject(`src/${paths.SERVER_DIR}/tsconfig.json`);
const clientErrorHandlingTs = ts.createProject(`src/${paths.CLIENT_DIR}/tsconfig.errorhandlers.json`);
const clientTs = ts.createProject(`src/${paths.CLIENT_DIR}/tsconfig.json`);
const sharedTs = ts.createProject(`src/${paths.SHARED_DIR}/tsconfig.json`);
const mockGithubTs = ts.createProject(`src/${paths.MOCK_GITHUB}/tsconfig.json`);
function transpileServer () {
return serverTs
.src()
.pipe(sourcemaps.init())
.pipe(serverTs()).js
.pipe(sourcemaps.write())
.pipe(dest(paths.BUILD_DIR));
}
function transpileShared () {
return sharedTs
.src()
.pipe(sourcemaps.init())
.pipe(sharedTs()).js
.pipe(sourcemaps.write())
.pipe(dest(paths.BUILD_DIR));
}
function transpileClient () {
return clientTs
.src()
.pipe(sourcemaps.init())
.pipe(clientTs()).js
.pipe(sourcemaps.write())
.pipe(dest(paths.BUILD_DIR));
}
function transpileClientErrorHandlers () {
return clientErrorHandlingTs
.src()
.pipe(sourcemaps.init())
.pipe(clientErrorHandlingTs()).js
.pipe(sourcemaps.write())
.pipe(dest(paths.BUILD_DIR));
}
function transpileMockGithub () {
return mockGithubTs
.src()
.pipe(sourcemaps.init())
.pipe(mockGithubTs()).js
.pipe(sourcemaps.write())
.pipe(dest(paths.BUILD_DIR));
}
async function clean () {
await del([paths.BUILD_DIR]);
}
function unitTests () {
return require('child_process')
.spawn(
'npx mocha -r ts-node/register test/unit/**/*-test.*',
{
shell: true,
stdio: 'inherit'
}
);
}
function e2eTests () {
return src(`${paths.E2E_TESTS}/*.js`)
.pipe(testcafe({ browsers: ['chrome:headless'] }));
}
function lint ({ fix = false } = {}) {
return require('child_process')
.spawn(
`npx eslint src test Gulpfile.js ${fix ? '--fix' : ''} --ext .js,.ts`,
{
shell: true,
stdio: 'inherit'
}
);
}
const buildServer = transpileServer;
const buildClient = parallel(transpileClientErrorHandlers, transpileClient);
const buildShared = transpileShared;
const buildMockGithub = transpileMockGithub;
exports['clean'] = clean;
exports['build'] = series(clean, parallel(buildServer, buildClient, buildShared, buildMockGithub));
exports['test'] = series(unitTests, e2eTests);
exports['lint'] = lint;
exports['lint-fix'] = () => lint({ fix: true });
exports['unit'] = unitTests;
exports['e2e'] = e2eTests;