Skip to content

Commit 32d0f46

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 133b1f8 + ba47afb commit 32d0f46

File tree

7 files changed

+68
-55
lines changed

7 files changed

+68
-55
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@types/pretty-hrtime": "1.x",
3737
"@types/shelljs": "0.x",
3838
"@types/yaml": "1.x",
39-
"@types/yargs": "13.x",
39+
"@types/yargs": "15.x",
4040
"pkg": "4.x",
4141
"source-map-support": "0.x",
4242
"tslint": "5.x",

src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import c = require("ansi-colors");
1+
import * as c from "ansi-colors";
22
import * as winston from "winston";
3-
import yargs = require("yargs");
4-
import {Parser} from "./parser";
3+
import * as yargs from "yargs";
4+
5+
import { Parser } from "./parser";
56

67
const colorizer = winston.format.colorize();
78

89
// Array polyfill
910
declare global {
1011
// tslint:disable-next-line:interface-name
1112
interface Array<T> {
12-
last(): T | undefined;
1313
first(): T | undefined;
14+
last(): T | undefined;
1415
}
1516
}
1617
Array.prototype.last = function() {
@@ -49,7 +50,7 @@ const runJobs = async () => {
4950
}
5051

5152
const jobNames = `${jobs.map((j) => j.name).join(" ")}`;
52-
console.log(`=> ${c.yellow(`${stageName}`)} > ${c.blueBright(`${jobNames}`)} ${c.magentaBright(`starting`)}...`);
53+
console.log(`=> ${c.yellow(`${stageName}`)} > ${c.blueBright(`${jobNames}`)} ${c.magentaBright("starting")}...`);
5354
for (const job of jobs) {
5455
const jobPromise = job.start();
5556
promises.push(jobPromise);
@@ -68,7 +69,7 @@ const runJobs = async () => {
6869
};
6970

7071
process.on("uncaughtException", (err) => {
71-
// handle the error safely
72+
// Handle the error safely
7273
console.log(err);
7374
});
7475

src/job.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import c = require("ansi-colors");
2-
import prettyHrtime = require("pretty-hrtime");
1+
import * as c from "ansi-colors";
2+
import * as prettyHrtime from "pretty-hrtime";
33
import * as shelljs from "shelljs";
44

55
const shell = process.env.EXEPATH ? `${process.env.EXEPATH}/bash.exe` : "/bin/bash";
66

77
export class Job {
8-
9-
public readonly stage: string;
108
public readonly name: string;
119

12-
private readonly cwd: any;
13-
private readonly globals: any;
14-
15-
private readonly variables: { [key: string]: string };
10+
public readonly stage: string;
11+
private readonly afterScripts: string[] = [];
1612

1713
private readonly allowFailure: boolean;
1814

1915
private readonly beforeScripts: string[] = [];
16+
17+
private readonly cwd: any;
18+
private readonly globals: any;
19+
20+
private running = false;
2021
private readonly scripts: string[] = [];
21-
private readonly afterScripts: string[] = [];
2222

23-
private running: boolean = false;
23+
private readonly variables: { [key: string]: string };
2424

25-
constructor(jobData: any, name: string, cwd: any, globals: any) {
25+
public constructor(jobData: any, name: string, cwd: any, globals: any) {
2626
this.name = name;
2727
this.cwd = cwd;
2828
this.globals = globals;
@@ -41,7 +41,7 @@ export class Job {
4141
this.running = true;
4242

4343
if (this.scripts.length === 0) {
44-
console.error(`${c.blueBright(`${this.name}`)} ${c.red(`must have script specified`)}`);
44+
console.error(`${c.blueBright(`${this.name}`)} ${c.red("must have script specified")}`);
4545
process.exit(1);
4646
}
4747

@@ -57,6 +57,7 @@ export class Job {
5757
console.error(this.getExitedString(prescriptsExitCode, true));
5858
console.log(this.getFinishedString(startTime));
5959
this.running = false;
60+
6061
return;
6162
}
6263

@@ -83,28 +84,14 @@ export class Job {
8384

8485
console.log(this.getFinishedString(startTime));
8586
this.running = false;
87+
8688
return;
8789
}
8890

8991
public toString() {
9092
return this.name;
9193
}
9294

93-
private getFinishedString(startTime: [number, number]) {
94-
const endTime = process.hrtime(startTime);
95-
const timeStr = prettyHrtime(endTime);
96-
return `${c.blueBright(`${this.name}`)} ${c.magentaBright(`finished`)} in ${c.magenta(`${timeStr}`)}`;
97-
}
98-
99-
private getExitedString(code: number, warning: boolean = false, prependString: string = "") {
100-
const mistakeStr = warning ? c.yellowBright(`warning with code ${code}`) + prependString : c.red(`exited with code ${code}`) + prependString;
101-
return `${c.blueBright(`${this.name}`)} ${mistakeStr}`;
102-
}
103-
104-
private getEnvs(): { [key: string]: string } {
105-
return {...this.globals.variables || {}, ...this.variables, ...process.env};
106-
}
107-
10895
private async exec(script: string): Promise<number> {
10996
return new Promise<any>((resolve, reject) => {
11097
const child = shelljs.exec(`${script}`, {
@@ -116,7 +103,7 @@ export class Job {
116103
});
117104

118105
child.on("error", (e) => {
119-
reject(`${c.blueBright(`${this.name}`)} ${c.red(`error ${e}`)}`);
106+
reject(`${c.blueBright(`${this.name}`)} ${c.red(`error ${String(e)}`)}`);
120107
});
121108

122109
if (child.stdout) {
@@ -126,7 +113,7 @@ export class Job {
126113
if (!l) {
127114
return;
128115
}
129-
process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(`>`)} ${c.green(`${l}`)}\n`);
116+
process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(">")} ${c.green(`${l}`)}\n`);
130117
});
131118
});
132119
}
@@ -138,12 +125,29 @@ export class Job {
138125
if (!l) {
139126
return;
140127
}
141-
process.stderr.write(`${c.blueBright(`${this.name}`)} ${c.redBright(`>`)} ${c.red(`${l}`)}\n`);
128+
process.stderr.write(`${c.blueBright(`${this.name}`)} ${c.redBright(">")} ${c.red(`${l}`)}\n`);
142129
});
143130
});
144131
}
145132

146133
child.on("exit", resolve);
147134
});
148135
}
136+
137+
private getEnvs(): { [key: string]: string } {
138+
return {...this.globals.variables || {}, ...this.variables, ...process.env};
139+
}
140+
141+
private getExitedString(code: number, warning: boolean = false, prependString: string = "") {
142+
const mistakeStr = warning ? c.yellowBright(`warning with code ${code}`) + prependString : c.red(`exited with code ${code}`) + prependString;
143+
144+
return `${c.blueBright(`${this.name}`)} ${mistakeStr}`;
145+
}
146+
147+
private getFinishedString(startTime: [number, number]) {
148+
const endTime = process.hrtime(startTime);
149+
const timeStr = prettyHrtime(endTime);
150+
151+
return `${c.blueBright(`${this.name}`)} ${c.magentaBright("finished")} in ${c.magenta(`${timeStr}`)}`;
152+
}
149153
}

src/parser.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import c = require("ansi-colors");
2-
import deepExtend = require("deep-extend");
3-
import fs = require("fs");
4-
import yaml = require("js-yaml");
1+
import * as c from "ansi-colors";
2+
import * as deepExtend from "deep-extend";
3+
import * as fs from "fs";
4+
import * as yaml from "js-yaml";
55
import * as winston from "winston";
6-
import {Job} from "./job";
7-
import {Stage} from "./stage";
6+
7+
import { Job } from "./job";
8+
import { Stage } from "./stage";
89

910
export class Parser {
1011

@@ -16,7 +17,7 @@ export class Parser {
1617
private readonly jobs: Map<string, Job> = new Map();
1718
private readonly stages: Map<string, Stage> = new Map();
1819

19-
constructor(cwd: any, logger: winston.Logger) {
20+
public constructor(cwd: any, logger: winston.Logger) {
2021
// Fail if .gitlab-ci.yml missing
2122
const gitlabCiYmlPath = `${cwd}/.gitlab-ci.yml`;
2223
if (!fs.existsSync(gitlabCiYmlPath)) {
@@ -77,19 +78,19 @@ export class Parser {
7778
stage.addJob(job);
7879
} else {
7980
const stagesJoin = Array.from(this.stages.keys()).join(", ");
80-
console.error(`${c.blueBright(`${job.name}`)} ${c.yellow(`${job.stage}`)} ${c.red(`isn't specified in stages. Must be one of the following`)} ${c.yellow(`${stagesJoin}`)}`);
81+
console.error(`${c.blueBright(`${job.name}`)} ${c.yellow(`${job.stage}`)} ${c.red("isn't specified in stages. Must be one of the following")} ${c.yellow(`${stagesJoin}`)}`);
8182
process.exit(1);
8283
}
8384

8485
this.jobs.set(key, job);
8586
}
8687
}
8788

88-
public getStages(): ReadonlyMap<string, Stage> {
89-
return this.stages;
90-
}
91-
9289
public getJobs(): ReadonlyMap<string, Job> {
9390
return this.jobs;
9491
}
92+
93+
public getStages(): ReadonlyMap<string, Stage> {
94+
return this.stages;
95+
}
9596
}

src/stage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {Job} from "./job";
1+
import { Job } from "./job";
22

33
export class Stage {
44

55
public readonly name: string;
66
private readonly jobs: Job[] = [];
77

8-
constructor(name: string) {
8+
public constructor(name: string) {
99
this.name = name;
1010
}
1111

tslint.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
22
"defaultSeverity": "error",
33
"extends": [
4-
"tslint:recommended"
4+
"tslint:all"
55
],
66
"jsRules": {},
77
"rules": {
8+
"strict-boolean-expressions": false,
9+
"newline-per-chained-call": false,
10+
"no-any": false,
11+
"no-unsafe-any": false,
12+
"completed-docs": false,
13+
"typedef": false,
14+
"no-use-before-declare": false,
815
"no-string-throw": false,
916
"no-console": false,
1017
"object-literal-sort-keys": false,

0 commit comments

Comments
 (0)