Skip to content

Commit

Permalink
allow passing in the --netlify-edge arg to bypass interactive promp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Roberts committed Oct 3, 2023
1 parent 1ef386a commit 54fddd5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 32 additions & 18 deletions remix.init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -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;
1 change: 1 addition & 0 deletions remix.init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"private": true,
"dependencies": {
"commander": "^11.0.0",
"inquirer": "^8.2.2"
}
}

0 comments on commit 54fddd5

Please sign in to comment.