Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yarn ipfs command to deploy on IPFS #1030

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test": "yarn hardhat:test",
"vercel": "yarn workspace @se-2/nextjs vercel",
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo",
"ipfs": "yarn workspace @se-2/nextjs ipfs",
"verify": "yarn hardhat:verify"
},
"packageManager": "[email protected]",
Expand Down
10 changes: 10 additions & 0 deletions packages/nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ const nextConfig = {
},
};

const isIpfs = process.env.npm_lifecycle_event === "ipfs";

if (isIpfs) {
nextConfig.output = "export";
nextConfig.trailingSlash = true;
nextConfig.images = {
unoptimized: true,
};
}

module.exports = nextConfig;
4 changes: 3 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"serve": "next start",
"start": "next dev",
"vercel": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env VERCEL_TELEMETRY_DISABLED=1",
"vercel:yolo": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --build-env VERCEL_TELEMETRY_DISABLED=1"
"vercel:yolo": "vercel --build-env YARN_ENABLE_IMMUTABLE_INSTALLS=false --build-env ENABLE_EXPERIMENTAL_COREPACK=1 --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --build-env VERCEL_TELEMETRY_DISABLED=1",
"ipfs": "yarn build && node scripts/deploy-ipfs.js"
},
"dependencies": {
"@heroicons/react": "^2.1.5",
Expand All @@ -22,6 +23,7 @@
"blo": "^1.2.0",
"burner-connector": "0.0.9",
"daisyui": "4.12.10",
"kubo-rpc-client": "^5.0.2",
"next": "^14.2.11",
"next-nprogress-bar": "^2.3.13",
"next-themes": "^0.3.0",
Expand Down
64 changes: 64 additions & 0 deletions packages/nextjs/scripts/deploy-ipfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { create } from "kubo-rpc-client";
import { globSource } from "kubo-rpc-client";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const ipfsConfig = {
host: "ipfs.nifty.ink",
port: 3001,
protocol: "https",
timeout: 250000,
};

async function addDirectoryToIpfs(path) {
console.log("📦 Adding directory to IPFS via Nifty Ink...");

try {
const ipfs = create(ipfsConfig);

// Track the root directory CID
let rootCid = null;

// Add the entire directory to IPFS
for await (const result of ipfs.addAll(globSource(path, "**/*"), {
pin: true,
wrapWithDirectory: true, // This is key - it wraps all files in a directory
})) {
if (result.path === "") {
// This is the root directory entry
rootCid = result.cid;
} else {
console.log(`Added ${result.path} - CID: ${result.cid}`);
}
}

if (!rootCid) {
throw new Error("Failed to get root directory CID");
}

return rootCid.toString();
} catch (error) {
console.error("Error adding directory to IPFS:", error);
throw error;
}
}

async function main() {
// Get the path to the out directory
const outDir = join(__dirname, "..", "out");

console.log("🚀 Uploading to Nifty Ink IPFS...");
const cid = await addDirectoryToIpfs(outDir);

console.log("\n✨ Upload complete! Your site is now available at:");
console.log(`🔗 Nifty Ink Gateway: https://gateway.nifty.ink:42069/ipfs/${cid}`);
console.log("\n💡 Note: Your content is being served through the Nifty Ink IPFS gateway");
}

main().catch(err => {
console.error("Error uploading to IPFS:", err);
process.exit(1);
});
Loading
Loading