This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.ts
120 lines (114 loc) · 3.55 KB
/
tasks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { cp, mkdir, rm, exec, cd, ExecOutputReturnValue } from "shelljs";
type TaskFn = () => ExecOutputReturnValue | void;
type TaskDescriptor = {
name: string;
fn: TaskFn;
dependsOn?: string[] | string | TaskFn | TaskFn[];
};
const visitedTasks: any[] = [];
function execute(name: string | TaskFn): ExecOutputReturnValue | void {
if (name instanceof Function) {
if (visitedTasks.indexOf(name) === -1) {
visitedTasks.push(name);
return name();
}
console.log(`Ignoring task "${name.name}", as it was executed previously`);
return;
}
const tasks = ((def as any).tasks || []) as TaskDescriptor[];
const task = tasks.find(x => x.name == name);
if (task) {
if (task.dependsOn !== undefined && task.dependsOn.length > 0) {
const dependsOn = [];
if (Array.isArray(task.dependsOn)) {
dependsOn.push(...task.dependsOn);
} else {
dependsOn.push(task.dependsOn);
}
for (const item of dependsOn) {
const result = execute(item);
if (result && result.code !== 0) {
return result;
}
}
}
return execute(task.fn);
}
}
function def(
name: string,
fn: TaskFn,
dependsOn?: string[] | string | Function | Function[]
) {
(def as any).tasks = ((def as any).tasks || []) as TaskDescriptor[];
Object.defineProperty(fn, "name", {
value: name,
writable: false
});
(def as any).tasks.push({ name, fn, dependsOn });
}
/////////////////////////////////////////////////////
def("build", () => {
rm("-rf", __dirname + "/@axonish/core/dist");
rm("-rf", __dirname + "/@axonish/cqrs/dist");
exec("tsc -b " + __dirname + "/@axonish/core");
return exec("tsc -b " + __dirname + "/@axonish/cqrs");
});
def(
"test",
() => {
return exec("ts-node --project ./tsconfig.json ./run-specs.ts");
},
"build"
);
def("init-pack", () => {
mkdir("-p", __dirname + "/out/@axonish");
rm("-rf", __dirname + "/out/@axonish");
mkdir("-p", __dirname + "/out/@axonish/core");
mkdir("-p", __dirname + "/out/@axonish/cqrs");
});
def("pack-core", () => {
try {
cp("-R", __dirname + "/@axonish/core", __dirname + "/out/@axonish");
rm("-rf", __dirname + "/out/@axonish/core/.vscode");
rm("-rf", __dirname + "/out/@axonish/core/src");
rm("-rf", __dirname + "/out/@axonish/core/dist/test-utils");
rm(__dirname + "/out/@axonish/core/tsconfig.json");
cd(__dirname + "/out/@axonish/core");
return exec("npm pack");
} finally {
cd(__dirname);
}
});
def("pack-cqrs", () => {
try {
cp("-R", __dirname + "/@axonish/cqrs", __dirname + "/out/@axonish");
rm("-rf", __dirname + "/out/@axonish/cqrs/.vscode");
rm("-rf", __dirname + "/out/@axonish/cqrs/src");
rm(__dirname + "/out/@axonish/cqrs/tsconfig.json");
cd(__dirname + "/out/@axonish/cqrs");
return exec("npm pack");
} finally {
cd(__dirname);
}
});
def("pack", () => {}, ["test", "init-pack", "pack-core", "pack-cqrs"]);
def(
"copy",
() => {
console.log("Copying...");
mkdir("-p", "/packages");
mkdir("-p", "c:/packages");
cp(__dirname + "/out/@axonish/core/*.tgz", "c:/packages");
cp(__dirname + "/out/@axonish/core/*.tgz", "/packages");
console.log("Copied @axonish/core tarball to /packages");
cp(__dirname + "/out/@axonish/cqrs/*.tgz", "c:/packages");
cp(__dirname + "/out/@axonish/cqrs/*.tgz", "/packages");
console.log("Copied @axonish/cqrs tarball to /packages");
},
["pack"]
);
const tasks = process.argv.slice(2);
tasks.length === 0 ? tasks.push("copy") : "";
console.log("Running tasks: ", tasks);
tasks.map(task => execute(task));