From ab767f6c679b8b8d4dae8bfe1197778544f54ca2 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Fri, 10 Jan 2020 14:18:28 -0600 Subject: [PATCH] Start converting files to typescript --- package-lock.json | 6 ++++++ package.json | 1 + scripts/run_development_local.sh | 2 ++ src/{config.js => config.ts} | 8 ++++---- src/{logging.js => logging.ts} | 2 +- src/message.js | 28 ---------------------------- src/message.ts | 28 ++++++++++++++++++++++++++++ tsconfig.json | 1 + 8 files changed, 43 insertions(+), 33 deletions(-) rename src/{config.js => config.ts} (76%) rename src/{logging.js => logging.ts} (97%) delete mode 100644 src/message.js create mode 100644 src/message.ts diff --git a/package-lock.json b/package-lock.json index 3515ea2..b924ed5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,12 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/node": { + "version": "13.1.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.6.tgz", + "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==", + "dev": true + }, "ajv": { "version": "6.10.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz", diff --git a/package.json b/package.json index 6ff7dc0..4d63987 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "winston": "^3.2.1" }, "devDependencies": { + "@types/node": "^13.1.6", "mocha": "^6.2.2", "typescript": "^3.7.4" } diff --git a/scripts/run_development_local.sh b/scripts/run_development_local.sh index 0228e31..b2db88f 100755 --- a/scripts/run_development_local.sh +++ b/scripts/run_development_local.sh @@ -10,6 +10,8 @@ echo "LOCAL_DEVELOPMENT_"$(cat build.info) > build.info export NODE_ENV=development export LOG_LEVEL=debug +npm run build + ./entrypoint.sh run rm build.info diff --git a/src/config.js b/src/config.ts similarity index 76% rename from src/config.js rename to src/config.ts index 2002dc5..eb717a4 100644 --- a/src/config.js +++ b/src/config.ts @@ -3,7 +3,7 @@ let { logger } = require('./logging'); let loadedConfigs = new Map(); -function sanitizeConfig(config, fields = []) { +function sanitizeConfig(config: any, fields = []) : any { let clonedConfig = { ...config }; fields.forEach((field) => { clonedConfig[field] = '******' @@ -11,7 +11,7 @@ function sanitizeConfig(config, fields = []) { return clonedConfig; } -function getConfig(configFile, sanitizedFields = [], reload = false) { +function getConfig(configFile: String, sanitizedFields: Array = [], reload: Boolean = false) : any { if (loadedConfigs.has(configFile) && !reload) { return loadedConfigs.get(configFile); } else { @@ -25,5 +25,5 @@ function getConfig(configFile, sanitizedFields = [], reload = false) { } } -exports.getConfig = getConfig; -exports.sanitizeConfig = sanitizeConfig; \ No newline at end of file +export { getConfig }; +export { sanitizeConfig }; \ No newline at end of file diff --git a/src/logging.js b/src/logging.ts similarity index 97% rename from src/logging.js rename to src/logging.ts index ddb9f3d..e2bff62 100644 --- a/src/logging.js +++ b/src/logging.ts @@ -34,4 +34,4 @@ if ('LOG_LEVEL' in process.env) { logger.level = process.env.LOG_LEVEL } -exports.logger = logger; \ No newline at end of file +export { logger }; \ No newline at end of file diff --git a/src/message.js b/src/message.js deleted file mode 100644 index 01b25e0..0000000 --- a/src/message.js +++ /dev/null @@ -1,28 +0,0 @@ -let showdown = require('showdown'); - -let converter = new showdown.Converter(); - -let messageTypes = { - TEXT: 'm.text', - NOTICE: 'm.notice' -} - -function createBasicMessage(body, msgtype = messageTypes.TEXT) { - return { - "body": body, - "msgtype": msgtype - }; -} - -function createMarkdownMessage(body, markdown, msgtype = messageTypes.TEXT) { - return { - "body": body, - "msgtype": msgtype, - "format": "org.matrix.custom.html", - "formatted_body": converter.makeHtml(markdown) - }; -} - -exports.types = messageTypes; -exports.createBasic = createBasicMessage; -exports.createMarkdown = createMarkdownMessage; \ No newline at end of file diff --git a/src/message.ts b/src/message.ts new file mode 100644 index 0000000..88952fd --- /dev/null +++ b/src/message.ts @@ -0,0 +1,28 @@ +let showdown = require('showdown'); + +let converter = new showdown.Converter(); + +enum MessageTypes { + TEXT = 'm.text', + NOTICE = 'm.notice' +} + +function createBasicMessage(body: String, msgtype: MessageTypes = MessageTypes.TEXT) { + return { + "body": body, + "msgtype": msgtype + }; +} + +function createMarkdownMessage(body: String, markdown: String, msgtype: MessageTypes = MessageTypes.TEXT) { + return { + "body": body, + "msgtype": msgtype, + "format": "org.matrix.custom.html", + "formatted_body": converter.makeHtml(markdown) + }; +} + +export { MessageTypes as types }; +export { createBasicMessage as createBasic }; +export { createMarkdownMessage as createMarkdown }; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 3b14de4..3c91846 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "outDir": "./dist", "allowJs": true, "target": "ES2015", + "module": "CommonJS", "typeRoots": [ "node_modules/@types" ]