forked from Kode/khamake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaxe.ts
37 lines (32 loc) · 1.12 KB
/
Haxe.ts
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
"use strict";
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as log from './log';
import {sys} from './exec';
export function executeHaxe(from: string, haxeDirectory: string, options): Promise<{}> {
return new Promise((resolve, reject) => {
let exe = 'haxe';
let env = process.env;
if (fs.existsSync(haxeDirectory) && fs.statSync(haxeDirectory).isDirectory()) {
let localexe = path.resolve(haxeDirectory, 'haxe' + sys());
if (!fs.existsSync(localexe)) localexe = path.resolve(haxeDirectory, 'haxe');
if (fs.existsSync(localexe)) exe = localexe;
const stddir = path.resolve(haxeDirectory, 'std');
if (fs.existsSync(stddir) && fs.statSync(stddir).isDirectory()) {
env.HAXE_STD_PATH = stddir;
}
}
let haxe = child_process.spawn(exe, options, {env: env, cwd: path.normalize(from)});
haxe.stdout.on('data', (data) => {
log.info(data.toString());
});
haxe.stderr.on('data', (data) => {
log.error(data.toString());
});
haxe.on('close', (code) => {
if (code === 0) resolve();
else reject('Haxe compiler error.')
});
});
}