This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (118 loc) · 3.56 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var rimraf = require('gulp-rimraf');
var runSequence = require('run-sequence');
var chug = require('gulp-chug');
var path = require("path");
var gitUpdate = require("npm-git-update");
var resolve = require("resolve");
var npm = require("npm");
var semver = require('semver-extra');
var nodeModulesPaths = require("resolve/lib/node-modules-paths")
var fs = require("fs");
var exec = require('child_process').exec;
function getPackage(name, basedir) {
var isFile = function (file) {
try { var stat = fs.statSync(file) }
catch (err) { if (err && err.code === 'ENOENT') return false }
return stat.isFile() || stat.isFIFO();
};
var dirs = nodeModulesPaths(basedir, { paths: [] });
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var pkgfile = path.join(dir, '/', name, '/package.json');
if (!isFile(pkgfile)) continue;
var body = fs.readFileSync(pkgfile, 'utf8');
var data = JSON.parse(body);
return {
dir: dir,
path: pkgfile,
data: data,
}
}
}
function installDevDependencies(name, cb) {
npm.load({ loaded: false }, function (err) {
npm.on("log", function (message) {
console.log(message);
});
var pkg = getPackage(name, __dirname);
var deps = pkg.data.devDependencies;
var install = [];
for(var depname in deps) {
var depver = deps[depname];
var deppkg = getPackage(depname, pkg.dir);
if(deppkg) {
var satisfies = semver.satisfies(deppkg.data.version, depver);
if (!satisfies) {
install.push(depname + "@" + depver);
}
} else {
install.push(depname + "@" + depver);
}
}
if(install.length > 0) {
console.log(install.join(", ") + " need to be installed for `" + name + "`")
npm.commands.install(install, cb);
} else {
cb();
}
});
}
function build_dep(name) {
try {
resolve.sync(name, { basedir: __dirname });
} catch(err) {
var gulpfile = path.join("./node_modules", name, "gulpfile.js");
return gulp.src(gulpfile).pipe(chug());
}
}
gulp.task("update:browser-relay-client", function(done) {
gitUpdate(["browser-relay-client"], __dirname, done);
});
gulp.task("install:browser-relay-client", function(done) {
installDevDependencies("browser-relay-client", done);
});
gulp.task("build:browser-relay-client", function () {
return build_dep("browser-relay-client");
});
gulp.task('default', function(done) {
runSequence(
"clean",
"update:browser-relay-client",
"install:browser-relay-client",
"build:browser-relay-client",
"compile",
done);
});
gulp.task('clean', function () {
return gulp.src([
'lib/**/*.js',
'lib/**/*.d.ts',
], { read: false })
.pipe(rimraf({ force: true }));
});
gulp.task('compile', function () {
var compiler = ts({
declarationFiles: true,
noExternalResolve: false,
module: 'commonjs',
target: 'ES5',
noImplicitAny: true,
noLib: false,
outDir: 'lib',
});
var result = gulp
.src([
'src/**/*.ts',
'typings/**/*.d.ts'
])
.pipe(compiler)
;
result.dts
.pipe(gulp.dest('lib'))
;
return result.js
.pipe(gulp.dest('lib'))
;
});