forked from jupyterlab/jupyterlab
/
ensure-buildutils.js
48 lines (45 loc) · 1.43 KB
/
ensure-buildutils.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
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
var fs = require('fs-extra');
var glob = require('glob');
var path = require('path');
var childProcess = require('child_process');
// Make sure that buildutils is built and current
var current = true;
if (fs.existsSync(path.join('buildutils', 'lib'))) {
var srcFiles = glob.sync(path.join('buildutils', 'src', '*'));
var libFiles = glob.sync(path.join('buildutils', 'lib', '*'));
srcFiles.forEach(function(srcPath) {
// Bail early if already not current
if (!current) {
return;
}
var name = path.basename(srcPath);
var ext = path.extname(name);
if (ext !== 'js') {
return;
}
var libPath = path.join('buildutils', 'lib', name.replace('.ts', '.js'));
if (libFiles.indexOf(libPath) === -1) {
current = false;
return;
}
var srcTime = fs.statSync(srcPath).mtime;
var libTime = fs.statSync(libPath).mtime;
if (libTime < srcTime) {
current = false;
}
});
} else {
current = false;
}
if (!current) {
// This must be "npm" because it is run during `pip install -e .` before
// jlpm is installed.
childProcess.execSync('npm run build', {
stdio: [0, 1, 2],
cwd: path.resolve('./buildutils')
});
}