Skip to content
Branch: master
Find file History
sw-yx
Latest commit ff8ea5d Jun 17, 2019

README.md

writing a detector

  • write as many checks as possible to fit your project
  • return false if its not your project
  • if it definitely is, return an object with this shape:
{
    type: String, // e.g. gatsby, vue-cli
    command: String, // e.g. yarn, npm
    port: Number, // e.g. 8888
    proxyPort: Number, // e.g. 3000
    env: Object, // env variables, see examples
    possibleArgsArrs: [[String]], // e.g [['run develop]], so that the combined command is 'npm run develop', but we allow for multiple
    urlRegexp: RegExp, // see examples
    dist: String, // static folder where a _redirect file would be placed, e.g. 'public' or 'static'. NOT the build output folder
}

things to note

  • 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

not sure if we want to support gitbook yet

requires a global install: https://github.com/GitbookIO/gitbook/blob/master/docs/setup.md

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"
  };
};
You can’t perform that action at this time.