From 93055f4b4a9829bafc21fb85f57df82843149248 Mon Sep 17 00:00:00 2001 From: Brad Buchanan Date: Fri, 17 Jun 2016 17:07:03 -0700 Subject: [PATCH] Prepare for npm publishing Introduces some small package changes that simplify publishing Piskel to NPM as a ready-to-use application. Since Piskel is not simply a JavaScript "module" (not something one would 'require' into another application) its role as a package on npm is somewhat unconventional - it contains the release build of Piskel, ready to serve as a static website, and a small `piskel-root` utility that will print the absolute path to that content (which will have been installed who-knows-where by npm). Mostly this works by adding the "files" and "bin" entries to package.json, and by adding an .npmignore file (which simply prevents npm from using your .gitignore and ignoring the built files that we want to ship). With these settings in place you could publish to npm anytime (as long as you have permission) but I've added `preversion` and `postversion` scripts to simplify and automate the process. Here's how you publish a release: ``` npm login # If not already logged in npm version [major|minor|patch|] # see `npm help version` for more options ``` By itself this will lint, run the full test suite, do a release build, make sure the working directory is clean, bump the version number in package.json, commit the version number change and add a git tag with the new version, push the new version to GitHub and publish the release build output to npm. If you don't have an npm account, create one at npmjs.com. You'll need to do the initial release. An npm user should then be able to download the latest Piskel release by running `npm install piskel`. They could then find the location of Piskel's index.html by running `` `npm bin`/piskel-root `` (perhaps more useful for automation purposes... our own build copies the built Piskel release from its npm-installed location to a directory where it gets served by Rails). By itself this may not seem _that_ useful, but it's a step toward making Piskel easier to embed with other appilications. I've got a start on the next big improvement, where a parent application can `require('piskel')` to get an API object that facilitates communication with the editor running within an iframe. You can see an early version of that at https://github.com/code-dot-org/piskel/pull/7 --- .npmignore | 3 +++ misc/scripts/piskel-root | 4 ++++ package.json | 13 +++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .npmignore create mode 100644 misc/scripts/piskel-root diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..b350e18 --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +node_modules/ +test/ + diff --git a/misc/scripts/piskel-root b/misc/scripts/piskel-root new file mode 100644 index 0000000..26cd8ab --- /dev/null +++ b/misc/scripts/piskel-root @@ -0,0 +1,4 @@ +#!/usr/bin/env node +// Writes the absolute path to the release build root to stdout +var path = require('path'); +process.stdout.write(path.resolve(__dirname, '../../dest/prod') + '\n'); diff --git a/package.json b/package.json index 51e139f..768590e 100644 --- a/package.json +++ b/package.json @@ -6,16 +6,25 @@ "contributors": [ "Vincent Renaudin" ], - "main": "./dest/prod/index.html", "homepage": "http://github.com/juliandescottes/piskel", "license": "Apache-2.0", "repository": { "type": "git", "url": "http://github.com/juliandescottes/piskel.git" }, + "files": [ + "dest/prod", + "misc/scripts/piskel-root" + ], + "bin": { + "piskel-root": "./misc/scripts/piskel-root" + }, + "main": "./dest/prod/index.html", "scripts": { "test": "grunt test", - "start": "nodewebkit" + "start": "nodewebkit", + "preversion": "grunt test-local build", + "postversion": "git push && git push --tags && npm publish" }, "devDependencies": { "dateformat": "1.0.11",