Skip to content

Commit ae4bbb4

Browse files
committed
Create run script which can be used to run typescript files using ts-node
1 parent efda87d commit ae4bbb4

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"use strict";
44

5-
import { format, init, lint, test } from "./scripts";
5+
import { format, init, lint, run, test } from "./scripts";
66

77
const args = process.argv.slice(2);
88
const scriptName = args[0];
@@ -31,6 +31,12 @@ switch (scriptName) {
3131
break;
3232
}
3333

34+
case "run": {
35+
const status = run();
36+
process.exit(status);
37+
break;
38+
}
39+
3440
case "test": {
3541
const status = test();
3642
process.exit(status);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cdimitroulas/typescript-scripts",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "A collection of scripts related to typescript development",
55
"repository": {
66
"type": "git",

scripts/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import format from "./format";
22
import init from "./init";
33
import lint from "./lint";
4+
import run from "./run";
45
import test from "./test";
56

6-
export { format, init, lint, test };
7+
export { format, init, lint, run, test };

scripts/run.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from "path";
2+
import spawn from "cross-spawn";
3+
4+
import { appDirectory } from "./utils";
5+
6+
const args = process.argv.slice(3);
7+
8+
function run(): number {
9+
const result = spawn.sync(
10+
path.join(appDirectory, "./node_modules/.bin/ts-node"),
11+
args,
12+
{ stdio: "inherit" }
13+
);
14+
15+
if (result.error) {
16+
console.error(result.error);
17+
}
18+
19+
return typeof result.status === "number" ? result.status : 1;
20+
}
21+
22+
export default run;

0 commit comments

Comments
 (0)