forked from PhotoboothProject/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.mjs
110 lines (98 loc) · 3.23 KB
/
gulpfile.mjs
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
import autoprefixer from 'autoprefixer';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import filters from 'gulp-filter';
import gulp from 'gulp';
import nodeSassImporter from 'node-sass-importer';
import postcss from 'gulp-postcss';
import rename from 'gulp-rename';
import sass from 'gulp-dart-sass';
import tailwindcss from 'tailwindcss';
import twAdminConfig from './config/tailwind.admin.config.mjs';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
gulp.task('sass', function () {
const twFilter = filters(['**/*', '!tailwind.admin.scss']);
return gulp
.src('./assets/sass/**/*.scss')
.pipe(twFilter)
.pipe(sass().on('error', sass.logError)) // Use sass() without .sync
.pipe(gulp.dest('./resources/css'));
});
gulp.task('js', function () {
return gulp
.src('./assets/js/**/*.js')
.pipe(babel({
presets: ['@babel/env'],
ignore: ['assets/js/sync-to-drive.js', 'assets/js/remotebuzzer-server.js']
}))
.pipe(gulp.dest('./resources/js'));
});
gulp.task('tailwind-admin', function () {
const plugins = [
tailwindcss(twAdminConfig),
autoprefixer(),
];
return gulp
.src('./assets/sass/tailwind.admin.scss')
.pipe(sass({
importer: nodeSassImporter
}).on('error', sass.logError))
.pipe(rename({
extname: '.scss'
}))
.pipe(postcss(plugins))
.pipe(rename({
extname: '.css'
}))
.pipe(gulp.dest('./resources/css'));
});
gulp.task('js-admin', function () {
return gulp
.src([
'./assets/js/tools.js',
'./assets/js/admin/index.js',
'./assets/js/admin/buttons.js',
'./assets/js/admin/navi.js',
'./assets/js/admin/keypad.js',
'./assets/js/admin/imageSelect.js',
'./assets/js/admin/toast.js',
])
.pipe(concat('main.admin.js'))
.pipe(babel({
presets: ['@babel/env'],
ignore: ['assets/js/sync-to-drive.js', 'assets/js/remotebuzzer-server.js']
}))
.pipe(gulp.dest('./resources/js'));
});
async function generateAssetRevisions() {
const resourcesFolder = 'resources';
const revisionsManifest = 'resources/revisions.json';
const manifest = {};
const processFile = async (filePath) => {
const content = fs.readFileSync(filePath);
const sha1Hash = crypto.createHash('sha1').update(content).digest('hex');
const relativePath = path.relative(resourcesFolder, filePath).replace(/\\/g, '/');
manifest[resourcesFolder + '/' + relativePath] = sha1Hash;
};
const processFolder = async (folderPath) => {
const files = fs.readdirSync(folderPath);
for (const file of files) {
const filePath = path.join(folderPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
await processFolder(filePath);
} else if (stats.isFile() && !filePath.endsWith('revisions.json')) {
await processFile(filePath);
}
}
};
await processFolder(resourcesFolder);
const manifestJSON = JSON.stringify(manifest, null, 2);
fs.writeFileSync(revisionsManifest, manifestJSON);
}
gulp.task('default', gulp.series(
gulp.parallel('sass', 'js', 'js-admin', 'tailwind-admin'),
generateAssetRevisions
));