From 1bac070ced5ca3da449d792eebe4303522b237c8 Mon Sep 17 00:00:00 2001 From: Matthias Konitzny <konitzny@ibr.cs.tu-bs.de> Date: Tue, 16 Nov 2021 17:59:39 +0100 Subject: [PATCH] Added improved build and bundling using gulp. Updated npm build targets. --- .eslintrc.json | 3 +- gulpfile.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++------ 3 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 gulpfile.js diff --git a/.eslintrc.json b/.eslintrc.json index c902b95..8c13838 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "env": { "es6": true, - "browser": true + "browser": true, + "node": true }, "extends": "eslint:recommended", "parserOptions": { diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..cfa8294 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,78 @@ +// Gulp.js configuration +"use strict"; + +const gulp = require("gulp"); +const replace = require("gulp-replace"); +const zip = require("gulp-zip"); +const del = require("del"); + +const dir = { + src: ".", + build: "./release/", +}; + +// PHP settings +const php = { + src: [dir.src + "/**/*.php", "!node_modules/**", "!release/**"], + build: dir.build, +}; + +const parcel = { + src: "./build/release/**", + build: dir.build + "build/release/", +}; + +function clean() { + return del(dir.build + "**", { force: true }); +} + +function copyPHP() { + return gulp + .src(php.src) + .pipe( + replace( + "$GLOBALS['build'] = 'debug';", + "$GLOBALS['build'] = 'release';" + ) + ) + .pipe(gulp.dest(php.build)); +} + +function copyParcel() { + return gulp.src(parcel.src).pipe(gulp.dest(parcel.build)); +} + +function zipBuild() { + return gulp + .src(dir.build + "**") + .pipe(zip("knowledge-space.zip")) + .pipe(gulp.dest(dir.build)); +} + +function copyDefaultSpace() { + return gulp + .src("datasets/space.json") + .pipe(gulp.dest(dir.build + "datasets/")); +} + +function copyEditorIcons() { + return gulp + .src("editor/images/**/*.png") + .pipe(gulp.dest(dir.build + "editor/images/")); +} + +function copyBackground() { + return gulp + .src("backgrounds/background_4.jpg") + .pipe(gulp.dest(dir.build + "backgrounds/")); +} + +exports.build = gulp.series( + clean, + copyPHP, + copyParcel, + copyDefaultSpace, + copyEditorIcons, + copyBackground, + zipBuild +); diff --git a/package.json b/package.json index d855e30..616eba0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "knowledge-space", "version": "1.0.0", "description": "A Wordpress-Plugin to display knowledge in a graph-structured way.", - "main": "index.js", + "source": "index.js", "debug": "build/debug/graph.js", "release": "build/release/graph.js", "targets": { @@ -13,20 +13,13 @@ "release": { "distDir": "build/release/", "sourceMap": false, - "optimize": true, - "includeNodeModules": [ - "three", - "3d-force-graph", - "force-graph" - ], - "isLibrary": true, - "context": "node" + "optimize": true } }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "watch": "parcel watch index.js", - "build": "parcel build index.js --target release" + "build": "parcel build index.js --target release && gulp build" }, "repository": { "type": "git", @@ -43,7 +36,11 @@ "devDependencies": { "@babel/core": "^7.14.8", "@babel/eslint-parser": "^7.14.9", + "del": "^6.0.0", "eslint": "^7.32.0", + "gulp": "^4.0.2", + "gulp-replace": "^1.1.3", + "gulp-zip": "^5.1.0", "parcel": "^2.0.0-rc.0", "prettier": "^2.3.2" }, -- GitLab