forked from anthonychu/funcvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.js
More file actions
executable file
·52 lines (40 loc) · 1.59 KB
/
func.js
File metadata and controls
executable file
·52 lines (40 loc) · 1.59 KB
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
#! /usr/bin/env node
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const { getLocations, constants } = require('./common');
const args = process.argv;
const version = '4.0.3928';
async function main() {
if (args.length >= 3 && args[2] === '--is-funcvm') {
console.log('yes');
return;
}
const { downloadDir } = await getLocations();
const versionFile = path.join(downloadDir, 'funcvm-core-tools-version.txt');
const localVersionFile = path.join(process.cwd(), '.func-version');
let version;
if (!!process.env[constants.versionEnvironmentVariableName]) {
version = process.env[constants.versionEnvironmentVariableName];
} else if (fs.existsSync(localVersionFile)) {
version = fs.readFileSync(localVersionFile, 'utf8').trim();
} else if (fs.existsSync(versionFile)) {
version = fs.readFileSync(versionFile, 'utf8');
} else {
console.error('funcvm not initialized. Run funcvm --help.');
process.exit(1);
}
const funcBin = path.join(downloadDir, version, 'func');
const funcBinWindows = path.join(downloadDir, version, 'func.exe');
if (!fs.existsSync(funcBin) && !fs.existsSync(funcBinWindows)) {
console.error(`func binary not found at ${funcBin}. Try running 'funcvm install ${version}' to repair.`);
process.exit(1);
}
const funcProc = spawn(funcBin, args.slice(2), {
stdio: [process.stdin, process.stdout, process.stderr, 'pipe']
});
funcProc.on('exit', code => {
process.exit(code);
});
}
main();