@mandors/cli 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm/lib/install.js +9 -22
- package/package.json +1 -1
package/npm/lib/install.js
CHANGED
|
@@ -25,9 +25,7 @@ function getPlatform() {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async function getLatestVersion(prerelease = false) {
|
|
28
|
-
const url =
|
|
29
|
-
? `https://api.github.com/repos/${REPO}/releases`
|
|
30
|
-
: `https://api.github.com/repos/${REPO}/releases/latest`;
|
|
28
|
+
const url = `https://api.github.com/repos/${REPO}/releases`;
|
|
31
29
|
|
|
32
30
|
return new Promise((resolve, reject) => {
|
|
33
31
|
https.get(url, { headers: { 'User-Agent': 'Mandor-CLI' } }, (res) => {
|
|
@@ -36,14 +34,9 @@ async function getLatestVersion(prerelease = false) {
|
|
|
36
34
|
res.on('end', () => {
|
|
37
35
|
try {
|
|
38
36
|
const parsed = JSON.parse(data);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} else if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].tag_name) {
|
|
43
|
-
tagName = parsed[0].tag_name;
|
|
44
|
-
}
|
|
45
|
-
if (tagName) {
|
|
46
|
-
resolve(tagName.replace(/^v/, ''));
|
|
37
|
+
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
38
|
+
const release = parsed[0];
|
|
39
|
+
resolve(release.tag_name.replace(/^v/, ''));
|
|
47
40
|
} else {
|
|
48
41
|
reject(new Error('No release found'));
|
|
49
42
|
}
|
|
@@ -73,10 +66,8 @@ function downloadFile(url, dest) {
|
|
|
73
66
|
});
|
|
74
67
|
}
|
|
75
68
|
|
|
76
|
-
async function install(
|
|
69
|
+
async function install() {
|
|
77
70
|
const { platform, arch } = getPlatform();
|
|
78
|
-
const version = options.version || 'latest';
|
|
79
|
-
const prerelease = options.prerelease || false;
|
|
80
71
|
const osArch = `${platform}-${arch}`;
|
|
81
72
|
const binaryName = platform === 'win32' ? 'mandor.exe' : 'mandor';
|
|
82
73
|
|
|
@@ -84,13 +75,9 @@ async function install(options = {}) {
|
|
|
84
75
|
console.log('================');
|
|
85
76
|
console.log(`OS: ${osArch}`);
|
|
86
77
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
installVersion = await getLatestVersion(prerelease);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
console.log(`Version: ${installVersion}`);
|
|
78
|
+
console.log('Fetching latest release...');
|
|
79
|
+
const version = await getLatestVersion();
|
|
80
|
+
console.log(`Version: ${version}`);
|
|
94
81
|
console.log('');
|
|
95
82
|
|
|
96
83
|
const binaryPath = path.join(INSTALL_DIR, binaryName);
|
|
@@ -101,7 +88,7 @@ async function install(options = {}) {
|
|
|
101
88
|
}
|
|
102
89
|
|
|
103
90
|
console.log('Downloading from GitHub releases...');
|
|
104
|
-
const downloadUrl = `https://github.com/${REPO}/releases/download/v${
|
|
91
|
+
const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${osArch}.tar.gz`;
|
|
105
92
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mandor-'));
|
|
106
93
|
const tarball = path.join(tempDir, `${osArch}.tar.gz`);
|
|
107
94
|
|