Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge remote-tracking branch 'template/main' into merge-webpack-changes-from-template #11

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
73b6310
Initial commit
tjcouch-sil Jan 17, 2023
1a3c09a
Added Vite/TypeScript/React and pulling papi types
tjcouch-sil Apr 26, 2023
f6c550b
Added package.json for extension because Paranext needs it
tjcouch-sil Apr 26, 2023
773e2f7
Added Vite/TypeScript/React and pulling papi.d.ts (#6)
tjcouch-sil Apr 26, 2023
a388924
Changed extensions back to commonjs because paranext does not support…
tjcouch-sil Apr 26, 2023
066cfca
Removed data provider info
tjcouch-sil Apr 26, 2023
d567018
Changed extensions back to commonjs because paranext does not support…
tjcouch-sil Apr 27, 2023
c5f822e
Added scss style example
tjcouch-sil Apr 27, 2023
079674d
Added scss style example (#8)
tjcouch-sil Apr 27, 2023
090a058
Added support for running paranext with this extension, added source …
tjcouch-sil May 3, 2023
111bb1c
Fixed typo in type declaration reference
tjcouch-sil May 4, 2023
f537c4d
Updated to new command-line argument name
tjcouch-sil May 4, 2023
0df259d
Moved vite config into vite folder
tjcouch-sil May 4, 2023
20aa3f3
Began splitting Vite into two build steps
tjcouch-sil May 5, 2023
46fe8ec
WebViews transpile and output into adjacent temp-vite folder
tjcouch-sil May 5, 2023
94fd341
Build step 2 grabs web view files built in step 1, excluded imports f…
tjcouch-sil May 8, 2023
518deb0
Got two-step vite build working, changed React webviews to use global…
tjcouch-sil May 9, 2023
4172c26
Cleanup
tjcouch-sil May 9, 2023
bd11174
Fixed build:vite, cleanup
tjcouch-sil May 9, 2023
33c0567
Small fix to the readme
FoolRunning May 10, 2023
04a478c
Some cleanup, adding comments where config is shared with paranext-core
tjcouch-sil May 15, 2023
85d2c3c
Upgraded to latest rollup-plugin-import-manager which includes the pa…
tjcouch-sil May 15, 2023
cec8985
Used imports in web view
tjcouch-sil May 15, 2023
e10fc2f
Added notice about import manager false positive
tjcouch-sil May 15, 2023
aebf2fa
Updated calls to addWebView
tjcouch-sil May 15, 2023
0efd9bf
Merge remote-tracking branch 'origin/main' into core-119-sourcemaps
tjcouch-sil May 15, 2023
fe6588a
Update rollup-plugin-import-manager to latest
tjcouch-sil May 16, 2023
2bd0eb8
Split Vite build into two steps to enable WebView debugging and libra…
tjcouch-sil May 16, 2023
c10f4a2
Replace NODE_ENV on WebViews in Vite (#12)
irahopkinson May 17, 2023
19b7a90
Updated data provider to data type api, other updates to match existi…
tjcouch-sil May 25, 2023
41280f1
Updated useData to new type api
tjcouch-sil May 26, 2023
c42497e
Updated to newer data provider api
tjcouch-sil Jun 2, 2023
0b4732b
Fix vite security vulnerability (#16)
irahopkinson Jun 8, 2023
a00a23d
Converted papi components to use package
tjcouch-sil Jun 13, 2023
4ea90e1
Bumped rollup-plugin-import-manager to fix irregular require statements
tjcouch-sil Jun 13, 2023
9cf57cf
Updated template to use web view provider api
tjcouch-sil Jun 13, 2023
f50db2b
Added template web view providers (#19)
tjcouch-sil Jun 13, 2023
9fc0646
Merge remote-tracking branch 'origin/main' into core-109-data-provide…
tjcouch-sil Jun 13, 2023
0028491
Updated data provider to data type api (#13)
tjcouch-sil Jun 18, 2023
f72d9f7
Update for split `papi.d.ts` (#20)
irahopkinson Jun 22, 2023
30e8847
Upgrade TypeScript (#21)
irahopkinson Jun 26, 2023
cc18c83
Shared paranext extension types, improved getting papi-dts
tjcouch-sil Jun 15, 2023
cda06b5
Converted extension types to modules, removed unnecessary path aliases
tjcouch-sil Jun 26, 2023
7b37b18
Fixed extension import in main
tjcouch-sil Jun 26, 2023
6a4b2b6
Use extension lib types instead of dist
tjcouch-sil Jul 5, 2023
1293300
Replace fetch to bible-api.com with the USFM data provider (#22)
lyonsil Jul 5, 2023
b564a87
Set `.editorconfig` (#23)
irahopkinson Jul 6, 2023
4efc66a
Update command syntax for papi-commands
tjcouch-sil Jul 7, 2023
39e5e34
Merge remote-tracking branch 'origin/main' into core-69-share-types
tjcouch-sil Jul 7, 2023
23d1849
Added more explanation for why we have public/assets/index.d.ts
tjcouch-sil Jul 7, 2023
f5bb4ab
Lower camel case in most ids
tjcouch-sil Jul 10, 2023
630247f
Standalone extensions, bundled extensions, and Core share types (#24)
tjcouch-sil Jul 12, 2023
03502f5
Fix problems seen when using the latest core branch (#25)
lyonsil Jul 14, 2023
d87be1c
Update security vulnerabilities (#30)
irahopkinson Jul 24, 2023
5e5d017
Changed build tool to webpack, many other small improvements
tjcouch-sil Jul 18, 2023
3db2f6d
Changed folder structure: lib to src, dist to release, and build to dist
tjcouch-sil Jul 18, 2023
3e95131
Various fixes and tweaks found while converting paranext-core to webpack
tjcouch-sil Jul 21, 2023
4e0228b
Added DEBUG_PROD for sourcemaps in production builds
tjcouch-sil Jul 21, 2023
94086ed
Minor update to package-lock.json
tjcouch-sil Jul 24, 2023
5b048d0
Added import that got removed in the rebase
tjcouch-sil Jul 24, 2023
d9ac4b3
Switched to commonjs-static modules for more predictable use
tjcouch-sil Jul 25, 2023
4f184fd
Prettier formatted all files
tjcouch-sil Jul 25, 2023
2a708a6
Changed extension dependencies to peerDependencies since the only ing…
tjcouch-sil Jul 26, 2023
89182dc
Changed extension bundling from Vite to webpack (#29)
tjcouch-sil Jul 26, 2023
a6364cf
Removed data url support since paranext does not support them
tjcouch-sil Jul 27, 2023
ab7c656
Removed data url support since paranext does not support them (#32)
tjcouch-sil Jul 27, 2023
be3024a
Apply updates based on changes to core
lyonsil Jul 31, 2023
fdb9025
Apply updates based on changes to core (#33)
lyonsil Jul 31, 2023
bfc8b14
Debug production (#34)
irahopkinson Aug 1, 2023
4e81002
[WIP] Merge remote-tracking branch 'template/main' into merge-webpack…
tombogle Aug 1, 2023
be9cdb9
Fixed name of types file in webpack.config.main.ts
tombogle Aug 2, 2023
b8dc5d6
Merge remote-tracking branch 'template/main' into merge-of-webpack-st…
tombogle Aug 3, 2023
be40da0
Removed the unsubscriber-related code. This is a follow-on to the pre…
tombogle Aug 3, 2023
bd934ac
Fixed problem with sneeze board and added unsubscribers to context.re…
tombogle Aug 3, 2023
e35360f
Removed an asset file that came in from the template but is not neede…
tombogle Aug 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*

node_modules
dist
release
dist-ssr
*.local

Expand All @@ -21,5 +22,5 @@ dist-ssr
*.sln
*.sw?

# Vite-built temp WebView files
temp-vite
# Temporary intermediate build files
temp-build
107 changes: 69 additions & 38 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Watch and Build Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "start:vite"]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Watch and Build Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "watch"]
},
{
"name": "Build WebViews",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "build:web-view"]
},
{
"name": "Build Main",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "build:main"]
},
{
"name": "Build Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "build"]
},
{
"name": "Debug Platform with Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start"],
"skipFiles": ["<node_internals>/**"],
"env": {
"MAIN_ARGS": "--inspect=5858 --remote-debugging-port=9223",
"IN_VSCODE": "true"
},
{
"name": "Build Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["run", "build:vite"]
},
{
"name": "Debug Paranext Core with Extension",
"type": "node",
"request": "launch",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "start"],
"skipFiles": ["<node_internals>/**"],
"env": {
"MAIN_ARGS": "--inspect=5858 --remote-debugging-port=9223",
"IN_VSCODE": "true"
},
"presentation": {
"hidden": false,
"group": "",
"order": 1
}
"presentation": {
"hidden": false,
"group": "",
"order": 1
}
]
}
},
{
"name": "Attach to Platform app",
"type": "node",
"request": "attach",
"port": 5858,
"timeout": 15000
},
{
"name": "Attach to Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 15000
}
]
}
32 changes: 31 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
"editor.wordWrapColumn": 100,

"files.eol": "\n",
"cSpell.words": [
"asyncs",
"endregion",
"papi",
"paranext",
"sillsdev",
"unsub",
"unsubscriber",
"usfm"
],

"cSpell.words": ["asyncs", "papi", "paranext", "unsub", "unsubscriber", "unsubscribers"]
"todohighlight.keywords": [
{
"text": "WARNING:",
"isWholeLine": true,
"color": "#FF0000",
"backgroundColor": "none",
"overviewRulerColor": "#FF000000"
},
{
"text": "#region",
"color": "#6cf5ff",
"backgroundColor": "none",
"overviewRulerColor": "#6cf5ff60"
},
{
"text": "#endregion",
"color": "#6cf5ff",
"backgroundColor": "none",
"overviewRulerColor": "#6cf5ff60"
}
]
}
91 changes: 58 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ Example Paranext extension to display a Sneeze Board

## Summary

This is a sample Paranext extension project: Sneeze Board to track team members' work-related sneezes.

- `lib` contains the source code for the extension
- `lib/main.ts` is the main entry file for the Sneeze Board extension
- `sneeze-board.web-view.tsx` file defines a React WebView that Paranext displays
- `public` contains static files that are transferred to the build folder
- `public/manifest.json` is the manifest file that defines the extension
- `public/package.json` defines the npm package for this extension and is required for Paranext to use it appropriately
- `public/paranext-extension-sneeze-board.d.ts` is this extension's types file that other extensions can use
- `dist` is a generated folder containing the built extension files
This is a sample webpack Platform.Bible extension project: Sneeze Board to track team members' work-related sneezes.
- `package.json` contains information about this extension npm package. It is required for Platform.Bible to use the extension properly. It is copied into the build folder
- `src` contains the source code for the extension
- `src/main.ts` is the main entry file for the Sneeze Board extension
- `src/types/sneeze-board.d.ts` is this extension's types file that defines how other extensions can use this extension through the `papi`. It is copied into the build folder
- `sneeze-board.web-view.tsx` file defines a React WebView that Platform.Bible displays
- `public` contains static files that are copied into the build folder
- `public/manifest.json` is the manifest file that defines the Sneeze Board extension and important properties for Platform.Bible
- `public/package.json` defines the npm package for this extension and is required for Platform.Bible to use it appropriately
- `public/assets` contains asset files the extension and its WebViews can retrieve using the `papi-extension:` protocol
- `dist` is a generated folder containing the built extension files
- `release` is a generated folder containing a zip of the built extension files

## To install

Expand All @@ -35,41 +37,64 @@ To run Paranext with your extension:

`npm start`

Note: The built extension will be in the `dist` folder. In order for Paranext to run your extension, you must provide the directory to your built extension to Paranext via a command-line argument. This command-line argument is already provided in this `package.json`'s `start` script. If you want to start Paranext and use your extension any other way, you must provide this command-line argument or put the `dist` folder into Paranext's `extensions` folder.
Note: The built extension will be in the `dist` folder. In order for Platform.Bible to run your extension, you must provide the directory to your 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 the Sneeze Board extension any other way, you must provide this command-line argument or put the `dist` folder into Platform.Bible's `extensions` folder.

### Building your extension independently

To watch extension files (in `lib`) for changes:
To watch extension files (in `src`) for changes:

`npm run watch`

To build the Sneeze Board extension once:

`npm run build`

## To package for distribution

To package the Sneeze Board extension into a zip file for distribution:

`npm run package`

## Special features of the template

`npm run start:vite`
The paranext-extension-template has special features and specific configuration to make building an extension for Platform.Bible easier. Following are a few important notes:

To build the extension once:
### React WebView files - `.web-view.tsx`

`npm run build:vite`
Platform.Bible WebViews must be treated differently than other code, so the template makes doing that simpler:

## Vite Build Explanation
- WebView code must be bundled and can only import specific packages provided by Platform.Bible (see `externals` in `webpack.config.base.ts`), so this template bundles React WebViews before bundling the main extension file to support this requirement. The template discovers and bundles files that end with `.web-view.tsx` in this way.
- Note: while watching for changes, if you add a new `.web-view.tsx` file, you must either restart webpack or make a nominal change and save in an existing `.web-view.tsx` file for webpack to discover and bundle this new file.
- WebView code and styles must be provided to the `papi` as strings, so you can import WebView files with [`?inline`](#special-imports) after the file path to import the file as a string.

This extension sneeze-board is built by Vite in two steps: a WebView transpilation step and a packaging step:
### Special imports

## Build 1: TypeScript WebView transpilation
- Adding `?inline` to the end of a file import causes that file to be imported as a string after being transformed by webpack loaders but before bundling dependencies (except if that file is a React WebView file, in which case dependencies will be bundled). The contents of the file will be on the file's default export.
- Ex: `import myFile from './file-path?inline`
- Adding `?raw` to the end of a file import treats a file the same way as `?inline` except that it will be imported directly without being transformed by webpack.

Vite prepares TypeScript WebViews for use and outputs them into `temp-vite` folders adjacent to the WebView files:
- Formats WebViews to match how they should look to work in Paranext
### Misc features

- Platform.Bible extension code must be bundled all together in one file, so webpack bundles all the code together into one main extension file.
- Platform.Bible extensions can interact with other extensions, but they cannot import and export like in a normal Node environment. Instead, they interact through the `papi`. As such, the `src/types` folder contains this extension's declarations file that tells other extensions how to interact with it through the `papi`.

### Two-step webpack build

This extension template is built by webpack (`webpack.config.ts`) in two steps: a WebView bundling step and a main bundling step:

#### Build 1: TypeScript WebView bundling

Webpack (`./webpack/webpack.config.web-view.ts`) prepares TypeScript WebViews for use and outputs them into temporary build folders adjacent to the WebView files:
- Formats WebViews to match how they should look to work in Platform.Bible
- Transpiles React/TypeScript WebViews into JavaScript
- Packages dependencies into the WebViews
- Bundles dependencies into the WebViews
- Embeds Sourcemaps into the WebViews inline

## Built 2: Packaging
#### Build 2: Main and final bundling

Vite packages the extension together into the `dist` folder:
Webpack (`./webpack/webpack.config.main.ts`) prepares the main extension file and bundles the extension together into the `dist` folder:
- Transpiles the main TypeScript file and its imported modules into JavaScript
- Injects the WebViews into the main file
- Packages dependencies into the main file
- Generates sourcemaps for the file
- Packages everything up into an extension folder in `dist`

Note: When performing the second build step, the following line may occur in your console. Please feel free to ignore it as it is a false positive. It is likely showing because WebViews are embedded in the entry file:

```bash
transforming (1) lib\main.ts[plugin:ImportManager] It seems like there are multiple imports of module 'react'. You should examine that.
```
- Injects the bundled WebViews into the main file
- Bundles dependencies into the main file
- Embeds Sourcemaps into the file inline
- Packages everything up into an extension folder `dist`
1 change: 0 additions & 1 deletion lib/vite-env.d.ts

This file was deleted.

Loading