[pathkit] Reorganize to be more like CanvasKit

Change-Id: I64226b57161f86277e0635592c2c11442888335a
Bug: skia:8216
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/502817
Reviewed-by: Nathaniel Nifong <nifong@google.com>
diff --git a/modules/pathkit/.gitignore b/modules/pathkit/.gitignore
index 6e849a1..9f1869c 100644
--- a/modules/pathkit/.gitignore
+++ b/modules/pathkit/.gitignore
@@ -1,3 +1,4 @@
 **/bin
 node_modules/
+build/
 package-lock.json
\ No newline at end of file
diff --git a/modules/pathkit/CHANGELOG.md b/modules/pathkit/CHANGELOG.md
index 4b5ed53..715a4f9 100644
--- a/modules/pathkit/CHANGELOG.md
+++ b/modules/pathkit/CHANGELOG.md
@@ -10,6 +10,7 @@
  - Now compile with emsdk 3.1.3
  - Internal calls no longer use dynamic dispatch (skbug.com/12795)
  - WASM Memory can grow beyond initial 32MB
+ - The debug and test builds of PathKit are no longer published to NPM.
 
 ## [0.7.0] 2019-07-20
 
diff --git a/modules/pathkit/Makefile b/modules/pathkit/Makefile
index 5260093..48205b6 100644
--- a/modules/pathkit/Makefile
+++ b/modules/pathkit/Makefile
@@ -1,9 +1,27 @@
-build:
-	./compile.sh
+debug:
+	./compile.sh debug
+	- rm -rf build/
+	mkdir  -p ./build/wasm ./build/asmjs
+	cp ../../out/pathkit/pathkit.js     ./build/wasm/pathkit.js
+	cp ../../out/pathkit/pathkit.wasm   ./build/wasm/pathkit.wasm
 
-npm: npm-test npm-debug
-	mkdir -p ./npm-wasm/bin
-	mkdir -p ./npm-asmjs/bin
+	./compile.sh asm.js debug
+	cp ../../out/pathkit/pathkit.js     ./build/asmjs/pathkit.js
+
+release:
+	./compile.sh
+	- rm -rf build/
+	mkdir  -p ./build/wasm ./build/asmjs
+	cp ../../out/pathkit/pathkit.js     ./build/wasm/pathkit.js
+	cp ../../out/pathkit/pathkit.wasm   ./build/wasm/pathkit.wasm
+
+	./compile.sh asm.js
+	cp ../../out/pathkit/pathkit.js     ./build/asmjs/pathkit.js
+	cp ../../out/pathkit/pathkit.js.mem ./build/asmjs/pathkit.js.mem
+
+npm:
+	rm -rf ./npm-wasm/bin ./npm-asmjs/bin
+	mkdir -p ./npm-wasm/bin ./npm-asmjs/bin
 	./compile.sh
 	cp ../../out/pathkit/pathkit.js   ./npm-wasm/bin
 	cp ../../out/pathkit/pathkit.wasm ./npm-wasm/bin
@@ -11,135 +29,17 @@
 	cp ../../out/pathkit/pathkit.js     ./npm-asmjs/bin/pathkit.js
 	cp ../../out/pathkit/pathkit.js.mem ./npm-asmjs/bin/pathkit.js.mem
 
-publish:
-	cd npm-wasm; npm publish
-	cd npm-asmjs; npm publish
-
-update-major:
-	cd npm-wasm; npm version major
-	cd ../npm-asmjs; npm version major
-	echo "Don't forget to publish."
-
-update-minor:
-	cd npm-wasm; npm version minor
-	cd npm-asmjs; npm version minor
-	echo "Don't forget to publish."
-
-update-patch:
-	cd npm-wasm; npm version patch
-	cd npm-asmjs; npm version patch
-	echo "Don't forget to publish."
-
-# Build the library and run the tests. If developing locally, test-continuous is better
-# suited for that, although if you make changes to the C++/WASM code, you will need
-# to manually call make npm-test to re-build.
-test: npm-test
-	npm install
-	npx karma start ./karma.conf.js --single-run
-	ASM_JS=1 npx karma start ./karma.conf.js --single-run
-
 test-continuous:
-	echo "Assuming npm install has been run by user"
-	echo "Also assuming make npm-test has also been run by a user (if needed)"
+	echo "Assuming npm ci has been run by user"
+	echo "Also assuming make debug or make release has also been run by a user (if needed)"
 	npx karma start ./karma.conf.js --no-single-run --watch-poll
 
 test-continuous-asmjs:
-	echo "Assuming npm install has been run by user"
-	echo "Also assuming make npm-test has also been run by a user (if needed)"
+	echo "Assuming npm ci has been run by user"
+	echo "Also assuming make debug or make release has also been run by a user (if needed)"
 	ASM_JS=1 npx karma start ./karma.conf.js --no-single-run --watch-poll
 
-# Build the library and run the tests using the docker image.  If developing locally,
-# test-docker-continuous is better, although if you make changes to the C++/WASM code,
-# you will need to manually call make npm-test to re-build.
-test-docker:
-	mkdir -p ./npm-wasm/bin/test
-	mkdir -p ./npm-asmjs/bin/test
-	mkdir -p $$SKIA_ROOT/out/dockerbuild
-
-	docker run --rm -v $$SKIA_ROOT:/SRC -v $$SKIA_ROOT/out/dockerbuild:/OUT \
-gcr.io/skia-public/emsdk-base:prod /SRC/infra/pathkit/build_pathkit.sh
-	cp ../../out/dockerbuild/pathkit.js   ./npm-wasm/bin/test/pathkit.js
-	cp ../../out/dockerbuild/pathkit.wasm ./npm-wasm/bin/test/pathkit.wasm
-
-	docker run --rm -v $$SKIA_ROOT:/SRC -v $$SKIA_ROOT/out/dockerbuild:/OUT \
-gcr.io/skia-public/emsdk-base:prod /SRC/infra/pathkit/build_pathkit.sh asm.js
-	cp ../../out/dockerbuild/pathkit.js     ./npm-asmjs/bin/test/pathkit.js
-	cp ../../out/dockerbuild/pathkit.js.mem ./npm-asmjs/bin/test/pathkit.js.mem
-
-	docker run --shm-size=2gb -v $$SKIA_ROOT:/SRC gcr.io/skia-public/karma-chrome-tests:72.0.3626.121_v1 \
-karma start /SRC/modules/pathkit/karma.conf.js --single-run
-	docker run --shm-size=2gb -v $$SKIA_ROOT:/SRC -e ASM_JS=1 gcr.io/skia-public/karma-chrome-tests:72.0.3626.121_v1 \
-karma start /SRC/modules/pathkit/karma.conf.js --single-run
-
-test-docker-continuous:
-	echo "Assuming make npm-test has also been run by a user (if needed)"
-	docker run --shm-size=2gb -v $$SKIA_ROOT:/SRC gcr.io/skia-public/karma-chrome-tests:72.0.3626.121_v1 \
-karma start /SRC/modules/pathkit/karma.conf.js --no-single-run
-
-test-docker-continuous-asmjs:
-	echo "Assuming make npm-test has also been run by a user (if needed)"
-	docker run --shm-size=2gb -v $$SKIA_ROOT:/SRC -e ASM_JS=1 gcr.io/skia-public/karma-chrome-tests:72.0.3626.121_v1 \
-karma start /SRC/modules/pathkit/karma.conf.js --no-single-run
-
-npm-test:
-	# This compile time is typically faster than release and good for use with
-	# local-example-test
-	mkdir -p ./npm-wasm/bin/test
-	mkdir -p ./npm-asmjs/bin/test
-	./compile.sh test
-	cp ../../out/pathkit/pathkit.js   ./npm-wasm/bin/test/pathkit.js
-	cp ../../out/pathkit/pathkit.wasm ./npm-wasm/bin/test/pathkit.wasm
-	./compile.sh asm.js test
-	cp ../../out/pathkit/pathkit.js     ./npm-asmjs/bin/test/pathkit.js
-	cp ../../out/pathkit/pathkit.js.mem ./npm-asmjs/bin/test/pathkit.js.mem
-
-npm-debug:
-	# This compile time is typically faster than release and good for use with
-	# local-example-test
-	mkdir -p ./npm-wasm/bin/debug
-	mkdir -p ./npm-asmjs/bin/debug
-	./compile.sh debug
-	cp ../../out/pathkit/pathkit.js     ./npm-wasm/bin/debug/pathkit.js
-	cp ../../out/pathkit/pathkit.wasm   ./npm-wasm/bin/debug/pathkit.wasm
-
-	./compile.sh asm.js debug
-	cp ../../out/pathkit/pathkit.js     ./npm-asmjs/bin/debug/pathkit.js
-
-
-example:
-	npm install pathkit-asmjs pathkit-wasm
-	echo "Go check out localhost:8000/npm-wasm/example.html"
-	python3 ../../tools/serve_wasm.py
-
 local-example:
-	rm -rf node_modules/pathkit-wasm
-	rm -rf node_modules/pathkit-asmjs
-	mkdir -p node_modules
-	ln -s -T ../npm-wasm  node_modules/pathkit-wasm
-	ln -s -T ../npm-asmjs node_modules/pathkit-asmjs
 	echo "Go check out http://localhost:8000/npm-wasm/example.html"
 	echo "or http://localhost:8000/npm-asmjs/example.html"
 	python3 ../../tools/serve_wasm.py
-
-local-example-test:
-	rm -rf node_modules/pathkit-wasm
-	rm -rf node_modules/pathkit-asmjs
-	mkdir -p node_modules/pathkit-wasm
-	mkdir -p node_modules/pathkit-asmjs
-	ln -s -T ../../npm-wasm/bin/test node_modules/pathkit-wasm/bin
-	ln -s -T ../../npm-asmjs/bin/test node_modules/pathkit-asmjs/bin
-	echo "Go check out localhost:8000/npm-wasm/example.html"
-	echo "or http://localhost:8000/npm-asmjs/example.html"
-	python3 ../../tools/serve_wasm.py
-
-local-example-debug:
-	rm -rf node_modules/pathkit-wasm
-	rm -rf node_modules/pathkit-asmjs
-	mkdir -p node_modules/pathkit-wasm
-	mkdir -p node_modules/pathkit-asmjs
-	ln -s -T ../../npm-wasm/bin/debug node_modules/pathkit-wasm/bin
-	ln -s -T ../../npm-asmjs/bin/debug node_modules/pathkit-asmjs/bin
-	echo "Go check out localhost:8000/npm-wasm/example.html"
-	echo "or http://localhost:8000/npm-asmjs/example.html"
-	python3 ../../tools/serve_wasm.py
-
diff --git a/modules/pathkit/README.md b/modules/pathkit/README.md
index e3316bf..ab963eb 100644
--- a/modules/pathkit/README.md
+++ b/modules/pathkit/README.md
@@ -14,17 +14,14 @@
 Run `./compile.sh` to compile a production, WASM build to `$SKIA_HOME/out/pathkit`.
 Add "--help" for more options.
 
-
 Deploying to npm
 ----------------
 
-    # Build all 3 versions (release, test, debug) for both asmjs and WASM
+    # Build the release version for both asmjs and WASM
     # These binaries will be placed in the proper places of npm-*/bin
-    # This takes 5-10 minutes.
     make npm
 
-    # Update the package.json files of both npm-asmjs and npm-wasm
-    make update-patch  # or update-minor or update-major
-
-    # Publish both repos
-    make publish
+    # In each npm- subdirectory, run:
+    npm version minor (or patch or major)
+    npm login --registry https://wombat-dressing-room.appspot.com
+    npm publish
diff --git a/modules/pathkit/karma.conf.js b/modules/pathkit/karma.conf.js
index 04ef023..0d84576 100644
--- a/modules/pathkit/karma.conf.js
+++ b/modules/pathkit/karma.conf.js
@@ -10,16 +10,16 @@
 
     // list of files / patterns to load in the browser
     files: [
-      { pattern: 'npm-wasm/bin/test/pathkit.wasm', included:false, served:true},
+      { pattern: 'build/wasm/pathkit.wasm', included:false, served:true},
       { pattern: 'tests/*.json', included:false, served:true},
       'tests/testReporter.js',
-      'npm-wasm/bin/test/pathkit.js',
+      'build/wasm/pathkit.js',
       'tests/pathkitinit.js',
       'tests/*.spec.js'
     ],
 
     proxies: {
-      '/pathkit/': '/base/npm-wasm/bin/test/'
+      '/pathkit/': '/base/build/wasm/'
     },
 
     // test results reporter to use
@@ -79,16 +79,16 @@
   if (process.env.ASM_JS) {
     console.log('asm.js is under test');
     cfg.files = [
-      { pattern: 'npm-asmjs/bin/test/pathkit.js.mem', included:false, served:true},
+      { pattern: 'build/asmjs/pathkit.js.mem', included:false, served:true},
       { pattern: 'tests/*.json', included:false, served:true},
       'tests/testReporter.js',
-      'npm-asmjs/bin/test/pathkit.js',
+      'build/asmjs/pathkit.js',
       'tests/pathkitinit.js',
       'tests/*.spec.js'
     ];
 
     cfg.proxies = {
-      '/pathkit/': '/base/npm-asmjs/bin/test/'
+      '/pathkit/': '/base/build/asmjs/'
     };
   } else {
     console.log('wasm is under test');
diff --git a/modules/pathkit/npm-asmjs/example.html b/modules/pathkit/npm-asmjs/example.html
index c50c453..e018621 100644
--- a/modules/pathkit/npm-asmjs/example.html
+++ b/modules/pathkit/npm-asmjs/example.html
@@ -47,12 +47,12 @@
 <h2> Solves Cubics for Y given X </h2>
 <canvas class=big id=cubics></canvas>
 
-<script type="text/javascript" src="/node_modules/pathkit-asmjs/bin/pathkit.js"></script>
+<script type="text/javascript" src="/build/asmjs/pathkit.js"></script>
 
 <script type="text/javascript" charset="utf-8">
 
   PathKitInit({
-    locateFile: (file) => '/node_modules/pathkit-asmjs/bin/'+file,
+    locateFile: (file) => '/build/asmjs/'+file,
   }).then((PathKit) => {
     window.PathKit = PathKit;
     OutputsExample(PathKit);
diff --git a/modules/pathkit/npm-wasm/example.html b/modules/pathkit/npm-wasm/example.html
index 488f6ec..6ba64c1 100644
--- a/modules/pathkit/npm-wasm/example.html
+++ b/modules/pathkit/npm-wasm/example.html
@@ -47,12 +47,12 @@
 <h2> Solves Cubics for Y given X </h2>
 <canvas class=big id=cubics></canvas>
 
-<script type="text/javascript" src="/node_modules/pathkit-wasm/bin/pathkit.js"></script>
+<script type="text/javascript" src="/build/wasm/pathkit.js"></script>
 
 <script type="text/javascript" charset="utf-8">
 
   PathKitInit({
-    locateFile: (file) => '/node_modules/pathkit-wasm/bin/'+file,
+    locateFile: (file) => '/build/wasm/'+file,
   }).then((PathKit) => {
     window.PathKit = PathKit;
     OutputsExample(PathKit);