Skip to content

Commit

Permalink
refactor: convert to typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The exported API is now a named export `createDMG` and the `debug` option has been removed.
  • Loading branch information
MarshallOfSound committed Oct 27, 2022
1 parent ddc6db7 commit 542a9ed
Show file tree
Hide file tree
Showing 14 changed files with 922 additions and 569 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"rules": {
"consistent-return": "off"
},
"extends": "airbnb-base"
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser"
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
node-version: [12.13.0, 14.x, 16.x]
node-version: [12.22.12, 14.x, 16.x]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage/
npm-debug.log
package-lock.json
test/fixture*
dist
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,15 @@ Path to the background for the DMG window. Background image should be of size 65
`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.

`debug` - *Boolean*
Enable debug message output.

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

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

`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].
Expand Down
41 changes: 0 additions & 41 deletions bin/electron-installer-dmg.js

This file was deleted.

36 changes: 23 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "electron-installer-dmg",
"description": "Create DMG installers for your electron apps.",
"version": "4.0.0",
"main": "./src/index.js",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"author": "Lucas Hrabovsky <[email protected]> (http://imlucas.com)",
"homepage": "http://github.com/electron-userland/electron-installer-dmg",
"repository": {
Expand All @@ -11,38 +12,47 @@
},
"scripts": {
"coverage": "nyc --reporter=lcov --reporter=text npm run spec",
"lint": "eslint src test bin",
"spec": "mocha",
"test": "npm run lint && 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": "bin/electron-installer-dmg.js"
"electron-installer-dmg": "dist/electron-installer-dmg-bin.js"
},
"engines": {
"node": ">= 12.13.0"
"node": ">= 12.22.12"
},
"files": [
"bin",
"dist",
"resources",
"src",
"usage.txt"
],
"dependencies": {
"debug": "^4.3.2",
"minimist": "^1.1.1"
"minimist": "^1.2.7"
},
"optionalDependencies": {
"appdmg": "^0.6.4"
},
"license": "Apache-2.0",
"devDependencies": {
"@electron/get": "^1.1.0",
"eslint": "^7.32.0",
"@electron/get": "^2.0.2",
"@types/appdmg": "^0.5.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": "^5.41.0",
"@typescript-eslint/parser": "^5.41.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"
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"ts-mocha": "^10.0.0",
"typescript": "^4.8.4"
},
"keywords": [
"mongodb.js",
Expand Down
Binary file removed resources/mac/atom.icns
Binary file not shown.
Binary file added resources/mac/electron.icns
Binary file not shown.
53 changes: 53 additions & 0 deletions src/electron-installer-dmg-bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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);
});
123 changes: 0 additions & 123 deletions src/index.js

This file was deleted.

Loading

0 comments on commit 542a9ed

Please sign in to comment.