Skip to content

Commit

Permalink
Merge branch 'main' of github.com:scaffold-eth/create-eth into exampl…
Browse files Browse the repository at this point in the history
…e-extension-related-info
  • Loading branch information
rin-st committed Dec 30, 2024
2 parents 351a73e + 5d85956 commit 9a09f22
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-onions-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

foundry: remove deploy:verify from base package.json
5 changes: 5 additions & 0 deletions .changeset/two-points-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

cli: allow github url as extension flag
40 changes: 30 additions & 10 deletions src/utils/external-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,45 @@ import { fileURLToPath } from "url";
import { ExternalExtension, RawOptions, SolidityFramework } from "../types";
import { CURATED_EXTENSIONS } from "../curated-extensions";
import { SOLIDITY_FRAMEWORKS } from "./consts";

function deconstructGithubUrl(url: string) {
const urlParts = url.split("/");
const ownerName = urlParts[3];
const repoName = urlParts[4];
const branch = urlParts[5] === "tree" ? urlParts[6] : undefined;

return { ownerName, repoName, branch };
}

// Gets the data from the argument passed to the `--extension` option.
// e.g. owner/project:branch => { githubBranchUrl, githubUrl, branch, owner, project }
export const getDataFromExternalExtensionArgument = (externalExtension: string) => {
if (CURATED_EXTENSIONS[externalExtension.toLowerCase()]) {
externalExtension = getArgumentFromExternalExtensionOption(CURATED_EXTENSIONS[externalExtension]);
}

const isGithubUrl = externalExtension.startsWith("https://github.com/");

// Check format: owner/project:branch (branch is optional)
const regex = /^[^/]+\/[^/]+(:[^/]+)?$/;
if (!regex.test(externalExtension)) {
throw new Error(`Invalid extension format. Use "owner/project" or "owner/project:branch"`);
if (!regex.test(externalExtension) && !isGithubUrl) {
throw new Error(`Invalid extension format. Use "owner/project", "owner/project:branch" or github url.`);
}

// Extract owner, project and branch
const owner = externalExtension.split("/")[0];
const project = externalExtension.split(":")[0].split("/")[1];
const branch = externalExtension.split(":")[1];
let owner;
let project;
let branch;

if (isGithubUrl) {
const { ownerName, repoName, branch: urlBranch } = deconstructGithubUrl(externalExtension);
owner = ownerName;
project = repoName;
branch = urlBranch;
} else {
// Extract owner, project and branch if format passed is owner/project:branch
owner = externalExtension.split("/")[0];
project = externalExtension.split(":")[0].split("/")[1];
branch = externalExtension.split(":")[1];
}

const githubUrl = `https://github.com/${owner}/${project}`;
let githubBranchUrl;
Expand Down Expand Up @@ -72,9 +94,7 @@ export const getSolidityFrameworkDirsFromExternalExtension = async (
}

const { branch, repository } = externalExtension;
const splitUrl = repository.split("/");
const ownerName = splitUrl[splitUrl.length - 2];
const repoName = splitUrl[splitUrl.length - 1];
const { ownerName, repoName } = deconstructGithubUrl(repository);
const githubApiUrl = `https://api.github.com/repos/${ownerName}/${repoName}/contents/extension/packages${branch ? `?ref=${branch}` : ""}`;
const res = await fetch(githubApiUrl);
if (!res.ok) {
Expand Down
1 change: 0 additions & 1 deletion templates/solidity-frameworks/foundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"chain": "yarn foundry:chain",
"compile": "yarn foundry:compile",
"deploy": "yarn foundry:deploy",
"deploy:verify": "yarn foundry:deploy-verify",
"fork": "yarn foundry:fork",
"format": "yarn next:format && yarn foundry:format",
"foundry:account": "yarn workspace @se-2/foundry account",
Expand Down

0 comments on commit 9a09f22

Please sign in to comment.