{"id":8530,"date":"2021-07-07T14:49:04","date_gmt":"2021-07-07T06:49:04","guid":{"rendered":"https:\/\/sdeno.com\/?p=8530"},"modified":"2022-02-18T17:00:34","modified_gmt":"2022-02-18T09:00:34","slug":"plop-%e7%94%a8%e5%91%bd%e4%bb%a4%e5%88%9b%e5%bb%ba%e5%88%9d%e5%a7%8b%e7%9a%84%e7%a9%ba%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=8530","title":{"rendered":"plop\u2014\u2014\u7528\u547d\u4ee4\u521b\u5efa\u521d\u59cb\u7684\u7a7a\u6a21\u677f"},"content":{"rendered":"<p>plopfile.js\u529f\u80fd\u7c7b\u4f3c\u4e8e\u50cf\u521b\u5efa\u4e00\u4e2axx.html\u7684\u7a7a\u6a21\u677f\uff0c\u6a21\u677f\u91cc\u9762\u7684\u6709\u56fa\u5b9a\u7684\u521d\u59cb\u5316\u6570\u636e\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">npm i -g plop@2.5.0 \/\/3.x\u662ftypeScript\u7684<\/pre>\n<p>&nbsp;<\/p>\n<p>\u6839\u76ee\u5f55\u521b\u5efa\uff1aplopfile.js<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">module.exports = function(plop) {\r\n    \/\/ controller generator\r\n    plop.setGenerator('controller', {\r\n        description: '\u63a7\u5236\u5668',\r\n        prompts: [\r\n            {   \/\/\u7b2c\u4e00\u4e2a\u64cd\u4f5c\r\n                type: 'input', \/\/\u8f93\u5165\u4e00\u4e2a\u503c\r\n                name: 'name',  \/\/\u53d8\u91cf\u540d\u662fname\r\n                message: 'controller name please'\r\n            },\r\n            {   \/\/\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\r\n                type: 'checkbox', \/\/\u591a\u9009\r\n                name: 'blocks',  \/\/\u6570\u7ec4\u53d8\u91cf\u540d\u662f blocks:['state','mutations','actions']\r\n                message: 'Blocks:',\r\n                choices: [\r\n                    {\r\n                        name: 'state', \/\/\u5916\u663e\u793a\u540d\u5b57\r\n                        value: 'state',\r\n                        checked: true \/\/\u9ed8\u8ba4\u9009\u4e2d\r\n                    },\r\n                    {\r\n                        name: 'mutations2',\r\n                        value: 'mutations',\r\n                        checked: true\r\n                    },\r\n                    {\r\n                        name: 'actions3',\r\n                        value: 'actions',\r\n                        checked: true\r\n                    }\r\n                ],\r\n                validate(value) { \/\/\u9a8c\u8bc1\u662f\u5426\u5fc5\u586b\r\n                    if (!value.includes('state') || !value.includes('mutations')) {\r\n                        return 'store require at least state and mutations'\r\n                    }\r\n                    return true\r\n                }\r\n            }\r\n        ],\r\n        actions(data) {\r\n            console.log(data) \/\/\u4e4b\u524d\u64cd\u4f5c\u83b7\u53d6\u5230\u7684\u6570\u636e { name: '00', blocks: [ 'state', 'mutations', 'actions' ] }\r\n            const name = '{{name}}' \/\/\u7b2c\u4e00\u4e2a\u64cd\u4f5c \u8bbe\u7f6e\u7684\u53d8\u91cf\r\n            const actions = [\r\n                {\r\n                    type: 'add',\r\n                    path: `src\/${name}.vue`,\r\n                    templateFile: 'plop-templates\/controller.hbs'\r\n                }\r\n            ]\r\n\r\n            return actions\/\/\u8fd4\u56de\u6570\u7ec4\r\n        }\r\n\r\n    });\r\n\r\n};\r\n<\/pre>\n<p><a href=\"https:\/\/plopjs.com\/documentation\/\" target=\"_blank\" rel=\"noopener\">https:\/\/plopjs.com\/documentation\/<\/a><\/p>\n<p>\u5b98\u7f51githun\uff1a<a href=\"https:\/\/github.com\/plopjs\/plop\/tree\/v2.5.0\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/plopjs\/plop\/tree\/v2.5.0<\/a><\/p>\n<p>\u66f4\u591a\u6709\u5173prompts\u53c2\u6570\u8bbe\u7f6e\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"https:\/\/github.com\/SBoudrias\/Inquirer.js\/\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/SBoudrias\/Inquirer.js\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u4e0b\u8f7d\u6587\u4ef6<a href=\"https:\/\/sdeno.com\/wp-content\/uploads\/2021\/07\/plop.zip\">plop<\/a>\uff0c\u89e3\u538b\u628a\u6587\u4ef6\u90fd\u653e\u5728\u6839\u76ee\u5f55\uff0c\u4e4b\u540e\u6267\u884cnpm run new\u5373\u53ef\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>plopfile.js\u529f\u80fd\u7c7b\u4f3c\u4e8e\u50cf\u521b\u5efa\u4e00\u4e2axx.html\u7684\u7a7a\u6a21\u677f\uff0c\u6a21\u677f\u91cc\u9762\u7684\u6709\u56fa\u5b9a\u7684\u521d\u59cb\u5316\u6570\u636e\u3002 &nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-8530","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8530"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/8530\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}