Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

jpm

Перевод не завершен. Пожалуйста, помогите перевести эту статью с английского.

Вы можете использовать jpm для Firefox 38 или более поздних версий.

Данный материал относится только для jpm.

Это Node-ориентированная замена устаревшего cfx. Даёт вам возможность тестировать, запускать и создавать дополнения для Firefox.

Смотри также jpm tutorial.

jpm вызывается через:

jpm [command] [options]

jpm поддерживает следующие глобальные опции:

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

Установка

jpm распространяется с помощью менеджера пакетов npm, поэтому чтобы установить jpm, вам необходимо предварительно установить менеджер пакетов npm, если вы этого ещё не сделали. npm входит в Node.js, поэтому чтобы установить npm - посетите nodejs.org и нажмите кнопку INSTALL.

После этого вы можете установить jpm, как и любой другой npm пакет:

npm install jpm -g

В зависимости от настроек и операционной системы, вам может потребоваться запустить его с правами администратора (Linux: Debian, Ubuntu, и т.п.):

sudo npm install jpm -g

После установки введите в командной строке:

jpm

Вы должны увидеть краткое описание доступных команд. Обратите внимание, что в отличие от cfx, jpm is available in every command prompt you start, as long as you installed it with the -g flag.

Проблемы?

Если у вас возникли проблемы, то обратитесь за помощью. Пользователи SDK и участники проекта готовы обсудить и предложения в project mailing list. Попробуйте поискать там, возможно похожий вопрос уже обсуждался там. Вы также можете обратиться к пользователям SDK в #jetpack на Mozilla's IRC network.

Справочник команд

В jpm доступно шесть команд:

jpm init Create a skeleton add-on as a starting point for your own add-on.
jpm run Launch an instance of Firefox with your add-on installed.
jpm test Runs your add-on's unit tests.
jpm xpi Package your add-on as an XPI file, which is the install file format for Firefox add-ons.
jpm post Package your add-on as an XPI file, then post it to some url.
jpm watchpost Package your add-on as an XPI file whenever there is a file changed, and post that to some url.

jpm init

Данная команда инициализирует новое дополнение, с нуля.

Для этого создайте новый каталог, перейдите в него и запустите jpm init.

mkdir my-addon
cd my-addon
jpm init

Вам будет предложено указать некоторую информацию о вашем дополнение: данная информация будет использована для создания файла настроек дополнения package.json.

Большинство из этих полей имеют значения по умолчанию, который указан в скобках после вопроса. Если вы просто нажмите Enter, то в настройках будет указано значение по умолчанию.

После того как вы укажете значения или выберите значение по умолчанию для этих свойств, вам будет показано полное содержание "package.json" и предложено принять его.

После jpm создаст каркас дополнения в качестве отправной точки для разрабатываемого вами дополнения, со следующей структурой файлов:

  • my-addon
    • index.js
    • package.json
    • test
      • test-index.js

jpm run

Эта команда запускает новый экземпляр Firefox с подключенным дополнением:

jpm run

jpm run принимает следующие значения:

-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'
--debug Run 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 --verbose Verbose 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:

  • look for a directory called "test" under the add-on's root
  • open every file in there whose name starts with "test-" (note the hyphen after "test" in the filename. jpm test will include a file called "test-myCode.js", but will exclude files called "test_myCode.js" or "testMyCode.js")
  • call every function exported from that file whose name starts with "test"
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'
--debug Run 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
--tbpl Print test output in Treeherder format
--times NUMBER

Run tests NUMBER of times:

jpm test --times 2
-v --verbose Verbose 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

Эта команда собирает дополнение в пакет XPI. Это формат дополнений, которые можно легко установить Mozilla.

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.

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, the 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 https://localhost:8888/

See Using Post and Watchpost for more information.

-v --verbose

Verbose operation:

jpm post --post-url https://localhost:8888/ -v

jpm watchpost

This command packages the add-on as an XPI file, the 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 https://localhost:8888/

See Using Post and Watchpost for more information.

-v --verbose

Verbose operation:

jpm watchpost --post-url https://localhost:8888/ -v

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:

  • you can use the -b or --binary option to instruct jpm to run a different version of Firefox. You can supply a path to a specific binary:

    jpm run -b /path/to/Firefox/Nightly

    As a shorthand for this, you can pass "nightly", "aurora", "beta", or "firefox" and jpm will look in the default location for these Firefox versions:

    jpm run -b nightly
  • you can set the JPM_FIREFOX_BINARY environment variable with the path to the version of Firefox you want to run. When you invoke jpm run or jpm test without the -b option, jpm will first check  JPM_FIREFOX_BINARY, and use this as the path if it is set.

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:

  • make a change to your add-on
  • run jpm post --post-url https://localhost:8888/, to make a xpi and post it.

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

jpm watchpost --post-url https://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:

  • get a local copy of the SDK modules that you want: this usually means checking out the SDK from its GitHub repo
  • set the JETPACK_ROOT environment variable to your local copy
  • pass the -o option to jpm run or jpm xpi:
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/"

Метки документа и участники

 Внесли вклад в эту страницу: BaNru
 Обновлялась последний раз: BaNru,