-
Notifications
You must be signed in to change notification settings - Fork 211
/
unzip.ts
54 lines (52 loc) · 1.29 KB
/
unzip.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
import { StepHandler } from '.';
import { unzipFile } from '@wp-playground/common';
import { logger } from '@php-wasm/logger';
/**
* @inheritDoc unzip
* @example
*
* <code>
* {
* "step": "unzip",
* "zipFile": {
* "resource": "vfs",
* "path": "/wordpress/data.zip"
* },
* "extractToPath": "/wordpress"
* }
* </code>
*/
export interface UnzipStep<ResourceType> {
step: 'unzip';
/** The zip file to extract */
zipFile?: ResourceType;
/**
* The path of the zip file to extract
* @deprecated Use zipFile instead.
*/
zipPath?: string;
/** The path to extract the zip file to */
extractToPath: string;
}
/**
* Unzip a zip file.
*
* @param playground Playground client.
* @param zipPath The zip file to unzip.
* @param extractTo The directory to extract the zip file to.
*/
export const unzip: StepHandler<UnzipStep<File>> = async (
playground,
{ zipFile, zipPath, extractToPath }
) => {
if (zipPath) {
// @TODO: Remove the zipPath option in the next major version
logger.warn(
`The "zipPath" option of the unzip() Blueprint step is deprecated and will be removed. ` +
`Use "zipFile" instead.`
);
} else if (!zipFile) {
throw new Error('Either zipPath or zipFile must be provided');
}
await unzipFile(playground, (zipFile || zipPath)!, extractToPath);
};