Skip to content

Commit

Permalink
Add curated extensions (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
carletex authored May 23, 2024
1 parent b681f58 commit e0c3546
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-turtles-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

Support for external extensions with -e
12 changes: 10 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, typedQuestion } from "./types";
import { Config, ExternalExtension, typedQuestion } from "./types";

const config: Config = {
questions: [
Expand All @@ -11,4 +11,12 @@ const config: Config = {
}),
],
};
export default config;

const CURATED_EXTENSIONS: { [key: string]: ExternalExtension } = {
subgraph: {
repository: "https://github.com/scaffold-eth/create-eth-extensions",
branch: "subgraph",
}
}

export { config, CURATED_EXTENSIONS };
2 changes: 1 addition & 1 deletion src/tasks/copy-template-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ncp from "ncp";
import path from "path";
import { promisify } from "util";
import link from "../utils/link";
import {getArgumentFromExternalExtensionOption} from "../utils/external-extensions";
import { getArgumentFromExternalExtensionOption } from "../utils/external-extensions";

const EXTERNAL_EXTENSION_TMP_FOLDER = "tmp-external-extension";
const copy = promisify(ncp);
Expand Down
10 changes: 6 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ export type RawOptions = {
install: boolean | null;
dev: boolean;
extensions: Extension[] | null;
externalExtension: {
repository: string;
branch?: string | null;
} | null;
externalExtension: ExternalExtension | null;
};

export type ExternalExtension = {
repository: string;
branch?: string | null;
};

type NonNullableRawOptions = {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/external-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { RawOptions } from "../types";
import { CURATED_EXTENSIONS } from "../config";

// 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]) {
externalExtension = getArgumentFromExternalExtensionOption(CURATED_EXTENSIONS[externalExtension]);
}

// Check format: owner/project:branch (branch is optional)
const regex = /^[^/]+\/[^/]+(:[^/]+)?$/;
if (!regex.test(externalExtension)) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/parse-arguments-into-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import arg from "arg";
import * as https from "https";
import { getDataFromExternalExtensionArgument } from "./external-extensions";
import chalk from "chalk";
import { CURATED_EXTENSIONS } from "../config";

const validateTemplate = async (
template: string
Expand Down Expand Up @@ -64,7 +65,7 @@ export async function parseArgumentsIntoOptions(
? await validateTemplate(args["--extension"])
: null;

if (extension) {
if (extension && !CURATED_EXTENSIONS[args["--extension"] as string]) {
console.log(chalk.yellow(` You are using a third-party extension. Make sure you trust the source of ${chalk.yellow.bold(extension.repository)}\n`));
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "../config";
import { config } from "../config";
import {
Extension,
ExtensionDescriptor,
Expand Down

0 comments on commit e0c3546

Please sign in to comment.