This repository was archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.ts
More file actions
115 lines (82 loc) · 2.48 KB
/
gulpfile.ts
File metadata and controls
115 lines (82 loc) · 2.48 KB
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
import { exec as execCallback } from 'child_process';
import del from 'del';
import fs from 'fs';
import gulp from 'gulp';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import ts from 'gulp-typescript';
import util from 'util';
import { generate as generatePrisma, pushDb, seedDb } from './prisma/functions';
const exec = util.promisify(execCallback);
// CONFIGS
const tsProject = ts.createProject('./tsconfig.json');
export const configs = {
buildDest: (tsProject.config.compilerOptions?.outDir as string) || './dist',
uploadsFolder: './uploads',
devPort: 3005,
prismaGeneratedFolder: 'src/_generated',
};
// UTILS
function generateGuid() {
const dashPositions = [8, 12, 16, 20];
return Array.from(Array(32))
.map((_v, index) => {
const randomChar = Math.floor(Math.random() * 16)
.toString(16)
.toUpperCase();
return dashPositions.includes(index) ? `-${randomChar}` : randomChar;
})
.join('');
}
// TASKS
// Build Tasks
function buildNest() {
return exec('npx nest build');
}
function buildPrisma() {
return gulp.src(['./prisma/schema.prisma', './prisma/migrations/**/*'], { base: '.' }).pipe(gulp.dest(configs.buildDest));
}
// Creation Tasks
function setupEnv() {
const devEnvName = '.env';
if (!fs.existsSync(devEnvName)) {
return gulp
.src('./.env.example')
.pipe(replace('MY_RANDOM_KEY', generateGuid()))
.pipe(replace('PORT=', `PORT=${configs.devPort}`))
.pipe(rename(devEnvName))
.pipe(gulp.dest('.'));
}
return Promise.resolve();
}
function generatePrismaHelpers() {
return generatePrisma();
}
function updateDatabaseSchema() {
return pushDb({ skipGenerators: true });
}
function seedDatabase() {
return seedDb();
}
// Delete tasks
function deleteDist() {
return del(configs.buildDest);
}
// function deleteUploads() {
// return del(configs.uploadsFolder);
// }
function deletePrismaGenerated() {
return del(configs.prismaGeneratedFolder);
}
// ------------------------
// | Gulp Commands |
// ------------------------
// COMBINES
export const build = gulp.series(deleteDist, buildNest, buildPrisma);
export const setupPrisma = gulp.series(deletePrismaGenerated, generatePrismaHelpers, updateDatabaseSchema);
export const init = gulp.parallel(deleteDist, gulp.series(setupEnv, setupPrisma));
export const cleanBuild = gulp.series(init, build);
export const cleanDb = gulp.series(setupEnv, updateDatabaseSchema);
export const cleanSeed = gulp.series(cleanDb, seedDatabase);
// Useful commands
export { deleteDist };