Skip to content

Commit 73e518e

Browse files
committed
jetbrains formatting
1 parent 75da939 commit 73e518e

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import {Parser} from "./parser";
55

66
const colorizer = winston.format.colorize();
77

8+
// Array polyfill
9+
declare global {
10+
// tslint:disable-next-line:interface-name
11+
interface Array<T> {
12+
last(): T | undefined;
13+
first(): T | undefined;
14+
}
15+
}
16+
Array.prototype.last = function() {
17+
return this[this.length - 1];
18+
};
19+
Array.prototype.first = function() {
20+
return this[0];
21+
};
22+
823
const logger: winston.Logger = winston.createLogger({
924
format: winston.format.combine(
1025
winston.format.timestamp({format: "HH:mm:SS"}),
@@ -44,7 +59,9 @@ const runJobs = async () => {
4459
await Promise.all(promises);
4560
console.log("");
4661
} catch (e) {
47-
if (e !== "") { console.error(e); }
62+
if (e !== "") {
63+
console.error(e);
64+
}
4865
process.exit(1);
4966
}
5067
}

src/job.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Job {
1212
private readonly cwd: any;
1313
private readonly globals: any;
1414

15-
private readonly variables: {[key: string]: string};
15+
private readonly variables: { [key: string]: string };
1616

1717
private readonly allowFailure: boolean;
1818

@@ -100,7 +100,7 @@ export class Job {
100100
return `${c.blueBright(`${this.name}`)} ${mistakeStr}`;
101101
}
102102

103-
private getEnvs(): {[key: string]: string} {
103+
private getEnvs(): { [key: string]: string } {
104104
return {...this.globals.variables || {}, ...this.variables, ...process.env};
105105
}
106106

@@ -122,7 +122,10 @@ export class Job {
122122
child.stdout.on("data", (buf) => {
123123
const lines = `${buf}`.split(/\r?\n/);
124124
lines.forEach((l) => {
125-
if (l) { process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(`>`)} ${c.green(`${l}`)}\n`); }
125+
if (!l) {
126+
return;
127+
}
128+
process.stdout.write(`${c.blueBright(`${this.name}`)} ${c.greenBright(`>`)} ${c.green(`${l}`)}\n`);
126129
});
127130
});
128131
}
@@ -131,7 +134,10 @@ export class Job {
131134
child.stderr.on("data", (buf) => {
132135
const lines = `${buf}`.split(/\r?\n/);
133136
lines.forEach((l) => {
134-
if (l) { process.stderr.write(`${c.blueBright(`${this.name}`)} ${c.redBright(`>`)} ${c.red(`${l}`)}\n`); }
137+
if (!l) {
138+
return;
139+
}
140+
process.stderr.write(`${c.blueBright(`${this.name}`)} ${c.redBright(`>`)} ${c.red(`${l}`)}\n`);
135141
});
136142
});
137143
}

src/parser.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import c = require("ansi-colors");
2-
import deepExtend = require("deep-extend");
2+
import deepExtend = require("deep-extend");
33
import fs = require("fs");
44
import yaml = require("js-yaml");
55
import * as winston from "winston";
@@ -36,11 +36,15 @@ export class Parser {
3636

3737
// Parse .gitlab-ci.yml
3838
orderedYml.push(yaml.safeLoad(fs.readFileSync(gitlabCiYmlPath, "utf8")));
39-
orderedVariables.push(orderedYml[orderedYml.length - 1].variables || {});
39+
if (!orderedYml.last()) { // Print if empty
40+
console.error(`${cwd}/.gitlab-ci.yml is empty`);
41+
process.exit(1);
42+
}
43+
orderedVariables.push(orderedYml.last().variables);
4044

4145
// Parse .gitlab-ci.local.yml
42-
orderedYml.push(yaml.safeLoad(fs.readFileSync(gitlabCiLocalYmlPath, "utf8")));
43-
orderedVariables.push(orderedYml[orderedYml.length - 1].variables || {});
46+
orderedYml.push(yaml.safeLoad(fs.readFileSync(gitlabCiLocalYmlPath, "utf8")) || {});
47+
orderedVariables.push(orderedYml.last().variables || {});
4448

4549
// Parse yamls included by other ci files.
4650
const includes = deepExtend.apply(this, orderedYml).include || [];
@@ -50,7 +54,7 @@ export class Parser {
5054
}
5155

5256
orderedYml.unshift(yaml.safeLoad(fs.readFileSync(`${cwd}/${value.local}`, "utf8")));
53-
orderedVariables.unshift(orderedYml[0].variables || {});
57+
orderedVariables.unshift(orderedYml.first().variables || {});
5458
}
5559

5660
// Setup variables and "merged" yml

0 commit comments

Comments
 (0)