Skip to content

Commit

Permalink
feat: export
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Aug 20, 2024
1 parent 07c247b commit cf40d8b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/build-deploy-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export function BuildDeployPanel() {
>
Deploy
</Button>
<Button
onClick={async () => {
try {
await commands.export();
} catch (err) {}
}}
>
Export
</Button>
</div>
);
}
26 changes: 26 additions & 0 deletions components/workspace/use-cli-commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { TerminalContext } from "react-terminal";
import { useWorkspaceId } from "./use-workspace-id";
import { uploadContractCode, useAudit, useAuditReport } from "@/data/audit";
import clsx from "clsx";
import { fileContentToZip } from "@/lib/file-content-to-zip";
import { saveAs } from "file-saver";

export function useCliCommands() {
const terminalContext = useContext(TerminalContext);
Expand All @@ -28,6 +30,7 @@ export function useCliCommands() {
</li>
<li className="ml-8">build - builds the current workspace</li>
<li className="ml-8">deploy - deploys the built smart contract</li>
<li className="ml-8">export - exports the current workspace</li>
<li className="ml-8">
check txID - checks the result of transaction
</li>
Expand Down Expand Up @@ -187,6 +190,29 @@ export function useCliCommands() {
</>
);
},
export: async () => {
if (typeof id !== "string") throw new Error("id is not string");
const start = `${pathname}/`;
terminalContext.setBufferedContent(
<>
<p>Loading files...</p>
</>
);
const files = (
await db.files.filter((file) => file.path.startsWith(start)).toArray()
).map((file) => ({
path: decodeURIComponent(file.path.replace(start, "")),
contents: file.contents,
}));

const zip = fileContentToZip(files);
const file = new File(
[zip],
`${pathname?.split("/")?.pop() || "export"}.zip`,
{ type: "data:application/octet-stream;base64," }
);
saveAs(file);
},
};

return commands;
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dexie": "^4.0.8",
"dexie-react-hooks": "^1.1.7",
"fflate": "^0.8.2",
"file-saver": "^2.0.5",
"inversify": "^6.0.2",
"inversify-react": "^1.1.1",
"lucide-react": "^0.408.0",
Expand Down Expand Up @@ -71,6 +72,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
"@types/node": "^20",
"@types/parse-github-url": "^1.0.3",
"@types/react": "^18",
Expand Down

0 comments on commit cf40d8b

Please sign in to comment.