Skip to content

Commit

Permalink
[NODESDK] Do not use sudo/global in Makefile
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Sep 8, 2016
1 parent af6d3e8 commit a506a02
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 70 deletions.
67 changes: 55 additions & 12 deletions sdk/node/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,67 @@
# under the License.
#

BINDIR := node_modules/.bin
TYPINGS := $(BINDIR)/typings
TSC := $(BINDIR)/tsc
TYPEDOC := $(BINDIR)/typedoc

DOCURI := "https://github.com/hyperledger/fabric/tree/master/sdk/node/"

SRC := $(shell find src -type f)
CONFIG := $(shell ls *.json)

EXECUTABLES = npm
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))

all: hfc
# npm tool->pkg mapping
npm.pkg.typings := typings
npm.pkg.tsc := typescript
npm.pkg.typedoc := typedoc

all: lib doc

.PHONY: lib doc
lib: lib/hfc.js
doc: doc/index.html

.SECONDARY: $(TYPINGS) $(TSC) $(TYPEDOC)
$(BINDIR)/%: $(CONFIG)
@echo "[INSTALL] $@"
npm install $(npm.pkg.$(@F))
@touch $@

doc/index.html: $(TYPEDOC) $(SRC) $(CONFIG) typedoc-special.d.ts Makefile
@echo "[BUILD] SDK documentation"
@-rm -rf $(@D)
@mkdir -p $(@D)
$(TYPEDOC) -m amd \
--name 'Node.js Hyperledger Fabric SDK' \
--includeDeclarations \
--excludeExternals \
--excludeNotExported \
--out $(@D) \
src/hfc.ts typedoc-special.d.ts
# Typedoc generates links to working GIT repo which is fixed
# below to use an official release URI.
find $(@D) -name '*.html' -exec sed -i 's!href="http.*sdk/node/!href="'$(DOCURI)'!' {} \;

.PHONY: hfc
hfc:
mkdir -p ./lib/protos
cp ../../protos/*.proto ./lib/protos
cp ../../membersrvc/protos/*.proto ./lib/protos
npm ls -g | grep 'typings' || sudo npm install -g typings
npm ls -g | grep 'typescript' || sudo npm install -g typescript
npm install && typings install
tsc
./makedoc.sh
lib/hfc.js: $(TYPINGS) $(TSC) $(SRC) $(CONFIG) Makefile
@echo "[BUILD] SDK"
@mkdir -p ./lib/protos
@cp ../../protos/*.proto ./lib/protos
@cp ../../membersrvc/protos/*.proto ./lib/protos
npm install
$(TYPINGS) install
$(TSC)

unit-tests: hfc
unit-tests: lib
@echo "[RUN] unit tests..."
@./bin/run-unit-tests.sh

clean:
@echo "[CLEAN]"
-rm -rf node_modules
-rm -rf doc
-find lib | grep -v "protos/google" | grep -v "hash.js" | xargs rm
58 changes: 0 additions & 58 deletions sdk/node/makedoc.sh

This file was deleted.

0 comments on commit a506a02

Please sign in to comment.