From 54fddd5480c1b9b30ea064b318994f85c4135b52 Mon Sep 17 00:00:00 2001 From: Sean Roberts Date: Tue, 3 Oct 2023 12:01:24 -0400 Subject: [PATCH] allow passing in the --netlify-edge arg to bypass interactive promp --- README.md | 3 +++ remix.init/index.js | 50 ++++++++++++++++++++++++++--------------- remix.init/package.json | 1 + 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8c98ef0..1eab7c3 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,14 @@ To use the template, run npx create-remix@latest --template netlify/remix-template ``` + This project includes: - Netlify Functions template for Remix sites - Netlify Edge Functions template for Remix sites +From the `create-remix` command, you may pass `--netlify-edge` or `--no-netlify-edge` to generate a template that uses Netlify Edge or Serverless functions explicitly. Without passing this option, the create workflow will ask you which you would prefer. + ## Development There is no need to run `npm install` as this is a template. The Remix CLI will install the dependencies for you. Make changes to files as you see fit. If there are transformations for files for either the Netlify Functions or Netlify Edge Functions template, make the appropriate changes to the `remix.init/index.js` file. diff --git a/remix.init/index.js b/remix.init/index.js index 37bc85b..0a62acc 100644 --- a/remix.init/index.js +++ b/remix.init/index.js @@ -3,6 +3,7 @@ const fs = require("fs/promises"); const { join } = require("path"); const PackageJson = require("@npmcli/package-json"); const execa = require("execa"); +const { Command } = require('commander'); const foldersToExclude = [".github", ".git"]; @@ -138,25 +139,38 @@ async function main({ rootDirectory }) { } async function shouldUseEdge() { - const { edge } = await inquirer.prompt([ - { - name: "edge", - type: "list", - message: "Run your Remix site with:", - choices: [ - { - name: "Netlify Functions", - value: false, - }, - { - name: "Netlify Edge Functions", - value: true, - }, - ], - }, - ]); - return edge; + // parse the top level command args to see if edge was passed in + const program = new Command(); + program + .option('--netlify-edge', 'explicitly use Netlify Edge Functions to serve this Remix site.', undefined) + .option('--no-netlify-edge', 'explicitly do NOT use Netlify Edge Functions to serve this Remix site - use Serverless Functions instead.', undefined) + program.allowUnknownOption().parse(); + + const passedEdgeOption = program.opts().netlifyEdge; + + if(passedEdgeOption !== true && passedEdgeOption !== false){ + const { edge } = await inquirer.prompt([ + { + name: "edge", + type: "list", + message: "Run your Remix site with:", + choices: [ + { + name: "Netlify Functions", + value: false, + }, + { + name: "Netlify Edge Functions", + value: true, + }, + ], + }, + ]); + return edge; + } + + return passedEdgeOption; } module.exports = main; diff --git a/remix.init/package.json b/remix.init/package.json index 18c0e43..6a957f9 100644 --- a/remix.init/package.json +++ b/remix.init/package.json @@ -5,6 +5,7 @@ "license": "MIT", "private": true, "dependencies": { + "commander": "^11.0.0", "inquirer": "^8.2.2" } }