Skip to content

Commit a70b698

Browse files
author
Íñigo Marquínez
authored
Merge pull request #39 from guidesmiths/fix-38-object
Fix built manifest when extra parameters is a nested object
2 parents 80becbb + 8600e39 commit a70b698

File tree

7 files changed

+1792
-4327
lines changed

7 files changed

+1792
-4327
lines changed

.github/workflows/cd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
publish-npm:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- uses: actions/setup-node@v2
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 14.x
14+
node-version: 18
1515
registry-url: 'https://registry.npmjs.org'
1616
- run: npm ci
1717
- name: Publish

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [10.x, 12.x, 13.x, 14.x]
14+
node-version: [14.x, 16.x, 18.x]
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717
- name: Set up Node.js version ${{ matrix.node-version }}
18-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v3
1919
with:
2020
node-version: ${{ matrix.node-version }}
2121
cache: 'npm'
22-
2322
- run: npm install
2423
- run: npm run lint

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run lint

bin/make-manifest

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#!/usr/bin/env node
22

3-
var program = require('commander')
4-
var makeManifest = require('../')
3+
const program = require('commander');
4+
const _set = require('lodash.set');
5+
const path = require('path')
6+
7+
const makeManifest = require('../');
8+
const pkg = require(path.join(process.cwd(), 'package.json'))
59

610
const collect = (value, memo) => {
7-
const values = value.split(/\s*:\s*/)
8-
memo[values[0]] = values.splice(1).join(':')
9-
return memo;
11+
const values = value.split(/\s*:\s*/);
12+
return _set(memo, values[0], values[1]);
1013
}
1114

1215
program
13-
.version('0.0.1')
14-
.option('-x --extra [string]', 'colon separated key value pair', collect, {})
16+
.version(pkg.version, '-v, --version', 'output the current version')
17+
.option('-x, --extra [string]', 'colon separated key value pair', collect, {})
1518
.parse(process.argv);
1619

17-
const extraArguments = { ...program.extra };
20+
program.parse();
21+
const options = program.opts();
1822

19-
makeManifest(extraArguments)
23+
makeManifest(options.extra);

index.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const pkg = require(path.join(process.cwd(), 'package.json'))
1+
const fs = require('fs');
2+
const path = require('path');
43
const gitCommit = require('git-rev-sync');
54
const gitRemote = require('remote-origin-url');
65

6+
const pkg = require(path.join(process.cwd(), 'package.json'));
7+
78
module.exports = extra => {
8-
const { name, version } = pkg;
9-
let scm = {};
9+
const { name, version } = pkg;
10+
let scm = {};
1011

11-
// Without commits, .git/packed-refs does not exists
12-
if( fs.existsSync(path.join(process.cwd(), '.git', 'packed-refs'))){
13-
scm = {
14-
remote: gitRemote.sync(),
15-
branch: gitCommit.branch(),
16-
commit: gitCommit.long()
17-
}
12+
// Without commits, .git/packed-refs does not exists
13+
if (fs.existsSync(path.join(process.cwd(), '.git', 'packed-refs'))) {
14+
scm = {
15+
remote: gitRemote.sync(),
16+
branch: gitCommit.branch(),
17+
commit: gitCommit.long()
1818
}
19+
}
20+
21+
const timestamp = new Date().toISOString();
22+
const manifest = { name, version, scm, timestamp, ...extra };
1923

20-
const timestamp = new Date().toISOString();
21-
const manifest = { name, version, scm, timestamp, ...extra };
22-
fs.writeFileSync('manifest.json', `${JSON.stringify(manifest, null, 2)}\n`, 'utf-8')
24+
fs.writeFileSync('manifest.json', `${JSON.stringify(manifest, null, 2)}\n`, 'utf-8');
2325
}

0 commit comments

Comments
 (0)