-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
114 lines (95 loc) · 3.43 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
/* eslint-env babel-node */
"use strict";
var fs = require("fs");
var path = require("path");
var gulp = require("gulp");
var gutil = require("gulp-util");
var webpack = require("webpack");
var mocha = require("gulp-mocha");
var wsTcpProxy = require("./tools/ws-tcp-proxy");
var http = require("http");
var ecstatic = require("ecstatic");
var express = require("express");
var morgan = require("morgan");
var proxy = require("express-http-proxy");
var WEBPACK_CONFIG_NAME = "webpack.config.js";
var customfs = require("./tools/loader/responses").customfs;
var PREFS_SRC_FILE = path.join(__dirname, "client", "preferences", "devtools.js");
var PREFS_OUTPUT_FILE = path.join(__dirname, "build", "preferences.json");
var CONNECT_HTTP_PORT = 8081;
gulp.task("build", function () {
console.error('Use `webpack --progress --color`');
});
gulp.task("watch", function() {
console.error('Use `webpack --progress --color --watch`');
});
gulp.task("build-connect", function() {
console.error('Use `webpack --progress --color`');
});
gulp.task("build-test", function (callback) {
console.error('Use `webpack --progress --color`');
});
/**
* Crudely parses `client/preferences/devtools.js` and generates
* a JSON representation of these prefs in `build/prefs.json`
* For preprocessing directives, it"ll just use the last form called in the file.
*/
gulp.task("build-prefs", function (callback) {
var lines = fs.readFileSync(PREFS_SRC_FILE, "utf8").split("\n");
fs.writeFile(PREFS_OUTPUT_FILE, JSON.stringify(lines.reduce(function (prefs, line) {
line = line.trim();
if (!line || line[0] === "#" || line[0] === "/") {
return prefs;
}
var prefNames = /^\s*pref\(['"]([\w\.]*)['"],\s(.*)\);/.exec(line);
if (!prefNames) {
return prefs;
}
var currentBranch = prefs;
var prefName = prefNames[1];
console.log(prefName, prefNames[2]);
var value = eval(prefNames[2]);
for (var branch of prefName.split(".")) {
currentBranch = (currentBranch[branch] = currentBranch[branch] || Object.create(null));
}
currentBranch.value = value;
// Use enums from
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIPrefBranch#Constants
currentBranch.type = typeof value === "boolean" ? 128 :
typeof value === "string" ? 32 :
typeof value === "number" ? 64 : 0;
return prefs;
}, Object.create(null)), null, 2), callback);
});
gulp.task("start-proxy", function() {
// WS <-> TCP server in Firefox
wsTcpProxy.listen({
wsPort: 9000,
tcpPort: 6080,
});
// WS <-> TCP server in Valence add-on <-> Chrome
wsTcpProxy.listen({
wsPort: 9001,
tcpPort: 6081
});
});
gulp.task("start", ["start-proxy"], function() {
var app = express();
app.use('/chrome-tab-list/json', proxy('localhost:9222', {
forwardPath: function(req, res) {
return "/json";
}
}));
app.use(morgan('dev'));
app.use(ecstatic({
root: path.join(__dirname),
baseDir: '/',
handleError: false,
fs: customfs,
}));
http.createServer(app).listen(CONNECT_HTTP_PORT);
console.log("Open http://localhost:8081/client/framework/toolbox-wrapper.html to test the toolbox");
console.log("Open http://localhost:8081/tools/connect/?wsPort=9000 for the test tool (for Firefox server)");
console.log("Open http://localhost:8081/tools/connect/?wsPort=9001 for the test tool (for Chrome server)");
});
gulp.task("default", ["build"]);