port app/utils and app/plugins to ts

This commit is contained in:
Labhansh Agrawal 2019-12-25 15:22:32 +05:30 committed by Benjamin Staneck
parent 5273ae3006
commit 5bb03972d7
9 changed files with 29 additions and 27 deletions

View file

@ -3,9 +3,9 @@ import queue from 'queue';
import ms from 'ms'; import ms from 'ms';
import {yarn, plugs} from '../config/paths'; import {yarn, plugs} from '../config/paths';
export const install = fn => { export const install = (fn: Function) => {
const spawnQueue = queue({concurrency: 1}); const spawnQueue = queue({concurrency: 1});
function yarnFn(args, cb) { function yarnFn(args: string[], cb: Function) {
const env = { const env = {
NODE_ENV: 'production', NODE_ENV: 'production',
ELECTRON_RUN_AS_NODE: 'true' ELECTRON_RUN_AS_NODE: 'true'
@ -30,7 +30,7 @@ export const install = fn => {
} else { } else {
cb(null); cb(null);
} }
end(); end?.();
spawnQueue.start(); spawnQueue.start();
} }
); );
@ -39,7 +39,7 @@ export const install = fn => {
spawnQueue.start(); 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) { if (err) {
return fn(err); return fn(err);
} }

View file

@ -79,13 +79,12 @@ const addBinToUserPath = () => {
}); });
}; };
const logNotify = (withNotification, ...args) => { const logNotify = (withNotification: boolean, title: string, body: string, details?: any) => {
//eslint-disable-next-line no-console console.log(title, body, details);
console.log(...args); withNotification && notify(title, body, details);
withNotification && notify(...args);
}; };
export const installCLI = withNotification => { export const installCLI = (withNotification: boolean) => {
if (process.platform === 'win32') { if (process.platform === 'win32') {
addBinToUserPath() addBinToUserPath()
.then(() => .then(() =>

View file

@ -1,5 +1,5 @@
const generatePrefixedCommand = (command, shortcuts) => { const generatePrefixedCommand = (command: string, shortcuts: string[]) => {
const result = {}; const result: Record<string, string[]> = {};
const baseCmd = command.replace(/:prefix$/, ''); const baseCmd = command.replace(/:prefix$/, '');
for (let i = 1; i <= 9; i++) { for (let i = 1; i <= 9; i++) {
// 9 is a special number because it means 'last' // 9 is a special number because it means 'last'
@ -11,14 +11,15 @@ const generatePrefixedCommand = (command, shortcuts) => {
return result; return result;
}; };
export default config => { export default (config: Record<string, string[] | string>) => {
return Object.keys(config).reduce((keymap, command) => { return Object.keys(config).reduce((keymap: Record<string, string[]>, command: string) => {
if (!command) { if (!command) {
return; return keymap;
} }
// We can have different keys for a same command. // We can have different keys for a same command.
const shortcuts = Array.isArray(config[command]) ? config[command] : [config[command]]; const _shortcuts = config[command];
const fixedShortcuts = []; const shortcuts = Array.isArray(_shortcuts) ? _shortcuts : [_shortcuts];
const fixedShortcuts: string[] = [];
shortcuts.forEach(shortcut => { shortcuts.forEach(shortcut => {
let newShortcut = shortcut; let newShortcut = shortcut;
if (newShortcut.indexOf('cmd') !== -1) { if (newShortcut.indexOf('cmd') !== -1) {

View file

@ -1,14 +1,14 @@
const rendererTypes = {}; const rendererTypes: Record<string, string> = {};
function getRendererTypes() { function getRendererTypes() {
return rendererTypes; return rendererTypes;
} }
function setRendererType(uid, type) { function setRendererType(uid: string, type: string) {
rendererTypes[uid] = type; rendererTypes[uid] = type;
} }
function unsetRendererType(uid) { function unsetRendererType(uid: string) {
delete rendererTypes[uid]; delete rendererTypes[uid];
} }

View file

@ -1,10 +1,10 @@
// Packages // Packages
const Color = require('color'); import Color from 'color';
// returns a background color that's in hex // returns a background color that's in hex
// format including the alpha channel (e.g.: `#00000050`) // format including the alpha channel (e.g.: `#00000050`)
// input can be any css value (rgb, hsl, string…) // input can be any css value (rgb, hsl, string…)
module.exports = bgColor => { export default (bgColor: string) => {
const color = Color(bgColor); const color = Color(bgColor);
if (color.alpha() === 1) { if (color.alpha() === 1) {

View file

@ -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 displays = electron.screen.getAllDisplays();
const [x, y] = position; 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; return x >= workArea.x && x <= workArea.x + workArea.width && y >= workArea.y && y <= workArea.y + workArea.height;
}); });
} }
module.exports = {
positionIsValid
};

View file

@ -303,6 +303,7 @@
"@types/fs-extra": "8.0.1", "@types/fs-extra": "8.0.1",
"@types/mkdirp": "0.5.2", "@types/mkdirp": "0.5.2",
"@types/mousetrap": "^1.6.3", "@types/mousetrap": "^1.6.3",
"@types/ms": "0.7.31",
"@types/node": "^12.12.21", "@types/node": "^12.12.21",
"@types/pify": "3.0.2", "@types/pify": "3.0.2",
"@types/plist": "3.0.2", "@types/plist": "3.0.2",

View file

@ -708,6 +708,11 @@
resolved "https://registry.yarnpkg.com/@types/mousetrap/-/mousetrap-1.6.3.tgz#3159a01a2b21c9155a3d8f85588885d725dc987d" resolved "https://registry.yarnpkg.com/@types/mousetrap/-/mousetrap-1.6.3.tgz#3159a01a2b21c9155a3d8f85588885d725dc987d"
integrity sha512-13gmo3M2qVvjQrWNseqM3+cR6S2Ss3grbR2NZltgMq94wOwqJYQdgn8qzwDshzgXqMlSUtyPZjysImmktu22ew== 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": "@types/node@*", "@types/node@^12.0.12", "@types/node@^12.12.21":
version "12.12.21" version "12.12.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.21.tgz#aa44a6363291c7037111c47e4661ad210aded23f" resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.21.tgz#aa44a6363291c7037111c47e4661ad210aded23f"