Skip to content

Commit 5a0babd

Browse files
Merge pull request #37 from Roky97/gulp-integration
Gulp integration - Release 2.8.0
2 parents af256ff + 519592c commit 5a0babd

File tree

8 files changed

+210
-20
lines changed

8 files changed

+210
-20
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Further information can be found in the [Wiki](https://github.com/DeMaCS-UNICAL/
5959

6060

6161
## Getting Started (Installation and Usage)
62-
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
62+
These instructions will get you a copy of the project up and running on your local machine.
6363

6464
### Prerequisites
6565
It requires only [Node.js®](https://nodejs.org)
@@ -70,7 +70,11 @@ Install dependencies:
7070
npm install
7171
```
7272

73-
### Running
73+
Now you can run LoIDE in development or in production mode.
74+
75+
### Running in production mode
76+
In this mode, LoIDE will be optimized for production.
77+
7478
Start the server:
7579
```
7680
npm start
@@ -81,6 +85,19 @@ Use _LoIDE_ in a browser at:
8185
http://localhost:8084
8286
```
8387

88+
### Running in development mode
89+
Run LoIDE in development mode only for development and testing purposes.
90+
91+
Start the server:
92+
```
93+
npm run start:dev
94+
```
95+
96+
The browser will be opened automatically _LoIDE_ in at:
97+
```
98+
http://localhost:7000
99+
```
100+
84101
### Note
85102
You need an "executor" in order to run the solvers.
86103

@@ -98,6 +115,16 @@ If you like it, you can use our [EmbASPServerExecutor](https://github.com/DeMaCS
98115
- [keymaster.js](https://github.com/madrobby/keymaster) - Used to implement keyboard shortcuts outside the editor
99116
- [Pugjs](https://pugjs.org) - Used to create a dynamic html pages
100117
- [Socket.io](https://socket.io) - Used for executor server connection
118+
- [Browsersync](https://www.browsersync.io) - Used to enable the live reload on the browser
119+
- [Gulp](https://gulpjs.com) - Used to automate and enhance the workflow with its plugins:
120+
- [gulp-nodemon](https://github.com/JacksonGariety/gulp-nodemon) - Used to monitor for any changes in the source files and automatically restart the server
121+
- [gulp-clean](https://github.com/peter-vilja/gulp-clean) - Used to remove files and folders
122+
- [gulp-uglify-es](https://gitlab.com/itayronen/gulp-uglify-es) - Used to minify JS files
123+
- [gulp-autoprefixer](https://github.com/sindresorhus/gulp-autoprefixer#readme) - Used to add CSS prefix
124+
- [gulp-csso](https://github.com/ben-eb/gulp-csso) - Used to minify CSS files
125+
- [gulp-shorthand](https://github.com/kevva/gulp-shorthand) - Used to make the CSS files lighter and more readable
126+
- [gulp-imagemin](https://github.com/sindresorhus/gulp-imagemin#readme) - Used to minify PNG, JPEG, GIF and SVG images
127+
101128
<!--
102129
## Contributing
103130

app.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ var pug = require('pug');
99
var jpointer = require('json-pointer');
1010
const compression = require('compression');
1111

12+
const environment = {
13+
dev: 'development',
14+
prod: 'production'
15+
}
16+
17+
const path = {
18+
dist: 'dist',
19+
src: 'resources'
20+
}
21+
22+
const currentEnv = process.env.NODE_ENV || environment.dev
23+
const resourcesPath = currentEnv == environment.prod ? path.dist : path.src
24+
1225
// System config loading
1326
var properties = require('./config/app-config.json');
1427
var httpPort = properties.port.http;
@@ -55,8 +68,8 @@ app.use(helmet.hsts({
5568
}));
5669

5770
app.use(compression());
58-
app.use(express.static('resources'));
59-
app.set('views', './resources');
71+
app.use(express.static(resourcesPath));
72+
app.set('views', './' + resourcesPath);
6073
app.set('view engine', 'pug');
6174

6275
// Load variables in to the .pug file

gulpfile.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
const { series, src, dest, parallel } = require('gulp');
2+
const csso = require('gulp-csso');
3+
const shorthand = require('gulp-shorthand');
4+
const clean = require('gulp-clean');
5+
const autoprefixer = require('gulp-autoprefixer');
6+
const uglify = require('gulp-uglify-es').default;
7+
const imagemin = require('gulp-imagemin');
8+
const nodemon = require('gulp-nodemon')
9+
var browserSync = require('browser-sync').create();
10+
11+
const path = {
12+
dist: 'dist/',
13+
src: 'resources/'
14+
}
15+
16+
const environment = {
17+
dev: 'development',
18+
prod: 'production'
19+
}
20+
21+
// System config loading
22+
var properties = require('./config/app-config.json');
23+
var httpPort = properties.port.http;
24+
25+
function cleanDir(){
26+
return src( path.dist + '*', {read: false})
27+
.pipe(clean());
28+
}
29+
30+
function css() {
31+
return src(path.src + 'css/*.css')
32+
.pipe(autoprefixer({
33+
cascade: false
34+
}))
35+
.pipe(shorthand())
36+
.pipe(csso())
37+
.pipe(dest(path.dist + 'css/'))
38+
}
39+
40+
function faviconImage() {
41+
return src(path.src + 'favicon/*.{png,svg}')
42+
.pipe(imagemin())
43+
.pipe(dest(path.dist + 'favicon/'))
44+
}
45+
46+
function faviconFiles() {
47+
return src(path.src + 'favicon/*.{ico,xml,webmanifest}')
48+
.pipe(dest(path.dist + 'favicon/'))
49+
}
50+
51+
function img() {
52+
return src(path.src + 'img/*.*')
53+
.pipe(imagemin())
54+
.pipe(dest(path.dist + 'img/'))
55+
}
56+
57+
function js() {
58+
return src(path.src + 'js/**/*.js')
59+
.pipe(uglify())
60+
.pipe(dest(path.dist + 'js/'))
61+
}
62+
63+
function pug() {
64+
return src(path.src + '**/*.pug')
65+
.pipe(dest(path.dist))
66+
}
67+
68+
function serveProd(done) {
69+
const server = nodemon({
70+
script: 'app.js'
71+
, ext: 'js json'
72+
, ignore: ['node_modules/', 'dist/', 'resources/', 'gulpfile.js']
73+
, env: { 'NODE_ENV': environment.prod }
74+
});
75+
76+
server.on('start', () => {
77+
done();
78+
});
79+
}
80+
81+
function serveDev(done) {
82+
const STARTUP_TIMEOUT = 5000;
83+
const server = nodemon({
84+
script: 'app.js'
85+
, stdout: false
86+
, ext: 'js json'
87+
, ignore: ['node_modules/', 'dist/', 'resources/', 'gulpfile.js']
88+
, env: { 'NODE_ENV': environment.dev }
89+
});
90+
let starting, restarting, crashed = false;
91+
92+
const onReady = () => {
93+
starting = false;
94+
if(restarting && !crashed) browserSync.reload();
95+
restarting = false;
96+
crashed = false;
97+
done();
98+
};
99+
100+
server.on('start', () => {
101+
starting = true;
102+
setTimeout(onReady, STARTUP_TIMEOUT);
103+
});
104+
105+
server.on('stdout', (stdout) => {
106+
process.stdout.write(stdout); // pass the stdout through
107+
if (starting || restarting) {
108+
onReady();
109+
}
110+
});
111+
112+
server.on('restart', () => {
113+
browserSync.notify("Reastarting LoIDE, please wait!");
114+
restarting = true;
115+
});
116+
117+
server.on('crash', () => {
118+
browserSync.notify("LoIDE crashed!", 5000);
119+
crashed = true;
120+
});
121+
}
122+
123+
function startBrowserSync(done){
124+
browserSync.init({
125+
proxy: "http://localhost:" + httpPort,
126+
files: [path.src + "/**/*.*"],
127+
port: 7000,
128+
}, done);
129+
}
130+
131+
const build = parallel(css,faviconImage,faviconFiles,img,js,pug);
132+
133+
exports.default = series(cleanDir, build, serveProd)
134+
exports.dev = series(cleanDir, serveDev, startBrowserSync)
135+
exports.clean = series(cleanDir)

package.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "LoIDE",
3-
"version": "2.7.1",
3+
"version": "2.8.0",
44
"description": "Web-based IDE for Logic Programming",
55
"main": "app.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "node app.js"
8+
"start": "npx gulp",
9+
"start:dev": "npx gulp dev",
10+
"clean": "npx gulp clean"
911
},
1012
"repository": {
1113
"type": "git",
@@ -48,7 +50,16 @@
4850
"websocket": "^1.0.30"
4951
},
5052
"devDependencies": {
51-
"compression": "^1.7.3"
53+
"browser-sync": "^2.26.7",
54+
"compression": "^1.7.3",
55+
"gulp": "^4.0.2",
56+
"gulp-autoprefixer": "^7.0.1",
57+
"gulp-clean": "^0.4.0",
58+
"gulp-csso": "^4.0.1",
59+
"gulp-imagemin": "^7.1.0",
60+
"gulp-nodemon": "^2.5.0",
61+
"gulp-shorthand": "^1.1.0",
62+
"gulp-uglify-es": "^2.0.0"
5263
},
5364
"analyze": true,
5465
"homepage": "https://github.com/DeMaCS-UNICAL/LoIDE#readme"

resources/index.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
</div>
141141
<div class="container">
142142
<form id="input" style="position: relative;">
143-
<div class="left-panel" style="height: auto">
143+
<div class="left-panel left-panel-show" style="height: auto">
144144
<div class="option-solver">
145145
<div class="text-center left-panel-title sticky-top pt-2 mb-2">
146146
<h5>Run options</h5>
@@ -409,7 +409,7 @@
409409
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
410410
<script src="https://code.jquery.com/jquery-migrate-3.3.0.min.js"></script>
411411
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
412-
<script src="js/jquery.layout_and_plugins.min.js" type="text/javascript"></script>
412+
<script src="js/plugin/jquery.layout_and_plugins.min.js" type="text/javascript"></script>
413413

414414
<!-- Bootstrap JavaScript -->
415415
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>

resources/js/jquery.layout_and_plugins.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

resources/js/plugin/jquery.layout_and_plugins.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/script.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ $(document).ready(function () {
312312
}
313313
},
314314
south__minSize: 125,
315+
east__minSize: 100,
315316
resizeWhileDragging: true,
316317
resizable: true,
317318
slidable: true,
@@ -387,12 +388,7 @@ $(document).ready(function () {
387388
});
388389

389390
$("#btn-option").click(function () {
390-
$('.left-panel').toggleClass('left-panel-show'); // add class 'left-panel-show' to increase the width of the left panel
391-
$('.option-solver > div').toggleClass(" show"); // add class to show option components
392-
$(".left-panel-show, .left-panel").one('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',
393-
function () {
394-
layout.resizeAll();
395-
});
391+
openRunOptions();
396392
});
397393

398394
$("#reset-editor").click(function () {
@@ -418,7 +414,7 @@ $(document).ready(function () {
418414

419415
setAceMode();
420416

421-
openRunOptions();
417+
closeRunOptionOnMobile();
422418

423419
// Set the default options
424420
resetSolverOptions();
@@ -2839,12 +2835,20 @@ function renameSelectOptionsAndBadge() {
28392835
});
28402836
}
28412837

2842-
function openRunOptions() {
2843-
if ($(window).width() > screen.small.size) {
2844-
$('#btn-option').trigger('click');
2838+
function closeRunOptionOnMobile() {
2839+
if ($(window).width() <= screen.small.size) {
2840+
$('.left-panel').removeClass('left-panel-show');
28452841
}
28462842
}
28472843

2844+
function openRunOptions() {
2845+
$('.left-panel').toggleClass('left-panel-show'); // add class 'left-panel-show' to increase the width of the left panel
2846+
$(".left-panel-show, .left-panel").one('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',
2847+
function () {
2848+
layout.resizeAll();
2849+
});
2850+
}
2851+
28482852
function getHTMLFromJQueryElement(jQueryElement) {
28492853
var DOMElement = '';
28502854

0 commit comments

Comments
 (0)