-
Notifications
You must be signed in to change notification settings - Fork 81
/
gulpfile.js
152 lines (130 loc) · 3.69 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
'use strict';
var gulp = require('gulp'),
replace = require('gulp-replace'),
rename = require("gulp-rename"),
insert = require('gulp-insert'),
beautifier = require('gulp-beautify');
function skippable(condition, fn){
if (condition) {
return fn;
}
function skipped(cb){
cb();
}
skipped.displayName = (fn.name || fn.displayName) + ' (skipped)';
return skipped;
}
var _browserRename = function (path) {
path.basename += "_browser";
};
var document = `var JSDOM = require('jsdom').JSDOM;
var window = (new JSDOM()).window;
var document = window.document;
var Element = window.Element;
var Node = window.Node;
var self = this;
`;
function blockly() {
return gulp.src('blockly/blockly_compressed.js')
.pipe(replace(
"this.navigator&&this.navigator.userAgent||",
''))
.pipe(insert.wrap(`
${document}
var xmlshim = require('xmlshim');
var XMLSerializer = xmlshim.XMLSerializer;
var DOMParser = xmlshim.DOMParser;
module.exports = (function(){ // `,
//....ORIGINAL CODE....
`return Blockly;
})()`))
.pipe(gulp.dest('lib'))
}
function blockly_browser() {
return gulp.src('blockly/blockly_compressed.js')
.pipe(replace(
"this.navigator&&this.navigator.userAgent||",
'window.navigator&&window.navigator.userAgent||'))
.pipe(insert.wrap(`
/* eslint-disable */
module.exports = (function(){ //`,
//....ORIGINAL CODE....
`return Blockly;
})()`))
.pipe(rename(_browserRename))
.pipe(gulp.dest('lib'))
}
function blocks() {
return gulp.src('blockly/blocks_compressed.js')
.pipe(insert.wrap(`
module.exports = function(Blockly){
var goog = Blockly.goog;
${document}
Blockly.Blocks={};`,
//....ORIGINAL CODE....
`return Blockly.Blocks;
}`))
.pipe(gulp.dest('lib'))
}
function blocks_browser() {
return gulp.src('blockly/blocks_compressed.js')
.pipe(insert.wrap(`
/* eslint-disable */
module.exports = function(Blockly){
Blockly.Blocks={};`,
//....ORIGINAL CODE....
`return Blockly.Blocks;
}`))
.pipe(rename(_browserRename))
.pipe(gulp.dest('lib'))
}
function js() {
return gulp.src('blockly/javascript_compressed.js')
.pipe(insert.wrap('module.exports = function(Blockly){', 'return Blockly.JavaScript;}'))
.pipe(gulp.dest('lib'))
}
function dart() {
return gulp.src('blockly/dart_compressed.js')
.pipe(insert.wrap('module.exports = function(Blockly){', 'return Blockly.Dart;}'))
.pipe(replace(/window\./g, ''))
.pipe(gulp.dest('lib'))
}
function python() {
return gulp.src('blockly/python_compressed.js')
.pipe(insert.wrap('module.exports = function(Blockly){', 'return Blockly.Python;}'))
.pipe(gulp.dest('lib'))
}
function php() {
return gulp.src('blockly/php_compressed.js')
.pipe(insert.wrap('module.exports = function(Blockly){', 'return Blockly.PHP;}'))
.pipe(gulp.dest('lib'))
}
function lua() {
return gulp.src('blockly/lua_compressed.js')
.pipe(insert.wrap('module.exports = function(Blockly){', 'return Blockly.Lua;}'))
.pipe(gulp.dest('lib'))
}
function i18n() {
return gulp.src('blockly/msg/js/*.js')
.pipe(replace(/goog\.[^\n]+/g, ''))
.pipe(insert.wrap('var Blockly = {}; Blockly.Msg={}; module.exports = function(){ ', 'return Blockly.Msg;}'))
.pipe(gulp.dest('lib/i18n/'))
}
function beautify() {
return gulp.src('lib/*.js')
.pipe(beautifier.js({indent_size: 2}))
.pipe(gulp.dest('lib/'));
};
exports.build = gulp.series(
blocks,
blocks_browser,
blockly,
blockly_browser,
i18n,
js,
php,
dart,
python,
lua,
skippable(process.env.DEBUG, beautify),
);