diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 683d018..a592cac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,19 +1,19 @@ -stages: - - build - - test - -typescript_build: - stage: build - script: - - cp ../config.json ./src/config.json - - yarn install --ignore-engines - - tsc -p ./tsconfig.json - -lint: - stage: test - before_script: - - cp ../config.json ./src/config.json - - yarn install --ignore-engines - script: - - yarn run lint-find - +stages: + - build + - test + +typescript_build: + stage: build + script: + - cp ../config.json ./src/config.json + - yarn install --ignore-engines + - tsc -p ./tsconfig.json + +lint: + stage: test + before_script: + - cp ../config.json ./src/config.json + - yarn install --ignore-engines + script: + - yarn run lint-find + diff --git a/package.json b/package.json index 17183e4..47f9981 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "uuid": "^3.3.3" }, "devDependencies": { - "@types/express": "^4.17.2", + "@types/express": "^4.17.6", + "@types/express-serve-static-core": "^4.17.5", "@types/fs-extra": "^8.0.0", "@types/helmet": "^0.0.45", "@types/ioredis": "^4.0.18", diff --git a/src/api/Security.ts b/src/api/Security.ts index 2dc019f..5488662 100644 --- a/src/api/Security.ts +++ b/src/api/Security.ts @@ -70,7 +70,7 @@ export default class Security { return req.headers.authorization.split(' ')[1]; } if (req.query && req.query.token) { - return req.query.token; + return req.query.token as string; } return '0000000000'; } diff --git a/src/class/Util.ts b/src/class/Util.ts index c2d8649..d3880d8 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -32,15 +32,25 @@ export default class Util { * @param options childProcess.ExecOptions */ public async exec(command: string, options: childProcess.ExecOptions = {}): Promise { - const ex = promisify(childProcess.exec); - let result: string; - try { - const res = await ex(command, options); - result = `${res.stdout}${res.stderr}`; - } catch (err) { - return Promise.reject(new Error(`Command failed: ${err.cmd}\n${err.stderr}${err.stdout}`)); - } - return result; + return new Promise((res, rej) => { + let error = false; + let output = ''; + const writeFunction = (data: string|Buffer|Error) => { + if (data instanceof Error) error = true; + output += `${data}`; + }; + const cmd = childProcess.exec(command, options); + cmd.stdout.on('data', writeFunction); + cmd.stderr.on('data', writeFunction); + cmd.on('error', writeFunction); + cmd.once('close', (code, signal) => { + cmd.stdout.removeListener('data', writeFunction); + cmd.stderr.removeListener('data', writeFunction); + cmd.removeListener('error', writeFunction); + if (error) rej(output); + res(output); + }); + }); } /** diff --git a/src/commands/load.ts b/src/commands/load.ts index 39df7c9..2e44703 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -32,7 +32,7 @@ export default class Load extends Command { delete require.cache[`${corepath}/commands/index.js`]; delete require.cache[`${corepath}/commands/${args[1]}.js`]; Object.keys(require.cache).filter((path) => path.includes(`${args[1]}_`)).forEach((path) => delete require.cache[path]); - const cmdIndex = require('../commands'); + const cmdIndex = require('.'); let Cmd = cmdIndex[args[1]]; if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); Cmd = require(`${corepath}/commands/${args[1]}`).default;