hapipal / discuss

The hapi pal discussion board
3 stars 0 forks source link

VS Code Snippets #6

Open damusix opened 3 years ago

damusix commented 3 years ago

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 commented 3 years ago

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.