Page 2 of 3
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:
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:
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
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
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.