Skip to content

Commit 400061b

Browse files
committed
feat: use options object to pass json
BREAKING CHANGE change from ordered arguments to `getInstallJson` to a single options object ```js const json = { packages: 'debug', env: { foo: 42 }, platform: 'linux' } getInstallJson(json) ```
1 parent aed7414 commit 400061b

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ The install will happen on all platforms
4343
```json
4444
{
4545
"platform": "*",
46+
"architecture": "x64",
4647
"packages": "debug,chalk"
4748
}
4849
```
4950
5051
Happy installation
5152
```
5253

53-
**note** `platform` can be `*` or specific one like `darwin` (from Node `os.platform()`) or a
54-
list of several platforms like `darwin,linux`
54+
**note** `platform` can be `*` or specific one like `darwin` (from Node `os.platform()`) or a list of several platforms like `darwin,linux`. `architecture` is usually 64 bit `x64` as returned by `os.arch()`.
5555

5656
### Specific commit
5757

src/commit-message-install-spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ describe('commit-message-install', () => {
7070
repo: 'bar',
7171
sha: '2d8687c143165218c6b52a76018b76cf99137e48'
7272
}
73-
const info = getInstallJson(['debug', 'chalk'], {}, 'linux', null, null, status)
73+
const options = {
74+
packages: ['debug', 'chalk'],
75+
env: {},
76+
platform: 'linux',
77+
status
78+
}
79+
const info = getInstallJson(options)
7480
const json = toMarkdownJsonBlock(info)
7581
const message = `some text\n\n` + json
7682

src/get-install-json-spec.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,47 @@ describe('getInstallJson', () => {
1313
})
1414

1515
it('sets properties and all platforms', () => {
16-
snapshot(getInstallJson('debug', { foo: 42 }, '*'))
16+
const json = { packages: 'debug', env: { foo: 42 }, platform: '*' }
17+
snapshot(getInstallJson(json))
1718
})
1819

1920
it('sets given platform', () => {
20-
snapshot(getInstallJson('debug', { foo: 42 }, 'linux'))
21+
const json = {
22+
packages: 'debug',
23+
env: { foo: 42 },
24+
platform: 'linux'
25+
}
26+
snapshot(getInstallJson(json))
2127
})
2228

2329
it('sets several modules', () => {
24-
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux'))
30+
const json = {
31+
packages: ['debug', 'chalk'],
32+
env: {},
33+
platform: 'linux'
34+
}
35+
snapshot(getInstallJson(json))
2536
})
2637

2738
it('sets branch', () => {
28-
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux', 'test-branch'))
39+
const json = {
40+
packages: ['debug', 'chalk'],
41+
env: {},
42+
platform: 'linux',
43+
branch: 'test-branch'
44+
}
45+
snapshot(getInstallJson(json))
2946
})
3047

3148
it('sets commit', () => {
32-
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux', null, 'b7ccfd8'))
49+
const json = {
50+
packages: ['debug', 'chalk'],
51+
env: {},
52+
platform: 'linux',
53+
branch: null,
54+
commit: 'b7ccfd8'
55+
}
56+
snapshot(getInstallJson(json))
3357
})
3458

3559
it('sets status object', () => {
@@ -38,6 +62,12 @@ describe('getInstallJson', () => {
3862
repo: 'bar',
3963
sha: '2d8687c143165218c6b52a76018b76cf99137e48'
4064
}
41-
snapshot(getInstallJson(['debug', 'chalk'], {}, 'linux', null, null, status))
65+
const json = {
66+
packages: ['debug', 'chalk'],
67+
env: {},
68+
platform: 'linux',
69+
status
70+
}
71+
snapshot(getInstallJson(json))
4272
})
4373
})

src/get-install-json.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ const isStatus = is.schema({
1111
})
1212

1313
// forms JSON object that can be parsed later
14-
function getInstallJson (packages, env, platform, branch, commit, status) {
14+
function getInstallJson ({
15+
packages,
16+
env,
17+
platform,
18+
arch,
19+
branch,
20+
commit,
21+
status
22+
}) {
1523
if (!env) {
1624
env = {}
1725
}
1826
if (!platform) {
1927
platform = os.platform()
2028
}
29+
if (!arch) {
30+
arch = os.arch()
31+
}
32+
2133
la(
2234
is.unemptyString(packages) || is.strings(packages),
2335
'invalid package / list of packages',

0 commit comments

Comments
 (0)