main b493acbb45f4 cached
13 files
27.4 KB
7.5k tokens
3 symbols
1 requests
Download .txt
Repository: electron-userland/electron-installer-dmg
Branch: main
Commit: b493acbb45f4
Files: 13
Total size: 27.4 KB

Directory structure:
gitextract_7u6fj9oy/

├── .eslintrc
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── LICENSE
├── README.md
├── package.json
├── resources/
│   └── mac/
│       └── electron.icns
├── src/
│   ├── electron-installer-dmg-bin.ts
│   └── index.ts
├── test/
│   └── index.test.ts
├── tsconfig.json
└── usage.txt

================================================
FILE CONTENTS
================================================

================================================
FILE: .eslintrc
================================================
{
  "env": {
    "mocha": true
  },
  "rules": {
    "consistent-return": "off"
  },
  "plugins": ["@typescript-eslint"],
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
  "parser": "@typescript-eslint/parser"
}


================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "daily"
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "daily"


================================================
FILE: .github/workflows/ci.yml
================================================
name: CI

on:
  push:
    branches:
      - main
    tags:
      - v[0-9]+.[0-9]+.[0-9]+*
  pull_request:

jobs:
  build:
    runs-on: macOS-latest
    strategy:
      matrix:
        node-version: [16.x, 18.x, 20.x]

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
      - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: ${{ matrix.node-version }}
          cache: yarn
      - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
        with:
          python-version: '3.11' # distutils is required by node-gyp and dropped by python core in 3.12
      - name: Install
        run: yarn --frozen-lockfile
      - name: Build
        run: yarn tsc
      - name: Lint
        run: yarn lint
      - name: Test
        run: yarn coverage
      - name: Upload code coverage to Codecov
        uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 #v3.1.6
        with:
          file: ./coverage/lcov.info
          env_vars: NODE_VERSION
        env:
          NODE_VERSION: ${{ matrix.node-version }}

  automerge:
    needs: build
    runs-on: ubuntu-latest

    steps:
      - uses: fastify/github-action-merge-dependabot@v2.7.1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}


================================================
FILE: .gitignore
================================================
*-error.log
node_modules/
.DS_Store
.nyc_output/
coverage/
npm-debug.log
package-lock.json
test/fixture*
dist


================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!)  The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


================================================
FILE: README.md
================================================
# electron-installer-dmg

[![CI status][actions_img]][actions_url]
[![npm][npm_img]][npm_url]
[![Code coverage](https://codecov.io/gh/electron-userland/electron-installer-dmg/branch/main/graph/badge.svg?token=xtM3VTig9I)](https://codecov.io/gh/electron-userland/electron-installer-dmg)

> Create DMG installers for your electron apps using [appdmg][appdmg].

## Requirements

This module requires using macOS and Node 16 or above.

## Installation

**For use in npm scripts:**
```bash
npm i electron-installer-dmg --save-dev
```

**For use from cli:**
```bash
npm i electron-installer-dmg -g
```

## Usage

```
Usage: electron-installer-dmg <path/to/.app> <appname>

Create DMG installers for your electron apps.

Usage:
  electron-installer-dmg ./FooBar-darwin-x64/FooBar.app FooBar

Options:
  --out=<path>         The directory to put the DMG into. [Default: `process.cwd()`].
  --icon=<path>        Path to the icon file that will be the app icon in the DMG window.
  --icon-size=<px>     How big to make the icon for the app in the DMG. [Default: `80`].
  --background=<path>  Path to a PNG image to use as the background of the DMG. [Size: 658 x 498]
  --title=<string>     The title of the produced DMG, which will be shown when mounted.
  --overwrite          Overwrite any existing DMG.
  -h --help            Show this screen.
  --version            Show version.
```

### API

```javascript
const { createDMG } = require('electron-installer-dmg');

async function buildDMG() {
  await createDMG({
    appPath: '/path/to/app.app',
    name: 'MyApp'
  });
}
```
#### createDMG(opts)

##### `opts`

`appPath` - *String* - **Required**
The `.app` directory generated by [electron-packager][electron-packager].

`name` - *String* - **Required**
The application name.

`title` - *String*
The title of the produced DMG, which will be shown when mounted.

`background` - *String*
Path to the background for the DMG window. Background image should be of size 658 × 498.

`icon` - *String*
Path to the icon to use for the app in the DMG window.

`iconSize` - *Number*
How big to make the icon for the app in the DMG. [Default: `80`].

`overwrite` - *Boolean*
Overwrite an existing DMG file if if already exists.

`out` - *String*
The directory to put the DMG into. [Default: `process.cwd()`].

`contents` - *Array* or *Function* that returns an Array of objects.
The content that will appear in the window when user opens the `.dmg` file.
[Default: Array of two icons, application and application destination folder].
Array example:
```javascript
[ { x: 448, y: 344, type: 'link', path: '/Applications'},
  { x: 192, y: 344, type: 'file', path: '/path/to/application.app'} ]
```
Function example (more flexible for getting useful options used in creating a DMG):
```javascript
function (opts) {
   return [ { x: 448, y: 344, type: 'link', path: '/Applications'},
            { x: 192, y: 344, type: 'file', path: opts.appPath} ];
}
```

`format` - *String*
Disk image format. [Default: `UDZO`].

[Must be one of the following][spec]:

- `UDRW` :arrow_right: read/write image
- `UDRO` :arrow_right: read-only image
- `UDCO` :arrow_right: ADC-compressed image
- `UDZO` :arrow_right: zlib-compressed image
- `UDBZ` :arrow_right: bzip2-compressed image
- `ULFO` :arrow_right: lzfse-compressed image (macOS 10.11+ only)

`additionalDMGOptions` - *Object*
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.

## License

Apache 2.0

[actions_img]: https://github.com/electron-userland/electron-installer-dmg/actions/workflows/ci.yml/badge.svg
[actions_url]: https://github.com/electron-userland/electron-installer-dmg/actions/workflows/ci.yml
[npm_img]: https://img.shields.io/npm/v/electron-installer-dmg.svg
[npm_url]: https://npm.im/electron-installer-dmg
[electron-packager]: https://github.com/electron/electron-packager
[appdmg]: https://github.com/LinusU/node-appdmg
[spec]: https://github.com/LinusU/node-appdmg#specification


================================================
FILE: package.json
================================================
{
  "name": "electron-installer-dmg",
  "description": "Create DMG installers for your electron apps.",
  "version": "5.0.1",
  "main": "./dist/index.js",
  "typings": "./dist/index.d.ts",
  "author": "Lucas Hrabovsky <lucas@mongodb.com> (http://imlucas.com)",
  "homepage": "http://github.com/electron-userland/electron-installer-dmg",
  "repository": {
    "type": "git",
    "url": "git://github.com/electron-userland/electron-installer-dmg.git"
  },
  "scripts": {
    "build": "tsc",
    "coverage": "nyc --reporter=lcov --reporter=text npm run spec",
    "lint": "eslint src test --ext js,ts",
    "spec": "ts-mocha test/*.test.ts",
    "test": "tsc && npm run lint && npm run spec",
    "prepublishOnly": "tsc"
  },
  "bin": {
    "electron-installer-dmg": "dist/electron-installer-dmg-bin.js"
  },
  "engines": {
    "node": ">= 16"
  },
  "files": [
    "dist",
    "resources",
    "usage.txt"
  ],
  "dependencies": {
    "@types/appdmg": "^0.5.5",
    "debug": "^4.3.2",
    "minimist": "^1.2.7"
  },
  "optionalDependencies": {
    "appdmg": "^0.6.4"
  },
  "license": "Apache-2.0",
  "devDependencies": {
    "@electron/get": "^2.0.2",
    "@types/debug": "^4.1.7",
    "@types/minimist": "^1.2.2",
    "@types/mocha": "^10.0.0",
    "@types/node": "^18.11.7",
    "@typescript-eslint/eslint-plugin": "6.21.0",
    "@typescript-eslint/parser": "6.21.0",
    "eslint": "^8.26.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-plugin-import": "^2.23.4",
    "extract-zip": "^2.0.1",
    "mocha": "^9.0.3",
    "nyc": "^15.1.0",
    "ts-mocha": "^10.0.0",
    "typescript": "5.5.2"
  },
  "keywords": [
    "mongodb.js",
    "electron",
    "installer",
    "electron-installer",
    "gulpfriendly",
    "dmg",
    "electron create dmg"
  ]
}


================================================
FILE: src/electron-installer-dmg-bin.ts
================================================
#!/usr/bin/env node

/* eslint no-console:0 no-sync:0 */
import * as fs from 'fs';
import * as minimist from 'minimist';
import * as path from 'path';

import { createDMG, ElectronInstallerDMGOptions } from '.';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg: { version: string } = require('../package.json');

const usage = fs.readFileSync(path.resolve(__dirname, '../usage.txt')).toString();
const args = minimist<Pick<ElectronInstallerDMGOptions, 'overwrite' | 'icon' | 'background' | 'title' | 'format'> & {
  out?: string;
  'icon-size'?: string;
}>(process.argv.slice(2), {
  boolean: ['overwrite'],
  string: ['out', 'icon', 'icon-size', 'background', 'title', 'format'],
});

const [appPath, name] = args._;

const options: ElectronInstallerDMGOptions = {
  appPath,
  name,
  overwrite: args.overwrite,
  icon: args.icon,
  iconSize: args['icon-size'] ? parseInt(args['icon-size'], 10) : undefined,
  background: args.background,
  title: args.title,
  format: args.format,
  out: args.out,
};

if (args.help || args.h || !options.appPath || !options.name) {
  console.error(usage);
  process.exit(1);
}

if (args.version) {
  console.error(pkg.version);
  process.exit(1);
}

createDMG(options)
  .then(() => {
    console.log(`Wrote DMG to:\n${args.dmgPath}`);
  })
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });


================================================
FILE: src/index.ts
================================================
import type appdmgType from 'appdmg';
import debugCreator from 'debug';
import { existsSync, promises as fs } from 'fs';
import * as path from 'path';

const debug = debugCreator('electron-installer-dmg');

export type ElectronInstallerDMGOptions = {
  /**
   * The `.app` directory generated by Electron Packager.
   */
  appPath: string;
  /**
   * The application name.
   */
  name: string;
  /**
   * The title of the produced DMG, which will be shown when mounted.
   *
   * @defaultValue the {@link ElectronInstallerDMGOptions.name | application name}
   */
  title?: string;
  /**
   * Path to the background image for the DMG window. Image should be of size 658x498.
   *
   * If you need to want to add a second Retina-compatible size, add a separate `@2x` image.
   * For example, if your image is called `background.png`, create a `background@2x.png` that is
   * double the size.
   */
  background?: string;
  /**
   * 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.
   *
   * @defaultValue 80
   */
  iconSize?: number;
  /**
   * Overwrite an existing DMG file if if already exists.
   */
  overwrite?: boolean;
  /**
   * The content that will appear in the window when user opens the `.dmg` file.
   *
   * @defaultValue An array of two icons: the application and the `/Applications` destination folder.
   */
  contents?:
    | appdmgType.SpecificationContents[]
    | ((
        opts: ElectronInstallerDMGOptions
      ) => appdmgType.SpecificationContents[]);
  /**
   * Disk image format.
   *
   * Must be one of the following:
   *  - `UDRW` -> read/write image
   *  - `UDRO` -> read-only image
   *  - `UDCO` -> ADC-compressed image
   *  - `UDZO` -> zlib-compressed image
   *  - `UDBZ` -> bzip2-compressed image
   *  - `ULFO` -> lzfse-compressed image (macOS 10.11+ only)
   *
   * @defaultValue `UDZO`
   */
  format?: 'UDRW' | 'UDRO' | 'UDCO' | 'UDZO' | 'UDBZ' | 'ULFO';
  /**
   * 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?: Omit<
    appdmgType.Specification,
    'title' | 'contents' | 'icon' | 'icon-size' | 'background' | 'format'
  >;
} & (
  | {
      /**
       * The directory to put the DMG into. This option cannot be specified at the same time as `dmgPath`.
       *
       * Defaults to `process.cwd()`.
       */
      out?: string;
    }
  | {
      /**
       * The full path to write the DMG to. This option cannot be specified at the same time as `out`.
       */
      dmgPath: string;
    }
);

async function build(spec: appdmgType.Specification, dmgPath: string) {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const appdmg: typeof appdmgType = require('appdmg');

  debug('DMG spec is:\n', spec);

  debug('creating dmg...');
  return await new Promise<void>((resolve, reject) => {
    appdmg({
      basepath: process.cwd(),
      target: dmgPath,
      specification: spec,
    }).on('progress', (info) => {
      if (info.type === 'step-begin') {
        debug('appdmg [%d/%d]: %s...', info.current, info.total, info.title);
      }
    }).on('finish', async () => {
      debug('appdmg finished!');
      resolve();
    }).on('error', (err) => {
      debug('appdmg errored!', err);
      reject(err);
    });
  });
}

export const createDMG = async (opts: Readonly<ElectronInstallerDMGOptions>) => {
  const defaultSpecContents: appdmgType.SpecificationContents[] = [
    {
      x: 448,
      y: 344,
      type: 'link',
      path: '/Applications',
    },
    {
      x: 192,
      y: 344,
      type: 'file',
      path: path.resolve(process.cwd(), opts.appPath),
    },
  ];
  const specContents = opts.contents ? (
    typeof opts.contents === 'function' ? opts.contents(opts) : opts.contents
  ) : defaultSpecContents;
  const spec: appdmgType.Specification = {
    title: opts.title || opts.name,
    format: opts.format || 'UDZO',
    contents: specContents,
    ...opts.additionalDMGOptions,
  };

  if (process.platform !== 'darwin') {
    throw new Error('Must be run on OSX');
  }

  if (!opts.background) {
    spec.background = path.resolve(__dirname, '../resources/mac/background.png');
  } else {
    spec.background = path.resolve(opts.background);
  }

  if (!opts.icon) {
    spec.icon = path.resolve(__dirname, '../resources/mac/electron.icns');
  } else {
    spec.icon = path.resolve(opts.icon);
  }

  spec['icon-size'] = opts.iconSize || 80;

  if (!opts.appPath || typeof opts.appPath !== 'string') {
    throw new Error('opts.appPath must be defined as a string');
  }

  let dmgPath: string;

  let configuredOut = 'out' in opts ? opts.out : undefined;
  if (!configuredOut && !('dmgPath' in opts)) {
    configuredOut = process.cwd();
  }

  if ('out' in opts && 'dmgPath' in opts) {
    throw new Error('Only one of opts.dmgPath or opts.out must be defined as a string');
  } else if (configuredOut) {
    if (typeof configuredOut !== 'string') {
      throw new Error(`Expected opts.out to be a string but it was "${typeof configuredOut}"`);
    }

    dmgPath = path.resolve(configuredOut, `${opts.name}.dmg`);
  } else if ('dmgPath' in opts) {
    if (typeof opts.dmgPath !== 'string') {
      throw new Error(`Expected opts.dmgPath to be a string but it was "${typeof opts.dmgPath}"`);
    }

    dmgPath = opts.dmgPath;
  } else {
    throw new Error('Either opts.dmgPath or opts.out must be defined as a string');
  }

  await fs.mkdir(path.dirname(dmgPath), { recursive: true });

  if (existsSync(dmgPath)) {
    if (!opts.overwrite) {
      debug('DMG already exists at `%s` and overwrite is false', dmgPath);
      const msg = `DMG already exists.  Run electron-installer-dmg again with \
\`--overwrite\` or remove the file and rerun. ${dmgPath}`;
      throw new Error(msg);
    } else {
      debug('DMG already exists at `%s`.  Removing...', dmgPath);
      await fs.unlink(dmgPath);
    }
  }

  return build(spec, dmgPath);
};


================================================
FILE: test/index.test.ts
================================================
import * as assert from 'assert';
import { download } from '@electron/get';
import { existsSync, promises as fs } from 'fs';
import * as path from 'path';
import * as unzip from 'extract-zip';

import { createDMG } from '../';

const MINUTES_IN_MS = 60 * 1000;

const fixtureDMGPath = path.resolve(__dirname, 'fixture.dmg');

describe('electron-installer-dmg', () => {
  before(() => {
    assert.equal(process.platform, 'darwin', 'tests can only run on darwin');
  });

  it('should be requireable', () => {
    assert.doesNotThrow(() => require('..')); // eslint-disable-line global-require
  });

  describe('with app', () => {
    const appPath = path.resolve(__dirname, 'fixture', 'Electron.app');

    before(async function downloadElectron() {
      this.timeout(2 * MINUTES_IN_MS);

      const zipPath = await download('18.2.0');
      await unzip(zipPath, { dir: appPath });
    });

    it('should succeed in creating a DMG', async function testCreate() {
      this.timeout(2 * MINUTES_IN_MS);
      await createDMG({
        appPath,
        dmgPath: fixtureDMGPath,
        name: 'Test App',
      });
      assert(existsSync(fixtureDMGPath), 'dmg should exist');
    });

    afterEach(async () => existsSync(fixtureDMGPath) ? fs.unlink(fixtureDMGPath) : null);

    after(async () => fs.rm(appPath, { recursive: true }));
  });
});


================================================
FILE: tsconfig.json
================================================
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "lib": [
      "es2017"
    ],
    "sourceMap": true,
    "strict": true,
    "outDir": "dist",
    "types": [
      "node"
    ],
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "declaration": true
  },
  "include": [
    "src"
  ]
}


================================================
FILE: usage.txt
================================================
Usage: electron-installer-dmg <path/to/.app> <appname>

Create DMG installers for your electron apps.

Usage:
  electron-installer-dmg ./FooBar-darwin-x64/FooBar.app FooBar

Options:
  --out=<path>         The directory to put the DMG into. [Default: `process.cwd()`].
  --icon=<path>        Path to the icon file that will be the app icon in the DMG window.
  --icon-size=<px>     How big to make the icon for the app in the DMG. [Default: `80`].
  --background=<path>  Path to a PNG image to use as the background of the DMG.
  --title=<string>     The title of the produced DMG, which will be shown when mounted.
  --format=<format>    Disk image format. [Default: `UDZO`].
  --overwrite          Overwrite any existing DMG.
  -h --help            Show this screen.
  --version            Show version.
Download .txt
gitextract_7u6fj9oy/

├── .eslintrc
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       └── ci.yml
├── .gitignore
├── LICENSE
├── README.md
├── package.json
├── resources/
│   └── mac/
│       └── electron.icns
├── src/
│   ├── electron-installer-dmg-bin.ts
│   └── index.ts
├── test/
│   └── index.test.ts
├── tsconfig.json
└── usage.txt
Download .txt
SYMBOL INDEX (3 symbols across 2 files)

FILE: src/index.ts
  type ElectronInstallerDMGOptions (line 8) | type ElectronInstallerDMGOptions = {
  function build (line 96) | async function build(spec: appdmgType.Specification, dmgPath: string) {

FILE: test/index.test.ts
  constant MINUTES_IN_MS (line 9) | const MINUTES_IN_MS = 60 * 1000;
Condensed preview — 13 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (30K chars).
[
  {
    "path": ".eslintrc",
    "chars": 242,
    "preview": "{\n  \"env\": {\n    \"mocha\": true\n  },\n  \"rules\": {\n    \"consistent-return\": \"off\"\n  },\n  \"plugins\": [\"@typescript-eslint\"]"
  },
  {
    "path": ".github/dependabot.yml",
    "chars": 203,
    "preview": "version: 2\nupdates:\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"daily\"\n  - package-ec"
  },
  {
    "path": ".github/workflows/ci.yml",
    "chars": 1347,
    "preview": "name: CI\n\non:\n  push:\n    branches:\n      - main\n    tags:\n      - v[0-9]+.[0-9]+.[0-9]+*\n  pull_request:\n\njobs:\n  build"
  },
  {
    "path": ".gitignore",
    "chars": 110,
    "preview": "*-error.log\nnode_modules/\n.DS_Store\n.nyc_output/\ncoverage/\nnpm-debug.log\npackage-lock.json\ntest/fixture*\ndist\n"
  },
  {
    "path": "LICENSE",
    "chars": 10255,
    "preview": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AN"
  },
  {
    "path": "README.md",
    "chars": 4098,
    "preview": "# electron-installer-dmg\n\n[![CI status][actions_img]][actions_url]\n[![npm][npm_img]][npm_url]\n[![Code coverage](https://"
  },
  {
    "path": "package.json",
    "chars": 1764,
    "preview": "{\n  \"name\": \"electron-installer-dmg\",\n  \"description\": \"Create DMG installers for your electron apps.\",\n  \"version\": \"5."
  },
  {
    "path": "src/electron-installer-dmg-bin.ts",
    "chars": 1375,
    "preview": "#!/usr/bin/env node\n\n/* eslint no-console:0 no-sync:0 */\nimport * as fs from 'fs';\nimport * as minimist from 'minimist';"
  },
  {
    "path": "src/index.ts",
    "chars": 6163,
    "preview": "import type appdmgType from 'appdmg';\nimport debugCreator from 'debug';\nimport { existsSync, promises as fs } from 'fs';"
  },
  {
    "path": "test/index.test.ts",
    "chars": 1348,
    "preview": "import * as assert from 'assert';\nimport { download } from '@electron/get';\nimport { existsSync, promises as fs } from '"
  },
  {
    "path": "tsconfig.json",
    "chars": 344,
    "preview": "{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"target\": \"es2017\",\n    \"lib\": [\n      \"es2017\"\n    ],\n    \"sourc"
  },
  {
    "path": "usage.txt",
    "chars": 806,
    "preview": "Usage: electron-installer-dmg <path/to/.app> <appname>\n\nCreate DMG installers for your electron apps.\n\nUsage:\n  electron"
  }
]

// ... and 1 more files (download for full content)

About this extraction

This page contains the full source code of the electron-userland/electron-installer-dmg GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 13 files (27.4 KB), approximately 7.5k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!