Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS Code Snippets #6

Open
damusix opened this issue Apr 11, 2021 · 1 comment
Open

VS Code Snippets #6

damusix opened this issue Apr 11, 2021 · 1 comment

Comments

@damusix
Copy link

damusix commented Apr 11, 2021

My team and I have a mess of our own vscode snippets for all things Hapi / Hapipal. I think it'd be nice if hapipal (and hapi) had official vscode snippets in the extensions marketplace. Perhaps a repo to contibute to would be nice as well. Here are mine:

Screenshot from 2021-04-11 01-37-52
Screenshot from 2021-04-11 01-42-02
Screenshot from 2021-04-11 01-39-10
Screenshot from 2021-04-11 01-38-36
Screenshot from 2021-04-11 01-38-19
Screenshot from 2021-04-11 01-38-07

{
	"Schmervice service class": {
		"prefix": "schmervice",
		"body": [
			"const Schmervice = require('@hapipal/schmervice');",
			"",
			"class ${1:MyService} extends Schmervice.Service {",
			"",
			"\tconstructor(server, options) {",
			"",
			"\t\tsuper(server, options);",
			"\t\t$2",
			"\t}",

			"",
			"\t${3:async myFunction}(server, options) {",
			"",
			"\t\treturn $4;",
			"\t}",

			"}",
			"",
			"module.exports = ${1:MyService};",
			""
		],
		"description": "Creates a schmervice class file"
	},
	"Schwifty model class": {
		"prefix": "schwifty",
		"body": [
			"const Schwifty = require('@hapipal/shwifty');",
			"const Joi = require('joi');",
			"",
			"class ${1:MyModel} extends Schwifty.Model {",
			"",
			"\tstatic tableName = '${2:my_table}';",
			"",
			"\tstatic joiSchema = Joi.object({",
			"\t\t$3",
			"\t});",
			"}",
			"",
			"module.exports = ${1:MyModel};",
			""
		],
		"description": "Creates a schwifty model class file"
	},
	"Hpal route": {
		"prefix": "hpalroute",
		"body": [
			"const Joi = require('joi');",
			"",
			"module.exports = {",
			"\tmethod: '${1:GET}',",
			"\tpath: '/$2',",
			"\thandler: ${6:async }(request, h) => {",
			"",
			"\t\treturn $7",
			"\t},",
			"\toptions: {",
			"\t\tvalidate: {",
			"\t\t\tparams: Joi.object({$3}),",
			"\t\t\tquery: Joi.object({$4}),",
			"\t\t\tpayload: Joi.object({$5})",
			"\t\t}",
			"\t}",
			"};",
			""
		],
		"description": "Creates an hpal route file"
	},
	"Hpal method": {
		"prefix": "hpalmethod",
		"body": [
			"module.exports = (server, options) => {",
			"",
			"\tconst method = ${1:async }($2) => {",
			"",
			"\t\treturn $3;",
			"\t};",
			"",
			"\treturn { method };",
			"};",
			"",
		],
		"description": "Creates hpal method file. Useful for methods, extensions, and decorations."
	},
	"Hpal method with cache": {
		"prefix": "hpalmethodcache",
		"body": [
			"module.exports = (server, pluginOptions) => {",
			"",
			"\tconst method = ${6:async }($7) => {",
			"",
			"\t\treturn $8;",
			"\t};",
			"",
			"\tconst options = {",
			"\t\tcache: {",
			"\t\t\tcache: '${1:cachename}',",
			"\t\t\tstaleIn: ${2:30000},",
			"\t\t\tstaleTimeout: ${3:1},",
			"\t\t\texpiresIn: ${4:86400000},",
			"\t\t\tgenerateTimeout: ${5:5000}",
			"\t\t}",
			"\t};",
			"",
			"",
			"\treturn { method, options };",
			"};",
			"",
		],
		"description": "Creates hpal method file. Useful for methods, extensions, and decorations."
	}
}
@devinivy
Copy link
Member

devinivy commented Apr 17, 2021

Perhaps the content output from hpal make would be a good starting point. If you want to access that programmatically, today you could do this:

const HauteCouture = require('@hapipal/haute-couture');
const Print = require('@hapipal/hpal/lib/print');

const route = HauteCouture.amendment('route');
console.log(Print.example(route.example));

I don't think it would be a problem to add hpal's example() to its public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants