-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.js
39 lines (35 loc) · 1.05 KB
/
target.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
var path = require('path');
var fs = require('fs');
const config = require('./package');
const http = require("http");
var extract = require('extract-zip');
let defaultUrl = `https://github.com/morganmora/icode-cli/blob/master/src/icode-${config.icodeVersion}A.zip`;
let fileZipName = path.resolve(__dirname, 'src', `icode-${config.icodeVersion}A.zip`);
let target = exports;
target.home = process.env.HOME || process.env.USERPROFILE;
target.home += '/.icode';
target.path = path.join(target.home, `icode-${config.icodeVersion}`, 'bin');
target.pathCheck = path.join(target.path, 'icode');
target.init = function() {
let nothing = true;
// Make dir .icode
try {
fs.accessSync(target.pathCheck, fs.F_OK);
nothing = false;
} catch (e) {
try {
fs.accessSync(target.home, fs.F_OK);
} catch (e) {
fs.mkdir(target.home);
}
}
// install icode
if (nothing) {
createFolder();
}
}
function createFolder() {
file = fs.createReadStream(fileZipName);
extract(fileZipName, {dir: target.home}, function (err) {});
}
target.init();