Basic extension template for Platform.Bible
This is a Webpack project template pre-configured to build a Platform.Bible extension. It contains the bare minimum of what an extension needs. Note that the *.web-view.* files and the public/assets folder mentioned in Summary are not present in this template. For inspiration on what these could look like, refer to any extension that is built using this template. An example would be the Text Collection extension.
There is also a template pre-configured to build an arbitrary number of Platform.Bible extensions in one repo.
Follow these instructions to customize the template to be your own Platform.Bible extension. This section is a more generalized version of the Your first extension guide, which contains step-by-step instructions to build a "Hello World" extension.
Note: please skip this section and continue with Replace placeholders if you are following these instructions as part of creating an extension within paranext-multi-extension-template.
To make the process of customizing from the template as smooth as possible, we recommend you do the following before anything else:
- Install and set up this repo
- Update this extension from the template to hook everything up for smooth updates in the future.
For your extension name, we recommend that you use lowerCamelCase in some contexts and kebab-case in other contexts. We generally recommend lowerCamelCase when using the name in code (like making a new command on the PAPI, for example), and we recommend kebab-case when using the name in relation to the file system, the repository, npm, and the extension's .d.ts types module. The following instructions are written accordingly.
-
At the top of this
README.md:- Replace the first line
# paranext-extension-templatewith# your-extension-name(kebab-case) - Below the first line, replace the extension description with your own description
- In the Summary section, replace
src/types/paranext-extension-template.d.tswithsrc/types/your-extension-name.d.ts(kebab-case)
- Replace the first line
-
In
manifest.json:- Replace
paranextExtensionTemplatewithyourExtensionName(lowerCamelCase) - Replace
src/types/paranext-extension-template.d.tswithsrc/types/your-extension-name.d.ts(kebab-case) - Update ownership information and other relevant fields as desired
- Replace
-
In
package.json:- Replace
paranext-extension-templatewithyour-extension-name(2 occurrences - kebab-case) - Update ownership information and other relevant fields as desired
- Replace
-
In
assets/displayData.json:-
If your extension has an icon, update the
iconvalue to point towards the icon file (for example:assets/icon.svg) -
Update the
moreInfoUrlfield to web URL to a page where users can find out more information about you / your organization / your extension. -
Update the
supportUrlfield to web URL to a support page where users can request help and report issues with your extension. -
Update the
enentry oflocalizedDisplayInfoso that:displayNamecontains a human-readable name for your extension (i.e.Your Extension Name).shortSummarycontains a short, few sentence summary of what your extension does.descriptionpoints to a Markdown (.md) file containing the full description of your extension (similar to what you would put in aREADME).
-
If your extension supports multiple languages, add another entry to
localizedDisplayInfoby copying and pasting theenentry, changingento the BCP 47 language tag of the language you want to support, and translating thedisplayName,shortSummary, anddescriptionfields appropriately. We recommend naming your description filesdescription-<language tag>.md.
-
-
In
LICENSE:- Adjust as desired (feel free to choose a different license)
- If you choose to stay with the current license, update the copyright statement
-
Rename
src/types/paranext-extension-template.d.tstosrc/types/your-extension-name.d.ts(kebab-case)- In this renamed file, replace
paranext-extension-templatewithyour-extension-name
- In this renamed file, replace
-
In
src/main.ts, replaceExtension templatewithYour Extension Name(2 occurrences) -
In
.github/assets/release-body.md, replaceExtension templatewithYour Extension Name, and make other adjustments as desired.
The manifest.json and package.json files contain information specific to your extension. Add your extension's details in these two files as needed. See more information on the manifest.json and package.json files in Extension Anatomy.
Once finished customizing this template to be your own, you can uncomment the HTML comment tag above the Template Info section to hide this template-related info in this readme. You can do this by clicking on the line and doing CTRL + / in VS Code. You can also do this manually by removing the first opening '<!--' and the only closing '-->' on the line. Leaving this info commented in your readme will hide it in your readme while avoiding merge conflicts if you decide to update this extension from the template in the future. If you never want to update this extension from the template, you can remove the Template Info section and sub-sections of this readme.
Note: if you update this extension from the template, there may be important changes in this section like additional customizations you must make to this extension. Please keep an eye out for readme changes when updating from the template.
The general file structure is as follows:
package.jsoncontains information about this extension's npm package. It is required for Platform.Bible to use the extension properly. It is copied into the build foldermanifest.jsonis the manifest file that defines the extension and important properties for Platform.Bible. It is copied into the build foldersrc/contains the source code for the extensionsrc/main.tsis the main entry file for the extensionsrc/types/paranext-extension-template.d.tsis this extension's types file that defines how other extensions can use this extension through thepapi. It is copied into the build folder*.web-view.tsxfiles will be treated as React WebViews*.web-view.htmlfiles are a conventional way to provide HTML WebViews (no special functionality)
assets/contains asset files the extension and its WebViews can retrieve using thepapi-extension:protocol, as well as textual descriptions in various languages. It is copied into the build folderassets/displayData.jsoncontains (optionally) a path to the extension's icon file as well as text for the extension's display name, short summary, and path to the full description fileassets/descriptions/contains textual descriptions of the extension in various languagesassets/descriptions/description-<locale>.mdcontains a brief description of the extension in the language specified by<locale>
contributions/contains JSON files the platform uses to extend data structures for things like menus and settings. The JSON files are referenced from the manifestpublic/contains other static files that are copied into the build folder.github/contains files to facilitate integration with GitHub.github/workflowscontains GitHub Actions workflows for automating various processes in this repo.github/assets/release-body.mdcombined with a generated changelog becomes the body of releases published using GitHub Actions
dist/is a generated folder containing the built extension filesrelease/is a generated folder containing a zip of the built extension files
- Follow the instructions to install
paranext-core. We recommend you cloneparanext-corein the same parent directory in which you cloned this repository so you do not have to reconfigure paths toparanext-core. - In this repo, run
npm installto install local and published dependencies
If you cloned paranext-core anywhere other than in the same parent directory in which you cloned this repository, update the paths to paranext-core in this repository's package.json to point to the correct paranext-core directory.
To run Platform.Bible with this extension:
npm start
Note: The built extension will be in the dist folder. In order for Platform.Bible to run this extension, you must provide the directory to this built extension to Platform.Bible via a command-line argument. This command-line argument is already provided in this package.json's start script. If you want to start Platform.Bible and use this extension any other way, you must provide this command-line argument or put the dist folder into Platform.Bible's extensions folder.
To watch extension files (in src) for changes:
npm run watch
To build the extension once:
npm run build
To package this extension into a zip file for distribution:
npm run package
These steps will walk you through releasing a version on GitHub and bumping the version to a new version so future changes apply to the new in-progress version.
-
Make sure the versions in this repo are on the version number you want to release. If they are not, run the
bump-versionsnpm script to set the versions to what you want to release. This script will create a branch namedbump-versions-<version>from your current head with the needed changes. Open a PR and merge that new branch into the branch you plan to release from. For example, to bump branchmy-branchto version 0.2.0, run the following:git checkout my-branch npm run bump-versions 0.2.0
Then create a PR and merge the
bump-versions-0.2.0branch intomy-branch.my-branchis now ready for release. -
Manually dispatch the Publish workflow in GitHub Actions targeting the branch you want to release from (in the previous example, this would be
my-branch). This workflow creates a new pre-release for the version you intend to release and creates a newbump-versions-<next_version>branch to bump the version after the release so future changes apply to a new in-progress version instead of to the already released version. This workflow has the following inputs:version: enter the version you intend to publish (e.g. 0.2.0). This is simply for verification to make sure you release the code that you intend to release. It is compared to the version in the code, and the workflow will fail if they do not match.newVersionAfterPublishing: enter the version you want to bump to after releasing (e.g. 0.3.0-alpha.0). Future changes will apply to this new version instead of to the version that was already released. Leave blank if you don't want to bumpbumpRef: enter the Git ref you want to create the bump versions branch from, e.g.main. Leave blank if you want to use the branch selected for the workflow run. For example, if you release from a stable branch namedrelease-prep, you may want to bump the version onmainso future development work happens on the new version, then you can rebaserelease-prepontomainwhen you are ready to start preparing the next stable release.
[Optional] Create a new pre-release and bump versions branch manually
Alternatively, you can create a new pre-release manually:
npm run package # Create a new pre-release in GitHub on tag `v<version>` # Copy `.github/assets/release-body.md` into the GitHub branch # Generate changelog # Attach contents of `release` folder
Then bump versions by running the following:
npm run bump-versions <next_version>
Or bump versions manually:
git checkout -b bump-versions-<next_version> npm version <next_version> --git-tag-version false # Change version in each extension's `manifest.json` git commit -a -m "Bumped versions to <next_version>"; git push -u origin HEAD
-
In GitHub, adjust the new draft release's body and other metadata as desired, then publish the release.
-
Open a PR and merge the newly created
bump-versions-<next_version>branch.
Following are some problems you may encounter while publishing and steps to solve them.
If you see the following error in the GitHub Actions workflow logs while packaging:
Module build failed (from ./node_modules/swc-loader/src/index.js):
Error: Failed to load native binding
You may have a different effective version of @swc/core than paranext-core does. Please make sure the version of @swc/core in your package-lock.json is the same as its version in paranext-core/package-lock.json. If they are not the same, please fix them to be the same by running npm i -D @swc/core <version> where the version is the version of @swc/core installed in paranext-core/package-lock.json (if you would like to set the version of @swc/core back to what it was before in package.json to stay synced with the extension template, change it back manually in package.json and then run npm i). If they are already the same, you may need to try regenerating your package-lock.json file by deleting it and running npm i.
This extension project is forked from paranext-extension-template, which is updated periodically and will sometimes receive updates that help with breaking changes on paranext-core. We recommend you periodically update your extension by merging the latest template updates into your extension.
To set up this extension to be updated from the template, run the following command once after cloning this repo:
git remote add template https://github.com/paranext/paranext-extension-templateTo update this extension from the template, make sure your repo has no working changes. Then run the following commands:
git fetch template
git merge template/main --allow-unrelated-historiesFor more information, read the instructions on the wiki.
Note: The merge/squash commits created when updating this repo from the template are important; Git uses them to compare the files for future updates. If you edit this repo's Git history, please preserve these commits (do not squash them, for example) to avoid duplicated merge conflicts in the future.
This project has special features and specific configuration to make building an extension for Platform.Bible easier. See Special features of paranext-multi-extension-template for information on these special features.