From c54d004d72baccb7e9b671e87cacd7d54986299a Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Tue, 28 Feb 2017 11:04:41 +0300 Subject: [PATCH] Typings added; code style improved --- BuildServer/app.ts | 6 +- BuildServer/lib/builder.ts | 2 +- BuildServer/lib/report-processor.ts | 44 ++++++++-- BuildServer/lib/tasks/zip.ts | 4 +- BuildServer/package.json | 122 +++++----------------------- BuildServer/routes/release.ts | 4 +- BuildServer/tsconfig.json | 4 + 7 files changed, 71 insertions(+), 115 deletions(-) diff --git a/BuildServer/app.ts b/BuildServer/app.ts index bf4b741..5ca853e 100644 --- a/BuildServer/app.ts +++ b/BuildServer/app.ts @@ -1,9 +1,9 @@ "use strict"; -import * as realFs from "fs"; -import * as fs from "graceful-fs"; +import * as fs from "fs"; +import { gracefulify } from "graceful-fs"; -fs.gracefulify(realFs); +gracefulify(fs); import * as express from "express"; import * as routes from "./routes"; diff --git a/BuildServer/lib/builder.ts b/BuildServer/lib/builder.ts index 422e3c8..bdb7c68 100644 --- a/BuildServer/lib/builder.ts +++ b/BuildServer/lib/builder.ts @@ -74,7 +74,7 @@ export const build = (options, buildCallback) => { const tmp = join(options.app.get("tmpcodepath"), rev.substr(0, maxTmpcodepathLength)); const exported = tmp + codePostfix; const release = join(options.app.get("releasepath"), owner, reponame, branch, rev); - const statusQueue = queue((task, queueCallback) => task(queueCallback), 1); + const statusQueue = queue((task: (callback: any) => void, queueCallback) => task(queueCallback), 1); const actualGitLoader = wrapGitLoader(skipGitLoader); const date = new Date(); const versionMajor = date.getFullYear(); diff --git a/BuildServer/lib/report-processor.ts b/BuildServer/lib/report-processor.ts index b11014b..e824786 100644 --- a/BuildServer/lib/report-processor.ts +++ b/BuildServer/lib/report-processor.ts @@ -8,6 +8,40 @@ import { ReadableStreamBuffer, WritableStreamBuffer } from "stream-buffers"; import * as _ from "underscore"; import * as JSONParse from "json-parse-safe"; +interface Message { + message: string; + prefix: string; +}; + +interface PartialMessagesLeaf { + $messages: string[]; +}; + +interface PartialMessagesRecursive { + [propName: string]: Messages; +}; + +interface PartialMessagesRoot { + $allMessages: Message[]; +}; + +type Messages = PartialMessagesLeaf & PartialMessagesRecursive; + +type MessagesRoot = PartialMessagesLeaf & PartialMessagesRecursive & PartialMessagesRoot; + +interface ReportResult { + errors: MessagesRoot; + warns: MessagesRoot; + infos: MessagesRoot; + messages: MessagesRoot; +}; + +interface Report { + date: number; + err?: string; + result?: ReportResult; +}; + const reportFilename = "report.json.gz"; const maxAttemptsNumber = 100; const attemptsTimeout = 30000; @@ -20,11 +54,11 @@ const readableStreamBufferOptions = { "frequency": 1 }; -const getAllErrors = (report) => ((report.result || {}).errors || {}).$allMessages || []; -const getAllWarns = (report) => ((report.result || {}).warns || {}).$allMessages || []; -const getAllInfos = (report) => ((report.result || {}).infos || {}).$allMessages || []; +const getAllErrors = (report: Report): Message[] => (report.result && report.result.errors && report.result.errors.$allMessages) || []; +const getAllWarns = (report: Report): Message[] => (report.result && report.result.warns && report.result.errors.$allMessages) || []; +const getAllInfos = (report: Report): Message[] => (report.result && report.result.infos && report.result.errors.$allMessages) || []; -export const writeReport = (releaseDir, err, result, callback) => { +export const writeReport = (releaseDir, err, result: ReportResult, callback) => { const data = JSON.stringify({ "date": Date.now(), err, @@ -67,7 +101,7 @@ export const readReport = (releaseDir, callback) => { return callback("ReportFileNotFound"); } - const { error, value } = JSONParse(data); + const { error, value }: { error: any, value?: Report } = JSONParse(data); if (error) { return callback("ReportFileMalformed"); } diff --git a/BuildServer/lib/tasks/zip.ts b/BuildServer/lib/tasks/zip.ts index b368d62..5c2a476 100644 --- a/BuildServer/lib/tasks/zip.ts +++ b/BuildServer/lib/tasks/zip.ts @@ -2,7 +2,7 @@ import { createWriteStream } from "fs"; import { join, normalize } from "path"; -import * as Archiver from "archiver"; +import { create as createArchiver } from "archiver"; export default (params, processor) => ({ "process": () => { @@ -12,7 +12,7 @@ export default (params, processor) => ({ processor.onInfo(`Compressing "${params.directory}" to "${params.archive}"`); const output = createWriteStream(targetArchivePath); - const archive = new Archiver("zip"); + const archive = createArchiver("zip"); output.on("close", () => processor.done()); diff --git a/BuildServer/package.json b/BuildServer/package.json index dcaca7b..a3087d6 100644 --- a/BuildServer/package.json +++ b/BuildServer/package.json @@ -4,8 +4,9 @@ "private": true, "scripts": { "start": "forever -c node app.js", - "test": "./node_modules/.bin/eslint .", - "tslint": "./node_modules/.bin/tslint --project tsconfig.json --type-check --force" + "build": "./node_modules/.bin/tsc -p .", + "pretest": "./node_modules/.bin/tsc -p . --noEmit", + "test": "./node_modules/.bin/tslint --project tsconfig.json --type-check" }, "dependencies": { "archiver": "^1.3.0", @@ -16,7 +17,7 @@ "eslint": "^3.12.2", "express": "4.14.0", "fs-extra": "^1.0.0", - "github": "~7.1.0", + "github": "~9.0.0", "glob": "~7.1.1", "graceful-fs": "^4.1.11", "jade": "*", @@ -25,7 +26,6 @@ "morgan": "^1.7.0", "mustache": "~2.3.0", "nodegit": "~0.16.0", - "nodemailer": "~2.7.0", "recursive-tree-copy": "0.0.1", "serve-favicon": "^2.3.2", "serve-static": "^1.11.1", @@ -33,106 +33,24 @@ "uglify-js": "^2.7.5", "underscore": "^1.8.3" }, - "eslintConfig": { - "env": { - "node": true - }, - "parserOptions": { - "ecmaVersion": 6 - }, - "plugins": [ - "fp" - ], - "extends": [ - "eslint:all", - "plugin:fp/recommended" - ], - "rules": { - "fp/no-unused-expression": "off", - "fp/no-nil": "off", - "fp/no-mutation": [ - "error", - { - "commonjs": true - } - ], - "prefer-destructuring": "off", - "quotes": [ - "warn", - "double" - ], - "require-jsdoc": "off", - "func-names": [ - "warn", - "never" - ], - "max-len": [ - "warn", - { - "code": 140 - } - ], - "operator-linebreak": [ - "warn", - "before" - ], - "padded-blocks": [ - "warn", - "never" - ], - "dot-notation": [ - "warn", - { - "allowPattern": "^[a-z]+(_[a-z]+)+$" - } - ], - "linebreak-style": [ - "warn", - "windows" - ], - "no-console": "off", - "dot-location": [ - "warn", - "property" - ], - "object-curly-spacing": [ - "warn", - "always" - ], - "one-var": [ - "warn", - { - "initialized": "never" - } - ], - "no-magic-numbers": [ - "warn", - { - "ignore": [ - 0, - 1 - ] - } - ], - "id-length": [ - "warn", - { - "exceptions": [ - "_" - ] - } - ], - "no-extra-parens": [ - "warn", - "all", - { - "nestedBinaryExpressions": false - } - ] - } - }, "devDependencies": { + "@types/archiver": "^0.15.37", + "@types/async": "^2.0.38", + "@types/body-parser": "0.0.34", + "@types/errorhandler": "0.0.30", + "@types/express": "^4.0.35", + "@types/fs-extra": "0.0.37", + "@types/github": "0.0.0", + "@types/glob": "^5.0.30", + "@types/jade": "0.0.30", + "@types/method-override": "0.0.29", + "@types/morgan": "^1.7.32", + "@types/mustache": "^0.8.29", "@types/node": "^7.0.5", + "@types/serve-favicon": "^2.2.28", + "@types/serve-static": "^1.7.31", + "@types/uglify-js": "^2.6.28", + "@types/underscore": "^1.7.36", "tslint": "^4.4.2", "typescript": "^2.2.1" } diff --git a/BuildServer/routes/release.ts b/BuildServer/routes/release.ts index c82fd9a..c4d5f0c 100644 --- a/BuildServer/routes/release.ts +++ b/BuildServer/routes/release.ts @@ -1,7 +1,7 @@ "use strict"; import { join } from "path"; -import * as Archiver from "archiver"; +import { create as createArchiver } from "archiver"; import { readReport } from "../lib/report-processor"; @@ -39,7 +39,7 @@ export default (req, res, next) => { return next(err); } - const archive = new Archiver("zip"); + const archive = createArchiver("zip"); archive.on("error", next); res.attachment(`${options.reponame}.${getDatePart(report)}.${options.rev}.zip`, "."); diff --git a/BuildServer/tsconfig.json b/BuildServer/tsconfig.json index be0fb57..4ce9f95 100644 --- a/BuildServer/tsconfig.json +++ b/BuildServer/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "module": "commonjs", "target": "es6", + "sourceMap": false, "typeRoots": [ "node_modules/@types" ] @@ -11,5 +12,8 @@ "settings.ts", "lib/**/*.ts", "routes/**/*.ts" + ], + "exclude": [ + "node_modules/**/*.ts" ] }