1 | import { mkdirp, remove } from "fs-promise";
|
2 | import { _, env } from "oly-core";
|
3 | import { join } from "path";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export class WorkspaceProvider {
|
9 |
|
10 | @env("WORKSPACE_DIRECTORY")
|
11 | public directory: string = join(process.cwd(), "workspace");
|
12 |
|
13 | @env("WORKSPACE_TMP")
|
14 | public tmp: string = ".tmp";
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 | public rand(): string {
|
22 | return this.join(this.tmp, _.shortid());
|
23 | }
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | public join(...entry: string[]): string {
|
32 | return join(this.directory, ...entry);
|
33 | }
|
34 |
|
35 | protected async onStart(): Promise<void> {
|
36 | await mkdirp(this.directory);
|
37 | await remove(this.join(this.tmp));
|
38 | await mkdirp(this.join(this.tmp));
|
39 | }
|
40 |
|
41 | protected async onStop(): Promise<void> {
|
42 | await remove(this.join(this.tmp));
|
43 | }
|
44 | }
|