2020-11-05 08:53:06 +01:00
|
|
|
/* eslint-disable no-console */
|
2017-06-10 22:35:01 +02:00
|
|
|
const gulp = require('gulp');
|
2017-08-30 04:16:03 +02:00
|
|
|
const fs = require('fs');
|
2017-06-10 22:35:01 +02:00
|
|
|
const exec = require('child_process').exec;
|
2021-05-12 01:47:09 +02:00
|
|
|
const log = require('fancy-log');
|
|
|
|
const parseArgs = require('minimist');
|
2017-08-30 04:16:03 +02:00
|
|
|
const browserSync = require('browser-sync').create();
|
|
|
|
const concat = require('gulp-concat');
|
2023-02-03 08:33:31 +01:00
|
|
|
const parallel = require('concurrent-transform');
|
2017-08-30 04:16:03 +02:00
|
|
|
const imageResize = require('gulp-image-resize');
|
2023-02-04 00:04:15 +01:00
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
function findSassBinary() {
|
|
|
|
const modulePath = require.resolve(
|
|
|
|
`sass-embedded-${process.platform}-${process.arch}/` +
|
|
|
|
'dart-sass-embedded/dart-sass-embedded' +
|
|
|
|
(process.platform === 'win32' ? '.bat' : '')
|
|
|
|
);
|
|
|
|
return path.dirname(modulePath);
|
|
|
|
}
|
2017-02-26 22:24:53 +01:00
|
|
|
|
2017-08-30 04:16:03 +02:00
|
|
|
gulp.task('scripts:games', function (callback) {
|
2023-02-04 00:04:15 +01:00
|
|
|
exec('yarn run compatdb', { cwd: './scripts/shared-hugo-scripts/' }, function (err, stdout, stderr) {
|
2020-11-05 08:53:06 +01:00
|
|
|
callback(err);
|
|
|
|
});
|
2017-08-30 04:16:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('scripts:wiki', function (callback) {
|
2023-02-04 00:04:15 +01:00
|
|
|
exec('yarn run wiki', { cwd: './scripts/shared-hugo-scripts/' }, function (err, stdout, stderr) {
|
2020-11-05 08:53:06 +01:00
|
|
|
callback(err);
|
|
|
|
});
|
2017-08-30 04:16:03 +02:00
|
|
|
});
|
2017-06-24 16:08:37 +02:00
|
|
|
|
2017-08-30 04:16:03 +02:00
|
|
|
gulp.task('assets:images', function() {
|
2023-02-03 08:13:01 +01:00
|
|
|
const baseImages = gulp.src('build/images/*', {base: './'})
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(gulp.dest('./'));
|
2023-02-03 08:13:01 +01:00
|
|
|
const jumbotronImages = gulp.src('build/images/jumbotron/*', {base: './'})
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(imageResize({ width: 786, height: 471, crop: true }))
|
|
|
|
.pipe(gulp.dest('./'));
|
2023-02-03 08:13:01 +01:00
|
|
|
const bannerImages = gulp.src('build/images/banners/*', {base: './'})
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(imageResize({ width: 824, height: 306, crop: false }))
|
|
|
|
.pipe(gulp.dest('./'));
|
2023-02-03 08:13:01 +01:00
|
|
|
const boxartImages = gulp.src('build/images/game/boxart/*', {base: './'})
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(imageResize({ width: 328, height: 300, crop: true }))
|
|
|
|
.pipe(gulp.dest('./'));
|
2023-02-03 08:13:01 +01:00
|
|
|
const iconImages = gulp.src('build/images/game/icons/*', {base: './'})
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(imageResize({ width: 48, height: 48, crop: true }))
|
|
|
|
.pipe(gulp.dest('./'));
|
2023-02-03 08:13:01 +01:00
|
|
|
const screenshotImages = gulp.src('build/images/screenshots/*')
|
2020-11-05 08:53:06 +01:00
|
|
|
.pipe(imageResize({ width: 400, height: 240, crop: false }))
|
|
|
|
.pipe(gulp.dest('build/images/screenshots/thumbs'));
|
2023-02-03 08:13:01 +01:00
|
|
|
|
2023-02-03 08:33:31 +01:00
|
|
|
return parallel(baseImages, jumbotronImages, bannerImages, boxartImages, iconImages, screenshotImages);
|
2017-08-30 04:16:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('assets:js', function() {
|
2020-11-05 08:53:06 +01:00
|
|
|
return gulp.src(['src/js/**/*.js'])
|
|
|
|
.pipe(concat('script.js'))
|
|
|
|
.pipe(gulp.dest('build/js'));
|
2017-08-30 04:16:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('assets:fonts', function(){
|
2020-11-05 08:53:06 +01:00
|
|
|
return gulp.src('./node_modules/bootstrap-sass/assets/fonts/**/*')
|
|
|
|
.pipe(gulp.dest('build/fonts/'));
|
2017-07-27 10:33:38 +02:00
|
|
|
});
|
|
|
|
|
2023-02-03 08:13:01 +01:00
|
|
|
gulp.task('hugo', (callback) => {
|
2023-02-04 00:04:15 +01:00
|
|
|
const sassPath = findSassBinary();
|
|
|
|
process.env.PATH = `${process.env.PATH}:${sassPath}`;
|
2023-02-03 08:13:01 +01:00
|
|
|
import('hugo-bin').then((hugo) => {
|
|
|
|
exec(hugo.default + ' -s ./site/ -d ../build/ -v --gc', (err, stdout, stderr) => {
|
|
|
|
console.log(stdout);
|
|
|
|
callback(err);
|
|
|
|
});
|
2023-02-04 00:04:15 +01:00
|
|
|
}).catch(err => callback(err));
|
2017-08-30 04:16:03 +02:00
|
|
|
});
|
|
|
|
|
2018-12-19 02:37:54 +01:00
|
|
|
gulp.task('final:serve', function(done) {
|
2017-08-30 04:16:03 +02:00
|
|
|
browserSync.init({
|
|
|
|
open: false,
|
|
|
|
server: {
|
|
|
|
baseDir: 'build'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-19 02:03:06 +01:00
|
|
|
gulp.watch('src/js/**/*', gulp.series('assets:js'));
|
2023-02-03 08:13:01 +01:00
|
|
|
gulp.watch('src/scss/**/*', gulp.series('hugo'));
|
2018-12-19 02:03:06 +01:00
|
|
|
gulp.watch('site/**/*.html', gulp.series('hugo'));
|
|
|
|
gulp.watch('site/**/*.md', gulp.series('hugo'));
|
2017-06-25 04:14:34 +02:00
|
|
|
|
2019-03-17 07:29:25 +01:00
|
|
|
gulp.watch('build/**/*').on('change', function(x) {
|
2020-11-05 08:53:06 +01:00
|
|
|
browserSync.reload(x);
|
2018-12-19 02:03:06 +01:00
|
|
|
});
|
2018-12-19 02:37:54 +01:00
|
|
|
|
2020-05-26 16:51:18 +02:00
|
|
|
done();
|
2017-06-25 01:04:10 +02:00
|
|
|
});
|
|
|
|
|
2018-12-19 02:37:54 +01:00
|
|
|
gulp.task('final:publish', function(done) {
|
2020-11-05 08:53:06 +01:00
|
|
|
fs.writeFileSync('build/CNAME', `${cname}`);
|
|
|
|
fs.writeFileSync('build/robots.txt', `Sitemap: https://${cname}/sitemap.xml\n\nUser-agent: *`);
|
|
|
|
done();
|
2017-02-26 22:24:53 +01:00
|
|
|
});
|
2018-12-19 02:03:06 +01:00
|
|
|
|
|
|
|
const cname = 'citra-emu.org';
|
|
|
|
var finalCommand = null;
|
2021-06-11 23:04:27 +02:00
|
|
|
let ephemeralURL = null;
|
2018-12-19 02:03:06 +01:00
|
|
|
|
2021-05-12 01:47:09 +02:00
|
|
|
if (parseArgs(process.argv).production) {
|
|
|
|
process.env.NODE_ENV = 'production';
|
2020-11-05 08:53:06 +01:00
|
|
|
process.env.HUGO_ENV = 'PRD';
|
|
|
|
process.env.HUGO_BASEURL = `https://${cname}`;
|
|
|
|
finalCommand = 'final:publish';
|
2021-06-11 23:04:27 +02:00
|
|
|
} else if ((ephemeralURL = parseArgs(process.argv).ephemeral)) {
|
|
|
|
process.env.NODE_ENV = 'production';
|
|
|
|
process.env.HUGO_ENV = 'PRD';
|
|
|
|
process.env.HUGO_BASEURL = ephemeralURL;
|
|
|
|
finalCommand = 'final:publish';
|
2018-12-19 02:03:06 +01:00
|
|
|
} else {
|
2020-11-05 08:53:06 +01:00
|
|
|
process.env.HUGO_ENV = 'DEV';
|
|
|
|
process.env.HUGO_BASEURL = 'http://localhost:3000';
|
|
|
|
finalCommand = 'final:serve';
|
2018-12-19 02:03:06 +01:00
|
|
|
}
|
|
|
|
|
2021-05-12 01:47:09 +02:00
|
|
|
log.info(`process.env.HUGO_ENV = '${process.env.HUGO_ENV}'`);
|
|
|
|
log.info(`process.env.HUGO_BASEURL = '${process.env.HUGO_BASEURL}'`);
|
2018-12-19 02:03:06 +01:00
|
|
|
|
2023-02-03 08:13:01 +01:00
|
|
|
gulp.task('default', gulp.series(gulp.parallel('assets:js', 'assets:fonts'), 'hugo', 'assets:images', finalCommand));
|
|
|
|
gulp.task('all', gulp.series(gulp.parallel('scripts:games', 'scripts:wiki'), gulp.parallel('assets:js', 'assets:fonts'), 'hugo', 'assets:images', finalCommand));
|
2020-11-05 08:53:06 +01:00
|
|
|
gulp.task('content', gulp.series('hugo', finalCommand));
|