Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read JSON and assign to a list of make variables

I can get a value from package.json with this:

LAST_VERSION := $(shell node -p "require('./package.json').version")

But what if I need several values? Like:

PROJECT     := $(shell node -p "require('./package.json').name")
LAST_VERSION:= $(shell node -p "require('./package.json').version")
DESCRIPTION := $(shell node -p "require('./package.json').description")
PROJECT_URL := $(shell node -p "require('./package.json').repository.url")

Is this the only way? Maybe there is a way to create kind of a list.

like image 383
Jonatas Walker Avatar asked Apr 16 '16 12:04

Jonatas Walker


1 Answers

At the end, I came up with this:

define GetFromPkg
$(shell node -p "require('./package.json').$(1)")
endef

PROJECT      := $(call GetFromPkg,name)
LAST_VERSION := $(call GetFromPkg,version)
DESCRIPTION  := $(call GetFromPkg,description)
PROJECT_URL  := $(call GetFromPkg,repository.url)
like image 93
Jonatas Walker Avatar answered Oct 31 '22 10:10

Jonatas Walker