forked from misskey-dev/misskey
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.ts
140 lines (119 loc) · 3.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
/**
* Gulp tasks
*/
import * as gulp from 'gulp';
import * as ts from 'gulp-typescript';
import * as sourcemaps from 'gulp-sourcemaps';
import tslint from 'gulp-tslint';
const postcss = require('gulp-postcss'); // import * as postcss from 'gulp-postcss';
import * as uglifyComposer from 'gulp-uglify/composer';
import * as cssnano from 'cssnano';
import * as rimraf from 'rimraf';
import chalk from 'chalk';
import * as imagemin from 'gulp-imagemin';
import * as rename from 'gulp-rename';
import * as mocha from 'gulp-mocha';
import * as replace from 'gulp-replace';
import * as uglifyes from 'uglify-es';
import locales from './locales';
const uglify = uglifyComposer(uglifyes, console);
const env = process.env.NODE_ENV || 'development';
const isProduction = env === 'production';
const isDebug = !isProduction;
const productionOnly = (src: NodeJS.ReadableStream, dst: NodeJS.ReadWriteStream) => isProduction ? src.pipe(dst) : src;
if (isDebug) {
console.warn(chalk.yellow.bold('WARNING! NODE_ENV is not "production".'));
console.warn(chalk.yellow.bold(' built script will not be compressed.'));
}
gulp.task('build:ts', () => {
const tsProject = ts.createProject('./tsconfig.json');
return tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.on('error', () => {})
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: '../built' }))
.pipe(gulp.dest('./built/'));
});
gulp.task('build:copy:views', () =>
gulp.src('./src/server/web/views/**/*').pipe(gulp.dest('./built/server/web/views'))
);
gulp.task('build:copy', gulp.parallel('build:copy:views', () =>
gulp.src([
'./build/Release/crypto_key.node',
'./src/const.json',
'./src/server/web/views/**/*',
'./src/**/assets/**/*',
'!./src/client/app/**/assets/**/*'
]).pipe(gulp.dest('./built/'))
));
gulp.task('lint', () =>
gulp.src('./src/**/*.ts')
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report())
);
gulp.task('format', () =>
gulp.src('./src/**/*.ts')
.pipe(tslint({
formatter: 'verbose',
fix: true
}))
.pipe(tslint.report())
);
gulp.task('mocha', () =>
gulp.src('./test/**/*.ts')
.pipe(mocha({
exit: true,
require: 'ts-node/register'
} as any))
);
gulp.task('test', gulp.task('mocha'));
gulp.task('clean', cb =>
rimraf('./built', cb)
);
gulp.task('cleanall', gulp.parallel('clean', cb =>
rimraf('./node_modules', cb)
));
gulp.task('build:client:script', () => {
const client = require('./built/client/meta.json');
return productionOnly(gulp.src(['./src/client/app/boot.js', './src/client/app/safe.js'])
.pipe(replace('VERSION', JSON.stringify(client.version)))
.pipe(replace('ENV', JSON.stringify(env)))
.pipe(replace('LANGS', JSON.stringify(Object.keys(locales)))),
uglify({
toplevel: true
} as any))
.pipe(gulp.dest('./built/client/assets/'));
});
gulp.task('build:client:styles', () =>
productionOnly(gulp.src('./src/client/app/init.css'),
postcss([
cssnano()
]))
.pipe(gulp.dest('./built/client/assets/'))
);
gulp.task('copy:client', () =>
productionOnly(gulp.src([
'./assets/**/*',
'./src/client/assets/**/*',
'./src/client/app/*/assets/**/*'
]),
(imagemin as any)())
.pipe(rename(path => {
path.dirname = path.dirname.replace('assets', '.');
}))
.pipe(gulp.dest('./built/client/assets/'))
);
gulp.task('build:client', gulp.parallel(
'build:client:script',
'build:client:styles',
'copy:client'
));
gulp.task('build', gulp.parallel(
'build:ts',
'build:copy',
'build:client'
));
gulp.task('default', gulp.task('build'));