-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1847 from polywrap/pileks/bugfix/ipfs-deployer-su…
…bdirectory-duplication Fix IPFS deployer subdirectory duplication issue
- Loading branch information
Showing
9 changed files
with
120 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GetPathToCliTestFiles } from "@polywrap/test-cases"; | ||
import { readDirContents } from "../../lib/defaults/deploy-modules/ipfs/utils"; | ||
import path from "path"; | ||
|
||
describe("IPFS Deployer", () => { | ||
const sampleBuildDir = path.join( | ||
GetPathToCliTestFiles(), | ||
"lib", | ||
"deployers", | ||
"mock-build-output" | ||
); | ||
|
||
it("properly reads build dir contents and builds out an IPFS-compatible directory entry", async () => { | ||
const dirents = await readDirContents(sampleBuildDir, ""); | ||
|
||
expect(dirents).toMatchObject({ | ||
name: "", | ||
files: [{ name: "wrap.info" }, { name: "wrap.wasm" }], | ||
directories: [ | ||
{ | ||
name: "docs", | ||
files: [{ name: "polywrap.docs.json" }], | ||
directories: [ | ||
{ | ||
name: "pages", | ||
files: [{ name: "readme.md" }], | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
63 changes: 2 additions & 61 deletions
63
packages/cli/src/lib/defaults/deploy-modules/ipfs/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/cli/src/lib/defaults/deploy-modules/ipfs/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export interface FileEntry { | ||
name: string; | ||
data: Uint8Array; | ||
} | ||
|
||
export interface DirectoryEntry { | ||
name: string; | ||
directories?: DirectoryEntry[]; | ||
files?: FileEntry[]; | ||
} | ||
|
||
export interface AddOptions { | ||
pin?: boolean; | ||
onlyHash?: boolean; | ||
wrapWithDirectory?: boolean; | ||
} | ||
|
||
export interface AddResult { | ||
name: string; | ||
hash: string; | ||
size: string; | ||
} | ||
|
||
export interface ArgsAddDir { | ||
data: DirectoryEntry; | ||
ipfsProvider: string; | ||
timeout?: number; | ||
addOptions?: AddOptions; | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/cli/src/lib/defaults/deploy-modules/ipfs/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { DirectoryEntry } from "./types"; | ||
|
||
import fs from "fs"; | ||
|
||
export const readDirContents = async ( | ||
path: string, | ||
dirName: string | ||
): Promise<DirectoryEntry> => { | ||
const dirents: fs.Dirent[] = await fs.promises.readdir(path, { | ||
withFileTypes: true, | ||
}); | ||
const data: DirectoryEntry = { name: dirName }; | ||
|
||
for (const dirent of dirents) { | ||
if (dirent.isDirectory()) { | ||
const subDir = await readDirContents( | ||
`${path}/${dirent.name}`, | ||
`${dirent.name}` | ||
); | ||
data.directories = data.directories ?? []; | ||
data.directories?.push(subDir); | ||
} else { | ||
const fileData = await fs.promises.readFile(`${path}/${dirent.name}`); | ||
data.files = data.files ?? []; | ||
data.files?.push({ | ||
name: dirent.name, | ||
data: fileData, | ||
}); | ||
} | ||
} | ||
|
||
return data; | ||
}; |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters