@openbuff/cli 0.1.0 → 1.1.1
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/index.js +49 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8,7 +8,6 @@ const os = require('os')
|
|
|
8
8
|
const path = require('path')
|
|
9
9
|
const zlib = require('zlib')
|
|
10
10
|
|
|
11
|
-
const tar = require('tar')
|
|
12
11
|
const { createReleaseHttpClient } = require('./http')
|
|
13
12
|
|
|
14
13
|
// npm package name — used for registry version checks (auto-update).
|
|
@@ -182,6 +181,45 @@ async function getLatestVersion() {
|
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
|
|
184
|
+
function getLocalPackageVersion() {
|
|
185
|
+
const packageJsonPaths = [
|
|
186
|
+
path.join(__dirname, '..', 'package.json'),
|
|
187
|
+
path.join(__dirname, 'package.json'),
|
|
188
|
+
]
|
|
189
|
+
|
|
190
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
191
|
+
try {
|
|
192
|
+
if (!fs.existsSync(packageJsonPath)) continue
|
|
193
|
+
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
|
194
|
+
if (packageData.version) return packageData.version
|
|
195
|
+
} catch (error) {
|
|
196
|
+
// Try the next local source.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return null
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function getMetadataVersion() {
|
|
204
|
+
try {
|
|
205
|
+
if (!fs.existsSync(CONFIG.metadataPath)) {
|
|
206
|
+
return null
|
|
207
|
+
}
|
|
208
|
+
const metadata = JSON.parse(fs.readFileSync(CONFIG.metadataPath, 'utf8'))
|
|
209
|
+
return metadata.version || null
|
|
210
|
+
} catch (error) {
|
|
211
|
+
return null
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getWrapperVersion() {
|
|
216
|
+
return getLocalPackageVersion() || getMetadataVersion() || getCurrentVersion() || 'dev'
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function isVersionFlag(args) {
|
|
220
|
+
return args.length === 1 && (args[0] === '--version' || args[0] === '-v')
|
|
221
|
+
}
|
|
222
|
+
|
|
185
223
|
function streamToString(stream) {
|
|
186
224
|
return new Promise((resolve, reject) => {
|
|
187
225
|
let data = ''
|
|
@@ -347,6 +385,8 @@ async function downloadBinary(version) {
|
|
|
347
385
|
})
|
|
348
386
|
|
|
349
387
|
// Extract to temp directory
|
|
388
|
+
const tar = require('tar')
|
|
389
|
+
|
|
350
390
|
await new Promise((resolve, reject) => {
|
|
351
391
|
res
|
|
352
392
|
.pipe(zlib.createGunzip())
|
|
@@ -573,9 +613,16 @@ function printCrashDiagnostics(code, signal) {
|
|
|
573
613
|
}
|
|
574
614
|
|
|
575
615
|
async function main() {
|
|
616
|
+
const args = process.argv.slice(2)
|
|
617
|
+
|
|
618
|
+
if (isVersionFlag(args)) {
|
|
619
|
+
console.log(getWrapperVersion())
|
|
620
|
+
return
|
|
621
|
+
}
|
|
622
|
+
|
|
576
623
|
await ensureBinaryExists()
|
|
577
624
|
|
|
578
|
-
const child = spawn(CONFIG.binaryPath,
|
|
625
|
+
const child = spawn(CONFIG.binaryPath, args, {
|
|
579
626
|
stdio: 'inherit',
|
|
580
627
|
})
|
|
581
628
|
|