Getting started with Jetpack
Written by Mike James   
Wednesday, 30 June 2010
Article Index
Getting started with Jetpack
Hello Jetpack
Widgets

The package structure

All Jetpack projects have a standard folder structure and a manifest to describe the application. Unlike other APIs that you may have encountered this one uses a JSON manifest rather than XML.

At the very minimum your project needs a root folder which contains a manifest.

Create the folder HelloJetpack using the command:

mkdir HelloJetpack

or any file handling utility you care to use.

Next use the file editor of your choice - Notepad under Windows and Gedit under Ubuntu are good choices - and enter the following lines to create the manifest:

{
 "name":"Hello",
"description":"HelloJetpack",
"author":"iProgrammer
(http://i-programmer.info)",
"dependencies":["jetpack-core"]
}

If you know your Javascript you will recognise this as JSON notation which creates an object with the properties specified.

You can find a full description of the properties that you can include in the manifest in the documentation.

 


 

In this case we provide a description, author identifier and a dependencies array. The dependency array is a list of packages that your application needs to work - they will be automatically loaded for you. We are going to load the Jetpack core module which contains just about everything.

The name property sets the name of the package and if you leave it out then the name defaults to the name of the root directory. In this case we have given the default directory a name that is illegal as a package name so we have no choice but to explicitly give it a legal name.

Undocumented "features" such as this are what wastes hours of debugging time.

Save the file under the name package.json in the HelloJetpack directory. The manefest always has this name and is always stored in the root of the project.

You can already run your Jetpack project. First change the current directory to HelloJetpack. The compiler always looks for the manefest in the current directory.

There is a command line parameter that you can use if you want to work with a manefest in antoher directory but using the current directory is easier in most cases.

With HelloJetpack as the current directory in the comand prompt use the command:

cfx run -a firefox

this loads an instance of Firefox and your Jetpack code. in this case you should see the error message

package.json does not have a 'main' entry

When you load a manefest in this way the default is for the package's entry point to be the Javascript in the file main.js stored in the lib subfolder.

Later you will discover that there are a number of other folders that serve specific purposes - but for the moment we have the root folder HelloJetpack which contains everything and a lib subfolder which contains main.js.

The main program

To make this all work we first need to create the lib subfolder and create in it the file main.js. Don't add any Javascript just yet - save an empty file.

Now when you run it package again you will see the warning message -
"No 'id' in package.json ..."

The system adds and id entry for you and saves the manefest.

All you have to do is run the whole thing again using the same command.

Following this you will now see an instance of Firefox start up - a completely standard and unmodified Firefox.

This is entirely reasonable as your addon doesn't actually do anything just yet. Close Firefox and you will see the message "Program Terminated Sucessfully" in the command console.

If you don't see this message there is something wrong - most likley you have some incorrect Javascript in main.js.

<ASIN:0596000529 >
<ASIN:0596009283 >

<ASIN:0764596500 >
<ASIN:0975240242 >

<ASIN:0470526912>

<ASIN:1449381871>

<ASIN:1430230541>

<ASIN:0321683919>



Last Updated ( Wednesday, 30 June 2010 )