Skip to content

Commit a506a02

Browse files
committed
[NODESDK] Do not use sudo/global in Makefile
The current SDK build relies on "npm install -g" for some of its tooling. This requires sudo in some cases, which can be problematic. This also means we are spraying binaries around a system which may not be appreciated in some environments. The global install is not strictly necessary as long as we can be intelligent about the paths of our prerequisite tooling. We therefore refactor the SDK build to use local installs with explicit path management. We also clean up the build process a bit so we add some build-avoidance in places where it is reasonable to do so. Change-Id: I802d2b3894e9b0a7cea07a1ac577fa1061634ebb Signed-off-by: Gregory Haskins <[email protected]>
1 parent af6d3e8 commit a506a02

File tree

2 files changed

+55
-70
lines changed

2 files changed

+55
-70
lines changed

sdk/node/Makefile

+55-12
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,67 @@
1616
# under the License.
1717
#
1818

19+
BINDIR := node_modules/.bin
20+
TYPINGS := $(BINDIR)/typings
21+
TSC := $(BINDIR)/tsc
22+
TYPEDOC := $(BINDIR)/typedoc
23+
24+
DOCURI := "https://github.com/hyperledger/fabric/tree/master/sdk/node/"
25+
26+
SRC := $(shell find src -type f)
27+
CONFIG := $(shell ls *.json)
28+
1929
EXECUTABLES = npm
2030
K := $(foreach exec,$(EXECUTABLES),\
2131
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))
2232

23-
all: hfc
33+
# npm tool->pkg mapping
34+
npm.pkg.typings := typings
35+
npm.pkg.tsc := typescript
36+
npm.pkg.typedoc := typedoc
37+
38+
all: lib doc
39+
40+
.PHONY: lib doc
41+
lib: lib/hfc.js
42+
doc: doc/index.html
43+
44+
.SECONDARY: $(TYPINGS) $(TSC) $(TYPEDOC)
45+
$(BINDIR)/%: $(CONFIG)
46+
@echo "[INSTALL] $@"
47+
npm install $(npm.pkg.$(@F))
48+
@touch $@
49+
50+
doc/index.html: $(TYPEDOC) $(SRC) $(CONFIG) typedoc-special.d.ts Makefile
51+
@echo "[BUILD] SDK documentation"
52+
@-rm -rf $(@D)
53+
@mkdir -p $(@D)
54+
$(TYPEDOC) -m amd \
55+
--name 'Node.js Hyperledger Fabric SDK' \
56+
--includeDeclarations \
57+
--excludeExternals \
58+
--excludeNotExported \
59+
--out $(@D) \
60+
src/hfc.ts typedoc-special.d.ts
61+
# Typedoc generates links to working GIT repo which is fixed
62+
# below to use an official release URI.
63+
find $(@D) -name '*.html' -exec sed -i 's!href="http.*sdk/node/!href="'$(DOCURI)'!' {} \;
2464

25-
.PHONY: hfc
26-
hfc:
27-
mkdir -p ./lib/protos
28-
cp ../../protos/*.proto ./lib/protos
29-
cp ../../membersrvc/protos/*.proto ./lib/protos
30-
npm ls -g | grep 'typings' || sudo npm install -g typings
31-
npm ls -g | grep 'typescript' || sudo npm install -g typescript
32-
npm install && typings install
33-
tsc
34-
./makedoc.sh
65+
lib/hfc.js: $(TYPINGS) $(TSC) $(SRC) $(CONFIG) Makefile
66+
@echo "[BUILD] SDK"
67+
@mkdir -p ./lib/protos
68+
@cp ../../protos/*.proto ./lib/protos
69+
@cp ../../membersrvc/protos/*.proto ./lib/protos
70+
npm install
71+
$(TYPINGS) install
72+
$(TSC)
3573

36-
unit-tests: hfc
74+
unit-tests: lib
75+
@echo "[RUN] unit tests..."
3776
@./bin/run-unit-tests.sh
3877

3978
clean:
79+
@echo "[CLEAN]"
80+
-rm -rf node_modules
81+
-rm -rf doc
82+
-find lib | grep -v "protos/google" | grep -v "hash.js" | xargs rm

sdk/node/makedoc.sh

-58
This file was deleted.

0 commit comments

Comments
 (0)