Skip to content

Commit 7953a8d

Browse files
Merge pull request #178 from electron-userland/ts-installer-dmg
refactor: convert to typescript and upgrade Node.js versions
2 parents 4fc4910 + 001ed46 commit 7953a8d

15 files changed

+943
-533
lines changed

.eslintrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
"rules": {
66
"consistent-return": "off"
77
},
8-
"extends": "airbnb-base"
8+
"plugins": ["@typescript-eslint"],
9+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
10+
"parser": "@typescript-eslint/parser"
911
}

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
python-version: '3.11' # distutils is required by node-gyp and dropped by python core in 3.12
2727
- name: Install
2828
run: yarn --frozen-lockfile
29+
- name: Build
30+
run: yarn tsc
2931
- name: Lint
3032
run: yarn lint
3133
- name: Test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ coverage/
66
npm-debug.log
77
package-lock.json
88
test/fixture*
9+
dist

README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
## Requirements
1010

11-
This module requires using macOS and Node 12 (LTS) or above.
11+
This module requires using macOS and Node 16 or above.
1212

1313
## Installation
1414

@@ -38,7 +38,6 @@ Options:
3838
--icon-size=<px> How big to make the icon for the app in the DMG. [Default: `80`].
3939
--background=<path> Path to a PNG image to use as the background of the DMG. [Size: 658 x 498]
4040
--title=<string> The title of the produced DMG, which will be shown when mounted.
41-
--debug Enable debug messages.
4241
--overwrite Overwrite any existing DMG.
4342
-h --help Show this screen.
4443
--version Show version.
@@ -75,18 +74,15 @@ Path to the background for the DMG window. Background image should be of size 65
7574
`icon` - *String*
7675
Path to the icon to use for the app in the DMG window.
7776

77+
`iconSize` - *Number*
78+
How big to make the icon for the app in the DMG. [Default: `80`].
79+
7880
`overwrite` - *Boolean*
7981
Overwrite an existing DMG file if if already exists.
8082

81-
`debug` - *Boolean*
82-
Enable debug message output.
83-
8483
`out` - *String*
8584
The directory to put the DMG into. [Default: `process.cwd()`].
8685

87-
`iconSize` - *Number*
88-
How big to make the icon for the app in the DMG. [Default: `80`].
89-
9086
`contents` - *Array* or *Function* that returns an Array of objects.
9187
The content that will appear in the window when user opens the `.dmg` file.
9288
[Default: Array of two icons, application and application destination folder].

bin/electron-installer-dmg.js

-41
This file was deleted.

package.json

+23-12
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,58 @@
22
"name": "electron-installer-dmg",
33
"description": "Create DMG installers for your electron apps.",
44
"version": "4.0.0",
5-
"main": "./src/index.js",
5+
"main": "./dist/index.js",
6+
"typings": "./dist/index.d.ts",
67
"author": "Lucas Hrabovsky <[email protected]> (http://imlucas.com)",
78
"homepage": "http://github.com/electron-userland/electron-installer-dmg",
89
"repository": {
910
"type": "git",
1011
"url": "git://github.com/electron-userland/electron-installer-dmg.git"
1112
},
1213
"scripts": {
14+
"build": "tsc",
1315
"coverage": "nyc --reporter=lcov --reporter=text npm run spec",
14-
"lint": "eslint src test bin",
15-
"spec": "mocha",
16-
"test": "npm run lint && npm run spec"
16+
"lint": "eslint src test --ext js,ts",
17+
"spec": "ts-mocha test/*.test.ts",
18+
"test": "tsc && npm run lint && npm run spec",
19+
"prepublishOnly": "tsc"
1720
},
1821
"bin": {
19-
"electron-installer-dmg": "bin/electron-installer-dmg.js"
22+
"electron-installer-dmg": "dist/electron-installer-dmg-bin.js"
2023
},
2124
"engines": {
22-
"node": ">= 12.13.0"
25+
"node": ">= 16"
2326
},
2427
"files": [
25-
"bin",
28+
"dist",
2629
"resources",
27-
"src",
2830
"usage.txt"
2931
],
3032
"dependencies": {
3133
"debug": "^4.3.2",
32-
"minimist": "^1.1.1"
34+
"minimist": "^1.2.7"
3335
},
3436
"optionalDependencies": {
3537
"appdmg": "^0.6.4"
3638
},
3739
"license": "Apache-2.0",
3840
"devDependencies": {
39-
"@electron/get": "^1.1.0",
40-
"eslint": "^7.32.0",
41+
"@electron/get": "^2.0.2",
42+
"@types/appdmg": "^0.5.2",
43+
"@types/debug": "^4.1.7",
44+
"@types/minimist": "^1.2.2",
45+
"@types/mocha": "^10.0.0",
46+
"@types/node": "^18.11.7",
47+
"@typescript-eslint/eslint-plugin": "6.21.0",
48+
"@typescript-eslint/parser": "6.21.0",
49+
"eslint": "^8.26.0",
4150
"eslint-config-airbnb-base": "^15.0.0",
4251
"eslint-plugin-import": "^2.23.4",
4352
"extract-zip": "^2.0.1",
4453
"mocha": "^9.0.3",
45-
"nyc": "^15.1.0"
54+
"nyc": "^15.1.0",
55+
"ts-mocha": "^10.0.0",
56+
"typescript": "5.5.2"
4657
},
4758
"keywords": [
4859
"mongodb.js",

resources/mac/atom.icns

-1.12 MB
Binary file not shown.

resources/mac/electron.icns

266 KB
Binary file not shown.

src/electron-installer-dmg-bin.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint no-console:0 no-sync:0 */
4+
import * as fs from 'fs';
5+
import * as minimist from 'minimist';
6+
import * as path from 'path';
7+
8+
import { createDMG, ElectronInstallerDMGOptions } from '.';
9+
10+
// eslint-disable-next-line @typescript-eslint/no-var-requires
11+
const pkg: { version: string } = require('../package.json');
12+
13+
const usage = fs.readFileSync(path.resolve(__dirname, '../usage.txt')).toString();
14+
const args = minimist<Pick<ElectronInstallerDMGOptions, 'overwrite' | 'icon' | 'background' | 'title' | 'format'> & {
15+
out?: string;
16+
'icon-size'?: string;
17+
}>(process.argv.slice(2), {
18+
boolean: ['overwrite'],
19+
string: ['out', 'icon', 'icon-size', 'background', 'title', 'format'],
20+
});
21+
22+
const [appPath, name] = args._;
23+
24+
const options: ElectronInstallerDMGOptions = {
25+
appPath,
26+
name,
27+
overwrite: args.overwrite,
28+
icon: args.icon,
29+
iconSize: args['icon-size'] ? parseInt(args['icon-size'], 10) : undefined,
30+
background: args.background,
31+
title: args.title,
32+
format: args.format,
33+
out: args.out,
34+
};
35+
36+
if (args.help || args.h || !options.appPath || !options.name) {
37+
console.error(usage);
38+
process.exit(1);
39+
}
40+
41+
if (args.version) {
42+
console.error(pkg.version);
43+
process.exit(1);
44+
}
45+
46+
createDMG(options)
47+
.then(() => {
48+
console.log(`Wrote DMG to:\n${args.dmgPath}`);
49+
})
50+
.catch((err) => {
51+
console.error(err);
52+
process.exit(1);
53+
});

src/index.js

-123
This file was deleted.

0 commit comments

Comments
 (0)