Skip to content

Commit 5de8493

Browse files
committed
added supported languages func
1 parent d1a705d commit 5de8493

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

src/functions/environment.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Environment } from "../constants";
2+
3+
export function parseEnvironment(platform: string): Environment {
4+
if (platform === "win32") {
5+
return Environment.WIN;
6+
} else {
7+
return Environment.UNIX;
8+
}
9+
}

src/executor.ts renamed to src/functions/executor.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ import {
88
Environment,
99
IExecuteOptions,
1010
defaultExecutionTimeout,
11-
} from "./constants";
12-
import path from "path";
13-
14-
function parseEnvironment(platform: string): Environment {
15-
if (platform === "win32") {
16-
return Environment.WIN;
17-
} else {
18-
return Environment.UNIX;
19-
}
20-
}
11+
} from "../constants";
12+
import { join } from "path";
13+
import { parseEnvironment } from "./environment";
2114

2215
/**
2316
*
@@ -39,7 +32,7 @@ export default async function execute(
3932

4033
const id = new Date().getTime() + "_" + Math.floor(Math.random() * 10000);
4134

42-
const tempFolder: string = path.join(tmpdir(), id);
35+
const tempFolder: string = join(tmpdir(), id);
4336

4437
try {
4538
mkdirSync(tempFolder);
@@ -61,9 +54,10 @@ export default async function execute(
6154
var filetype = env === Environment.WIN ? "bat" : "sh";
6255

6356
// Path to runner file
64-
var runnerpath = path.join(
57+
var runnerpath = join(
6558
__dirname,
6659
"..",
60+
"..",
6761
"runners",
6862
env,
6963
`${language}.${filetype}`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { parseEnvironment } from "./environment";
2+
import { platform } from "os";
3+
import { readdirSync } from "fs";
4+
import { join } from "path";
5+
6+
export default function getSupportedLanguages(): string[] {
7+
const env = parseEnvironment(platform());
8+
const runnerpath = join(__dirname, "..", "..", "runners", env);
9+
const files = readdirSync(runnerpath);
10+
return files.map((file) => {
11+
return file.split(".")[0];
12+
});
13+
}

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"use strict";
22

3-
import executer from "./executor";
3+
import executeFunc from "./functions/executor";
4+
import getSupportedLanguagesFunc from "./functions/supported-languages";
45
import { Language } from "./constants";
56
import lxc from "./lxc";
67

78
export const languages = Language;
8-
export const execute = executer;
9+
export const execute = executeFunc;
910
export const LXC = lxc;
11+
export const getSupportedLanguages = getSupportedLanguagesFunc;

tests/all.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,10 @@ int main() {
100100
});
101101
}, 30000);
102102
});
103+
104+
describe("Testing Basic Functions", () => {
105+
test("getSupportedLanguages()", () => {
106+
var l = cee.getSupportedLanguages();
107+
expect(l.length).toBeGreaterThan(0);
108+
}, 30000);
109+
});

0 commit comments

Comments
 (0)