-
Notifications
You must be signed in to change notification settings - Fork 19
/
install.js
executable file
·100 lines (83 loc) · 2.64 KB
/
install.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
#!/usr/bin/env node
var os = require('os');
var fsx = require('fs-extra');
var fs = require('fs');
var path = require('path');
var packageConfig = require('./lib/package-config');
var haxeUrl = require('./lib/haxe-url');
var vars = require('./lib/vars');
var localConfig = require('./package.json');
var Cache = require('./lib/cache');
var TaskRunner = require('./lib/task-runner').TaskRunner;
var ClearTask = require('./lib/clear-task').ClearTask;
var DownloadHaxeTask = require('./lib/download-haxe-task').DownloadHaxeTask;
var DownloadHaxelibTask = require('./lib/download-haxelib-task').DownloadHaxelibTask;
var DownloadNekoTask = require('./lib/download-neko-task').DownloadNekoTask;
var InstallHaxelibDependenciesTask = require('./lib/install-haxelib-dependencies-task').InstallHaxelibDependenciesTask;
function findPackageJson() {
var startPath = process.cwd();
var ignore = 0;
var searchPath = path.join(startPath + '/..');
var fileFound = false;
var nextPath = '';
var numSearch = 0;
while (!fileFound) {
searchPath = nextPath || searchPath;
numSearch++;
if(numSearch>4){
return false;
}
try {
fs.statSync(path.join(searchPath + '/package.json'));
if (ignore > 0) {
ignore--;
} else {
fileFound = true;
}
} catch (err) {}
nextPath = path.join(searchPath + '/..');
if (nextPath === path.normalize('/') || nextPath === '.' || nextPath === '..') {
break;
}
}
if (fileFound) {
return {
read: function () {
return fs.readFileSync(path.join(searchPath + '/package.json'), 'utf8');
},
parse: function () {
return JSON.parse(fs.readFileSync(path.join(searchPath + '/package.json'), 'utf8'));
},
path: path.join(searchPath + '/package.json')
};
}
return false;
};
var pack = findPackageJson();
function getHaxeDependencies(){
var deps;
try {
deps = pack.parse().haxeDependencies;
} catch (error){
console.warn('no dependencies');
}
return deps;
}
function getVersion(module){
var envVersion = packageConfig(module);
var packageVersion;
try {
packageVersion = getHaxeDependencies()[module];
} catch (error){
console.warn('using default '+ module +' version');
}
var localFallbackVersion = localConfig.haxeDependencies[module];
return packageVersion || envVersion || localFallbackVersion;
}
var runner = new TaskRunner();
runner.addTask(new ClearTask());
runner.addTask(new DownloadHaxeTask(getVersion('haxe')));
runner.addTask(new DownloadHaxelibTask(getVersion('haxelib')));
runner.addTask(new DownloadNekoTask(getVersion('neko')));
runner.addTask(new InstallHaxelibDependenciesTask(getHaxeDependencies()));
runner.run();