-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
178 lines (143 loc) · 5.25 KB
/
gulpfile.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import gulp from "gulp"
import fileInclude from "gulp-file-include"
import replace from 'gulp-replace'
import insert from 'gulp-insert'
import clean from 'gulp-clean'
import * as manifest from './package.json' with { type: "json" }
import htmlmin from 'gulp-html-minifier-terser'
const mainPath = "html/index.html"
const mainPathDist = "webapp/"
const docs = [
"html/docs/index.html",
"html/docs/java/*.html",
"html/docs/pascal/*.html",
"html/docs/rekarel/*.html",
"html/docs/java_tutorial/*.html",
"html/docs/pascal_tutorial/*.html",
];
const docsDist = "webapp/docs"
gulp.task('bundle-html', ()=> {
return gulp.src([mainPath])
.pipe(
fileInclude({
prefix: '@@',
basepath: '@file',
context: {
shortVersion: manifest.default.version.replace(/[\.\-]/g,"_"),
longVersion: manifest.default.version,
coreVersion: manifest.default.dependencies["@rekarel/core"].replace(/^\^/, "")
}
}))
.pipe(htmlmin({
collapseWhitespace:true,
removeComments:true
}))
.pipe(gulp.dest(mainPathDist))
})
// Task to copy images
gulp.task('bundle-images', function () {
return gulp.src('resources/img/**/*', {encoding:false})
.pipe(gulp.dest('webapp/img'));
});
// Task to copy CSS
gulp.task('bundle-css', function () {
return gulp.src('resources/css/**/*')
.pipe(gulp.dest('webapp/css'));
});
// Task to copy JavaScript
gulp.task('bundle-js', function () {
return gulp.src('resources/js/**/*')
.pipe(gulp.dest('webapp/js'));
});
// Default task to run all copy tasks
gulp.task('bundle-resources', gulp.parallel('bundle-images', 'bundle-css', 'bundle-js'));
gulp.task('bundle-docs', ()=> {
return gulp.src(docs, { base: 'html/docs' })
.pipe(
fileInclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(htmlmin({
collapseWhitespace:true,
removeComments:true
}))
.pipe(gulp.dest(docsDist))
})
gulp.task('clean-docs', ()=> {
return gulp.src(docsDist, {allowEmpty: true})
.pipe(clean());
})
gulp.task('process-jison-java', ()=> {
const path = 'js/kareljava.js'
return gulp.src(path)
.pipe(insert.append('\nfunction javaParser() {\n return kareljava.parse.apply(kareljava, arguments);\n}\nexport {kareljava, javaParser }\n'))
.pipe(replace("_token_stack:", '// _token_stack:'))
.pipe(replace("loc: yyloc,", 'loc: lexer.yylloc, // Implement fix: https://github.com/zaach/jison/pull/356'))
.pipe(gulp.dest('js/'));
})
gulp.task('process-jison-pascal', ()=> {
const path = 'js/karelpascal.js'
return gulp.src(path)
.pipe(insert.append('\nfunction pascalParser () {\n return karelpascal.parse.apply(karelpascal, arguments);\n}\nexport {karelpascal, pascalParser}'))
.pipe(replace("_token_stack:", '// _token_stack:'))
.pipe(replace("loc: yyloc,", 'loc: lexer.yylloc, // Implement fix: https://github.com/zaach/jison/pull/356'))
.pipe(gulp.dest('js/'));
})
gulp.task('process-jison-java2pascal', ()=> {
const path = 'js/java2pascal.js'
return gulp.src(path)
.pipe(insert.append('\nfunction java2pascalParser () {\n return java2pascal.parse.apply(java2pascal, arguments);\n}\nexport {java2pascal, java2pascalParser}'))
.pipe(replace("_token_stack:", '// _token_stack:'))
.pipe(replace("loc: yyloc,", 'loc: lexer.yylloc, // Implement fix: https://github.com/zaach/jison/pull/356'))
.pipe(gulp.dest('js/'));
})
gulp.task('process-jison-pascal2java', ()=> {
const path = 'js/pascal2java.js'
return gulp.src(path)
.pipe(insert.append('\nfunction pascal2javaParser () {\n return pascal2java.parse.apply(pascal2java, arguments);\n}\nexport {pascal2java, pascal2javaParser}'))
.pipe(replace("_token_stack:", '// _token_stack:'))
.pipe(replace("loc: yyloc,", 'loc: lexer.yylloc, // Implement fix: https://github.com/zaach/jison/pull/356'))
.pipe(gulp.dest('js/'));
})
const paths = {
html: [
'./webapp/index.html',
'./webapp/ayuda.html',
'./webapp/ayuda-java.html',
'./webapp/ayuda-pascal.html',
],
js: [
'./webapp/js/cindex.js',
],
img: './webapp/img/*',
css: './webapp/css/*',
license: './LICENSE',
build: './build'
};
gulp.task('clean', ()=> {
return gulp.src(paths.build, {allowEmpty: true, read: false})
.pipe(clean());
});
gulp.task('copy-html', () => {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.build));
});
gulp.task('copy-js', () => {
return gulp.src(paths.js)
.pipe(gulp.dest(`${paths.build}/js`));
});
gulp.task('copy-img', () => {
return gulp.src(paths.img)
.pipe(gulp.dest(`${paths.build}/img`));
});
gulp.task('copy-css', () => {
return gulp.src(paths.css)
.pipe(gulp.dest(`${paths.build}/css`));
});
gulp.task('copy-license', () => {
return gulp.src(paths.license)
.pipe(gulp.dest(`${paths.build}`));
});
gulp.task('default', gulp.series('bundle-html', 'clean-docs', 'bundle-docs', 'bundle-resources'));
gulp.task('build', gulp.series('clean', 'copy-html', 'copy-js', 'copy-img', 'copy-css','copy-license'));