-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
159 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,102 @@ | ||
var gulp = require('gulp'); | ||
var webpack = require('webpack-stream'); | ||
var merge = require('merge2'); | ||
const replace = require('gulp-replace'); | ||
var clean = require('gulp-clean'); | ||
var argv = require('yargs').argv; | ||
var fs = require('fs'); | ||
const gulp = require("gulp"); | ||
const webpack = require("webpack-stream"); | ||
const merge = require("merge2"); | ||
const replace = require("gulp-replace"); | ||
const clean = require("gulp-clean"); | ||
const argv = require("yargs").argv; | ||
const fs = require("fs"); | ||
|
||
gulp.task('drop-cache', function(){ | ||
return gulp.src(['./src/main/resources/public/dist'], { read: false }) | ||
.pipe(clean()); | ||
}); | ||
function dropCache() { | ||
return gulp | ||
.src(["./src/main/resources/public/dist"], { | ||
read: false, | ||
allowEmpty: true, | ||
}) | ||
.pipe(clean()); | ||
} | ||
|
||
function buildDev() { | ||
return gulp | ||
.src("./src/main/resources/public") | ||
.pipe(webpack(require("./webpack.config.js"))) | ||
.on("error", function handleError() { | ||
this.emit("end"); // Recover from errors | ||
}) | ||
.pipe(gulp.dest("./src/main/resources/public/dist")); | ||
} | ||
|
||
gulp.task('webpack', ['drop-cache'], () => { | ||
return gulp.src('./src/main/resources/public') | ||
.pipe(webpack(require('./webpack.config.js'))) | ||
.on('error', function handleError() { | ||
this.emit('end'); // Recover from errors | ||
}) | ||
.pipe(gulp.dest('./src/main/resources/public/dist')); | ||
}); | ||
function build(done) { | ||
const refs = gulp | ||
.src("./src/main/resources/view-src/**/*.+(html|json)") | ||
.pipe(replace("@@VERSION", Date.now())) | ||
.pipe(gulp.dest("./src/main/resources/view")); | ||
|
||
gulp.task('build', ['webpack'], () => { | ||
var refs = gulp.src("./src/main/resources/view-src/**/*.+(html|json)") | ||
.pipe(replace('@@VERSION', Date.now())) | ||
.pipe(gulp.dest("./src/main/resources/view")); | ||
const copyBehaviours = gulp | ||
.src("./src/main/resources/public/dist/behaviours.js") | ||
.pipe(gulp.dest("./src/main/resources/public/js")); | ||
|
||
var copyBehaviours = gulp.src('./src/main/resources/public/dist/behaviours.js') | ||
.pipe(gulp.dest('./src/main/resources/public/js')); | ||
merge[(refs, copyBehaviours)]; | ||
done(); | ||
} | ||
|
||
return merge[refs, copyBehaviours]; | ||
}); | ||
gulp.task("drop-cache", dropCache); | ||
gulp.task("build-dev", buildDev); | ||
gulp.task("build", build); | ||
|
||
function getModName(fileContent){ | ||
var getProp = function(prop){ | ||
return fileContent.split(prop + '=')[1].split(/\r?\n/)[0]; | ||
} | ||
return getProp('modowner') + '~' + getProp('modname') + '~' + getProp('version'); | ||
function getModName(fileContent) { | ||
const getProp = function (prop) { | ||
return fileContent.split(prop + "=")[1].split(/\r?\n/)[0]; | ||
}; | ||
return ( | ||
getProp("modowner") + "~" + getProp("modname") + "~" + getProp("version") | ||
); | ||
} | ||
|
||
gulp.task('watch', () => { | ||
var springboard = argv.springboard; | ||
if(!springboard){ | ||
springboard = '../springboard-open-ent/'; | ||
} | ||
if(springboard[springboard.length - 1] !== '/'){ | ||
springboard += '/'; | ||
} | ||
function watchFiles() { | ||
let springboard = argv.springboard; | ||
if (!springboard) { | ||
springboard = "../springboard-open-ent/"; | ||
} | ||
if (springboard[springboard.length - 1] !== "/") { | ||
springboard += "/"; | ||
} | ||
|
||
gulp.watch('./src/main/resources/public/ts/**/*.ts', () => gulp.start('build')); | ||
gulp.watch( | ||
"./src/main/resources/public/ts/**/*.ts", | ||
gulp.series("drop-cache", "build-dev", "build") | ||
); | ||
|
||
fs.readFile("./gradle.properties", "utf8", function(err, content){ | ||
var modName = getModName(content); | ||
gulp.watch(['./src/main/resources/public/js'], () => { | ||
console.log('Copying resources to ' + springboard + 'mods/' + modName); | ||
gulp.src('./src/main/resources/**/*') | ||
.pipe(gulp.dest(springboard + 'mods/' + modName)); | ||
}); | ||
gulp.watch(['./src/main/resources/public/template/**/*.html', '!./src/main/resources/public/template/entcore/*.html'], () => { | ||
console.log('Copying resources to ' + springboard + 'mods/' + modName); | ||
gulp.src('./src/main/resources/**/*') | ||
.pipe(gulp.dest(springboard + 'mods/' + modName)); | ||
}); | ||
fs.readFile("./gradle.properties", "utf8", function (err, content) { | ||
const modName = getModName(content); | ||
gulp.watch(["./src/main/resources/public/js"], () => { | ||
console.log("Copying resources to " + springboard + "mods/" + modName); | ||
gulp | ||
.src("./src/main/resources/**/*") | ||
.pipe(gulp.dest(springboard + "mods/" + modName)); | ||
}); | ||
gulp.watch( | ||
[ | ||
"./src/main/resources/public/template/**/*.html", | ||
"!./src/main/resources/public/template/entcore/*.html", | ||
], | ||
() => { | ||
console.log("Copying resources to " + springboard + "mods/" + modName); | ||
gulp | ||
.src("./src/main/resources/**/*") | ||
.pipe(gulp.dest(springboard + "mods/" + modName)); | ||
} | ||
); | ||
|
||
gulp.watch('./src/main/resources/view/**/*.html', () => { | ||
console.log('Copying resources to ' + springboard + 'mods/' + modName); | ||
gulp.src('./src/main/resources/**/*') | ||
.pipe(gulp.dest(springboard + 'mods/' + modName)); | ||
}); | ||
gulp.watch("./src/main/resources/view/**/*.html", () => { | ||
console.log("Copying resources to " + springboard + "mods/" + modName); | ||
gulp | ||
.src("./src/main/resources/**/*") | ||
.pipe(gulp.dest(springboard + "mods/" + modName)); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
gulp.task("watch", watchFiles); | ||
|
||
exports.watch = gulp.parallel("watch"); | ||
exports.build = gulp.series("drop-cache", "build-dev", "build"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters