Skip to content

Commit

Permalink
Javascript into Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
hvlxh committed Jul 29, 2023
1 parent 5aeb886 commit 659d503
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 118 deletions.
2 changes: 1 addition & 1 deletion examples/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Dialog, ButtonClickedTypes } = require('../index')
const { Dialog, ButtonClickedTypes } = require('../build/native')

const dialog = new Dialog({
title: "Title",
Expand Down
9 changes: 0 additions & 9 deletions index.js

This file was deleted.

24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"name": "node-dialogs",
"version": "1.0.1",
"description": "An package to send windows dialogs, etc",
"main": "index.js",
"typings": "index.d.ts",
"main": "build/native",
"scripts": {
"build": "node-gyp configure && node-gyp build",
"build": "node-gyp configure && node-gyp build && tsc",
"pack": "npm pack"
},
"binary": {
Expand Down Expand Up @@ -38,7 +37,11 @@
"homepage": "https://github.com/hvlxh/node-dialogs#readme",
"dependencies": {
"node-addon-api": "^7.0.0",
"node-gyp": "^9.4.0"
"node-gyp": "^9.4.0",
"typescript": "^5.1.6"
},
"gypfile": true
"gypfile": true,
"devDependencies": {
"@types/node": "^20.4.5"
}
}
58 changes: 0 additions & 58 deletions src/Dialog.js

This file was deleted.

64 changes: 64 additions & 0 deletions src/Dialog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @ts-ignore
import { showDialog } from '../build/Release/dialog';
import { ButtonTypes, IconTypes, DefaultButtonTypes} from './DialogTypes'

export class Dialog {
private message: string;
private title: string;
private buttonType: ButtonTypes;
private iconType: IconTypes;
private defaultButtonType: DefaultButtonTypes;

constructor(title: string | {
title: string,
message: string,
buttonType: ButtonTypes,
defaultButtonType: DefaultButtonTypes,
iconType: IconTypes
}, message: string, buttonType: ButtonTypes = ButtonTypes.Ok, iconType: IconTypes = IconTypes.Information, defaultButtonType: DefaultButtonTypes = DefaultButtonTypes.One) {
if(typeof title === "object") {
if(!title["message"]) throw new Error('"message" arg is not available');
if(!title["title"]) throw new Error('"title" arg is not available');

this.title = title["title"]
this.message = title["message"]
this.buttonType = title["buttonType"],
this.defaultButtonType = title["defaultButtonType"]
this.iconType = title["iconType"]
} else if (typeof title == 'string') {
this.title = title
this.message = message
this.buttonType = buttonType,
this.defaultButtonType = defaultButtonType,
this.iconType = iconType
}
}

setTitle(title: string) {
this.title = title
}

setMessage(message: string) {
this.message = message
}

setButtonType(buttonType: ButtonTypes) {
this.buttonType = buttonType
}

setDefaultButtonType(defaultButtonType: DefaultButtonTypes) {
this.defaultButtonType = defaultButtonType
}

setIconType(iconType: IconTypes) {
this.iconType = iconType
}

run() {
if(typeof this.message != 'string') throw new Error('"message" is undefined')
if(typeof this.title != 'string') throw new Error('"title" is undefined')
const { message, title, buttonType, defaultButtonType, iconType } = this

return showDialog(message, title, buttonType, defaultButtonType, iconType)
}
}
44 changes: 0 additions & 44 deletions src/DialogTypes.js

This file was deleted.

37 changes: 37 additions & 0 deletions src/DialogTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export enum ButtonTypes {
AbortRetryIgnore = "ABORT_RETRY_IGNORE",
CancelTryContinue = "CANCEL_TRY_CONTINUE",
Ok = "OK",
OkCancel = "OK_CANCEL",
RetryCancel = "RETRY_CANCEL",
YesNo = "YES_NO",
YesNoCancel = "YES_NO_CANCEL",
}

export enum IconTypes {
Information = "INFORMATION",
Error = "ERROR",
Stop = "ERROR",
Warning = "WARNING",
Exclamation = "WARNING",
Question = "QUESTION",
}

export enum DefaultButtonTypes {
One = "DEFAULT_1",
Two = "DEFAULT_2",
Three = "DEFAULT_3",
Four = "DEFAULT_4",
}

export enum ButtonClickedTypes {
Ok = 1,
Cancel = 2,
Abort = 3,
Retry = 4,
Ignore = 5,
Yes = 6,
No = 7,
TryAgain = 10,
Continue = 11,
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Dialog'
export * from './DialogTypes'
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "NodeNext",
"target": "ES6",
"lib": ["ESNext"],
"declaration": true,
"inlineSourceMap": true,
"rootDir": "src",
"outDir": "build/native",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": false,
"alwaysStrict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}

0 comments on commit 659d503

Please sign in to comment.