From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../add-ons/sdk/tools/cfx_to_jpm/index.html | 192 +++++++ files/fr/mozilla/add-ons/sdk/tools/index.html | 13 + files/fr/mozilla/add-ons/sdk/tools/jpm/index.html | 600 +++++++++++++++++++++ 3 files changed, 805 insertions(+) create mode 100644 files/fr/mozilla/add-ons/sdk/tools/cfx_to_jpm/index.html create mode 100644 files/fr/mozilla/add-ons/sdk/tools/index.html create mode 100644 files/fr/mozilla/add-ons/sdk/tools/jpm/index.html (limited to 'files/fr/mozilla/add-ons/sdk/tools') diff --git a/files/fr/mozilla/add-ons/sdk/tools/cfx_to_jpm/index.html b/files/fr/mozilla/add-ons/sdk/tools/cfx_to_jpm/index.html new file mode 100644 index 0000000000..e8b50f5006 --- /dev/null +++ b/files/fr/mozilla/add-ons/sdk/tools/cfx_to_jpm/index.html @@ -0,0 +1,192 @@ +--- +title: De cfx à jpm +slug: Mozilla/Add-ons/SDK/Tools/cfx_to_jpm +translation_of: Archive/Add-ons/Add-on_SDK/Tools/cfx_to_jpm +--- +
+

L'Add-on SDK inclut un outil de ligne de commande que vous utilisez pour initialiser, exécuter, tester, et empaqueter des add-ons. L'outil actuel est appelé jpm, il est basé sur Node.js . Il remplace l'outil cfx.

+ +

Vous pouvez utiliser jpm à partir de Firefox 38.

+ +

Cet article met en évidence les principales différences entre cfx et jpm.

+
+ +

Un guide pour travailler avec jpm si vous êtes déjà familier avec cfx.

+ +

Installation

+ +

cfx est basée sur Python et est distribué comme un fichier zip. jpm est baser sur Node.js qui est distribué par npm . Donc, pour jpm vous n'avez pas besoin de Python, mais vous avez besoin npm.

+ +

Pour obtenir les mises de cfx vous deviez télécharger et extraire un fichier zip, tandis que pour obtenir la nouvelle version de jpm, utilisez npm update .

+ +

Pour obtenir des instructions d'installation de jmp, consultez la section de l' Installation dans la référentiel de jmp.

+ +

Activation

+ +

Vous devez appeler cfx activate avant de pouvoir utiliser cfx, et cela ne fonctionne que dans le shell de commande de courant:. Si vous ouvrez un nouveau shell, vous devez appeler activate de nouveau

+ +

Avec jpm, pas d'activation. Une fois qu'il est installé, vous pouvez simplement l'utiliser.

+ +

Incompatibilités

+ +

Dans la plupart cas, les add-ons créés avec cfx fonctionnent bien avec jpm. Cependant, il y a quelques différences que vous devez connaitre.

+ +

Add-on ID

+ +

L'ID de add-on est l'identifiant unique de votre add-on. Dans un xpi, c'est le champ ID dans le fichier Manifest d'instalation de l'add-on (install.rdf).

+ +

L'identifiant est utilisé à des fins variées. Par exemple: addons.mozilla.org l'utilise pour distinguer entre les nouvelles add-ons et les mises à jour d'add-ons existantes, et le module simple-storage l'utilise pour déterminer lesquelles des données stockées appartiennent à tel add-on.

+ +

Manipulation avec l'ID cfx

+ +

Lorsque vous utilisez cfx, l'ID est tiré du champ id dans le fichier de package.json de l'add-on. Vous pouvez éditer ce fichier pour créer votre propre identité, mais si vous ne le faites pas, cfx va le générer pour vous, ce qui va ressembler à quelque chose comme "jid1-F3BoogbjQJE67A". L'ID Add-on doit être l'un des deux types suivant : un GUID ou une chaîne qui comprend un symbole "@". Le SDK ne prévoit que le dernier format, et si l'ID dans package.json ne contient pas de "@", cfx xpi ajouter "@jetpack" dans le champ de package.json, ce qui transforme l'ID de l'add-on.

+ +

Donc: si vous n'avez jamais manipulé l'ID lors de l'utilisation cfx, alors la valeur dans le package.json de votre add-on sera quelque chose comme "jid1-F3BoogbjQJE67A", et l'ID correspondant dans la install.rdf sera "jid1-F3BoogbjQJE67A@jetpack".

+ +

Manipulation d'ID avec jpm

+ +

Lorsque vous créez un xpi avec jpm xpi:

+ + + +

Ce que vous devez faire

+ +

Tout cela signifie que: si votre package.json contient un champ id, et sa valeur ne contient pas «@», alors vous devez ajouter "@jetpack» lors du passage à jpm .

+ +

Si vous faites cela, l'ID de l'add-on sera la même que l'id utilisée avec cfx.

+ +

Point d'entrée

+ +

Le point d'entrée de l'add-on est le fichier qui est exécutée lorsque l'add-on a besoin de s'initialiser: par exemple, au démarrage de Firefox, ou lorsque l'add-on est installé, activé, ou mis à niveau. Avec cfx, la valeur par défaut à "lib/main.js", même si elle peut être réglée sur un autre fichier en utilisant le main champ dans le package.json .

+ +

Dans jpm, le point d'entrée par défaut est "index.js". Donc, lors de la commutation vers jpm:

+ + + +

Chargement des modules

+ +

L'outil jpm utilise la même logique que Node.js pour déterminer comment résoudre l'argument require(). Dans la plupart des cas, c'est la même logique que cfx. Cependant, il existe quelques différences, parce certaines compatibilités ont été retirées.

+ +

Requérir à des modules locaux

+ +

Supposons que votre add-on est structuré en modules séparés :

+ + + +

Lorsque vous voulez utiliser un module "utils.js" dans "main.js", vous devez utiliser un chemin relatif à "main.js", et le préfixer avec "./" pour indiquer que c'est un chemin relatif:

+ +
var utils = require("./utils");
+ +

Cependant, avec cfx vous êtes également autorisé à omettre le "./":

+ +
var utils = require("utils"); // this will not work with jpm!
+ +

Cette seconde forme ne fonctionnera pas avec jpm.

+ +

Requérir des modules de code de test

+ +

Similarly, suppose you've written some tests for your add-on:

+ + + +

Avec cfx, le code de "test-my-addon.js" peut importer "my-addon.js" en utilisant une déclaration de ce genre:

+ +
var my_addon = require("my-addon"); // ceci ne fonctionne pas avec jpm!
+ +

Avec jpm, vous devez spécifier le chemin vers «my-addon" explicitement, en utilisant un chemin relatif:

+ +
var my_addon = require("../lib/my-addon");
+
+ +

Modules tiers

+ +

Le SDK a toujours soutenu les modules tiers: les développeurs peuvent écrire leurs propres modules qui étendent les API du SDK ou ajouter de nouvelles API, et d'autres add-on peuvent faire usage de ces modules de la même manière qu'ils utilisent les modules intégré au SDK.

+ +

Dans jpm cette façon d'utiliser des modules tiers ne fonctionne plus. Au lieu de cela, jpm n'accepte que les modules tiers hébergés sur la npm, vous pouvez les utiliser en les installant à partir de la npm dans l'arbre de répertoire de votre add-on. Voir le tutoriel utilisant des modules tiers avec jpm.

+ +

Les commandes et les options de commande

+ +

Commandes définitivement retiré

+ +

jpm ne soutient plus les commandes cfx "interne".

+ +

Options définitivement retiré

+ +

jpm ne soutient plus :

+ +
--extra-packages
+--use-config
+--package-path
+--pkgdir
+--no-strip-xpi
+--harness-option
+--manifest-overload
+--output-file
+--templatedir
+--keydir
+--profiledir
+--overload-modules
+--static-args
+--app
+--no-run
+--addons
+--e10s
+--logfile
+--dependencies
+--test-runner-pkg
+ +

Au lieu de --profiledir et de --overload-modules, utilisez --profile et --overload

+ +

Champs Package.json

+ +

Beaucoup de champs package.json sont des commandes implicites de cfx. Dans jpm, nous avons supprimé le soutien de certains de ces domaines, et travaillons toujours sur le soutien des autres.

+ +

Champs définitivement retiré

+ + + +

Echappement dans Package.json

+ +

Où avec cfx vous auriez dû échapper avec 2 voir 3 barres obliques inverses (\), jpm n'en a besoin que d'une.

+ +

 

diff --git a/files/fr/mozilla/add-ons/sdk/tools/index.html b/files/fr/mozilla/add-ons/sdk/tools/index.html new file mode 100644 index 0000000000..89f1db963b --- /dev/null +++ b/files/fr/mozilla/add-ons/sdk/tools/index.html @@ -0,0 +1,13 @@ +--- +title: Tools +slug: Mozilla/Add-ons/SDK/Tools +tags: + - Add-on SDK + - CFX + - JPM + - TopicStub +translation_of: Archive/Add-ons/Add-on_SDK/Tools +--- +

Les articles répertoriés ici fournissent une référence pour les outils du SDK:

+ +

{{ LandingPageListSubpages ("/en-US/Add-ons/SDK/Tools", 7) }}

diff --git a/files/fr/mozilla/add-ons/sdk/tools/jpm/index.html b/files/fr/mozilla/add-ons/sdk/tools/jpm/index.html new file mode 100644 index 0000000000..c079f3b0b5 --- /dev/null +++ b/files/fr/mozilla/add-ons/sdk/tools/jpm/index.html @@ -0,0 +1,600 @@ +--- +title: jpm +slug: Mozilla/Add-ons/SDK/Tools/jpm +translation_of: Archive/Add-ons/Add-on_SDK/Tools/jpm +--- +
+

Vous pouvez utiliser jpm pour Firefox 38 et au-delà.

+ +

Cet article est la référence pour jpm.

+
+ +

The Node-based replacement for cfx. Enables you to test, run, and package add-ons.

+ +

Voir aussi le tutoriel jpm pour débuter.

+ +

jpm usage is:

+ +
jpm [command] [options]
+
+ +

jpm supports the following global options:

+ +
-h, --help        - show a help message and exit
+-V, --version     - print the jpm version number
+
+ +

Installation

+ +

jpm is distributed using the node package manager npm, so to get jpm you need to have npm installed, if you haven't already. npm is included in Node.js. To install npm, you can either visit nodejs.org and download the latest binary or if you have a package manager like APT installed on your system, you might want to use this package manager to install npm. For example, if you are using an Ubuntu or Debian operating system, execute sudo apt-get install nodejs followed by sudo apt-get install npm in a terminal window.

+ +

After that you can install jpm just as you would any other npm package:

+ +
npm install jpm --global
+ +

Depending on your setup, you might need to run this as an administrator:

+ +
sudo npm install jpm --global
+ +

Or, you can install jpm using git:

+ +
git clone https://github.com/mozilla-jetpack/jpm.git
+cd jpm
+npm install
+npm link
+
+ +

À l'invite de commande, tapez:

+ +
jpm
+ +

You should see a screen summarizing the available jpm commands. Note that unlike cfx, jpm is available in every command prompt you start, as long as you installed it with the --global flag.

+ +

If you get an error message saying  /usr/bin/env: node: No such file or directory and you have installed nodejs through a package manager, nodejs may have been installed in the wrong directory. A corresponding topic at stackoverflow.org might help you to solve this problem. Basically, you can solve it by creating a symlink to the node:

+ +
sudo ln -s "$(which nodejs)" /usr/bin/node
+ +

Problems?

+ +

If you don't see this, ask for help. SDK users and project team members discuss problems and proposals on the project mailing list. Someone else may have had the same problem you do, so try searching the list. You're welcome to post a question, too. You can also chat with other SDK users in #jetpack on Mozilla's IRC network.

+ +

Command reference

+ +

There are six jpm commands:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
jpm initCreate a skeleton add-on as a starting point for your own add-on.
jpm runLaunch an instance of Firefox with your add-on installed.
jpm testRuns your add-on's unit tests.
jpm xpiPackage your add-on as an XPI file, which is the install file format for Firefox add-ons.
jpm postPackage your add-on as an XPI file, then post it to some url.
jpm watchpostPackage your add-on as an XPI file whenever there is a file changed, and post that to some url.
jpm signPackage your add-on as an XPI file, then retrieve a new XPI signed by Mozilla.
+ +

jpm init

+ +

This command initializes a new add-on from scratch.

+ +

Create a new directory, change into it, and run jpm init.

+ +
mkdir my-addon
+cd my-addon
+jpm init
+ +

You'll then be asked to supply some information about your add-on: this will be used to create your add-on's package.json file.

+ + + +

Most of these fields have a default, which is shown in brackets after the question. If you just press Enter, your add-on will get the default value.

+ +

Once you've supplied a value or accepted the default for these properties, you'll be shown the complete contents of "package.json" and asked to accept it.

+ +

Then jpm will create an skeleton add-on, as a starting point for your own add-on development, with the following file structure:

+ + + +

jpm run

+ +

This command runs a new instance of Firefox with the add-on installed:

+ +
jpm run
+ +

jpm run accepts the following options:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-b --binary BINARY +

Use the version of Firefox specified in BINARY. BINARY may be specified as a full path or as a path relative to the current directory.

+ +
+jpm run -b /path/to/Firefox/Nightly
+ See Selecting a browser version.
--binary-args CMDARGS +

Pass extra arguments to Firefox.

+ +

For example, to pass the -jsconsole argument to Firefox, which will launch the Browser Console, try the following:

+ +
+jpm run --binary-args -jsconsole
+ +

To pass multiple arguments, or arguments containing spaces, quote them:

+ +
+jpm run --binary-args '-url mzl.la -jsconsole'
+
--debugRun the add-on debugger attached to the add-on.
-o --overload PATH +

Rather than use the SDK modules built into Firefox, use the modules found at PATH. If -o is specified and PATH is omitted, jpm will look for the JETPACK_ROOT environment variable and use its value as the path.

+ +

See Overloading the built-in modules for more information.

+
-p --profile= PROFILE +

By default, jpm uses a clean temporary Firefox profile each time you call jpm run. Use the --profile option to instruct jpm to launch Firefox with an existing profile.

+ +

The PROFILE value may be a profile name or the path to the profile.

+ +

See Using profiles for more information.

+
-v --verboseVerbose operation.
--no-copy +
Use with caution because jpm run|test changes many preferences, never use with your main profile.
+ +
This only applies when --profile is used.
+ Disables the copying of the profile used, which allows one to reuse a profile.
 
+ +

jpm test

+ +

Use this command to run an add-on's unit tests. It will:

+ + + +
jpm test
+
+ +

See the tutorial on unit testing and the reference documentation for the assert module for more details on this.

+ +

jpm test accepts the following options:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-b --binary BINARY +

Use the version of Firefox specified in BINARY. BINARY may be specified as a full path or as a path relative to the current directory.

+ +
+jpm test -b /path/to/Firefox/Nightly
+ +

See Selecting a browser version.

+
--binary-args CMDARGS +

Pass extra arguments to Firefox.

+ +

For example, to pass the -jsconsole argument to Firefox, which will launch the Browser Console, try the following:

+ +
+jpm test --binary-args -jsconsole
+ +

To pass multiple arguments, or arguments containing spaces, quote them:

+ +
+jpm test --binary-args '-url mzl.la -jsconsole'
+
--debugRun the add-on debugger attached to the add-on.
-f --filter FILE[:TEST] +

Only run tests whose filenames match FILE and optionally match TEST, both regexps.

+ +
+jpm test --filter base64:btoa
+ +

The above command only runs tests in files whose names contain "base64", and in those files only runs tests whose names contain "btoa".

+
-o --overload PATH +

Rather than use the SDK modules built into Firefox, use the modules found at PATH. If -o is specified and PATH is omitted, jpm will look for the JETPACK_ROOT environment variable and use its value as the path.

+ +

See Overloading the built-in modules for more information.

+
-p --profile PROFILE +

By default, jpm uses a clean temporary Firefox profile each time you call jpm run. Use the --profile option to instruct jpm to launch Firefox with an existing profile.

+ +

The PROFILE value may be a profile name or the path to the profile.

+ +

See Using profiles for more information.

+
--stop-on-error +

By default jpm test keeps running tests even after tests fail. Specify --stop-on-error to stop running tests after the first failure:

+ +
+jpm test --stop-on-error
+
--tbplPrint test output in Treeherder format
--times NUMBER +

Run tests NUMBER of times:

+ +
+jpm test --times 2
+
-v --verboseVerbose operation.
--no-copy +
Use with caution because jpm run|test changes many preferences, never use with your main profile.
+ +
This only applies when --profile is used.
+ Disables the copying of the profile used, which allows one to reuse a profile.
+ +

jpm xpi

+ +

This command packages the add-on as an XPI file, which is the install file format for Mozilla add-ons.

+ +
jpm xpi
+ +

It looks for a file called package.json in the current directory and creates the corresponding XPI file. It ignores any ZIPs or XPIs in the add-on's root, and any test files. It includes all other files. If you want to exclude extra files, see the .jpmignore file.

+ +

Once you have built an XPI file you can distribute your add-on by submitting it to addons.mozilla.org.

+ +

jpm xpi accepts the following option:

+ + + + + + + + +
-v --verbose +

Verbose operation:

+ +
+jpm xpi -v
+
+ +

jpm post

+ +

This command packages the add-on as an XPI file then posts it to some url.

+ +
jpm post
+ +

It looks for a file called package.json in the current directory and creates a XPI file with which to post to the --post-url.

+ +

jpm post accepts the following options:

+ + + + + + + + + + + + +
--post-url URL +

The url to post the extension to after creating a XPI.

+ +
+jpm post --post-url http://localhost:8888/
+ +

See Using Post and Watchpost for more information.

+
-v --verbose +

Verbose operation:

+ +
+jpm post --post-url http://localhost:8888/ -v
+
+ +

jpm watchpost

+ +

This command packages the add-on as an XPI file then posts it to some url whenever a file in the current working directory changes.

+ +
jpm watchpost
+ +

Creates a XPI whenever a file in the current working directory changes and posts that to the --post-url.

+ +

jpm watchpost accepts the following options:

+ + + + + + + + + + + + +
--post-url URL +

The url to post the extension to after creating a XPI.

+ +
+jpm watchpost --post-url http://localhost:8888/
+ +

See Using Post and Watchpost for more information.

+
-v --verbose +

Verbose operation:

+ +
+jpm watchpost --post-url http://localhost:8888/ -v
+
+ +

jpm sign

+ +
+

This feature is only supported from jpm 1.0.4 onwards.

+
+ +

This command retrieves a new XPI for your add-on signed by Mozilla. This allows you to self-host your add-on so that users can install it without error when signed add-ons are required.

+ +
jpm sign --api-key ${AMO_API_KEY} --api-secret ${AMO_API_SECRET}
+ +

This creates an XPI, submits it to the addons.mozilla.org signing API, then downloads a new signed XPI to the working directory if it passes validation. Here are some possible outcomes of running the sign command:

+ + + +

Under the hood, jpm sign creates an unlisted add-on inside addons.mozilla.org which means you must distribute the XPI file yourself in order for your users to install it. If you need to create a listed add-on, just submit it directly to addons.mozilla.org where it will be signed automatically. See the debugging section if you're experiencing difficulty installing a signed add-on.

+ +

jpm sign accepts the following options:

+ + + + + + + + + + + + + + + + +
--api-key API_KEY +

API access key (string) generated on the addons.mozilla.org key management page.

+
--api-secret API_SECRET +

API access secret (string) generated on the addons.mozilla.org key management page. This value should be guarded with care and never checked into version control. If your secret is compromised, another developer could upload add-ons to your account. You should revoke and regenerate compromised API credentials immediately.

+
--api-url-prefix http://.../api +

An optional API URL prefix in case you'd like to use a pre-production signing API. Here is an example of using a dev instance of addons.mozilla.org :

+ +
+jpm sign ... --api-url-prefix https://addons-dev.allizom.org/api/v3
+
+ +

Techniques

+ +

Selecting a browser version

+ +

By default, jpm run and jpm test will run the release version of Firefox. You can instruct jpm to use a different version in one of two ways:

+ + + +

Using .jpmignore to ignore files

+ +

Using .jpmignore is similar to using .gitignore with git, .hgignore with Mercurial, or .npmignore with npm. By using this file you can let jpm know which files you would like it to ignore when building a .xpi file with jpm xpi.

+ +

Here is an example:

+ +
# Ignore .DS_Store files created by mac
+.DS_Store
+
+# Ignore any zip or xpi files
+*.zip
+*.xpi
+
+ +

A .jpmignore file with the above contents would ignore all zip files and .DS_Store files from the xpi generated by jpm xpi.

+ +

Using profiles

+ +

By default, jpm run uses a new profile each time it is executed. This means that any profile-specific data entered from one run of jpm will not, by default, be available in the next run.

+ +

This includes, for example, any extra add-ons you installed, or your history, or any data stored using the simple-storage API.

+ +

To make jpm use a specific profile, pass the --profile option, specifying the name of the profile you wish to use, or the path to the profile.

+ +
jpm run --profile boogaloo
+
+ +
jpm run --profile path/to/boogaloo
+ +

If you supply --profile but its argument is not the name of or path to an existing profile, jpm will open the profile manager,  enabling you to select and existing profile or create a new one:

+ +
jpm run --profile i-dont-exist
+ +

Developing without browser restarts

+ +

Because jpm run restarts the browser each time you invoke it, it can be a little cumbersome if you are making very frequent changes to an add-on. An alternative development model is to use the Extension Auto-Installer add-on: this listens for new XPI files on a specified port and installs them automatically. That way you can test new changes without needing to restart the browser:

+ + + +

You could even automate this workflow with a simple script. For example:

+ +
jpm watchpost --post-url http://localhost:8888/
+
+ +

Note that the logging level defined for the console is different when you use this method, compared to the logging level used when an add-on is run using jpm run. This means that if you want to see output from console.log() messages, you'll have to tweak a setting. See the documentation on logging levels for the details on this.

+ +

Overloading the built-in modules

+ +

The SDK modules you use to implement your add-on are built into Firefox. When you run or package an add-on using jpm run or jpm xpi, the add-on will use the versions of the modules in the version of Firefox that hosts it.

+ +

As an add-on developer, this is usually what you want. But if you're developing the SDK modules themselves, of course, it isn't. In this case you need to:

+ + + +
jpm run -o
+
+ +

This instructs jpm to use the local copies of the SDK modules, not the ones in Firefox. If you don't want to set the JETPACK_ROOT environment variable, you can pass the location of your copy of the SDK modules along with -o:

+ +
jpm run -o "/path/to/SDK/"
+ +

Supporting updates for self-hosted add-ons

+ +
+

This feature is only supported from jpm 1.0.3 onwards.

+
+ +

When you make updates to your add-on to add features or fix bugs, you'll want any previously installed versions of the add-on to update themselves to the new version.

+ +

If you list your add-on on addons.mozilla.org, then all you have to do here is submit the new version; add-ons default to checking addons.mozilla.org for new versions of themselves. You can stop reading this section.

+ +

If you do not list your add-on on addons.mozilla.org, you need to generate a Mozilla-signed XPI and tell Firefox where it can find new versions of your add-on. The way this works is:

+ + + +

To do this, include two extra keys in package.json:

+ + + +

+ +

If you include updateURL and updateLink (and also updateKey in case updateURL is not HTTPS), then jpm xpi will:

+ + + +

You then host the update manifest at updateURL, and host new versions of the XPI at updateLink.

+ +

For some more details on this, see Automatic Add-on Update Checking.

-- cgit v1.2.3-54-g00ecf