Browse Source

Start converting files to typescript

develop
Drew Short 5 years ago
parent
commit
ab767f6c67
  1. 6
      package-lock.json
  2. 1
      package.json
  3. 2
      scripts/run_development_local.sh
  4. 8
      src/config.ts
  5. 2
      src/logging.ts
  6. 28
      src/message.js
  7. 28
      src/message.ts
  8. 1
      tsconfig.json

6
package-lock.json

@ -4,6 +4,12 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "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": { "ajv": {
"version": "6.10.2", "version": "6.10.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz",

1
package.json

@ -18,6 +18,7 @@
"winston": "^3.2.1" "winston": "^3.2.1"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^13.1.6",
"mocha": "^6.2.2", "mocha": "^6.2.2",
"typescript": "^3.7.4" "typescript": "^3.7.4"
} }

2
scripts/run_development_local.sh

@ -10,6 +10,8 @@ echo "LOCAL_DEVELOPMENT_"$(cat build.info) > build.info
export NODE_ENV=development export NODE_ENV=development
export LOG_LEVEL=debug export LOG_LEVEL=debug
npm run build
./entrypoint.sh run ./entrypoint.sh run
rm build.info rm build.info

8
src/config.js → src/config.ts

@ -3,7 +3,7 @@ let { logger } = require('./logging');
let loadedConfigs = new Map(); let loadedConfigs = new Map();
function sanitizeConfig(config, fields = []) {
function sanitizeConfig(config: any, fields = []) : any {
let clonedConfig = { ...config }; let clonedConfig = { ...config };
fields.forEach((field) => { fields.forEach((field) => {
clonedConfig[field] = '******' clonedConfig[field] = '******'
@ -11,7 +11,7 @@ function sanitizeConfig(config, fields = []) {
return clonedConfig; return clonedConfig;
} }
function getConfig(configFile, sanitizedFields = [], reload = false) {
function getConfig(configFile: String, sanitizedFields: Array<String> = [], reload: Boolean = false) : any {
if (loadedConfigs.has(configFile) && !reload) { if (loadedConfigs.has(configFile) && !reload) {
return loadedConfigs.get(configFile); return loadedConfigs.get(configFile);
} else { } else {
@ -25,5 +25,5 @@ function getConfig(configFile, sanitizedFields = [], reload = false) {
} }
} }
exports.getConfig = getConfig;
exports.sanitizeConfig = sanitizeConfig;
export { getConfig };
export { sanitizeConfig };

2
src/logging.js → src/logging.ts

@ -34,4 +34,4 @@ if ('LOG_LEVEL' in process.env) {
logger.level = process.env.LOG_LEVEL logger.level = process.env.LOG_LEVEL
} }
exports.logger = logger;
export { logger };

28
src/message.js

@ -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;

28
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 };

1
tsconfig.json

@ -3,6 +3,7 @@
"outDir": "./dist", "outDir": "./dist",
"allowJs": true, "allowJs": true,
"target": "ES2015", "target": "ES2015",
"module": "CommonJS",
"typeRoots": [ "typeRoots": [
"node_modules/@types" "node_modules/@types"
] ]

Loading…
Cancel
Save