Skip to content

Commit 66ab2ac

Browse files
committed
Support blobpack or benthos config key
1 parent 8292c1b commit 66ab2ac

File tree

10 files changed

+36
-43
lines changed

10 files changed

+36
-43
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ add this to your `package.json`,
6868
"scripts": {
6969
"postinstall": "blobpack install"
7070
},
71-
"benthos": {
71+
"blobpack": {
7272
"name": "benthos-lambda",
7373
"version": "3.54.1",
7474
"platform": "linux_amd64",
@@ -104,7 +104,7 @@ boring:
104104
include: []
105105
```
106106
107-
First, add the `artifacts` section to the `benthos` config.
107+
First, add the `artifacts` section to the `blobpack` config.
108108
This will generate a new artifact to `dist/boring.zip` which uses
109109
`config/boring.yaml` and intelligently merges resources in both
110110
`resources/outputs.yaml` and `node_modules/@my-org/blobd/resources/logger.yaml`.
@@ -114,7 +114,7 @@ If two files have the same key, the last one wins._
114114

115115
```json
116116
{
117-
"benthos": {
117+
"blobpack": {
118118
"artifacts": [
119119
{
120120
"name": "boring",
@@ -133,7 +133,7 @@ you can use this shorthand,
133133

134134
```json
135135
{
136-
"benthos": {
136+
"blobpack": {
137137
"artifacts": [
138138
"boring"
139139
]
@@ -146,7 +146,7 @@ you can use the `include` property,
146146

147147
```json
148148
{
149-
"benthos": {
149+
"blobpack": {
150150
"include": {
151151
"resources": ["logger"]
152152
},

fixtures/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"benthos": {
2+
"blobpack": {
33
"name": "benthos-lambda",
44
"version": "3.54.1",
55
"platform": "linux_amd64",

lib/build.doc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Build Benthos artifacts for AWS Lambda.
33
* @function build
44
* @param {Object} parameters
5-
* @param {string} [parameters.configPath=package.json] Path to JSON file with a benthos config key.
5+
* @param {string} [parameters.configPath=package.json] Path to JSON file with a blobpack config key.
66
* @param {string} [parameters.tmpRoot=s3] Temporary directory to download artifacts.
77
* @param {string} [parameters.configRoot=config] Path where configs are located.
88
* @param {string} [parameters.resourcesRoot=resources] Path where resources are located.

lib/build.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mkdirp from 'mkdirp'
55
import jsYaml from 'js-yaml'
66
import jszip from 'jszip'
77

8-
import { loadJson } from './load-json.js'
8+
import { loadConfig } from './config.js'
99
import { zipName } from './zip-name.js'
1010
import { mergeArrayProps, mergeConfig } from './merge.js'
1111

@@ -23,13 +23,9 @@ export const build = async ({
2323
logger = console
2424
} = {}) => {
2525
try {
26-
const { benthos } = await loadJson(configPath)
26+
const config = await loadConfig(configPath)
2727

28-
if (!benthos) {
29-
throw new Error(`Cannot find key benthos in config at ${configPath}`)
30-
}
31-
32-
const artifacts = await createArtifacts(benthos, {
28+
const artifacts = await createArtifacts(config, {
3329
tmpRoot,
3430
configRoot,
3531
resourcesRoot,

lib/config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import fs from 'fs'
2+
3+
export const loadConfig = async (configPath) => {
4+
const { benthos, blobpack } = await loadJson(configPath)
5+
const config = blobpack ?? benthos
6+
7+
if (!config) {
8+
throw new Error(
9+
`Cannot find key blobpack or benthos in config at ${configPath}`
10+
)
11+
}
12+
13+
return config
14+
}
15+
16+
const loadJson = async (name) => {
17+
const data = await fs.promises.readFile(name)
18+
return JSON.parse(data)
19+
}

lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './build.js'
22
export * from './install.js'
3-
export * from './load-json.js'

lib/install.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import download from 'download'
66
import mkdirp from 'mkdirp'
77

88
import { zipName } from './zip-name.js'
9-
import { loadJson } from './load-json.js'
9+
import { loadConfig } from './config.js'
1010

1111
export const install = async ({
1212
configPath = 'package.json',
1313
tmpRoot = 'tmp',
1414
logger = console
1515
} = {}) => {
1616
try {
17-
const { benthos } = await loadJson(configPath)
18-
19-
if (!benthos) {
20-
throw new Error(`Cannot find key 'benthos' in config at ${configPath}`)
21-
}
22-
23-
const { data, name } = await pull(benthos)
17+
const config = await loadConfig(configPath)
18+
const { data, name } = await pull(config)
2419
await write(tmpRoot, name, data)
2520
const outputPath = path.resolve(tmpRoot, name)
2621
logger.log(`Verified ${outputPath}`)

lib/load-json.doc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/build.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import path from 'path'
44
import test from 'ava'
55

66
import { zipName } from '../lib/zip-name.js'
7-
import { build, install, loadJson } from '../index.js'
7+
import { loadConfig } from '../lib/config.js'
8+
import { build, install } from '../index.js'
89

910
const tmpRoot = path.join('tmp', 'build-spec')
1011
const configPath = path.join('fixtures', 'config.json')
1112

1213
test.beforeEach(async (t) => {
13-
const { benthos } = await loadJson(configPath)
14-
const name = zipName(benthos)
14+
const config = await loadConfig(configPath)
15+
const name = zipName(config)
1516
const outputPath = path.join(tmpRoot, name)
1617
const logger = {
1718
log: (msg) => t.log(msg),

test/load-json.spec.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)