1 | ## writing a detector
|
2 |
|
3 | - write as many checks as possible to fit your project
|
4 | - return false if its not your project
|
5 | - if it definitely is, return an object with this shape:
|
6 |
|
7 | ```ts
|
8 | {
|
9 | type: String, // e.g. gatsby, vue-cli
|
10 | command: String, // e.g. yarn, npm
|
11 | port: Number, // e.g. 8888
|
12 | proxyPort: Number, // e.g. 3000
|
13 | env: Object, // env variables, see examples
|
14 | possibleArgsArrs: [[String]], // e.g [['run develop]], so that the combined command is 'npm run develop', but we allow for multiple
|
15 | urlRegexp: RegExp, // see examples
|
16 | dist: String, // static folder where a _redirect file would be placed, e.g. 'public' or 'static'. NOT the build output folder
|
17 | }
|
18 | ```
|
19 |
|
20 | ## things to note
|
21 |
|
22 | - Dev block overrides will supercede anything you write in your detector: https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection
|
23 | - detectors are language agnostic. don't assume npm or yarn.
|
24 | - 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 { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect')
|
38 | module.exports = function() {
|
39 | // REQUIRED FILES
|
40 | if (!hasRequiredFiles(['README.md', 'SUMMARY.md'])) return false
|
41 | // // REQUIRED DEPS
|
42 | // if (!hasRequiredDeps(["hexo"])) return false;
|
43 |
|
44 | /** everything below now assumes that we are within gatsby */
|
45 |
|
46 | const possibleArgsArrs = [['gitbook', 'serve']]
|
47 | // scanScripts({
|
48 | // preferredScriptsArr: ["start", "dev", "develop"],
|
49 | // preferredCommand: "hexo server"
|
50 | // });
|
51 |
|
52 | return {
|
53 | type: 'gitbook',
|
54 | command: getYarnOrNPMCommand(),
|
55 | port: 8888,
|
56 | proxyPort: 4000,
|
57 | env: { ...process.env },
|
58 | possibleArgsArrs,
|
59 | urlRegexp: new RegExp(`(http://)([^:]+:)${4000}(/)?`, 'g'),
|
60 | dist: 'public'
|
61 | }
|
62 | }
|
63 | ```
|