1 | const util = require('util');
|
2 | const { rm } = require('fs/promises');
|
3 | const { rmSync } = require('fs');
|
4 | const is = require('is-type-of');
|
5 |
|
6 | const setTimeoutPromise = util.promisify(setTimeout);
|
7 |
|
8 | module.exports = {
|
9 | async sleep(delay) {
|
10 | await setTimeoutPromise(delay);
|
11 | },
|
12 |
|
13 | async rimraf(filepath) {
|
14 | await rm(filepath, { force: true, recursive: true });
|
15 | },
|
16 |
|
17 | rimrafSync(filepath) {
|
18 | rmSync(filepath, { force: true, recursive: true });
|
19 | },
|
20 |
|
21 | getProperty(target, prop) {
|
22 | const member = target[prop];
|
23 | if (is.function(member)) {
|
24 | return member.bind(target);
|
25 | }
|
26 | return member;
|
27 | },
|
28 | getEggOptions() {
|
29 | const options = {};
|
30 |
|
31 | if (process.env.EGG_BASE_DIR) {
|
32 | options.baseDir = process.env.EGG_BASE_DIR;
|
33 | } else {
|
34 | options.baseDir = process.cwd();
|
35 | }
|
36 | if (process.env.EGG_FRAMEWORK) {
|
37 | options.framework = process.env.EGG_FRAMEWORK;
|
38 | }
|
39 | return options;
|
40 | },
|
41 | };
|