amorphous-cli 0.3.0 → 0.3.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.mjs +9 -2
- package/lib/help.mjs +1 -0
- package/lib/version.mjs +4 -0
- package/lib/version.test.mjs +21 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3,14 +3,21 @@ import { loadDotEnv } from './lib/config.mjs'
|
|
|
3
3
|
import { runCommand } from './lib/commands.mjs'
|
|
4
4
|
import { ensureLocalHttpsTrust } from './lib/tls.mjs'
|
|
5
5
|
import { startUpdateCheck } from './lib/update-check.mjs'
|
|
6
|
+
import { CLI_VERSION, isVersionRequest } from './lib/version.mjs'
|
|
7
|
+
|
|
8
|
+
const argv = process.argv.slice(2)
|
|
9
|
+
if (isVersionRequest(argv)) {
|
|
10
|
+
console.log(CLI_VERSION)
|
|
11
|
+
process.exit(0)
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
ensureLocalHttpsTrust()
|
|
8
15
|
loadDotEnv()
|
|
9
16
|
|
|
10
|
-
const update = startUpdateCheck({ argv
|
|
17
|
+
const update = startUpdateCheck({ argv })
|
|
11
18
|
|
|
12
19
|
try {
|
|
13
|
-
await runCommand(
|
|
20
|
+
await runCommand(argv)
|
|
14
21
|
await update.finish()
|
|
15
22
|
} catch (e) {
|
|
16
23
|
console.error(e instanceof Error ? e.message : e)
|
package/lib/help.mjs
CHANGED
package/lib/version.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
2
|
|
|
3
3
|
export const CLI_VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version
|
|
4
|
+
|
|
5
|
+
export function isVersionRequest(argv) {
|
|
6
|
+
return argv.length === 1 && (argv[0] === '--version' || argv[0] === '-v')
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import test from 'node:test'
|
|
5
|
+
import { isVersionRequest } from './version.mjs'
|
|
6
|
+
|
|
7
|
+
test('version is a standalone global CLI option', () => {
|
|
8
|
+
assert.equal(isVersionRequest(['--version']), true)
|
|
9
|
+
assert.equal(isVersionRequest(['-v']), true)
|
|
10
|
+
assert.equal(isVersionRequest(['list', '--version']), false)
|
|
11
|
+
assert.equal(isVersionRequest([]), false)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('CLI prints its package version without running a command', () => {
|
|
15
|
+
const entry = fileURLToPath(new URL('../index.mjs', import.meta.url))
|
|
16
|
+
const output = execFileSync(process.execPath, [entry, '--version'], {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
env: { ...process.env, AMORPHOUS_NO_UPDATE_CHECK: '1' },
|
|
19
|
+
})
|
|
20
|
+
assert.equal(output.trim(), '0.3.1')
|
|
21
|
+
})
|