Skip to content

Commit

Permalink
Typescriptify main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Oct 1, 2021
1 parent e033fd2 commit 9a1430a
Show file tree
Hide file tree
Showing 22 changed files with 722 additions and 525 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -193,7 +193,7 @@ module.exports = grunt => {
process.platform === 'win32' ? 'electron.cmd' : 'electron';

const path = join(__dirname, 'node_modules', '.bin', electronBinary);
const args = [join(__dirname, 'main.js')];
const args = [join(__dirname, 'app', 'main.js')];
grunt.log.writeln('Starting path', path, 'with args', args);
const app = new Application({
path,
Expand Down
16 changes: 9 additions & 7 deletions app/base_config.ts
Expand Up @@ -7,18 +7,20 @@ import { get, set } from 'lodash';

const ENCODING = 'utf8';

type ConfigType = Record<string, unknown>;
type InternalConfigType = Record<string, unknown>;

export type ConfigType = {
set: (keyPath: string, value: unknown) => void;
get: (keyPath: string) => unknown;
remove: () => void;
};

export function start(
name: string,
targetPath: string,
options?: { allowMalformedOnStartup?: boolean }
): {
set: (keyPath: string, value: unknown) => void;
get: (keyPath: string) => unknown;
remove: () => void;
} {
let cachedValue: ConfigType | undefined;
): ConfigType {
let cachedValue: InternalConfigType | undefined;

try {
const text = readFileSync(targetPath, ENCODING);
Expand Down
19 changes: 5 additions & 14 deletions app/config.ts
Expand Up @@ -4,6 +4,8 @@
import { join } from 'path';
import { app } from 'electron';

import type { IConfig } from 'config';

import {
Environment,
getEnvironment,
Expand Down Expand Up @@ -34,21 +36,9 @@ if (getEnvironment() === Environment.Production) {
process.env.SIGNAL_ENABLE_HTTP = '';
}

export type ConfigType = {
get: (key: string) => unknown;
has: (key: string) => unknown;
[key: string]: unknown;
util: {
getEnv: (keY: string) => string | undefined;
};
};

// We load config after we've made our modifications to NODE_ENV
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config: ConfigType = require('config');

config.environment = getEnvironment();
config.enableHttp = process.env.SIGNAL_ENABLE_HTTP;
// eslint-disable-next-line import/order, import/first
import config from 'config';

// Log resulting env vars in use by config
[
Expand All @@ -65,3 +55,4 @@ config.enableHttp = process.env.SIGNAL_ENABLE_HTTP;
});

export default config;
export type { IConfig as ConfigType };
12 changes: 7 additions & 5 deletions app/locale.ts
Expand Up @@ -32,17 +32,19 @@ function getLocaleMessages(locale: string): LocaleMessagesType {
return JSON.parse(readFileSync(targetFile, 'utf-8'));
}

export type LocaleType = {
i18n: LocalizerType;
name: string;
messages: LocaleMessagesType;
};

export function load({
appLocale,
logger,
}: {
appLocale: string;
logger: LoggerType;
}): {
i18n: LocalizerType;
name: string;
messages: LocaleMessagesType;
} {
}): LocaleType {
if (!appLocale) {
throw new TypeError('`appLocale` is required');
}
Expand Down

0 comments on commit 9a1430a

Please sign in to comment.