diff --git a/.changeset/soft-turtles-study.md b/.changeset/soft-turtles-study.md new file mode 100644 index 000000000..54f5dcfa2 --- /dev/null +++ b/.changeset/soft-turtles-study.md @@ -0,0 +1,5 @@ +--- +"create-eth": patch +--- + +Support for external extensions with -e diff --git a/src/config.ts b/src/config.ts index a6f281e99..e66d40ac9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,4 @@ -import { Config, typedQuestion } from "./types"; +import { Config, ExternalExtension, typedQuestion } from "./types"; const config: Config = { questions: [ @@ -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 }; diff --git a/src/tasks/copy-template-files.ts b/src/tasks/copy-template-files.ts index a3fd15d15..240f74d5a 100644 --- a/src/tasks/copy-template-files.ts +++ b/src/tasks/copy-template-files.ts @@ -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); diff --git a/src/types.ts b/src/types.ts index 88bd28aa9..b7ff84910 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 = { diff --git a/src/utils/external-extensions.ts b/src/utils/external-extensions.ts index 5734ddd06..cef21bcac 100644 --- a/src/utils/external-extensions.ts +++ b/src/utils/external-extensions.ts @@ -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)) { diff --git a/src/utils/parse-arguments-into-options.ts b/src/utils/parse-arguments-into-options.ts index 4c6802fa5..5edc89767 100644 --- a/src/utils/parse-arguments-into-options.ts +++ b/src/utils/parse-arguments-into-options.ts @@ -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 @@ -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`)); } diff --git a/src/utils/prompt-for-missing-options.ts b/src/utils/prompt-for-missing-options.ts index 7402d0848..630e80962 100644 --- a/src/utils/prompt-for-missing-options.ts +++ b/src/utils/prompt-for-missing-options.ts @@ -1,4 +1,4 @@ -import config from "../config"; +import { config } from "../config"; import { Extension, ExtensionDescriptor,