@wp-playground/common 0.7.20 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +24 -3
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -11,3 +11,4 @@
11
11
  import { UniversalPHP } from '../../../php-wasm/universal/src/index.ts';
12
12
  export declare const RecommendedPHPVersion = "8.0";
13
13
  export declare const unzipFile: (php: UniversalPHP, zipPath: string | File, extractToPath: string) => Promise<void>;
14
+ export declare const zipDirectory: (php: UniversalPHP, directoryPath: string) => Promise<Uint8Array>;
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- function c(t){return`json_decode(base64_decode('${s(JSON.stringify(t))}'), true)`}function a(t){const e={};for(const n in t)e[n]=c(t[n]);return e}function s(t){return u(new TextEncoder().encode(t))}function u(t){const e=String.fromCodePoint(...t);return btoa(e)}const f="8.0",i="/tmp/file.zip",$=async(t,e,n)=>{if(e instanceof File){const r=e;e=i,await t.writeFile(e,new Uint8Array(await r.arrayBuffer()))}const o=a({zipPath:e,extractToPath:n});await t.run({code:`<?php
1
+ function a(t){return`json_decode(base64_decode('${s(JSON.stringify(t))}'), true)`}function c(t){const e={};for(const i in t)e[i]=a(t[i]);return e}function s(t){return u(new TextEncoder().encode(t))}function u(t){const e=String.fromCodePoint(...t);return btoa(e)}const $="8.0",n="/tmp/file.zip",f=async(t,e,i)=>{if(e instanceof File){const o=e;e=n,await t.writeFile(e,new Uint8Array(await o.arrayBuffer()))}const r=c({zipPath:e,extractToPath:i});await t.run({code:`<?php
2
2
  function unzip($zipPath, $extractTo, $overwrite = true)
3
3
  {
4
4
  if (!is_dir($extractTo)) {
@@ -14,5 +14,26 @@ function c(t){return`json_decode(base64_decode('${s(JSON.stringify(t))}'), true)
14
14
  throw new Exception("Could not unzip file");
15
15
  }
16
16
  }
17
- unzip(${o.zipPath}, ${o.extractToPath});
18
- `}),await t.fileExists(i)&&await t.unlink(i)};export{f as RecommendedPHPVersion,$ as unzipFile};
17
+ unzip(${r.zipPath}, ${r.extractToPath});
18
+ `}),await t.fileExists(n)&&await t.unlink(n)},p=async(t,e)=>{const i=`/tmp/file${Math.random()}.zip`,r=c({directoryPath:e,outputPath:i});await t.run({code:`<?php
19
+ function zipDirectory($directoryPath, $outputPath) {
20
+ $zip = new ZipArchive;
21
+ $res = $zip->open($outputPath, ZipArchive::CREATE);
22
+ if ($res !== TRUE) {
23
+ throw new Exception('Failed to create ZIP');
24
+ }
25
+ $files = new RecursiveIteratorIterator(
26
+ new RecursiveDirectoryIterator($directoryPath)
27
+ );
28
+ foreach ($files as $file) {
29
+ $file = strval($file);
30
+ if (is_dir($file)) {
31
+ continue;
32
+ }
33
+ $zip->addFile($file, substr($file, strlen($directoryPath)));
34
+ }
35
+ $zip->close();
36
+ chmod($outputPath, 0777);
37
+ }
38
+ zipDirectory(${r.directoryPath}, ${r.outputPath});
39
+ `});const o=await t.readFileAsBuffer(i);return t.unlink(i),o};export{$ as RecommendedPHPVersion,f as unzipFile,p as zipDirectory};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/common",
3
- "version": "0.7.20",
3
+ "version": "0.9.4",
4
4
  "description": "Common exports and utilities for WordPress Playground",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,5 +27,5 @@
27
27
  "access": "public",
28
28
  "directory": "../../../dist/packages/playground/common"
29
29
  },
30
- "gitHead": "5915ef756c88da8dcb665f9f0e49ddc0c0b10d50"
30
+ "gitHead": "702bb9bed9c153ea23651059592aea19c1ba9be4"
31
31
  }