Skip to content

Commit

Permalink
fix(utils): use the reducer to build objects from entries (#79)
Browse files Browse the repository at this point in the history
closes #78
  • Loading branch information
derevnjuk committed Aug 28, 2020
1 parent f187ca8 commit 668af26
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@ on:
- 'v*'

jobs:
prepare:
if: github.event.base_ref == 'refs/heads/development'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.value }}
project: ${{ steps.project.outputs.value }}
steps:
- id: version
run: echo ::set-output name=value::${GITHUB_REF/refs\/tags\//}
- id: project
run: echo ::set-output name=value::$(echo ${GITHUB_REPOSITORY#*/} | tr A-Z a-z)

build:
runs-on: ubuntu-latest
env:
PROJECT_VERSION: ${{ needs.prepare.outputs.version }}
PROJECT: ${{ needs.prepare.outputs.project }}
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -18,10 +33,9 @@ jobs:
node-version: 12
registry-url: 'https://registry.npmjs.org'

- run: echo :set-env name=VERSION::${GITHUB_REF/refs\/tags\//}
- run: npm ci -q
- run: npm run build
- run: npm version --no-git-tag-version "$VERSION"
- run: npm version --no-git-tag-version "$PROJECT_VERSION"
- run: npm run pack:win

- uses: actions/upload-artifact@v2
Expand All @@ -39,6 +53,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
needs: build
env:
PROJECT_VERSION: ${{ needs.prepare.outputs.version }}
PROJECT: ${{ needs.prepare.outputs.project }}
steps:
- uses: actions/download-artifact@v2
with:
Expand All @@ -63,8 +80,7 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.GPR_TOKEN }}

- run: echo :set-env name=VERSION::${GITHUB_REF/refs\/tags\//}
- run: docker build . --file Dockerfile --build-arg VERSION=$VERSION -t "neuralegion/repeater:$VERSION" -t "neuralegion/repeater:latest"
- run: docker build . --file Dockerfile --build-arg VERSION=$PROJECT_VERSION -t neuralegion/repeater:$PROJECT_VERSION -t neuralegion/repeater:latest
- run: docker login --username=${{ secrets.DOCKER_USER }} --password=${{ secrets.DOCKER_TOKEN }}
- run: docker push neuralegion/repeater

Expand Down
13 changes: 1 addition & 12 deletions .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,7 @@
"releasedLabels": false,
"failTitle": false,
"failComment": false,
"successComment": false,
"assets": [
{
"path": "bin/win64/nexploit-cli.exe",
"label": "nexploit-cli-windows-x64.exe"
},
{ "path": "bin/mac/nexploit-cli", "label": "nexploit-cli-mac-x64" },
{
"path": "bin/linux/nexploit-cli",
"label": "nexploit-cli-linux-x64"
}
]
"successComment": false
}
]
],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
"test": "mocha -r ts-node/register -r tsconfig-paths/register src/**/*.spec.ts",
"build": "webpack --config webpack.config.js --mode=production",
"semantic-release": "semantic-release",
"prepublishOnly": "npm run build",
"pack:win": "nexe -o bin/win/nexploit-cli.exe -t windows-x64-10.16.0 --rc {CompanyName: 'NeuraLegion', ProductName: 'NexPloit CLI', OriginalFilename: 'nexploit-cli.exe'} dist/index.js",
"pack:mac": "nexe -o bin/mac/nexploit-cli -t mac-x64-10.19.0 dist/index.js ",
"pack:linux": "nexe -o bin/linux/nexploit-cli -t linux-x64-10.20.1 dist/index.js"
Expand Down
8 changes: 5 additions & 3 deletions src/Utils/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export class Helpers {
public static parseHeaders(headers: string[] = []): Record<string, string> {
ok(Array.isArray(headers), 'First argument must be an instance of Array.');

return Object.fromEntries(
headers.map((value: string) => this.parseHeader(value))
);
return headers.reduce((acc: Record<string, string>, value: string) => {
const [key, header]: [string, string] = this.parseHeader(value);

return { ...acc, [key]: header };
}, {});
}

private static parseHeader(header: string): [string, string] | undefined {
Expand Down

0 comments on commit 668af26

Please sign in to comment.