Skip to content

Commit 711c0c5

Browse files
JSDoc API type definition
1 parent 3f771af commit 711c0c5

File tree

7 files changed

+237
-133
lines changed

7 files changed

+237
-133
lines changed

api-type-definitions.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* OPTIONAL: console.error is called by default if verbose: true.
3+
*
4+
* Your own custom logging function called with helpful warning/error
5+
* messages from the internal validators. Only used if verbose: true.
6+
*
7+
* @callback {Function} CUSTOMLOGGER
8+
* @param {string} message The human readable warning/error message
9+
* @param {object} [error] Sometimes an error or options object is passed
10+
* @return {void}
11+
*/
12+
13+
/**
14+
* @typedef {object} WINDOWS
15+
* @property {string} filePath The target the shortcut points to.
16+
* @property {string} [outputPath] Path where shortcut will be placed. Defaults to user's desktop.
17+
* @property {string} [name] Name of the shortcut file.
18+
* @property {string} [comment] Metadata file "comment" property. Description of what the shortcut would open.
19+
* @property {string} [icon] Image shown on the shortcut icon. You can also pass in an index if file contains multiple icons, like `'C:\\file.exe,0'`
20+
* @property {string} [arguments] Additional arguments passed in to the end of your target `filePath`.
21+
* @property {string} [windowMode="normal"] How the window should be displayed by default. Valid inputs: 'normal', 'maximized', 'minimized'. Defaults to 'normal'.
22+
* @property {string} [hotkey] A global hotkey to associate to opening this shortcut, like 'CTRL+ALT+F'.
23+
* @property {string} [workingDirectory] The working directory for the shortcut when it launches, must be a valid path to a folder.
24+
* @property {string} [VBScriptPath] This is an advanced option specifically and only for projects packaged with `pkg`.
25+
* [See documentation](https://github.com/nwutils/create-desktop-shortcuts#windows-settings).
26+
*/
27+
28+
/**
29+
* @typedef {object} LINUX
30+
* @property {string} filePath The target the shortcut points to.
31+
* @property {string} [outputPath] Path where shortcut will be placed. Defaults to user's desktop.
32+
* @property {string} [name] Name of the shortcut file.
33+
* @property {string} [comment] Metadata file "comment" property. Description of what the shortcut would open.
34+
* @property {string} [icon] Image shown on the shortcut icon. Preferably a 256x256 PNG.
35+
* @property {string} [type] Type of shortcut. Valid inputs: 'Link', 'Directory', 'Application'.
36+
* @property {boolean} [terminal=false] If true, will run in a terminal.
37+
* @property {boolean} [chmod=true] If true, will apply a `chmod +x` (755) to the shortcut after creation to allow execution permission.
38+
* @property {string} [arguments] Additional arguments passed in to the end of your target `filePath`.
39+
*/
40+
41+
/**
42+
* @typedef {object} OSX
43+
* @property {string} filePath The target the shortcut points to.
44+
* @property {string} [outputPath] Path where shortcut will be placed. Defaults to user's desktop.
45+
* @property {string} [name] Name of the shortcut file.
46+
* @property {boolean} [overwrite=false] If true, will replace any existing file in the `outputPath` with matching `name`.
47+
* [See documentation](https://github.com/nwutils/create-desktop-shortcuts#osx-settings).
48+
*/
49+
50+
/**
51+
* @typedef {object} OPTIONS
52+
* @property {boolean} [onlyCurrentOS=true] Only create a shortcut for the current OS even if other OS's are passed in.
53+
* @property {boolean} [verbose=true] Logs out helpful warnings/errors using `customLogger` or console.error.
54+
* @property {CUSTOMLOGGER} [customLogger] Called (if verbose: true) with helpful warning/error messages from internal validators.
55+
* @property {WINDOWS} [windows] Windows shortcut settings.
56+
* @property {LINUX} [linux] Linux shortcut settings.
57+
* @property {OSX} [osx] OSX shortcut settings.
58+
*/
59+
60+
/**
61+
* @type {OPTIONS}
62+
*/
63+
let OPTIONS;
64+
65+
module.exports = {
66+
OPTIONS
67+
};

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
const validation = require('./src/validation.js');
88
const library = require('./src/library.js');
9+
const { OPTIONS } = require('./api-type-definitions.js');
910

1011
/**
11-
* Creates OS based shortcuts for files, folders, and applications.
12+
* Creates OS based shortcuts for files, folders, urls, and applications.
1213
*
1314
* @example
1415
* createDesktopShortcut({
1516
* windows: { filePath: 'C:\\path\\to\\executable.exe' },
16-
* linux: { filePath: '/home/path/to/executable' },
17-
* osx: { filePath: '/home/path/to/executable' }
17+
* linux: { filePath: '/home/path/to/executable' },
18+
* osx: { filePath: '/home/path/to/executable' }
1819
* });
1920
*
20-
* @param {object} options Options object for each OS.
21+
* @param {OPTIONS} options Options object for each OS, and global options
2122
* @return {boolean} True = success, false = failed to create the icon or set its permissions (Linux).
2223
*/
2324
function createDesktopShortcut (options) {

0 commit comments

Comments
 (0)