diff --git a/app/plugins/extensions.js b/app/plugins/extensions.ts similarity index 100% rename from app/plugins/extensions.js rename to app/plugins/extensions.ts diff --git a/app/plugins/install.js b/app/plugins/install.ts similarity index 87% rename from app/plugins/install.js rename to app/plugins/install.ts index a1b44276..023fa111 100644 --- a/app/plugins/install.js +++ b/app/plugins/install.ts @@ -3,9 +3,9 @@ import queue from 'queue'; import ms from 'ms'; import {yarn, plugs} from '../config/paths'; -export const install = fn => { +export const install = (fn: Function) => { const spawnQueue = queue({concurrency: 1}); - function yarnFn(args, cb) { + function yarnFn(args: string[], cb: Function) { const env = { NODE_ENV: 'production', ELECTRON_RUN_AS_NODE: 'true' @@ -30,7 +30,7 @@ export const install = fn => { } else { cb(null); } - end(); + end?.(); spawnQueue.start(); } ); @@ -39,7 +39,7 @@ export const install = fn => { spawnQueue.start(); } - yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], err => { + yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], (err: any) => { if (err) { return fn(err); } diff --git a/app/utils/cli-install.js b/app/utils/cli-install.ts similarity index 93% rename from app/utils/cli-install.js rename to app/utils/cli-install.ts index f0da9f54..78a7c361 100644 --- a/app/utils/cli-install.js +++ b/app/utils/cli-install.ts @@ -79,13 +79,12 @@ const addBinToUserPath = () => { }); }; -const logNotify = (withNotification, ...args) => { - //eslint-disable-next-line no-console - console.log(...args); - withNotification && notify(...args); +const logNotify = (withNotification: boolean, title: string, body: string, details?: any) => { + console.log(title, body, details); + withNotification && notify(title, body, details); }; -export const installCLI = withNotification => { +export const installCLI = (withNotification: boolean) => { if (process.platform === 'win32') { addBinToUserPath() .then(() => diff --git a/app/utils/map-keys.js b/app/utils/map-keys.ts similarity index 69% rename from app/utils/map-keys.js rename to app/utils/map-keys.ts index aac64ceb..52e097c9 100644 --- a/app/utils/map-keys.js +++ b/app/utils/map-keys.ts @@ -1,5 +1,5 @@ -const generatePrefixedCommand = (command, shortcuts) => { - const result = {}; +const generatePrefixedCommand = (command: string, shortcuts: string[]) => { + const result: Record = {}; const baseCmd = command.replace(/:prefix$/, ''); for (let i = 1; i <= 9; i++) { // 9 is a special number because it means 'last' @@ -11,14 +11,15 @@ const generatePrefixedCommand = (command, shortcuts) => { return result; }; -export default config => { - return Object.keys(config).reduce((keymap, command) => { +export default (config: Record) => { + return Object.keys(config).reduce((keymap: Record, command: string) => { if (!command) { - return; + return keymap; } // We can have different keys for a same command. - const shortcuts = Array.isArray(config[command]) ? config[command] : [config[command]]; - const fixedShortcuts = []; + const _shortcuts = config[command]; + const shortcuts = Array.isArray(_shortcuts) ? _shortcuts : [_shortcuts]; + const fixedShortcuts: string[] = []; shortcuts.forEach(shortcut => { let newShortcut = shortcut; if (newShortcut.indexOf('cmd') !== -1) { diff --git a/app/utils/renderer-utils.js b/app/utils/renderer-utils.ts similarity index 55% rename from app/utils/renderer-utils.js rename to app/utils/renderer-utils.ts index 7ea6b643..4fc1d434 100644 --- a/app/utils/renderer-utils.js +++ b/app/utils/renderer-utils.ts @@ -1,14 +1,14 @@ -const rendererTypes = {}; +const rendererTypes: Record = {}; function getRendererTypes() { return rendererTypes; } -function setRendererType(uid, type) { +function setRendererType(uid: string, type: string) { rendererTypes[uid] = type; } -function unsetRendererType(uid) { +function unsetRendererType(uid: string) { delete rendererTypes[uid]; } diff --git a/app/utils/to-electron-background-color.js b/app/utils/to-electron-background-color.ts similarity index 87% rename from app/utils/to-electron-background-color.js rename to app/utils/to-electron-background-color.ts index 6612bf68..d9a5c988 100644 --- a/app/utils/to-electron-background-color.js +++ b/app/utils/to-electron-background-color.ts @@ -1,10 +1,10 @@ // Packages -const Color = require('color'); +import Color from 'color'; // returns a background color that's in hex // format including the alpha channel (e.g.: `#00000050`) // input can be any css value (rgb, hsl, string…) -module.exports = bgColor => { +export default (bgColor: string) => { const color = Color(bgColor); if (color.alpha() === 1) { diff --git a/app/utils/window-utils.js b/app/utils/window-utils.ts similarity index 68% rename from app/utils/window-utils.js rename to app/utils/window-utils.ts index 7ba4eb91..9a45f88b 100644 --- a/app/utils/window-utils.js +++ b/app/utils/window-utils.ts @@ -1,6 +1,6 @@ -const electron = require('electron'); +import electron from 'electron'; -function positionIsValid(position) { +export function positionIsValid(position: [number, number]) { const displays = electron.screen.getAllDisplays(); const [x, y] = position; @@ -8,7 +8,3 @@ function positionIsValid(position) { return x >= workArea.x && x <= workArea.x + workArea.width && y >= workArea.y && y <= workArea.y + workArea.height; }); } - -module.exports = { - positionIsValid -}; diff --git a/package.json b/package.json index 672d378b..c32c5f5f 100644 --- a/package.json +++ b/package.json @@ -303,6 +303,7 @@ "@types/fs-extra": "8.0.1", "@types/mkdirp": "0.5.2", "@types/mousetrap": "^1.6.3", + "@types/ms": "0.7.31", "@types/node": "^12.12.21", "@types/pify": "3.0.2", "@types/plist": "3.0.2", diff --git a/yarn.lock b/yarn.lock index 5157da53..4916a502 100644 --- a/yarn.lock +++ b/yarn.lock @@ -708,6 +708,11 @@ resolved "https://registry.yarnpkg.com/@types/mousetrap/-/mousetrap-1.6.3.tgz#3159a01a2b21c9155a3d8f85588885d725dc987d" integrity sha512-13gmo3M2qVvjQrWNseqM3+cR6S2Ss3grbR2NZltgMq94wOwqJYQdgn8qzwDshzgXqMlSUtyPZjysImmktu22ew== +"@types/ms@0.7.31": + version "0.7.31" + resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" + integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== + "@types/node@*", "@types/node@^12.0.12", "@types/node@^12.12.21": version "12.12.21" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.21.tgz#aa44a6363291c7037111c47e4661ad210aded23f"