@nwutils/packager 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,16 @@
4
4
 
5
5
  Package NW.js applications for Linux, MacOS and Windows.
6
6
 
7
- Currently supported: packaging a Linux application as an [AppImage](https://appimage.org/).
7
+ Supported output formats, selected via `format`:
8
+
9
+ | Format | Platform | Status |
10
+ | ---------- | -------- | ----------- |
11
+ | `AppImage` | Linux | Implemented |
12
+ | `deb` | Linux | Planned |
13
+ | `rpm` | Linux | Planned |
14
+ | `msix` | Windows | Planned |
15
+ | `nsis` | Windows | Planned |
16
+ | `dmg` | MacOS | Planned |
8
17
 
9
18
  ## Getting Started
10
19
 
@@ -13,11 +22,11 @@ Currently supported: packaging a Linux application as an [AppImage](https://appi
13
22
  ## Usage
14
23
 
15
24
  This composes with `@nwutils/builder`: run it against the `outDir` (and `app.name`)
16
- that `@nwutils/builder` produced for `platform: "linux"`.
25
+ that `@nwutils/builder` produced.
17
26
 
18
27
  ```js
19
28
  import build from "@nwutils/builder";
20
- import { appImage } from "@nwutils/packager";
29
+ import packager from "@nwutils/packager";
21
30
 
22
31
  await build({
23
32
  version: "0.115.0",
@@ -33,7 +42,8 @@ await build({
33
42
  },
34
43
  });
35
44
 
36
- const appImagePath = await appImage({
45
+ const appImagePath = await packager({
46
+ format: "AppImage",
37
47
  appDir: "./out",
38
48
  appName: "Demo",
39
49
  cacheDir: "./cache",
@@ -43,6 +53,12 @@ const appImagePath = await appImage({
43
53
  console.log(`AppImage written to ${appImagePath}`);
44
54
  ```
45
55
 
56
+ `packager({ format, ...options })` dispatches to the packager for `format` -
57
+ `options` is whatever that packager expects (see `appImage(options)` below).
58
+ Passing a `format` that isn't `"AppImage"` yet throws a clear "not implemented
59
+ yet" error rather than doing nothing. `appImage` is also exported directly, if
60
+ you'd rather skip the dispatch and know you only ever target AppImage.
61
+
46
62
  The first time it runs for a given architecture, `appImage()` downloads
47
63
  [`appimagetool`](https://github.com/AppImage/appimagetool) into `cacheDir` and
48
64
  reuses it on subsequent calls. `appimagetool` is a native Linux binary, so
@@ -55,6 +71,15 @@ FUSE is typically unavailable.
55
71
 
56
72
  ## API Reference
57
73
 
74
+ ### `packager({ format, ...options })`
75
+
76
+ | Name | Type | Description |
77
+ | ------ | -------------------------------------------------- | ---------------------------------------------------------------------------- |
78
+ | format | `"AppImage" \| "deb" \| "rpm" \| "MSIX" \| "NSIS"` | Which packager to run. Only `"AppImage"` is implemented today. |
79
+ | ... | - | The remaining options are passed through to the packager for `format` as-is. |
80
+
81
+ Resolves with the path to the resulting packaged artifact.
82
+
58
83
  ### `appImage(options)`
59
84
 
60
85
  Options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nwutils/packager",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Package NW.js applications for Linux, MacOS and Windows.",
5
5
  "keywords": [
6
6
  "NW.js",
package/src/index.js CHANGED
@@ -1,7 +1,39 @@
1
1
  import appImage from "./appImage.js";
2
2
 
3
- export default {
4
- appImage,
5
- };
3
+ /**
4
+ * Supported packaged output formats.
5
+ *
6
+ * `AppImage`, `deb` and `rpm` package a Linux build. `MSIX` and `NSIS`
7
+ * package a Windows build. Only `"AppImage"` is implemented today - the
8
+ * others are reserved so this option doesn't need to change shape once they
9
+ * land.
10
+ * @typedef {"AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg"} PackageFormat
11
+ */
6
12
 
7
- export { appImage };
13
+ /**
14
+ * Package a built NW.js application.
15
+ * @async
16
+ * @function
17
+ * @param {{format: PackageFormat} & Record<string, any>} options `format`, plus the options the matching packager (eg. `appImage`) expects.
18
+ * @returns {Promise<string>} Path to the resulting packaged artifact.
19
+ */
20
+ async function packager({ format, ...options }) {
21
+ switch (format) {
22
+ case "AppImage":
23
+ return appImage(/** @type {any} */ (options));
24
+ case "deb":
25
+ case "rpm":
26
+ case "msix":
27
+ case "nsis":
28
+ case "dmg":
29
+ throw new Error(
30
+ `options.format ${JSON.stringify(format)} is not implemented yet. Currently only "AppImage" is supported.`,
31
+ );
32
+ default:
33
+ throw new Error(
34
+ `Expected options.format to be one of "AppImage", "deb", "rpm", "msix", "nsis" or "dmg". Got ${JSON.stringify(format)}.`,
35
+ );
36
+ }
37
+ }
38
+
39
+ export default packager;
package/types/index.d.ts CHANGED
@@ -1,6 +1,21 @@
1
- import appImage from "./appImage.js";
2
- declare const _default: {
3
- appImage: typeof appImage;
4
- };
5
- export default _default;
6
- export { appImage };
1
+ export type PackageFormat = "AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg";
2
+ /**
3
+ * Supported packaged output formats.
4
+ *
5
+ * `AppImage`, `deb` and `rpm` package a Linux build. `MSIX` and `NSIS`
6
+ * package a Windows build. Only `"AppImage"` is implemented today - the
7
+ * others are reserved so this option doesn't need to change shape once they
8
+ * land.
9
+ * @typedef {"AppImage" | "deb" | "rpm" | "msix" | "nsis" | "dmg"} PackageFormat
10
+ */
11
+ /**
12
+ * Package a built NW.js application.
13
+ * @async
14
+ * @function
15
+ * @param {{format: PackageFormat} & Record<string, any>} options `format`, plus the options the matching packager (eg. `appImage`) expects.
16
+ * @returns {Promise<string>} Path to the resulting packaged artifact.
17
+ */
18
+ declare function packager({ format, ...options }: {
19
+ format: PackageFormat;
20
+ } & Record<string, any>): Promise<string>;
21
+ export default packager;