Git Product home page Git Product logo

nw-boilerplate's Introduction

nw-boilerplate

Comprehensive boilerplate application for NW.js.

This project gives you mainly three things:

  1. Cross-platform development environment (works the same way on OSX, Windows and Linux).
  2. Basic structure for NW.js app.
  3. Scripts to generate installers of your app for all three operating systems.

By the way, there is a twin project to this one: electron-boilerplate, which is the same thing but for Electron.

Quick start

The only development dependency of this project is Node.js. So just make sure you have it installed. Then type few commands known to every Node developer...

git clone https://github.com/szwacz/nw-boilerplate.git
cd nw-boilerplate
npm install
npm start

... and boom! You have running desktop application on your screen.

Structure of the project

There are two package.json files:

1. For development

Sits on path: nw-boilerplate/package.json. Here you declare dependencies for your development environment and build scripts. This file is not distributed with real application!

Also here you declare wersion of NW.js runtime you want to use:

"devDependencies": {
  "nw": "^0.12.1"
}

2. For your application

Sits on path: nw-boilerplate/app/package.json. This is real manifest of your application, as specified by NW wiki. Declare your app dependencies here.

There is one extra field in this file you won't find in NW docs: productName. Unlike the name field, which have to be file-path-freindly (no spaces and strange characters), productName could have any characters you like, and it's used as the app name displayed to the user.

Project's folders

  • app - code of your application goes here.
  • config - place for you to declare environment specific stuff.
  • build - in this folder lands built, runnable application.
  • releases - ready for distribution installers will land here.
  • resources - resources for particular operating system.
  • tasks - build and development environment scripts.

Development

Installation

npm install

It will also download NW runtime, and install dependencies for second package.json file inside app folder.

Starting the app

npm start

Module loader

How about splitting your JavaScript code into modules? This project supports it by new ES6 syntax (thanks to babel). ES6 modules are translated into AMD (RequireJS) modules. The main advantage of this setup is that you can use ES6/RequireJS for your own modules, and at the same time have normal access to node's require() to obtain stuff from npm.

// Modules you write are required through new ES6 syntax
// (It will be translated into AMD definition).
import myOwnModule from './my_own_module';
// Node.js (npm) modules are required the same way as always
// (so you can still access all the goodness in npm).
var moment = require('moment');

Unit tests

nw-boilerplate has preconfigured jasmine unit test runner. To run it go with standard:

npm test

You don't have to declare paths to spec files in any particular place. The runner will search through the project for all *.spec.js files and include them automatically.

Making a release

Note: There are various icon and bitmap files in resources directory. Those are used in installers and are intended to be replaced by your own graphics.

To make ready for distribution installer use command:

npm run release

It will start the packaging process for operating system you are running this command on. Ready for distribution file will be outputted to releases directory.

You can create Windows installer only when running on Windows, the same is true for Linux and OSX. So to generate all three installers you need all three operating systems.

Special precautions for Windows

As installer NSIS is used. You have to install it (version 3.0), and add NSIS folder to PATH in Environment Variables, so it is reachable to scripts in this project (path should look something like C:/Program Files (x86)/NSIS).

License

The MIT License (MIT)

Copyright (c) 2014-2015 Jakub Szwacz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nw-boilerplate's People

Contributors

brownl avatar runlevelsix avatar szwacz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nw-boilerplate's Issues

Watches crash during development

Jakub:

I am really enjoying working with the boilerplate :)

The problem I am having though is that the watches seem to crash during development. After running

npm start

...and making a change to a JavaScript file, the script stalls. Here's a screenshot of what I see:

image

Is there something I am doing wrong?

Not really an issue

While running the release script I ran into:
Error in script "C:\Users\desktop\myapp\tmp\installer.nsi" on line 98 -- aborting creation process
Line in question:
File /r "${src}*"

Basically it was the windows filename too long error due to 3rd party node modules included in the project.
When I moved my project to c:\myapp all went fine.

Great job.

requrejs is not defined at Win32

Hi,
Thanks for your open source, nw-boilerplate which looks like very helpful for nw beginner such as me.
I am trying to use this package at Window8, but I got the below error message.
The app/index.html reference vendor/requre.js which is exist at the app/vendor dir.
Do I need to fix something at Window?
Could you give me any guide for this case. Thanks.

C:\projectnw\nw-boilerplate>npm install
npm WARN package.json @ No repository field.
npm WARN optional dep failed, continuing [email protected]

@ postinstall C:\projectnw\nw-boilerplate
cd ./app && npm install

npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data

C:\projectnw\nw-boilerplate>npm start

@ start C:\projectnw\nw-boilerplate
node ./tasks/start

[21:32:25] Working directory changed to c:\projectnw\nw-boilerplate
[21:32:25] Using gulpfile c:\projectnw\nw-boilerplate\gulpfile.js
[21:32:25] Starting 'clean'...
[21:32:25] Finished 'clean' after 10 ms
[21:32:25] Starting 'transpile'...
[21:32:25] Starting 'less'...
[21:32:25] Starting 'copy'...
[21:32:25] Starting 'finalize'...
[21:32:25] Finished 'finalize' after 6.29 ms
[21:32:26] Finished 'less' after 67 ms
[21:32:26] Finished 'transpile' after 98 ms
[21:32:26] Finished 'copy' after 90 ms
[21:32:26] Starting 'build'...
[21:32:26] Finished 'build' after 12 μs
[7220:0420/213226:ERROR:nw_shell.cc(335)] ReferenceError: requirejs is not defined
at file:///C:/projectnw/nw-boilerplate/build/index.html:33:9
[21:32:26] Working directory changed to c:\projectnw\nw-boilerplate
[21:32:27] Using gulpfile c:\projectnw\nw-boilerplate\gulpfile.js
[21:32:27] Starting 'watch'...
[21:32:27] Finished 'watch' after 39 ms

How to use with existing nwjs projects?

I am trying to integrate an existing nwjs project into nw-boilerplate and having issues I don't understand.
For instance, if I get https://github.com/dukeofharen/markdown-editor and do "npm install && nwjs .", the markdown-editor app starts just fine.

But if I then copy the "markdown-editor" directory over to be the "app" directory of nw-boilerplate and then do "npm start", I get a slew of errors starting with:

14388:0509/171424:ERROR:nw_shell.cc(335)] ReferenceError: define is not defined
    at file:///Users/tod/projects/node/nw-boilerplate/build/js/jquery/jquery.min.js:1:1
[14388:0509/171424:INFO:CONSOLE(1)] "Uncaught ReferenceError: define is not defined", source: file:///Users/tod/projects/node/nw-boilerplate/build/js/jquery/jquery.min.js (1)
[14388:0509/171424:ERROR:nw_shell.cc(335)] ReferenceError: define is not defined
    at file:///Users/tod/projects/node/nw-boilerplate/build/js/main.js:1:1

The app then sorta starts but is very broken.

"unexpected whitespace character" undefined "?"

I'm trying to run "npm run release" and i'm getting some errors. With prepackaged app everything works as expected. The c2runtime.js file is generated using C2 game engine, and fails minified or not.

I've managed to pin point the error on following lines of code in tasks/build.js
lines 130,131:

            container.getModule(relPath);     
            container.write(destForCodeDir.path(relPath));

If i comment them out, everything is built ok, but when i install and run the installed project i get a message that jquery is undefined.

dump log:

C:\Users\MaliJuda\Documents\nwbolierplate>npm run release

> @ release C:\Users\MaliJuda\Documents\nwbolierplate
> gulp release --target=release

[15:02:00] Using gulpfile ~\Documents\nwbolierplate\gulpfile.js
[15:02:00] Starting 'clean'...
[15:02:00] Finished 'clean' after 13 ms
[15:02:00] Starting 'prepare-runtime'...
[15:02:00] Finished 'prepare-runtime' after 219 ms
[15:02:00] Starting 'copy'...
[15:02:00] Starting 'finalize'...
[15:02:00] Finished 'finalize' after 3.43 ms
[15:02:00] Starting 'transpile'...
[15:02:00] Starting 'less'...
[15:02:00] 'transpile' errored after 50 ms
[15:02:00] Error: c2runtime.js "unexpected whitespace character" undefined "?"!!
!
    at formatError (C:\Users\MaliJuda\Documents\nwbolierplate\node_modules\gulp\
bin\gulp.js:161:10)
    at Gulp.<anonymous> (C:\Users\MaliJuda\Documents\nwbolierplate\node_modules\
gulp\bin\gulp.js:187:15)
    at Gulp.emit (events.js:95:17)
    at Gulp.Orchestrator._emitTaskDone (C:\Users\MaliJuda\Documents\nwbolierplat
e\node_modules\gulp\node_modules\orchestrator\index.js:264:8)
    at C:\Users\MaliJuda\Documents\nwbolierplate\node_modules\gulp\node_modules\
orchestrator\index.js:275:23
    at finish (C:\Users\MaliJuda\Documents\nwbolierplate\node_modules\gulp\node_
modules\orchestrator\lib\runTask.js:21:8)
    at DestroyableTransform.<anonymous> (C:\Users\MaliJuda\Documents\nwbolierpla
te\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:52:4)
    at DestroyableTransform.f (C:\Users\MaliJuda\Documents\nwbolierplate\node_mo
dules\gulp\node_modules\orchestrator\node_modules\end-of-stream\node_modules\onc
e\once.js:17:25)
    at DestroyableTransform.emit (events.js:117:20)
    at onwriteError (C:\Users\MaliJuda\Documents\nwbolierplate\node_modules\thro
ugh2\node_modules\readable-stream\lib\_stream_writable.js:250:10)
[15:02:00] Finished 'less' after 139 ms
[15:02:00] Finished 'copy' after 160 ms

npm ERR! @ release: `gulp release --target=release`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ release script.
npm ERR! This is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     gulp release --target=release
npm ERR! You can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "release"
npm ERR! cwd C:\Users\MaliJuda\Documents\nwbolierplate
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\MaliJuda\Documents\nwbolierplate\npm-debug.log
npm ERR! not ok code 0

C:\Users\MaliJuda\Documents\nwbolierplate>

If additional info is needed i'll provide!

edit: contents of my app folder can be downloaded here: http://ge.tt/4z4AI322/v/0?c so you can try to reproduce!

Windows release file not created

When running npm run release, the process appears to finish successfully, and the success message gets output to the CLI, but the file is not actually written.

Here is my output from the pertinent place in the CLI output:

[12:07:11] Building installer with NSIS...
Processing config: c:\Program Files (x86)\NSIS\nsisconf.nsh
Processing script file: ".\tmp\installer.nsi" (ACP)

Processed 1 file, writing output (x86-ansi):

Output: "c:\path\nw-boilerplate\releases\nw-boilerplate_0.1.0.exe"
Can't open output file
Error - aborting creation process
[12:07:41] Installer nw-boilerplate_0.1.0.exe ready!
[12:07:41] Finished 'release' after 30 s

How to run the app with env = production

I tried

npm start -env production

npm start --env production

npm start --env=production

NODE_ENV=production npm start

the only way I could is by hard coding it in utils.js. tried logging the argv array inside getEnvName in utlis.js but in-vain

Can someone please help

Less watch not working

The less watches do not fire when changing a less file. This seems to be the same problem as in this issue. I changed line 107 in build.js to gulp.watch('app/**/*.less', ['less-watch']); and now it works.

Better gulp watches needed

  • saving of html files doesn't lead to rebuild
  • .less files should be looked in whole project, not only in stylesheets folder

spawn makensis ENOENT on "npm run release" in windows

I install NSIS successfully,and add folder to PATH in Enviroment Variables("C:\Program Files (x86)\NSIS"),when i execute "npm run release" an error occured.
Error: spawn makensis ENOENT at exports._errnoException (util.js:873:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at nextTickCallbackWith2Args (node.js:442:9) at process._tickCallback (node.js:356:17)

Update the dependencies

In order to suppoprt newer node and nw.js versions, an update of the dependency versions should be done.
I have struggled some time to fight upcoming errors. ;-)

"devDependencies": {
"fs-jetpack": "^0.7.0",
"gulp": "^3.8.8",
"gulp-babel": "^6.1.2",
"babel-preset-es2015": "^6.6.0",
"gulp-less": "^3.0.5",
"gulp-sourcemaps": "^1.5.2",
"gulp-util": "^3.0.1",
"nw": "^0.12.3",
"q": "^1.0.1",
"tree-kill": "^1.0.0",
"yargs": "^4.2.0"
},
"optionalDependencies": {
"appdmg": "^0.3.6"
},
Furthermore, you have to change the call to babel in "taks/build.js" to:
.pipe(babel({ presets: ['es2015'] }))
The old "module" configuration is no more available.

Additionally, I had to modify the tests. The used imports must be expandd by the relative path "hello_world". But I am unsure if it is a side effect of the version updates---or that I am just to stupid to execute "npm test"... ;-)

Unable to compile windows installer

When building the windows installer i bump into an error.
The installer nsis script isn't able to find the required (node_modules)

File: failed opening file "c:\Users\IEUser\Desktop\###\tmp\Combiner\node_modules\node-xlsx\no
de_modules\lodash.map\node_modules\lodash.createcallback\node_modules\lodash.keys\node_modules\lodash._shimkeys\node_modules\lodash._ob
jecttypes\LICENSE.txt"
Error in script "c:\Users\IEUser\Desktop\##\tmp\installer.nsi" on line 98 -- aborting creati
on process

I tried to compile the windows installer on mac (using brew install nsis ) and windows, but both failed. Compiling the Mac dmg works just fine.

Anybody have a clue what the problem might be?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.