{"name":"fastify-cli","version":"4.0.0","keywords":["fastify","cli","one command"],"author":{"url":"http://delved.org","name":"Tomas Della Vedova - @delvedor"},"license":"MIT","_id":"fastify-cli@4.0.0","maintainers":[{"name":"simenb","email":"sbekkhus91@gmail.com"},{"name":"coopflow","email":"community@coopflow.com"},{"name":"simoneb","email":"simone.busoli@gmail.com"},{"name":"rafaelgss","email":"rafael.nunu@hotmail.com"},{"name":"starptech","email":"deusdustin@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"allevo","email":"tomallevi@gmail.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"zekth","email":"vince.legoff@gmail.com"},{"name":"ethan_arrowood","email":"ethan@arrowood.dev"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"fox1t","email":"maksim@sinik.it"},{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"},{"name":"airhorns","email":"harry@harry.me"},{"name":"kibertoad","email":"iselwin@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"}],"contributors":[{"name":"Matteo Collina","email":"hello@matteocollina.com"}],"homepage":"https://github.com/fastify/fastify-cli#readme","bugs":{"url":"https://github.com/fastify/fastify-cli/issues"},"bin":{"fastify":"cli.js"},"tsd":{"directory":"test"},"dist":{"shasum":"08c2caa7fd24a0f1632221ce7c6b00446496ad39","tarball":"http://registry-npm.ywwl.com/fastify-cli/download/fastify-cli-4.0.0.tgz","fileCount":116,"integrity":"sha512-bvVcost+T9qu7YTxfmzk9s/6FUP/c2CcZAyXC1JWsU+0b60pDflCJ7PQP41936Vqx6gXcziJotjOI4TerIC8gQ==","signatures":[{"sig":"MEQCIB5V/Hrc5/l7rmWIhDWoiw9vcV1G2htowUzmjry2KmNCAiBrmbv9BJIKKvxnZm1/FOQH2Y2q379c4lXLer2lDuy1og==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":144742,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJii6xZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmogeRAAkkRDoEPR7bqdmbJZNHLY3S6sm7lLgYM+Avhf8FukBIdUMsWf\r\nYkvju85tykrn+4HgFalXZvGvQFuoEv3TWcuBJKPKnruhtw+Ww3WVoZS1LVsf\r\nBvR+BN+kSSGVGTU6fTpFcloY2jw7iHfhbTEjZvKhzLO9Ql/9Ma1z6IkTgMVE\r\n6YvBBXi2bEFOUMzROGD6qR6nk5cfbMR0HLEEeP3NjZHeaA+6XQ5WsuuYP2gP\r\n/gyWmVjrBoCBbbtmXbkHwxhlHW9zoGA59RyqXXWme3hDIF5bVRxB1p++Um44\r\nC91F/z3oOzAp9/IDwnJ53MZr0LBB7MOfGwY/dtEeZrafqZ4rs1rvq5VaVbNi\r\ntP64aLhzjmcO8y6tVr4Z1CcWByJh7ZRPDs9351c4o85j4yKofg73/zKRMZwS\r\nXyAy1B4pldHz3EuBQ4/qSREt2pFBCq8AW+zWysHF3/gHtrGvGrAXseQChjKC\r\n9VmE5qgloNH7fWwR1AN3gfI10NpPP1ZlNxY4p7dptWEZ3xVfTvZtVikWelPW\r\nMr3vjKoxV3yv3+Gua4zO0r0iymwibjwqi9fWu6LyhbnrLil+iCHAP5vFRFX+\r\nt+FsOgdRTElIm9w5GB+ZvDrHkSYrlC4JQX9IgQLYQyQ1kEAqHK4P01TByMKs\r\nvCLzCTZCNIiJ1Hf55aXyTwF8PHxFSTLRdLI=\r\n=RI6N\r\n-----END PGP SIGNATURE-----\r\n","size":34438,"noattachment":false,"key":"/fastify-cli/-/fastify-cli-4.0.0.tgz"},"main":"cli.js","readme":"# fastify-cli\n\n![CI](https://github.com/fastify/fastify-cli/workflows/CI/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/fastify-cli.svg?style=flat)](https://www.npmjs.com/package/fastify-cli)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nCommand line tools for [Fastify](https://github.com/fastify/fastify).\nGenerate, write, and run an application with one single command!\n\n## Install\n```bash\nnpm install fastify-cli --global\n```\n\n## Usage\n\n`fastify-cli` offers a single command line interface for your Fastify\nproject:\n\n```bash\n$ fastify\n```\n\nWill print an help:\n\n```\nFastify command line interface, available commands are:\n\n  * start                 start a server\n  * generate              generate a new project\n  * generate-plugin       generate a new plugin project\n  * readme                generate a README.md for the plugin\n  * print-routes          prints the representation of the internal radix tree used by the router, useful for debugging.\n  * version               the current fastify-cli version\n  * help                  help about commands\n\nLaunch 'fastify help [command]' to know more about the commands.\n\nThe default command is start, you can hit\n\n  fastify start plugin.js\n\nto start plugin.js.\n```\n\n### start\n\nYou can start any Fastify plugin with:\n\n```bash\n$ fastify start plugin.js\n```\n\nA plugin can be as simple as:\n\n```js\n// plugin.js\nmodule.exports = function (fastify, options, next) {\n  fastify.get('/', function (req, reply) {\n    reply.send({ hello: 'world' })\n  })\n  next()\n}\n```\n\nIf you are using Node 8+, you can use `Promises` or `async` functions too:\n\n```js\n// async-await-plugin.js\nmodule.exports = async function (fastify, options) {\n  fastify.get('/', async function (req, reply) {\n    return { hello: 'world' }\n  })\n}\n```\n\nFor a list of available flags for `fastify start` see the help: `fastify help start`.\n\nIf you want to use custom options for the server creation, just export an options object with your route and run the cli command with the `--options` flag.\n\n```js\n// plugin.js\nmodule.exports = function (fastify, options, next) {\n  fastify.get('/', function (req, reply) {\n    reply.send({ hello: 'world' })\n  })\n  next()\n}\n\nmodule.exports.options = {\n  https: {\n    key: 'key',\n    cert: 'cert'\n  }\n}\n```\n\nIf you want to use custom options for your plugin, just add them after the `--` terminator.\n\n```js\n// plugin.js\nmodule.exports = function (fastify, options, next) {\n  if (option.one) {\n    //...\n  }\n  //...\n  next()\n}\n```\n\n```bash\n$ fastify start plugin.js -- --one\n```\n\nModules in EcmaScript Module format can be used on Node.js >= 14 or >= 12.17.0 but < 13.0.0'\n```js\n// plugin.js\nexport default async function plugin (fastify, options) {\n  fastify.get('/', async function (req, reply) {\n    return options\n  })\n}\n```\n\nThis works with a `.js` extension if you are using Node.js >= 14 and the nearest parent `package.json` has `\"type\": \"module\"`\n([more info here](https://nodejs.medium.com/announcing-core-node-js-support-for-ecmascript-modules-c5d6dc29b663)).\nIf your `package.json` does not have `\"type\": \"module\"`, use `.mjs` for the extension (`plugin.mjs` in the above example).\n\n#### Options\nYou can pass the following options via CLI arguments. Every option has a corresponding environment variable:\n\n| Description                                                                                                                             | Short command | Full command       | Environment variable     |\n| --------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------------ | ------------------------ |\n| Port to listen on (default to 3000)                                                                                                     | `-p`          | `--port`           | `FASTIFY_PORT or PORT`   |\n| Address to listen on                                                                                                                    | `-a`          | `--address`        | `FASTIFY_ADDRESS`        |\n| Socket to listen on                                                                                                                     | `-s`          | `--socket`         | `FASTIFY_SOCKET`         |\n| Module to preload                                                                                                                       | `-r`          | `--require`        | `FASTIFY_REQUIRE`        |\n| Log level (default to fatal)                                                                                                            | `-l`          | `--log-level`      | `FASTIFY_LOG_LEVEL`      |\n| Path to logging configuration module to use                                                                                             | `-L`          | `--logging-module`  | `FASTIFY_LOGGING_MODULE` |\n| Start Fastify app in debug mode with nodejs inspector                                                                                   | `-d`          | `--debug`          | `FASTIFY_DEBUG`          |\n| Set the inspector port (default: 9320)                                                                                                  | `-I`          | `--debug-port`     | `FASTIFY_DEBUG_PORT`     |\n| Set the inspector host to listen on (default: loopback address or `0.0.0.0` inside Docker)                                              |               | `--debug-host`     | `FASTIFY_DEBUG_HOST`     |\n| Prints pretty logs                                                                                                                      | `-P`          | `--pretty-logs`    | `FASTIFY_PRETTY_LOGS`    |\n| Watch process.cwd() directory for changes, recursively; when that happens, the process will auto reload                                 | `-w`          | `--watch`          | `FASTIFY_WATCH`          |\n| Ignore changes to the specified files or directories when watch is enabled. (e.g. `--ignore-watch='node_modules .git logs/error.log'` ) |               | `--ignore-watch`   | `FASTIFY_IGNORE_WATCH`   |\n| Prints events triggered by watch listener (useful to debug unexpected reload when using `--watch` )                                     |               | `--verbose-watch`  | `FASTIFY_VERBOSE_WATCH`   |\n| Use custom options                                                                                                                      | `-o`          | `--options`        | `FASTIFY_OPTIONS`        |\n| Set the prefix                                                                                                                          | `-x`          | `--prefix`         | `FASTIFY_PREFIX`         |\n| Set the plugin timeout                                                                                                                  | `-T`          | `--plugin-timeout` | `FASTIFY_PLUGIN_TIMEOUT` |\n| Defines the maximum payload, in bytes,<br>that the server is allowed to accept                                                               |               | `--body-limit`     | `FASTIFY_BODY_LIMIT`     |\n\nBy default `fastify-cli` runs [`dotenv`](https://www.npmjs.com/package/dotenv), so it will load all the env variables stored in `.env` in your current working directory.\n\nThe default value for `--plugin-timeout` is 10 seconds.\nBy default `--ignore-watch` flag is set to ignore `node_modules build dist .git bower_components logs .swp' files.\n\n#### Containerization\n\nWhen deploying to a Docker, and potentially other, containers, it is advisable to set a fastify address of `0.0.0.0` because these containers do not default to exposing mapped ports to localhost.\n\nFor containers built and run specifically by the Docker Daemon, fastify-cli is able to detect that the server process is running within a Docker container and the `0.0.0.0` listen address is set automatically.\n\nOther containerization tools (eg. Buildah and Podman) are not detected automatically, so the `0.0.0.0` listen address must be set explicitly with either the `--address` flag or the `FASTIFY_ADDRESS` environment variable.\n\n#### Fastify version discovery\n\nIf Fastify is installed as a project dependency (with `npm install --save fastify`),\nthen `fastify-cli` will use that version of Fastify when running the server.\nOtherwise, `fastify-cli` will use the version of Fastify included within `fastify-cli`.\n\n#### Migrating out of fastify-cli start\n\nIf you would like to turn your application into a standalone executable,\njust add the following `server.js`:\n\n```js\n'use strict'\n\n// Read the .env file.\nrequire('dotenv').config()\n\n// Require the framework\nconst Fastify = require('fastify')\n\n// Require library to exit fastify process, gracefully (if possible)\nconst closeWithGrace = require('close-with-grace')\n\n// Instantiate Fastify with some config\nconst app = Fastify({\n  logger: true\n})\n\n// Register your application as a normal plugin.\nconst appService = require('./app.js')\napp.register(appService)\n\n// delay is the number of milliseconds for the graceful close to finish\nconst closeListeners = closeWithGrace({ delay: 500 }, async function ({ signal, err, manual }) {\n  if (err) {\n    app.log.error(err)\n  }\n  await app.close()\n})\n\napp.addHook('onClose', (instance, done) => {\n  closeListeners.uninstall()\n  done()\n})\n\n// Start listening.\napp.listen({ port: process.env.PORT || 3000 }, (err) => {\n  if (err) {\n    app.log.error(err)\n    process.exit(1)\n  }\n})\n```\n\n#### Unhandled rejections\n\nfastify-cli uses [make-promises-safe](https://github.com/mcollina/make-promises-safe) to avoid memory leaks\nin case of an `'unhandledRejection'`.\n\n### generate\n\n`fastify-cli` can also help with generating some project scaffolding to\nkickstart the development of your next Fastify application. To use it:\n\n1. `fastify generate <yourapp>`\n2. `cd yourapp`\n3. `npm install`\n\nThe sample code offers you the following npm tasks:\n\n* `npm start` - starts the application\n* `npm run dev` - starts the application with\n  [`pino-colada`](https://github.com/lrlna/pino-colada) pretty logging\n  (not suitable for production)\n* `npm test` - runs the tests\n\nYou will find three different folders:\n- `plugins`: the folder where you will place all your custom plugins\n- `routes`: the folder where you will declare all your endpoints\n- `test`: the folder where you will declare all your test\n\nFinally, there will be an `app.js` file, which is your entry point.\nIt is a standard Fastify plugin and you will not need to add the `listen` method to run the server, just run it with one of the scripts above.\n\nIf the target directory exists `fastify generate` will fail unless the target directory is `.`, as in the current directory.\n\nIf the target directory is the current directory (`.`) and it already contains a `package.json` file, `fastify generate` will fail. This can\nbe overidden with the `--integrate` flag:\n\n`fastify generate . --integrate`\n\nThis will add or alter the `main`, `scripts`, `dependencies` and `devDependencies` fields on the `package.json`. In cases of file name collisions\nfor any files being added, the file will be overwritten with the new file added by `fastify generate`. If there is an existing `app.js` in this scenario,\nit will be overwritten. Use the `--integrate` flag with care.\n\n#### Options\n\n| Description | Full command |\n| --- | --- |\n| Use the TypeScript template | `--lang=ts`, `--lang=typescript` |\n| Overwrite it when the target directory is the current directory (`.`) | `--integrate`|\n\n### generate-plugin\n\n`fastify-cli` can help you improve your plugin development by generating a scaffolding project:\n\n1. `fastify generate-plugin <yourplugin>`\n2. `cd yourplugin`\n3. `npm install`\n\nThe boilerplate provides some useful npm scripts:\n* `npm run unit`: runs all unit tests\n* `npm run lint`: to check your project's code style\n* `npm run test:typescript`: runs types tests\n* `npm test`: runs all the checks at once\n\n### readme\n\n`fastify-cli` can also help with generating a concise and informative readme for your plugin. If no `package.json` is provided a new one is generated automatically.\nTo use it:\n\n1. `cd yourplugin`\n2. `fastify readme <path-to-your-plugin-file>`\n\nFinally, there will be a new `README.md` file, which provides internal information about your plugin e.g:\n\n* Install instructions\n* Example usage\n* Plugin dependencies\n* Exposed decorators\n* Encapsulation semantics\n* Compatible Fastify version\n\n### linting\n\n`fastify-cli` is unopinionated on the choice of linter. We recommend you to add a linter, like so:\n\n```diff\n\"devDependencies\": {\n+ \"standard\": \"^11.0.1\",\n}\n\n\"scripts\": {\n+ \"pretest\": \"standard\",\n  \"test\": \"tap test/**/*.test.js\",\n  \"start\": \"fastify start -l info app.js\",\n  \"dev\": \"fastify start -l info -P app.js\",\n+ \"lint\": \"standard --fix\"\n},\n```\n\n## Test helpers\n\nWhen you use `fastify-cli` to run your project you need a way to load your application because you can run the CLI command.\nTo do so, you can use the this module to load your application and give you the control to write your assertions.\nThese utilities are async functions that you may use with the [`node-tap`](https://www.npmjs.com/package/tap) testing framework.\n\nThere are two utilities provided:\n\n- `build`: builds your application and returns the `fastify` instance without calling the `listen` method.\n- `listen`: starts your application and returns the `fastify` instance listening on the configured port.\n\nBoth of these utilities have the `function(arg, pluginOptions)` parameters:\n\n- `cliArgs`: is a string or a string array within the same arguments passed to the `fastify-cli` command.\n- `pluginOptions`: is an object containing the options provided to the started plugin (eg: `app.js`).\n\n```js\n// load the utility helper functions\nconst { build, listen } = require('fastify-cli/helper')\n\n// write a test\nconst { test } = require('tap')\ntest('test my application', async t => {\n  const argv = ['app.js']\n  const app = await build(argv, {\n    extraParam: 'foo'\n  })\n  t.teardown(() => app.close())\n\n  // test your application here:\n  const res = await app.inject('/')\n  t.same(res.json(), { hello: 'one' })\n})\n```\n\n\n## Contributing\nIf you feel you can help in any way, be it with examples, extra testing, or new features please open a pull request or open an issue.\n\n### How to execute the CLI\nInstead of using the `fastify` keyword before each command, use `node cli.js`\n<br/>Example: replace `fastify start` with `node cli.js start`\n\n## License\n**[MIT](https://github.com/fastify/fastify-cli/blob/master/LICENSE)**\n","engines":{"node":">= 10"},"gitHead":"d563ce0c601f73946e2cb1c89a62d71bab8ab9e9","scripts":{"lint":"standard","test":"npm run lint && npm run unit && npm run test:typescript","unit":"tap \"test/**/*.test.{js,ts}\" \"templates/**/*.test.{js,ts}\"","pretest":"xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'","lint:fix":"standard --fix","test:typescript":"tsd templates/plugin && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"standard":{"ignore":["test/data/parsing-error.js","test/data/undefinedVariable.js"]},"repository":{"url":"git+https://github.com/fastify/fastify-cli.git","type":"git"},"_npmVersion":"8.5.5","description":"Run a fastify route with one command!","directories":{},"_nodeVersion":"16.15.0","dependencies":{"pump":"^3.0.0","chalk":"^4.1.2","dotenv":"^16.0.0","pkg-up":"^3.1.0","semver":"^7.3.5","split2":"^4.1.0","commist":"^2.0.0","fastify":"^4.0.0-rc.2","help-me":"^3.0.0","chokidar":"^3.5.2","generify":"^4.0.0","is-docker":"^2.0.0","pino-colada":"^2.2.2","resolve-from":"^5.0.0","yargs-parser":"^20.0.0","close-with-grace":"^1.1.0","make-promises-safe":"^5.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"tap":"^16.1.0","tsd":"^0.16.0","sinon":"^14.0.0","rimraf":"^3.0.2","walker":"^1.0.8","del-cli":"^3.0.1","ts-node":"^10.4.0","standard":"^17.0.0","minimatch":"^5.1.0","@types/tap":"^15.0.5","pre-commit":"^1.2.2","proxyquire":"^2.1.3","simple-get":"^4.0.0","strip-ansi":"^6.0.1","typescript":"^4.5.4","@types/node":"^17.0.8","ts-standard":"^11.0.0","concurrently":"^7.0.0","fastify-plugin":"^3.0.0","fastify-tsconfig":"^1.0.1","@fastify/autoload":"^5.0.0","@fastify/sensible":"^4.1.0"},"_npmOperationalInternal":{"tmp":"tmp/fastify-cli_4.0.0_1653320792815_0.4259950628125948","host":"s3://npm-registry-packages"},"publish_time":1653320792974,"_cnpm_publish_time":1653320792974,"dist-tags":{"latest":"8.0.3","next":"7.0.0"}}