Permalink
Switch branches/tags
660/documentation-build-process first-timers-year fozy81-patch-1 fozy81-patch-2 gr2m-patch-1 greenkeeper/async-2.6.1 greenkeeper/async-pin-2.6.0 greenkeeper/browserify-pin-14.1.0 greenkeeper/good-8.0.0 greenkeeper/good-8.0.1 greenkeeper/good-8.1.0 greenkeeper/good-8.1.1 greenkeeper/h2o2-7.0.0 greenkeeper/h2o2-7.0.1 greenkeeper/h2o2-7.0.2 greenkeeper/h2o2-8.0.0 greenkeeper/h2o2-8.0.1 greenkeeper/h2o2-8.1.0 greenkeeper/h2o2-8.1.1 greenkeeper/h2o2-8.1.2 greenkeeper/hapi-17.0.0 greenkeeper/hapi-17.0.2 greenkeeper/hapi-17.1.0 greenkeeper/hapi-17.1.1 greenkeeper/hapi-17.2.0 greenkeeper/hapi-17.2.1 greenkeeper/hapi-17.2.2 greenkeeper/hapi-17.2.3 greenkeeper/hapi-17.3.0 greenkeeper/hapi-17.3.1 greenkeeper/hapi-17.4.0 greenkeeper/hapi-17.5.0 greenkeeper/inert-5.0.0 greenkeeper/inert-5.0.1 greenkeeper/inert-5.1.0 greenkeeper/lodash-4.17.1 greenkeeper/lodash-4.17.9 greenkeeper/nock-9.0.9 greenkeeper/nock-9.0.10 greenkeeper/nock-9.0.21 greenkeeper/nock-9.0.23 greenkeeper/nock-9.0.24 greenkeeper/nock-9.0.25 greenkeeper/nock-pin-9.0.8 greenkeeper/nock-pin-9.0.22 greenkeeper/npmlog-4.0.1 greenkeeper/proxyquire-2.0.0 greenkeeper/proxyquire-2.0.1 greenkeeper/rc-1.2.4 greenkeeper/rc-pin-1.2.3 greenkeeper/request-2.83.0 greenkeeper/request-2.84.0 greenkeeper/request-2.85.0 greenkeeper/request-2.86.0 greenkeeper/request-2.87.0 greenkeeper/request-pin-2.82.0 greenkeeper/request-pin-2.83.0 greenkeeper/semantic-release-15.0.0 greenkeeper/semantic-release-15.0.1 greenkeeper/semantic-release-15.0.2 greenkeeper/semantic-release-15.0.3 greenkeeper/semantic-release-15.1.2 greenkeeper/semantic-release-15.1.3 greenkeeper/semantic-release-15.1.4 greenkeeper/semantic-release-15.1.5 greenkeeper/semantic-release-15.1.6 greenkeeper/semantic-release-15.1.7 greenkeeper/semantic-release-15.1.8 greenkeeper/semantic-release-15.1.11 greenkeeper/semantic-release-15.3.0 greenkeeper/semantic-release-15.4.1 greenkeeper/semantic-release-15.4.2 greenkeeper/semantic-release-15.4.3 greenkeeper/semantic-release-15.4.4 greenkeeper/semantic-release-15.5.0 greenkeeper/semver-5.5.0 greenkeeper/semver-pin-5.4.1 greenkeeper/tap-12.0.0 greenkeeper/tap-12.0.1 greenkeeper/yargs-8.0.1 greenkeeper/yargs-9.0.1 greenkeeper/yargs-10.0.3 greenkeeper/yargs-10.1.1 greenkeeper/yargs-11.0.0 hoodie-client-legacy legacy master
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
167 lines (119 sloc) 5.13 KB

Files & Folders

package.json

The package.json file describes your project in JSON. It its dependencies, scripts needed to run or use or develop on your project, and other information described in the NPM documentation for package.json.

The file is created when you run this:

npm init

It will prompt you for details about your projects, such as its name, version, description, test suite, author, and software license. Fill it out or leave it for later. You can always edit the file directly.

Hoodie modifies your package.json when it is installed to add a "start" script that starts your server by running hoodie without options.

When adding new dependencies, you can save their name and version information to package.json by using the --save flag, like this:

npm install --save <package name>

With your dependencies documented in package.json, you can install all your dependencies at once by running this:

npm install

This makes it very easy for others to get your project up and running quickly.

README.md

The README.md file describes your project in Markdown. It is intended for humans to read, and should include information about what your project is or does, how to install it, use it, test it, and contribute to it if appropriate.

For an example readme, try the one used by Hoodie :)

.hoodie/

The .hoodie/ folder contains compiled client assets and database records, including query indexes. You should never need to modify these files directly.

hoodie/

The hoodie/ folder contains the JavaScript code that runs in your server and the user's browser, and the code that they share. Hoodie uses two files as hooks to package code for the client and server:

  • hoodie/client/index.js is included as a Hoodie plugin using Browserify, so it can use require() to include code from dependencies or other folders.
  • hoodie/server/index.js is included in the server as a Hapi plugin. It can define new routes and other server-side logic.

Hoodie does not create a hoodie/ folder, so you will need to create it:

mkdir hoodie
mkdir hoodie/{client,server}
touch hoodie/{client,server}/index.js

Although Hoodie doesn't treat it in any special way, you can use a folder like hoodie/lib/ to store code shared between the client and the server. Client and server scripts can require() code from other folders like hoodie/lib/.

The hoodie/client/index.js file exports a Hoodie plugin. A Hoodie plugin exports a function that accepts a 'hoodie' object as its sole parameter. This object contains the interfaces to Hoodie's client APIs: 'account', 'store', 'connectionStatus', and 'log'.

You can also attach new methods to the 'hoodie' object, like the 'hello' method in this example hoodie/client/index.js file:

module.exports = function (hoodie) {
  hoodie.hello = function (what) {
    return Promise.resolve('Hello, ' + (what || 'world') + '!')
  }
}

The hoodie/server/index.js exports a Hapi plugin, like this:

module.exports.register = function (server, options, next) {
  server.route({
    method: 'GET',
    path: '/hello',
    handler: function (request, reply) {
      reply({ hello: 'world' })
    }
  })
  next()
}

module.exports.register.attributes = {
  name: '<app name>',
  version: '<app version>'
}

In this example, the register function is used to add a route to the server at /hoodie/<app name>/hello that responds with a JSON object like this: { "hello": "world" }. All of your app's server routes are prefixed with /hoodie/<app name>/.

The 'register' method allows you to modify the server by adding routes and other server logic. You can read more about how to do that on Hapi's website. You can access Hoodie's server-side libraries via server.plugins.

public/

When you open your app in the browser you will see Hoodie’s default page telling you that your app has no public/ folder. So let’s create it

mkdir public
touch public/index.html

Now edit the public/index.html file and pass in the following content.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My Hoodie App</title>
  </head>
  <body>
    <h1>My Hoodie App</h1>

    <script src="/hoodie/client.js"></script>
  </body>
</html>

You need to stop the server now (ctrl + c) and start it again. If you reload your app in your browser, you will now see your HTML file.