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

feat: add TypeScript definitions #54

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"lint": "eslint src test bin",
"mocha": "mocha",
"test": "npm run lint && npm run mocha"
"test": "npm run lint && npm run mocha && tsd src"
},
"bin": {
"electron-installer-dmg": "bin/electron-installer-dmg.js"
Expand All @@ -31,12 +31,14 @@
"license": "Apache-2.0",
"devDependencies": {
"@electron/get": "^1.1.0",
"@types/appdmg": "^0.5.1",
"cross-zip": "^2.1.5",
"eslint": "^5.16.0",
"eslint-config-airbnb-base": "^13.0.0",
"eslint-plugin-import": "^2.13.0",
"mocha": "^6.1.4",
"rimraf": "^2.6.2"
"rimraf": "^2.6.2",
"tsd": "0.17.0"
},
"keywords": [
"mongodb.js",
Expand Down
57 changes: 57 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import appdmg = require('appdmg');

declare namespace createDMG {
/**
* The content that will appear in the window when the user opens the .dmg file.
*/
interface Content {
path: string;
type: 'link' | 'file';
x: number;
y: number;
}

interface DMGOptions {
/**
* Additional options to pass through to [`appdmg`](https://npm.im/appdmg).
* You can use this to set additional features like `background-color` and `code-sign`.
* See the docs of the `appdmg` module for all possible options.
*/
additionalDMGOptions?: Partial<appdmg.Specification>;
/**
* The `.app` directory generated by
* [electron-packager](https://github.com/electron/electron-packager).
*/
appPath: string;
/** Path to the background for the DMG window. Background image should be of size 658×498. */
background?: string;
/**
* The content that will appear in the window when user opens the .dmg file.
ffflorian marked this conversation as resolved.
Show resolved Hide resolved
* [Default: Array of two icons, application and application destination folder].
*/
contents?: Content[] | ((opts?: DMGOptions) => Content[]);
/** Enable debug message output. */
debug?: boolean;
/** Disk image format. [Default: `UDZO`]. */
format?: 'UDRW' | 'UDRO' | 'UDCO' | 'UDZO' | 'UDBZ' | 'ULFO';
/** Path to the icon to use for the app in the DMG window. */
icon?: string;
/** How big to make the icon for the app in the DMG. [Default: `80`]. */
iconSize?: number;
/** The application name. */
name: string;
/** The directory to put the DMG into. [Default: `process.cwd()`]. */
out?: string;
/** Overwrite an existing DMG file if if already exists. */
overwrite?: boolean;
/** The title of the produced DMG, which will be shown when mounted. */
title?: string;
}
}

/**
* Generate a DMG for a bundled & customized Electron app.
*/
declare function createDMG(createOptions: createDMG.DMGOptions): Promise<createDMG.DMGOptions>;
ffflorian marked this conversation as resolved.
Show resolved Hide resolved

export = createDMG;
40 changes: 40 additions & 0 deletions src/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {expectType} from 'tsd';
import createDMG = require('.');

expectType<Promise<createDMG.DMGOptions>>(createDMG({
appPath: '',
name: 'my dmg',
}));

expectType<Promise<createDMG.DMGOptions>>(createDMG({
contents: [
{ x: 448, y: 344, type: 'link', path: '/Applications' },
{ x: 192, y: 344, type: 'file', path: '/path/to/application.app' },
],
appPath: '',
name: 'my dmg',
}));

function getContents(): createDMG.Content[] {
return [
{ x: 448, y: 344, type: 'link', path: '/Applications' },
{ x: 192, y: 344, type: 'file', path: '/path/to/application.app' },
];
}

expectType<Promise<createDMG.DMGOptions>>(createDMG({
contents: getContents,
appPath: '',
name: 'my dmg',
}));

expectType<Promise<createDMG.DMGOptions>>(createDMG({
appPath: '',
format: 'UDBZ',
additionalDMGOptions: {
window: {
position: { x: 100, y: 100 },
},
},
name: 'my dmg',
}))
Loading