Skip to content

Commit 3d4597a

Browse files
erickzhaogitbook-bot
authored andcommitted
GITBOOK-190: Document forge config transpilation
1 parent becf880 commit 3d4597a

File tree

10 files changed

+133
-94
lines changed

10 files changed

+133
-94
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Configuration <a href="#config" id="config"></a>
1313

1414
* [Overview](config/configuration.md)
15+
* [TypeScript Configuration](config/typescript-configuration.md)
1516
* [Plugins](config/plugins/README.md)
1617
* [Webpack Plugin](config/plugins/webpack.md)
1718
* [Vite Plugin](config/plugins/vite.md)

config/publishers/bitbucket.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# Bitbucket
1+
---
2+
description: >-
3+
The Bitbucket publish target allows you to publish your artifacts directly to
4+
Bitbucket where users will be able to download them.
5+
---
26

3-
The Bitbucket publish target allows you to publish your artifacts directly to Bitbucket where users will be able to download them.
7+
# Bitbucket
48

59
{% hint style="warning" %}
610
This publish target is for [Bitbucket Cloud](https://bitbucket.org) only and will not work with self hosted Bitbucket Server instances.
711
{% endhint %}
812

9-
## Installation
10-
11-
```bash
12-
npm install --save-dev @electron-forge/publisher-bitbucket
13-
```
13+
Full configuration options are documented in [`PublisherBitbucketConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_bitbucket.PublisherBitbucketConfig.html).
1414

1515
## Usage
1616

17-
To use `@electron-forge/publisher-bitbucket`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
18-
1917
{% code title="forge.config.js" %}
2018
```javascript
2119
module.exports = {
@@ -39,7 +37,18 @@ module.exports = {
3937
```
4038
{% endcode %}
4139

42-
Full configuration options are documented in [`PublisherBitbucketConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_bitbucket.PublisherBitbucketConfig.html).
40+
you can (and should) use environment variables for the authentication
41+
42+
{% code title="env.sh" %}
43+
```bash
44+
BITBUCKET_USERNAME="myusername"
45+
BITBUCKET_APP_PASSWORD="mysecretapppassword"
46+
```
47+
{% endcode %}
48+
49+
```bash
50+
$ source env.sh
51+
```
4352

4453
{% hint style="info" %}
4554
Your artifacts can be found under the `Downloads` tab of your Bitbucket repository.

config/publishers/electron-release-server.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ The Electron Release Server target publishes all your artifacts to a hosted inst
44

55
Please note that Electron Release Server is a community powered project and is not associated with Electron Forge or the Electron project directly.
66

7-
## Installation
8-
9-
```bash
10-
npm install --save-dev @electron-forge/publisher-electron-release-server
11-
```
12-
13-
## Usage
7+
Configuration options are documented in [`PublisherERSConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_electron\_release\_server.PublisherERSConfig.html).
148

15-
To use `@electron-forge/publisher-electron-release-server`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
9+
### Usage
1610

1711
{% code title="forge.config.js" %}
1812
```javascript
@@ -31,5 +25,3 @@ module.exports = {
3125
};
3226
```
3327
{% endcode %}
34-
35-
Configuration options are documented in [`PublisherERSConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_electron\_release\_server.PublisherERSConfig.html).

config/publishers/gcs.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ This Publisher was added in Electron Forge **v7.1.0**.
1010

1111
The Google Cloud Storage target publishes all your artifacts to a [Google Cloud Storage bucket](https://cloud.google.com/storage/docs).
1212

13-
## Installation
13+
## Authentication
1414

15-
```bash
16-
npm install --save-dev @electron-forge/publisher-gcs
17-
```
15+
Under the hood, the Google Cloud Storage Publisher uses the `@google-cloud/storage` SDK and its associated authentication options.
16+
17+
We recommend following [Google's authentication documentation for client libraries](https://cloud.google.com/docs/authentication/client-libraries#node.js) to get authentication configured.
1818

1919
## Usage
2020

21-
To use `@electron-forge/publisher-gcs`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
21+
To pass options into the Google Cloud Storage SDK's [Storage constructor](https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/storageoptions), use the `config.storageOptions` parameter.
2222

2323
{% code title="forge.config.js" %}
2424
```javascript
@@ -42,24 +42,14 @@ module.exports = {
4242
```
4343
{% endcode %}
4444

45-
Additional configuration options are documented in [`PublisherGCSConfig`](http://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_gcs.PublisherGCSConfig.html).
46-
47-
To pass options into the Google Cloud Storage SDK's [Storage constructor](https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/storageoptions), use the `config.storageOptions` parameter.
48-
49-
### Output location
50-
5145
When executed, the Publisher will publish to your GCS bucket under the following key:
5246

5347
```
5448
${config.folder || version}/${artifactName}
5549
```
5650

51+
Additional configuration options are documented in [`PublisherGCSConfig`](http://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_gcs.PublisherGCSConfig.html).
52+
5753
{% hint style="warning" %}
5854
If you run publish twice with the same version on the same platform, it is possible for your old artifacts to get overwritten in Storage. It is your responsibility to ensure that you don't overwrite your own releases.
5955
{% endhint %}
60-
61-
### Authentication
62-
63-
Under the hood, the Google Cloud Storage Publisher uses the `@google-cloud/storage` SDK and its associated authentication options.
64-
65-
We recommend following [Google's authentication documentation for client libraries](https://cloud.google.com/docs/authentication/client-libraries#node.js) to get authentication configured.

config/publishers/github.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# GitHub
22

3-
The GitHub target publishes all your artifacts to GitHub releases, this allows your users to download the files straight from your repository. If your repository is open source you can use [update.electronjs.org](https://github.com/electron/update.electronjs.org) and get a free hosted update service.
3+
The GitHub target publishes all your artifacts to GitHub releases, this allows your users to download the files straight from your repository or if your repository is open source you can use [update.electronjs.org](https://github.com/electron/update.electronjs.org) and get a free hosted update service.
44

5-
## Installation
5+
Configuration options are documented in [`PublisherGitHubConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_github.PublisherGitHubConfig.html)
66

7-
```bash
8-
npm install --save-dev @electron-forge/publisher-github
9-
```
7+
{% hint style="info" %}
8+
You can use this target to publish to GitHub Enterprise using the host configuration options of `octokitOptions`. Check out the configuration options linked above.
9+
{% endhint %}
1010

1111
## Usage
1212

13-
To use `@electron-forge/publisher-github`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
14-
1513
{% code title="forge.config.js" %}
1614
```javascript
1715
module.exports = {
@@ -32,12 +30,6 @@ module.exports = {
3230
```
3331
{% endcode %}
3432

35-
Configuration options are documented in [`PublisherGitHubConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_github.PublisherGitHubConfig.html).
36-
37-
### Uploading to GitHub Enterprise instances
38-
39-
You can use this target to publish to GitHub Enterprise using the host configuration options of `octokitOptions`. Check out the configuration options linked above.
40-
4133
### Auto updating from GitHub
4234

4335
Updating from a GitHub release for a **public** repository is as simple as adding the [`update-electron-app`](https://github.com/electron/update-electron-app) module to your app's main process.

config/publishers/nucleus.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
The Nucleus target publishes all your artifacts to an instance of Nucleus Update Server, this update service supports all three platforms. Check out the README at [`atlassian/nucleus`](https://github.com/atlassian/nucleus) for more information on this project.
44

5-
## Installation
5+
Configuration options are documented in [`PublisherNucleusConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_nucleus.PublisherNucleusConfig.html)
66

7-
```bash
8-
npm install --save-dev @electron-forge/publisher-nucleus
9-
```
7+
{% hint style="warning" %}
8+
We recommend you set the `token` option using an environment variable, don't hard code it into your config
9+
{% endhint %}
1010

1111
## Usage
1212

13-
To use `@electron-forge/publisher-nucleus`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
14-
1513
{% code title="forge.config.js" %}
1614
```javascript
1715
module.exports = {
@@ -30,5 +28,3 @@ module.exports = {
3028
};
3129
```
3230
{% endcode %}
33-
34-
Configuration options are documented in [`PublisherNucleusConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_nucleus.PublisherNucleusConfig.html).

config/publishers/s3.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ description: How to publish your distributable Electron app artifacts to Amazon
66

77
The S3 target publishes your Make artifacts to an Amazon S3 bucket.
88

9-
## Installation
9+
## Authentication
1010

11-
```bash
12-
npm install --save-dev @electron-forge/publisher-s3
13-
```
11+
It is recommended to follow the [Amazon AWS guide](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) and set either a shared credentials guide or the proper environment variables. However, if that is not possible, the publisher config allows the setting of the `accessKeyId` and `secretAccessKey` configuration options.
1412

1513
## Usage
1614

17-
To use `@electron-forge/publisher-s3`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
15+
Configuration options are documented in [`PublisherS3Config`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_s3.PublisherS3Config.html).
1816

1917
{% code title="forge.config.js" %}
2018
```javascript
@@ -33,12 +31,6 @@ module.exports = {
3331
```
3432
{% endcode %}
3533

36-
Configuration options are documented in [`PublisherS3Config`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_s3.PublisherS3Config.html).
37-
38-
### Authentication
39-
40-
It is recommended to follow the [Amazon AWS guide](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) and set either a shared credentials guide or the proper environment variables. However, if that is not possible, the publisher config allows the setting of the `accessKeyId` and `secretAccessKey` configuration options.
41-
4234
### Key management
4335

4436
By default, the S3 publisher will upload its objects to the `{prefix}/{platform}/{arch}/{name}` key, where:

config/publishers/snapcraft.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
# Snapcraft
22

3-
The Snapcraft target publishes your `.snap` artifacts to the [Snap Store](https://snapcraft.io/store). All configuration of your package is done via the [snapcraft.md](../makers/snapcraft.md "mention") maker.
3+
The Snapcraft target publishes your `.snap` artifacts to the [Snap Store](https://snapcraft.io/store). All configuration of your package is done via the [Snapcraft maker](../makers/snapcraft.md).
44

5-
## Requirements
5+
This target requires that the system has the `snapcraft` utility installed.
66

7-
You can only publish to the Snap Store on Linux systems with the [`snapcraft`](https://snapcraft.io/) package installed.
7+
Configuration options are documented in [`PublisherSnapConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_snapcraft.PublisherSnapcraftConfig.html)
88

9-
## Installation
10-
11-
```bash
12-
npm install --save-dev @electron-forge/publisher-snapcraft
13-
```
14-
15-
## Usage
16-
17-
To use `@electron-forge/publisher-snapcraft`, add it to the `publishers` array in your [Forge configuration](../configuration.md):
9+
### Usage
1810

1911
{% code title="forge.config.js" %}
2012
```javascript
@@ -31,5 +23,3 @@ module.exports = {
3123
};
3224
```
3325
{% endcode %}
34-
35-
Configuration options are documented in [`PublisherSnapConfig`](https://js.electronforge.io/interfaces/\_electron\_forge\_publisher\_snapcraft.PublisherSnapcraftConfig.html).

config/typescript-configuration.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
description: Set up your Forge configuration to use TypeScript
3+
---
4+
5+
# TypeScript Configuration
6+
7+
By default, Electron Forge's [configuration](broken-reference) only supports JavaScript and JSON files as inputs.
8+
9+
Forge also supports configuration files in other languages that transpile down to JavaScript as long as a transpiler is installed locally in your project's `devDependencies`. These configuration files follow the same format as `forge.config.js`.
10+
11+
## Installation
12+
13+
For TypeScript, we recommend installing [`ts-node`](https://github.com/TypeStrong/ts-node). Upon installation, it will automatically be registered as a module loader for `.ts` files.
14+
15+
```bash
16+
npm install --save-dev ts-node
17+
```
18+
19+
## Configuration file
20+
21+
Once you have `ts-node` installed, Forge will be able to load a `forge.config.ts` file from your project's root directory.
22+
23+
This config format is functionally identical to `forge.config.js`.
24+
25+
{% code title="forge.config.ts" %}
26+
```typescript
27+
import type { ForgeConfig } from '@electron-forge/shared-types';
28+
29+
const config: ForgeConfig = {
30+
packagerConfig: {
31+
asar: true,
32+
osxSign: {}
33+
}
34+
makers: [
35+
{
36+
name: '@electron-forge/maker-squirrel',
37+
platforms: ['win32'],
38+
config: {
39+
authors: "Electron contributors"
40+
}
41+
},
42+
{
43+
name: '@electron-forge/maker-zip',
44+
platforms: ['darwin'],
45+
config: {}
46+
},
47+
{
48+
name: '@electron-forge/maker-deb',
49+
platforms: ['linux'],
50+
config: {}
51+
},
52+
]
53+
};
54+
55+
export default config;
56+
```
57+
{% endcode %}
58+
59+
## Using module constructor syntax
60+
61+
When using a TypeScript configuration file, you may want to have stronger type validation around the individual options for each Maker, Publisher, or Plugin.
62+
63+
To achieve this, you can import each module's constructor, which accepts its config object as the first parameter and the list of target platforms as the second parameter.
64+
65+
For example, the below configuration is equivalent to the `makers` array from the example above:
66+
67+
{% code title="forge.config.ts" %}
68+
```typescript
69+
import type { ForgeConfig } from '@electron-forge/shared-types';
70+
import { MakerDeb } from '@electron-forge/maker-deb';
71+
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
72+
import { MakerZIP } from '@electron-forge/maker-zip';
73+
74+
const config: ForgeConfig = {
75+
makers: [
76+
new MakerSquirrel({
77+
authors: 'Electron contributors'
78+
}, ['win32']),
79+
new MakerZIP({}, ['darwin']),
80+
new MakerDeb({}, ['linux']),
81+
new MakerRpm({}, ['linux']),
82+
]
83+
};
84+
85+
export default config;
86+
```
87+
{% endcode %}

core-concepts/why-electron-forge.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,9 @@ Forge is also built with advanced use cases in mind—you can add any build logi
2828

2929
Electron Forge can be considered an alternative to [Electron Builder](https://electron.build/), which fulfills the same use-case for application building and publishing.
3030

31-
The key difference in philosophy between the two projects is that Electron Forge focuses on combining existing first-party tools into a single build pipeline, while Builder rewrites its own in-house logic for most build tasks.&#x20;
31+
The key difference in philosophy between the two projects is that Electron Forge focuses on combining existing first-party tools into a single build pipeline, while Builder rewrites its own in-house logic for most build tasks.
3232

3333
We believe there are two main advantages to using Forge:
3434

3535
1. **Forge receives new features for application building as soon as they are supported in Electron** (e.g. [ASAR integrity](https://electronjs.org/docs/latest/tutorial/asar-integrity) or [universal macOS builds](https://github.com/electron/universal)). These features are built with first-party Electron tooling in mind, so Forge receives them as soon as they are released.
3636
2. **Forge's multi-package architecture makes it easier to understand and extend.** Since Forge is made up of many smaller packages with clear responsibilities, it is easier to follow the flow of the code. Also, its extensible API design means that you can write your own build logic separate from the provided configuration options for advanced use cases.
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
## &#x20;

0 commit comments

Comments
 (0)