This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 639
feat: Adds Typescript Fastify CLI Application #154
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// in ".releaserc.js" or "release.config.js" | ||
|
||
const {promisify} = require('util') | ||
const dateFormat = require('dateformat') | ||
const readFileAsync = promisify(require('fs').readFile) | ||
const path = require('path') | ||
// Given a `const` variable `TEMPLATE_DIR` which points to "<semantic-release-gitmoji>/lib/assets/templates" | ||
const TEMPLATE_DIR = 'node_modules/semantic-release-gitmoji/lib/assets/templates' | ||
// the *.hbs template and partials should be passed as strings of contents | ||
const template = readFileAsync(path.join(TEMPLATE_DIR, 'default-template.hbs')) | ||
const commitTemplate = readFileAsync(path.join(TEMPLATE_DIR, 'commit-template.hbs')) | ||
|
||
module.exports = { | ||
branch: "master", | ||
generateNotes: ['semantic-release-gitmoji'], | ||
analyzeCommits: ['semantic-release-gitmoji'], | ||
plugins: [ | ||
[ | ||
'semantic-release-gitmoji', { | ||
releaseRules: { | ||
major: [':boom:'], | ||
minor: [':sparkles:'], | ||
patch: [ | ||
':bug:', | ||
':ambulance:', | ||
':lock:' | ||
] | ||
}, | ||
releaseNotes: { | ||
template: template, | ||
partials: {commitTemplate}, | ||
helpers: { | ||
datetime: function (format = 'UTC:yyyy-mm-dd') { | ||
return dateFormat(new Date(), format) | ||
} | ||
}, | ||
issueResolution: { | ||
template: '{baseUrl}/{owner}/{repo}/issues/{ref}', | ||
baseUrl: 'https://github.com', | ||
source: 'github.com' | ||
} | ||
} | ||
} | ||
], | ||
"@semantic-release/release-notes-generator", | ||
["@semantic-release/changelog", { | ||
"changelogFile": "CHANGELOG.md" | ||
}], | ||
['@semantic-release/git', { | ||
"assets": ["CHANGELOG.md", "package.json", "packages"], | ||
"message": ":bookmark: (release) ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
}] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const AutoLoad = require('fastify-autoload') | ||
|
||
module.exports = function (fastify, opts, next) { | ||
// Place here your custom code! | ||
|
||
// Do not touch the following lines | ||
|
||
// This loads all plugins defined in plugins | ||
// those should be support plugins that are reused | ||
// through your application | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'plugins'), | ||
includeTypeScript: true, | ||
options: Object.assign({}, opts) | ||
}) | ||
|
||
// This loads all plugins defined in services | ||
// define your routes in one of these | ||
fastify.register(AutoLoad, { | ||
dir: path.join(__dirname, 'services'), | ||
includeTypeScript: true, | ||
options: Object.assign({}, opts) | ||
}) | ||
|
||
// Make sure to call next when done | ||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
extends: ["gitmoji"], | ||
parserPreset: { | ||
parserOpts: { | ||
headerPattern: /^(:\w*:)(?:\s)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/, | ||
headerCorrespondence: ["type", "scope", "subject", "ticket"] | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@hospitalrun-org/server", | ||
"version": "1.0.0", | ||
"description": "Fastify Application", | ||
"main": "app.ts", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "ts-node ./node_modules/tap/bin/run.js test/**/*.test.ts", | ||
"start": "ts-node ./node_modules/fastify-cli/cli.js start -l info app.ts", | ||
"dev": "ts-node ./node_modules/fastify-cli/cli.js start -l info -P app.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"fastify": "^2.0.0", | ||
"fastify-plugin": "^1.5.0", | ||
"fastify-autoload": "^1.0.0", | ||
"fastify-cli": "^1.2.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you think we need a fastify-cli? |
||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^8.1.0", | ||
"@commitlint/core": "^8.1.0", | ||
"@semantic-release/changelog": "^3.0.4", | ||
"@semantic-release/git": "^7.0.16", | ||
"@semantic-release/github": "^5.4.3", | ||
"@semantic-release/npm": "^5.1.15", | ||
"@semantic-release/release-notes-generator": "^7.3.0", | ||
"@types/node": "^12.7.4", | ||
"commitizen": "^4.0.3", | ||
"commitlint-config-gitmoji": "^1.0.1", | ||
"cz-emoji": "^1.1.2", | ||
"husky": "^3.0.5", | ||
"semantic-release": "^15.13.24", | ||
"semantic-release-cli": "^5.2.1", | ||
"semantic-release-gitmoji": "^1.3.2", | ||
"tap": "^12.5.3", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.6.2" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-emoji" | ||
} | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "npm test" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Plugins Folder | ||
|
||
Plugins define behavior that is common to all the routes in your | ||
application. Authentication, caching, templates, and all the other cross | ||
cutting concerns should be handled by plugins placed in this folder. | ||
|
||
Files in this folder are typically defined through the | ||
[`fastify-plugin`](https://github.com/fastify/fastify-plugin) module, | ||
making them non-encapsulated. They can define decorators and set hooks | ||
that will then be used in the rest of your application. | ||
|
||
Check out: | ||
|
||
* [The hitchhiker's guide to plugins](https://github.com/fastify/fastify/blob/master/docs/Plugins-Guide.md) | ||
* [Fastify decorators](https://www.fastify.io/docs/latest/Decorators/). | ||
* [Fastify lifecycle](https://www.fastify.io/docs/latest/Lifecycle/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
import * as fp from 'fastify-plugin' | ||
|
||
|
||
export default fp((fastify, opts, next) => { | ||
fastify.decorate('someSupport', function () { | ||
return 'hugs' | ||
}) | ||
next() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Services Folder | ||
|
||
Services define routes within your application. Fastify provides an | ||
easy path to a microservice architecture, in the future you might want | ||
to independently deploy some of those. | ||
|
||
In this folder you should define all the services that define the routes | ||
of your web application. | ||
Each service is a [Fastify | ||
plugin](https://www.fastify.io/docs/latest/Plugins/), it is | ||
encapsulated (it can have its own independent plugins) and it is | ||
typically stored in a file; be careful to group your routes logically, | ||
e.g. all `/users` routes in a `users.js` file. We have added | ||
a `root.js` file for you with a '/' root added. | ||
|
||
If a single file become too large, create a folder and add a `index.js` file there: | ||
this file must be a Fastify plugin, and it will be loaded automatically | ||
by the application. You can now add as many files as you want inside that folder. | ||
In this way you can create complex services within a single monolith, | ||
and eventually extract them. | ||
|
||
If you need to share functionality between services, place that | ||
functionality into the `plugins` folder, and share it via | ||
[decorators](https://www.fastify.io/docs/latest/Decorators/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
module.exports = function (fastify, opts, next) { | ||
fastify.get('/example', function (request, reply) { | ||
reply.send('this is an example') | ||
}) | ||
|
||
next() | ||
} | ||
|
||
// If you prefer async/await, use the following | ||
// | ||
// module.exports = async function (fastify, opts) { | ||
// fastify.get('/example', async function (request, reply) { | ||
// return 'this is an example' | ||
// }) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
import * as fastify from 'fastify' | ||
import { Server, IncomingMessage, ServerResponse } from 'http' | ||
|
||
|
||
export default (fastify: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>, opts, next) => { | ||
fastify.get('/', (request, reply) => { | ||
reply.send({ root: true }) | ||
}) | ||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
// This file contains code that we reuse | ||
// between our tests. | ||
|
||
const Fastify = require('fastify') | ||
const fp = require('fastify-plugin') | ||
const App = require('../app') | ||
|
||
// Fill in this config with all the configurations | ||
// needed for testing the application | ||
export const config = () => { | ||
return {} | ||
} | ||
|
||
// automatically build and tear down our instance | ||
export const build = (t) => { | ||
const app = Fastify() | ||
|
||
// fastify-plugin ensures that all decorators | ||
// are exposed for testing purposes, this is | ||
// different from the production setup | ||
app.register(fp(App), config()) | ||
|
||
// tear down our app after we are done | ||
t.tearDown(app.close.bind(app)) | ||
|
||
return app | ||
} | ||
|
||
export default { | ||
config, | ||
build | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { test } = require('tap') | ||
const Fastify = require('fastify') | ||
import Support from '../../plugins/support' | ||
|
||
test('support works standalone', (t) => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
fastify.register(Support) | ||
|
||
fastify.ready((err) => { | ||
t.error(err) | ||
t.equal(fastify.someSupport(), 'hugs') | ||
}) | ||
}) | ||
|
||
// If you prefer async/await, use the following | ||
// | ||
// test('support works standalone', async (t) => { | ||
// const fastify = Fastify() | ||
// fastify.register(Support) | ||
// | ||
// await fastify.ready() | ||
// t.equal(fastify.someSupport(), 'hugs') | ||
// }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this lines will not work on Windows.
Also the glob paths have to be surrounded by "". Again, no single quotes because of Windows.