veyron/examples: Moving running of services inside its own script for
FortuneJs and PipeToBrowser as well.
also moving the trap to the top of the file so if Ctrl-C happens in the middle
of the script, we still kill anything spawned so far
Change-Id: Ieb991cf327e1fceff1aacb95aa0adb875deac1d9
diff --git a/examples/pipetobrowser/Makefile b/examples/pipetobrowser/Makefile
index 1abc787..e80138b 100644
--- a/examples/pipetobrowser/Makefile
+++ b/examples/pipetobrowser/Makefile
@@ -1,14 +1,8 @@
PATH:=$(VEYRON_ROOT)/environment/cout/node/bin:$(PATH)
-PATH:=$(VEYRON_ROOT)/veyron/go/bin:$(PATH)
PATH:=node_modules/.bin:../node_modules/.bin:$(PATH)
-VEYRON_PROXY_ADDR=proxy.envyor.com:8100
-VEYRON_WSPR_PORT=7776
-HTTP_PORT=8080
-NAMESPACE_ROOT=/proxy.envyor.com:8101
VEYRON_JS_API=$(VEYRON_ROOT)/veyron/javascript/api
VEYRON_BUILD_SCRIPT=$(VEYRON_ROOT)/veyron/scripts/build/go
-VEYRON_IDENTITY_PATH=/tmp/p2b_identity
# All JS files except build.js and third party
JS_FILES = $(shell find browser -name "*.js" -a -not -name "build.js" -a -not -path "*third-party*")
@@ -39,7 +33,6 @@
# Install JSPM and Bower packages as listed in browser/package.json from JSPM and browser/bower.json from bower
browser/third-party: browser/package.json browser/bower.json
cd browser; \
- jspm prune; \
jspm install -h; \
bower prune; \
bower install
@@ -59,16 +52,7 @@
# Serve
start:
- identity generate veyron_p2b_identity > $(VEYRON_IDENTITY_PATH)
- export VEYRON_IDENTITY=$(VEYRON_IDENTITY_PATH) ; \
- export NAMESPACE_ROOT=$(NAMESPACE_ROOT); \
- wsprd --v=1 -alsologtostderr=true -vproxy=$(VEYRON_PROXY_ADDR) --port $(VEYRON_WSPR_PORT) & \
- serve browser/. --port $(HTTP_PORT) --compress &
-
-# Stop serving
-stop:
- pkill wsprd || true
- lsof -i:$(HTTP_PORT) | grep node | awk '{printf "%s\n",$$2}' | xargs --no-run-if-empty kill
+ ./services.sh
# Continuously watch for changes to .js, .html or .css files.
# Rebundle the appropriate file (build.js and/or index.html) when local files change
@@ -76,10 +60,10 @@
watch -n 1 make
# Clean all build artifacts
-clean: stop
+clean:
rm -rf browser/third-party
rm -rf node_modules
rm -f browser/index.html
rm -f browser/build.js
-.PHONY: start stop clean watch
+.PHONY: start clean watch
diff --git a/examples/pipetobrowser/README.md b/examples/pipetobrowser/README.md
index 8a38312..d8a9148 100644
--- a/examples/pipetobrowser/README.md
+++ b/examples/pipetobrowser/README.md
@@ -1,5 +1,3 @@
-**TODO(aghassemi) Finish and clean up documentation, ensure it aligns with Design Doc on Google Drive.**
-
# Pipe to Browser
P2B allows one to pipe anything from shell console to the browser. Data being piped to the browser then is displayed in a graphical and formatted way by a "viewer" Viewers are pluggable pieces of code that know how to handle and display a stream of data.
@@ -17,6 +15,8 @@
where **google/p2b/jane** is the Object name where p2b service is running in the browser. The suffix **console** or **image** specifies what viewer should be used to display the data.
+Please see the help page inside the P2B application for detailed tutorials.
+
## Building and Running
To build
``
@@ -28,63 +28,9 @@
``
and then navigate to http://localhost:8080
-To stop
-``
-make stop
-``
+To stop simply Ctrl-C the console that started it
To clean
``
make clean
-``
-
-## Built-in Viewers
-TODO
-
-## How to Write Custom Viewer Plugins
-TODO
-
-## Concepts and Technical Design
-### UI Framework
-#### View
-a View consists of:
-A framework-specific wrapper that exposes the public API (ie. exposed properties and events ) of the View as a JavaScript module. This is what the application uses to interact with the view.
-A Web Component that encapsulates all of the view including rendering, event binding, life-cycle management, attributes binding, etc… The Web Component exposes functionality of the view through properties and events as a DOM object.
-
-Application never interacts with the Web Component part of the view directly. It only uses View’s wrapper API.
-
-**Rationale:**
-Web Component provides the functionality that traditional view frameworks ( e.g. Backbone , AngularJS views ) had to provide. Since a Web Component is a DOM element, it by default provides support for events and attributes. Web Component specification adds life-cycle management ( e.g. knowing when view is rendered, created or removed ), templating, data-binding and encapsulation in a single element. Bringing functionality on par with View frameworks out there.
-
-The wrapper JS object around the Web Component adds a layer of indirection which exposes the public API in a cleaner way, and also hides the DOM object, which should be considered implementation details, from the rest of the application. This would allow us to switch the implementation of the View without changing the application.
-
-#### Actions
-Actions are cohesive pieces of functionality that can be triggered from any other action in a decoupled way by just using the action name. Actions glue views and application services and state.
-
-Action names are a similar concepts to routes and simply provide an indirection through string names to register and call functions. Action handlers, which are functions tied to an action name, are a similar concept to controllers. Using actions to group and call larger, self-contained functionality like page transitions allows the framework to provide undo/back support by using history API or localStorage.
-
-### Pipe To Browser
-
-#### Pipe-Viewer
-When a user sends a pipe request to p2b, the suffix of the Object name indicates what **viewer** should be used to display the data. For instance:
-
-``
-ls -l | p2b google/p2b/aghassemi/DataTable
-``
-
-indicates the DataTable viewer should be used to display the data whereas:
-
-``
-ls -l | p2b google/p2b/aghassemi/List
-``
-
-requests List viewer to be used.
-
-A pipe-viewer is an interface defined by p2b as an abstract class. Any viewer that wants to plugin to the system has to inherit from that class. pipe-viewer contract demands that any implementation to have a unique name which is used to find the viewer plugin and a play function that will be called and supplied by a stream object.
-play(stream)needs to return a View or promise of a View that will be appended to the UI by the p2b framework. If a promise, p2b UI will display a loading widget until promise is resolved.
-
-pipe-viewer manager is responsible for finding and loading pipe-viewers on demand based on their name. This on-demand loading allows us to support arbitrary viewers even from external sources. For instance we should be able to support: (not implemented yet)
-
-``
-ls -l | p2b google/p2b/aghassemi/external/HypnoDataTable --viewer-source=http://www.p2bMarketPlace.com/plugins/HypnoDataTable.js
``
\ No newline at end of file
diff --git a/examples/pipetobrowser/services.sh b/examples/pipetobrowser/services.sh
new file mode 100755
index 0000000..3987577
--- /dev/null
+++ b/examples/pipetobrowser/services.sh
@@ -0,0 +1,19 @@
+export PATH=$VEYRON_ROOT/veyron/go/bin:$PATH
+export PATH=node_modules/.bin:$PATH
+
+VEYRON_PROXY_ADDR=proxy.envyor.com:8100
+VEYRON_WSPR_PORT=7776
+HTTP_PORT=8080
+NAMESPACE_ROOT=/proxy.envyor.com:8101
+VEYRON_IDENTITY_PATH=/tmp/p2b_identity
+
+trap 'kill -TERM 0' SIGINT SIGTERM EXIT
+
+identity generate veyron_p2b_identity > "${VEYRON_IDENTITY_PATH}"
+
+export VEYRON_IDENTITY=$VEYRON_IDENTITY_PATH; \
+export NAMESPACE_ROOT=$NAMESPACE_ROOT; \
+wsprd --v=1 -alsologtostderr=true -vproxy=$VEYRON_PROXY_ADDR --port $VEYRON_WSPR_PORT & \
+serve browser/. --port $HTTP_PORT --compress
+
+wait
\ No newline at end of file