Skip to content

Commit 867b4c9

Browse files
authored
Merge pull request #2 from razor-x/args
Add basic arg support
2 parents 3f31905 + 5618efd commit 867b4c9

File tree

5 files changed

+81
-4
lines changed

5 files changed

+81
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](https://semver.org/).
77

8+
## 1.1.0 / 2021-09-09
9+
10+
### Added
11+
12+
- Option arguments to `blobpack` CLI.
13+
814
## 1.0.0 / 2021-09-09
915

1016
- Initial release.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,37 @@ you can use the `include` property,
157157
}
158158
```
159159

160+
### CLI
161+
162+
The `blobpack` command supports passing options:
163+
164+
```
165+
$ blobpack --version
166+
$ blobpack version
167+
```
168+
169+
```
170+
$ blobpack install \
171+
--config-path ./package.json \
172+
--tmp-root ./tmp
173+
```
174+
175+
```
176+
$ blobpack \
177+
--config-path ./package.json \
178+
--tmp-root ./tmp \
179+
--config-root ./config \
180+
--resources-root ./resources \
181+
--dist-root ./dist
182+
183+
$ blobpack build \
184+
--config-path ./package.json \
185+
--tmp-root ./tmp \
186+
--config-root ./config \
187+
--resources-root ./resources \
188+
--dist-root ./dist
189+
```
190+
160191
## Development and Testing
161192
162193
### Quickstart

bin/blobpack.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
#!/usr/bin/env node
22

3-
import { build, install } from '../index.js'
3+
import path from 'path'
4+
import { fileURLToPath } from 'url'
45

5-
const cmd = process.argv[2]
6+
import arg from 'arg'
67

7-
if (cmd === 'install') await install()
8-
if (cmd === 'build' || cmd == null) await build()
8+
import { build, install, loadJson } from '../index.js'
9+
10+
const args = arg({
11+
'--version': Boolean,
12+
'--config-path': String,
13+
'--tmp-root': String,
14+
'--config-root': String,
15+
'--resources-root': String,
16+
'--dist-root': String
17+
})
18+
19+
if (args['--version'] || args._[0] === 'version') {
20+
const dir = path.dirname(fileURLToPath(import.meta.url))
21+
const pkg = await loadJson(path.join(dir, '..', 'package.json'))
22+
// eslint-disable-next-line no-console
23+
console.log(pkg.version)
24+
process.exit(0)
25+
}
26+
27+
if (args._[0] === 'install') {
28+
await install({
29+
configPath: args['--config-path'],
30+
tmpRoot: args['--tmp-root']
31+
})
32+
}
33+
34+
if (args._[0] === 'build' || args._[0] == null) {
35+
await build({
36+
configPath: args['--config-path'],
37+
tmpRoot: args['--tmp-root'],
38+
configRoot: args['--config-root'],
39+
resourcesRoot: args['--resources-root'],
40+
distRoot: args['--dist-root']
41+
})
42+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"node": ">=14.15.0"
5656
},
5757
"dependencies": {
58+
"arg": "^5.0.1",
5859
"download": "^8.0.0",
5960
"js-yaml": "^4.1.0",
6061
"jszip": "^3.7.1",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ archy@^1.0.0:
795795
resolved "https://registry.yarnpkg.com/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40"
796796
integrity sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=
797797

798+
arg@^5.0.1:
799+
version "5.0.1"
800+
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.1.tgz#eb0c9a8f77786cad2af8ff2b862899842d7b6adb"
801+
integrity sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==
802+
798803
argparse@^1.0.7:
799804
version "1.0.10"
800805
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"

0 commit comments

Comments
 (0)