From 7485eaf143f0cf665c76b2de546885611695d699 Mon Sep 17 00:00:00 2001 From: sw-yx Date: Mon, 8 Apr 2019 13:54:18 -0400 Subject: [PATCH] add nextjs, hexo, gridsome, phenomic, docusaurus, brunch --- README.md | 34 ++++++++++++++-------------- src/detectors/README.md | 44 +++++++++++++++++++++++++++++++++++++ src/detectors/brunch.js | 30 +++++++++++++++++++++++++ src/detectors/docusaurus.js | 30 +++++++++++++++++++++++++ src/detectors/gridsome.js | 30 +++++++++++++++++++++++++ src/detectors/hexo.js | 34 ++++++++++++++++++++++++++++ src/detectors/next.js | 34 ++++++++++++++++++++++++++++ src/detectors/phenomic.js | 30 +++++++++++++++++++++++++ 8 files changed, 249 insertions(+), 17 deletions(-) create mode 100644 src/detectors/brunch.js create mode 100644 src/detectors/docusaurus.js create mode 100644 src/detectors/gridsome.js create mode 100644 src/detectors/hexo.js create mode 100644 src/detectors/next.js create mode 100644 src/detectors/phenomic.js diff --git a/README.md b/README.md index f450c6a..da639ad 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This is how we pull down your build environment variables and manage your addons Pro tip: Aliasing commands + As these commands are expected to be frequently used, it may be helpful to define aliases in your terminal (Mac: [bash](https://jonsuh.com/blog/bash-command-line-shortcuts/), [zsh](https://askubuntu.com/questions/758496/how-to-make-a-permanent-alias-in-oh-my-zsh), Windows: [doskey](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt), [registry](https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt)) to your personal preference. For example: ```bash @@ -39,18 +40,6 @@ alias ndx="netlify dev:exec " -## Live Share - -To share your ongoing dev session with a coworker, just run Netlify Dev with a `--live` flag: - -```bash -netlify dev --live -``` - -You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as long as you keep your session open. - -> Note: there are currently known issues with ending the live session alongside your webdevserver, as well as with live reloading. We are working on fixing it, and would appreciate repro cases. In the mean time you can run `ps aux | grep live-tunnel` and kill these sessions manually. - ## Using the beta Currently the Netlify dev plugin is in private beta. You'll need to follow these steps to enable it: @@ -97,14 +86,25 @@ COMMANDS dev:exec Exec command ``` +## Live Share + +To share your ongoing dev session with a coworker, just run Netlify Dev with a `--live` flag: + +```bash +netlify dev --live +``` + +You will get a URL that looks like `https://clever-cray-2aa156-6639f3.netlify.live/`. This can be accessed by anyone as long as you keep your session open. + +> Note: there are currently known issues with ending the live session alongside your webdevserver, as well as with live reloading. We are working on fixing it, and would appreciate repro cases. In the mean time you can run `ps aux | grep live-tunnel` and kill these sessions manually. + ## Project detection -Netlify Dev will attempt to detect the SSG or build command that you are using, and run these on your behalf, while adding other development utilities. +Netlify Dev will attempt to detect the SSG or build command that you are using, and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it looks for the best `package.json` script to run for you, using simple heuristics, so you can use the full flexibility of npm scripts. We may add more intelligence to this in future. -**Overriding the detectors**: The number of project types which Netlify Dev can detect is growing, but if yours is not yet supported automatically, you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. +**Overriding the detectors**: The number of [project types which Netlify Dev can detect](https://github.com/netlify/netlify-dev-plugin/tree/master/src/detectors) is growing, but if yours is not yet supported (contributions welcome!), you can instruct Netlify Dev to run the project on your behalf by declaring it in a `[dev]` block of your `netlify.toml` file. ```toml - #sample dev block in the toml [dev] command = "yarn start" # Command to start your dev server @@ -114,13 +114,13 @@ Netlify Dev will attempt to detect the SSG or build command that you are using,
-Explanation of detectors and ports in Netlify Dev +Explanation of ports in Netlify Dev There will be a number of ports that you will encounter when using Netlify Dev, especially when running a static site generator like Gatsby which has its own dev server. All the port numbers can be a bit confusing, so here is a brief explainer. - If your SSG has a devserver on port 8000 for example, Netlify Dev needs to be told to proxy that port so it can merge it in with the rest of the local Netlify environment (say, running on port 8888), which is what you want to get the full Netlify Dev experience with Functions, Redirects, and so on. -- If you're running a project we have a detector for, we hardcode those conventional ports so you don't have to supply it yourself. +- If you're running a project we have a detector for, we hardcode those conventional ports so you don't have to supply it yourself. If we have multiple detectors that match, we'll ask you to choose. - However, sometimes you're using some other project (we welcome contributions for detectors!) or just have a custom port you want Netlify Dev to point to for some reason. This is when you go to the `netlify.toml` `[dev]` block to specify exactly what port we should listen to. As for which port to use while doing local development in Netlify Dev, always look for this box in your console output and use that: diff --git a/src/detectors/README.md b/src/detectors/README.md index d844649..b5f3897 100644 --- a/src/detectors/README.md +++ b/src/detectors/README.md @@ -22,3 +22,47 @@ - Dev block overrides will supercede anything you write in your detector: https://github.com/netlify/netlify-dev-plugin#project-detection - detectors are language agnostic. don't assume npm or yarn. - if default args (like 'develop') are missing, that means the user has configured it, best to tell them to use the -c flag. + +## detector notes + +- metalsmith is popular but has no dev story so we have skipped it +- hub press doesnt even have cli https://github.com/HubPress/hubpress.io#what-is-hubpress +- gitbook: + +not sure if we want to support gitbook yet + +requires a global install: https://github.com/GitbookIO/gitbook/blob/master/docs/setup.md + +```js +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["README.md", "SUMMARY.md"])) return false; + // // REQUIRED DEPS + // if (!hasRequiredDeps(["hexo"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = [["gitbook", "serve"]]; + // scanScripts({ + // preferredScriptsArr: ["start", "dev", "develop"], + // preferredCommand: "hexo server" + // }); + + return { + type: "gitbook", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 4000, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${4000}(/)?`, "g"), + dist: "public" + }; +}; +``` diff --git a/src/detectors/brunch.js b/src/detectors/brunch.js new file mode 100644 index 0000000..a0ba261 --- /dev/null +++ b/src/detectors/brunch.js @@ -0,0 +1,30 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json", "brunch-config.js"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["brunch"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["start"], + preferredCommand: "brunch watch --server" + }); + + return { + type: "brunch", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 3333, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${3333}(/)?`, "g"), + dist: "app/assets" + }; +}; diff --git a/src/detectors/docusaurus.js b/src/detectors/docusaurus.js new file mode 100644 index 0000000..746948c --- /dev/null +++ b/src/detectors/docusaurus.js @@ -0,0 +1,30 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json", "siteConfig.js"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["docusaurus"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["start"], + preferredCommand: "docusaurus-start" + }); + + return { + type: "docusaurus", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 3000, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${3000}(/)?`, "g"), + dist: "static" + }; +}; diff --git a/src/detectors/gridsome.js b/src/detectors/gridsome.js new file mode 100644 index 0000000..efe026c --- /dev/null +++ b/src/detectors/gridsome.js @@ -0,0 +1,30 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json", "gridsome.config.js"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["gridsome"])) return false; + + /** everything below now assumes that we are within gridsome */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["develop"], + preferredCommand: "gridsome develop" + }); + + return { + type: "gridsome", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 8080, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${8080}(/)?`, "g"), + dist: "static" + }; +}; diff --git a/src/detectors/hexo.js b/src/detectors/hexo.js new file mode 100644 index 0000000..1fdd5e8 --- /dev/null +++ b/src/detectors/hexo.js @@ -0,0 +1,34 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json", "_config.yml"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["hexo"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["start", "dev", "develop"], + preferredCommand: "hexo server" + }); + + if (!possibleArgsArrs.length) { + // ofer to run it when the user doesnt have any scripts setup! 🤯 + possibleArgsArrs.push(["hexo", "server"]); + } + return { + type: "hexo", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 4000, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${4000}(/)?`, "g"), + dist: "public" + }; +}; diff --git a/src/detectors/next.js b/src/detectors/next.js new file mode 100644 index 0000000..e014d04 --- /dev/null +++ b/src/detectors/next.js @@ -0,0 +1,34 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["next"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["dev", "develop", "start"], + preferredCommand: "next" + }); + + if (!possibleArgsArrs.length) { + // ofer to run it when the user doesnt have any scripts setup! 🤯 + possibleArgsArrs.push(["next"]); + } + return { + type: "next.js", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 3000, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${3000}(/)?`, "g"), + dist: "out" + }; +}; diff --git a/src/detectors/phenomic.js b/src/detectors/phenomic.js new file mode 100644 index 0000000..485eb03 --- /dev/null +++ b/src/detectors/phenomic.js @@ -0,0 +1,30 @@ +const { + hasRequiredDeps, + hasRequiredFiles, + getYarnOrNPMCommand, + scanScripts +} = require("./utils/jsdetect"); +module.exports = function() { + // REQUIRED FILES + if (!hasRequiredFiles(["package.json"])) return false; + // REQUIRED DEPS + if (!hasRequiredDeps(["@phenomic/core"])) return false; + + /** everything below now assumes that we are within gatsby */ + + const possibleArgsArrs = scanScripts({ + preferredScriptsArr: ["start"], + preferredCommand: "phenomic start" + }); + + return { + type: "phenomic", + command: getYarnOrNPMCommand(), + port: 8888, + proxyPort: 3333, + env: { ...process.env }, + possibleArgsArrs, + urlRegexp: new RegExp(`(http://)([^:]+:)${3333}(/)?`, "g"), + dist: "public" + }; +};