forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-data.js
59 lines (49 loc) · 1.32 KB
/
extract-data.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
var rpt = require('read-package-tree');
var data = require('./package.json');
var path = require('path');
var glob = require('glob');
var fs = require('fs-extra');
var seen = {};
var schemaDir = path.resolve('./schemas');
fs.removeSync(schemaDir);
fs.ensureDirSync(schemaDir);
var themesDir = path.resolve('./themes');
fs.removeSync(themesDir);
fs.ensureDirSync(themesDir);
function extractNode(data) {
data.children.forEach(function(child) {
extractNode(child);
});
if (seen[data.package.name]) {
return;
}
seen[data.package.name] = true;
var jlab = data.package.jupyterlab
if (!jlab) {
return;
}
// Handle schemas.
var schemaDir = jlab['schemaDir'];
if (schemaDir) {
debugger;
schemaDir = path.join(data.realpath, schemaDir);
var schemas = glob.sync(path.join(schemaDir, '*'));
schemas.forEach(function(schemaPath) {
var file = path.basename(schemaPath);
var to = path.join('schemas', file);
fs.copySync(schemaPath, to);
});
}
// Handle themes.
var themeDir = jlab['themeDir'];
if (themeDir) {
var name = data.package.name.replace('@', '');
name = name.replace('/', '-');
var from = path.join(data.realpath, themeDir);
var to = path.join('themes', name);
fs.copySync(from, to);
}
}
rpt('.', function (er, data) {
extractNode(data);
})