Writing Mac App with nw.js

Last week I bought a new MacBook Air. In order to make myself feel like a “power user”, I decide to write a simple mac app.

Why nw.js?

I don’t know how to write Objective-C or Swift, and have no idea how to setup Xcode, so it’s better to use some more familiar technologies and nw.js just looks promising.

Steps

Rather than showing how to write a fancy javascript app with nw.js, I will demonstrate the simple setup & develop flow that I used.

My final app can be found at here. (And I won’t tell what is it.) OK, talk is cheap, just show you the steps:

1. Install Homebrew.

One package manager to rule them all, isn’t it?

But don’t just use the one-line install script in homebrew’s index page, make sure you understand how it works before you install it.

2. Install Node.js.

Easy as a pie. But I just found [brewformulas][brwformulas] is very useful.

$ brew install node

3. Install your favourite editor with homebrew.

Cool kids use Vim.

$ brew install mvim

4. Setup your working directory.

$ cd /path/to/your/working/dir/
$ npm init

5. Code like a boss!

But when you coding in javascript, do as the Pro do.

6. Add node-webkit-builder to your package.

$ npm install node-webkit-builder --save-dev

7. Trial run!

$ ./node_modules/node-webkit-builder/bin/nwbuild -r .

But we don’t need to re-compile our project every time, python-livereload helps you develop on the fly.

8. Feeling good? Publish your awesome app!

$ ./node_modules/node-webkit-builder/bin/nwbuild -o build .

Don’t forget to check out the official guide on packagment and distribution.

9. Install your app.

Drag and drop it into application folder. But the default icon may seem rigid, you can follow this guide to update it.

10. Use it!

enigma

comments powered by Disqus

Since 2014