diff --git a/examples/test.js b/examples/test.js index d6cfb53..31cb898 100644 --- a/examples/test.js +++ b/examples/test.js @@ -1,4 +1,4 @@ -const { Dialog, ButtonClickedTypes } = require('../index') +const { Dialog, ButtonClickedTypes } = require('../build/native') const dialog = new Dialog({ title: "Title", diff --git a/index.js b/index.js deleted file mode 100644 index fdb69a8..0000000 --- a/index.js +++ /dev/null @@ -1,9 +0,0 @@ -const Dialog = require('./src/Dialog') -const { DefaultButtonTypes, ButtonTypes, IconTypes } = require('./src/DialogTypes') - -module.exports = { - Dialog, - ButtonTypes, - IconTypes, - DefaultButtonTypes -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5579f1e..aa91786 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,11 @@ "license": "MIT", "dependencies": { "node-addon-api": "^7.0.0", - "node-gyp": "^9.4.0" + "node-gyp": "^9.4.0", + "typescript": "^5.1.6" + }, + "devDependencies": { + "@types/node": "^20.4.5" } }, "node_modules/@isaacs/cliui": { @@ -103,6 +107,12 @@ "node": ">= 10" } }, + "node_modules/@types/node": { + "version": "20.4.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.5.tgz", + "integrity": "sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg==", + "dev": true + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -1186,6 +1196,18 @@ "node": ">=8" } }, + "node_modules/typescript": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/unique-filename": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-3.0.0.tgz", diff --git a/package.json b/package.json index 175c77f..eeb79c3 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" + } } diff --git a/src/Dialog.js b/src/Dialog.js deleted file mode 100644 index 090f374..0000000 --- a/src/Dialog.js +++ /dev/null @@ -1,58 +0,0 @@ -const { showDialog } = require('../build/Release/dialog') - -class Dialog { - message; - title; - buttonType; - iconType; - defaultButtonType; - - constructor(title, message, buttonType, iconType, defaultButtonType) { - 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"] || "OK", - this.defaultButtonType = title["defaultButtonType"] || "DEFAULT_1", - this.iconType = title["iconType"] || "INFORMATION" - } else if (typeof message == 'string' && typeof title !== 'string') { - this.title = title - this.message = message - this.buttonType = buttonType || "OK", - this.defaultButtonType = defaultButtonType || "DEFAULT_1", - this.iconType = iconType || "INFORMATION" - } - } - - setTitle(title) { - this.title = title - } - - setMessage(message) { - this.message = message - } - - setButtonType(buttonType) { - this.buttonType = buttonType - } - - setDefaultButtonType(defaultButtonType) { - this.defaultButtonType = defaultButtonType - } - - setIconType(iconType) { - 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) - } -} - -module.exports = Dialog diff --git a/src/Dialog.ts b/src/Dialog.ts new file mode 100644 index 0000000..f8822ea --- /dev/null +++ b/src/Dialog.ts @@ -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) + } +} \ No newline at end of file diff --git a/src/DialogTypes.js b/src/DialogTypes.js deleted file mode 100644 index fee00df..0000000 --- a/src/DialogTypes.js +++ /dev/null @@ -1,44 +0,0 @@ -class ButtonTypes { - static AbortRetryIgnore = "ABORT_RETRY_IGNORE" - static CancelTryContinue = "CANCEL_TRY_CONTINUE" - static Ok = "OK" - static OkCancel = "OK_CANCEL" - static RetryCancel = "RETRY_CANCEL" - static YesNo = "YES_NO" - static YesNoCancel = "YES_NO_CANCEL" -} - -class IconTypes { - static Information = "INFORMATION" - static Error = "ERROR" - static Stop = "ERROR" - static Warning = "WARNING" - static Exclamation = "WARNING" - static Question = "QUESTION" -} - -class DefaultButtonTypes { - static One = "DEFAULT_1" - static Two = "DEFAULT_2" - static Three = "DEFAULT_3" - static Four = "DEFAULT_4" -} - -class ButtonClickedTypes { - static Ok = 1 - static Cancel = 2 - static Abort = 3 - static Retry = 4 - static Ignore = 5 - static Yes = 6 - static No = 7 - static TryAgain = 10 - static Continue = 11 -} - -module.exports = { - ButtonTypes, - DefaultButtonTypes, - IconTypes, - ButtonClickedTypes -} \ No newline at end of file diff --git a/src/DialogTypes.ts b/src/DialogTypes.ts new file mode 100644 index 0000000..230a2a1 --- /dev/null +++ b/src/DialogTypes.ts @@ -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, +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..fde5e9b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './Dialog' +export * from './DialogTypes' \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..965a784 --- /dev/null +++ b/tsconfig.json @@ -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 + } +} \ No newline at end of file