Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit c25f606

Browse files
authored
Merge pull request #102 from netlify/addDetectors
add nextjs, hexo, gridsome, phenomic, docusaurus, brunch
2 parents 79387cd + 7485eaf commit c25f606

File tree

8 files changed

+249
-17
lines changed

8 files changed

+249
-17
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This is how we pull down your build environment variables and manage your addons
2626
<summary>
2727
<b>Pro tip: Aliasing commands</b>
2828
</summary>
29+
2930
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:
3031

3132
```bash
@@ -39,18 +40,6 @@ alias ndx="netlify dev:exec "
3940

4041
</details>
4142

42-
## Live Share
43-
44-
To share your ongoing dev session with a coworker, just run Netlify Dev with a `--live` flag:
45-
46-
```bash
47-
netlify dev --live
48-
```
49-
50-
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.
51-
52-
> 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.
53-
5443
## Using the beta
5544

5645
Currently the Netlify dev plugin is in private beta. You'll need to follow these steps to enable it:
@@ -97,14 +86,25 @@ COMMANDS
9786
dev:exec Exec command
9887
```
9988
89+
## Live Share
90+
91+
To share your ongoing dev session with a coworker, just run Netlify Dev with a `--live` flag:
92+
93+
```bash
94+
netlify dev --live
95+
```
96+
97+
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.
98+
99+
> 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.
100+
100101
## Project detection
101102
102-
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.
103+
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.
103104
104-
**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.
105+
**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.
105106
106107
```toml
107-
108108
#sample dev block in the toml
109109
[dev]
110110
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,
114114
115115
<details>
116116
<summary>
117-
<b>Explanation of detectors and ports in Netlify Dev</b>
117+
<b>Explanation of ports in Netlify Dev</b>
118118
</summary>
119119
120120
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.
121121
122122
- 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.
123-
- 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.
123+
- 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.
124124
- 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.
125125
126126
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:

src/detectors/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,47 @@
2222
- Dev block overrides will supercede anything you write in your detector: https://github.com/netlify/netlify-dev-plugin#project-detection
2323
- detectors are language agnostic. don't assume npm or yarn.
2424
- if default args (like 'develop') are missing, that means the user has configured it, best to tell them to use the -c flag.
25+
26+
## detector notes
27+
28+
- metalsmith is popular but has no dev story so we have skipped it
29+
- hub press doesnt even have cli https://github.com/HubPress/hubpress.io#what-is-hubpress
30+
- gitbook:
31+
32+
not sure if we want to support gitbook yet
33+
34+
requires a global install: https://github.com/GitbookIO/gitbook/blob/master/docs/setup.md
35+
36+
```js
37+
const {
38+
hasRequiredDeps,
39+
hasRequiredFiles,
40+
getYarnOrNPMCommand,
41+
scanScripts
42+
} = require("./utils/jsdetect");
43+
module.exports = function() {
44+
// REQUIRED FILES
45+
if (!hasRequiredFiles(["README.md", "SUMMARY.md"])) return false;
46+
// // REQUIRED DEPS
47+
// if (!hasRequiredDeps(["hexo"])) return false;
48+
49+
/** everything below now assumes that we are within gatsby */
50+
51+
const possibleArgsArrs = [["gitbook", "serve"]];
52+
// scanScripts({
53+
// preferredScriptsArr: ["start", "dev", "develop"],
54+
// preferredCommand: "hexo server"
55+
// });
56+
57+
return {
58+
type: "gitbook",
59+
command: getYarnOrNPMCommand(),
60+
port: 8888,
61+
proxyPort: 4000,
62+
env: { ...process.env },
63+
possibleArgsArrs,
64+
urlRegexp: new RegExp(`(http://)([^:]+:)${4000}(/)?`, "g"),
65+
dist: "public"
66+
};
67+
};
68+
```

src/detectors/brunch.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json", "brunch-config.js"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["brunch"])) return false;
12+
13+
/** everything below now assumes that we are within gatsby */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["start"],
17+
preferredCommand: "brunch watch --server"
18+
});
19+
20+
return {
21+
type: "brunch",
22+
command: getYarnOrNPMCommand(),
23+
port: 8888,
24+
proxyPort: 3333,
25+
env: { ...process.env },
26+
possibleArgsArrs,
27+
urlRegexp: new RegExp(`(http://)([^:]+:)${3333}(/)?`, "g"),
28+
dist: "app/assets"
29+
};
30+
};

src/detectors/docusaurus.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json", "siteConfig.js"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["docusaurus"])) return false;
12+
13+
/** everything below now assumes that we are within gatsby */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["start"],
17+
preferredCommand: "docusaurus-start"
18+
});
19+
20+
return {
21+
type: "docusaurus",
22+
command: getYarnOrNPMCommand(),
23+
port: 8888,
24+
proxyPort: 3000,
25+
env: { ...process.env },
26+
possibleArgsArrs,
27+
urlRegexp: new RegExp(`(http://)([^:]+:)${3000}(/)?`, "g"),
28+
dist: "static"
29+
};
30+
};

src/detectors/gridsome.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json", "gridsome.config.js"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["gridsome"])) return false;
12+
13+
/** everything below now assumes that we are within gridsome */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["develop"],
17+
preferredCommand: "gridsome develop"
18+
});
19+
20+
return {
21+
type: "gridsome",
22+
command: getYarnOrNPMCommand(),
23+
port: 8888,
24+
proxyPort: 8080,
25+
env: { ...process.env },
26+
possibleArgsArrs,
27+
urlRegexp: new RegExp(`(http://)([^:]+:)${8080}(/)?`, "g"),
28+
dist: "static"
29+
};
30+
};

src/detectors/hexo.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json", "_config.yml"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["hexo"])) return false;
12+
13+
/** everything below now assumes that we are within gatsby */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["start", "dev", "develop"],
17+
preferredCommand: "hexo server"
18+
});
19+
20+
if (!possibleArgsArrs.length) {
21+
// ofer to run it when the user doesnt have any scripts setup! 🤯
22+
possibleArgsArrs.push(["hexo", "server"]);
23+
}
24+
return {
25+
type: "hexo",
26+
command: getYarnOrNPMCommand(),
27+
port: 8888,
28+
proxyPort: 4000,
29+
env: { ...process.env },
30+
possibleArgsArrs,
31+
urlRegexp: new RegExp(`(http://)([^:]+:)${4000}(/)?`, "g"),
32+
dist: "public"
33+
};
34+
};

src/detectors/next.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["next"])) return false;
12+
13+
/** everything below now assumes that we are within gatsby */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["dev", "develop", "start"],
17+
preferredCommand: "next"
18+
});
19+
20+
if (!possibleArgsArrs.length) {
21+
// ofer to run it when the user doesnt have any scripts setup! 🤯
22+
possibleArgsArrs.push(["next"]);
23+
}
24+
return {
25+
type: "next.js",
26+
command: getYarnOrNPMCommand(),
27+
port: 8888,
28+
proxyPort: 3000,
29+
env: { ...process.env },
30+
possibleArgsArrs,
31+
urlRegexp: new RegExp(`(http://)([^:]+:)${3000}(/)?`, "g"),
32+
dist: "out"
33+
};
34+
};

src/detectors/phenomic.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const {
2+
hasRequiredDeps,
3+
hasRequiredFiles,
4+
getYarnOrNPMCommand,
5+
scanScripts
6+
} = require("./utils/jsdetect");
7+
module.exports = function() {
8+
// REQUIRED FILES
9+
if (!hasRequiredFiles(["package.json"])) return false;
10+
// REQUIRED DEPS
11+
if (!hasRequiredDeps(["@phenomic/core"])) return false;
12+
13+
/** everything below now assumes that we are within gatsby */
14+
15+
const possibleArgsArrs = scanScripts({
16+
preferredScriptsArr: ["start"],
17+
preferredCommand: "phenomic start"
18+
});
19+
20+
return {
21+
type: "phenomic",
22+
command: getYarnOrNPMCommand(),
23+
port: 8888,
24+
proxyPort: 3333,
25+
env: { ...process.env },
26+
possibleArgsArrs,
27+
urlRegexp: new RegExp(`(http://)([^:]+:)${3333}(/)?`, "g"),
28+
dist: "public"
29+
};
30+
};

0 commit comments

Comments
 (0)