Syntax Highlighting for Docker and Yaml (#177)
* Implement dynamic component for docker and yaml prism components. Also removes chunk limit for lazy-loading. * Fix eslint with babel-eslint and remove unusued LimitChunkCount plugin.pull/180/head
							parent
							
								
									40aed64034
								
							
						
					
					
						commit
						3aba7956ef
					
				|  | @ -8,6 +8,7 @@ module.exports = { | |||
|     'plugin:vue/recommended', | ||||
|   ], | ||||
|   parserOptions: { | ||||
|     parser: "babel-eslint", | ||||
|     ecmaVersion: 2018, | ||||
|     sourceType: 'module', | ||||
|   }, | ||||
|  |  | |||
|  | @ -2458,6 +2458,20 @@ | |||
|       "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz", | ||||
|       "integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==" | ||||
|     }, | ||||
|     "babel-eslint": { | ||||
|       "version": "10.1.0", | ||||
|       "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz", | ||||
|       "integrity": "sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==", | ||||
|       "dev": true, | ||||
|       "requires": { | ||||
|         "@babel/code-frame": "^7.0.0", | ||||
|         "@babel/parser": "^7.7.0", | ||||
|         "@babel/traverse": "^7.7.0", | ||||
|         "@babel/types": "^7.7.0", | ||||
|         "eslint-visitor-keys": "^1.0.0", | ||||
|         "resolve": "^1.12.0" | ||||
|       } | ||||
|     }, | ||||
|     "babel-plugin-dynamic-import-node": { | ||||
|       "version": "2.3.3", | ||||
|       "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", | ||||
|  |  | |||
|  | @ -57,6 +57,7 @@ | |||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@vue/cli-service": "^4.5.4", | ||||
|     "babel-eslint": "^10.1.0", | ||||
|     "copyfiles": "^2.3.0", | ||||
|     "duplicate-package-checker-webpack-plugin": "^3.0.0", | ||||
|     "eslint": "^7.8.1", | ||||
|  |  | |||
|  | @ -80,12 +80,15 @@ THE SOFTWARE. | |||
|                 <div :class="`column ${splitColumn ? 'is-half' : 'is-full'} is-full-touch`"> | ||||
|                     <h2>{{ i18n.templates.app.configFiles }}</h2> | ||||
|                     <div ref="files" class="columns is-multiline files"> | ||||
|                         <NginxPrism v-for="confContents in confFilesOutput" | ||||
|                                     :key="confContents[2]" | ||||
|                                     :name="confContents[0]" | ||||
|                                     :conf="confContents[1]" | ||||
|                                     :half="Object.keys(confFilesOutput).length > 1 && !splitColumn" | ||||
|                         ></NginxPrism> | ||||
|                         <template v-for="confContents in confFilesOutput"> | ||||
|                             <component | ||||
|                                 :is="getPrismComponent(confContents[0])" | ||||
|                                 :key="confContents[2]" | ||||
|                                 :name="confContents[0]" | ||||
|                                 :conf="confContents[1]" | ||||
|                                 :half="Object.keys(confFilesOutput).length > 1 && !splitColumn" | ||||
|                             ></component> | ||||
|                         </template> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </div> | ||||
|  | @ -113,9 +116,10 @@ THE SOFTWARE. | |||
|     import Domain from './domain'; | ||||
|     import Global from './global'; | ||||
|     import Setup from './setup'; | ||||
|     import NginxPrism from './prism/nginx'; | ||||
|     import Footer from './footer'; | ||||
| 
 | ||||
|     import NginxPrism from './prism/nginx'; | ||||
| 
 | ||||
|     export default { | ||||
|         name: 'App', | ||||
|         components: { | ||||
|  | @ -125,6 +129,8 @@ THE SOFTWARE. | |||
|             Global, | ||||
|             Setup, | ||||
|             NginxPrism, | ||||
|             'YamlPrism': () => import('./prism/yaml'), | ||||
|             'DockerPrism': () => import('./prism/docker'), | ||||
|         }, | ||||
|         data() { | ||||
|             return { | ||||
|  | @ -264,6 +270,17 @@ THE SOFTWARE. | |||
|             splitColumnEvent(nonInteraction = false) { | ||||
|                 analytics('toggle_split_column', 'Button', undefined, Number(this.$data.splitColumn), nonInteraction); | ||||
|             }, | ||||
|             getPrismComponent(confName) | ||||
|             { | ||||
|                 switch (confName) { | ||||
|                 case '/etc/nginx/Dockerfile': | ||||
|                     return 'DockerPrism'; | ||||
|                 case '/etc/nginx/docker-compose.yaml': | ||||
|                     return 'YamlPrism'; | ||||
|                 default: | ||||
|                     return 'NginxPrism'; | ||||
|                 } | ||||
|             }, | ||||
|         }, | ||||
|     }; | ||||
| </script> | ||||
|  |  | |||
|  | @ -0,0 +1,50 @@ | |||
| <!-- | ||||
| Copyright 2020 DigitalOcean | ||||
| 
 | ||||
| This code is licensed under the MIT License. | ||||
| You may obtain a copy of the License at | ||||
| https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/ | ||||
| 
 | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions : | ||||
| 
 | ||||
| The above copyright notice and this permission notice shall be included in | ||||
| all copies or substantial portions of the Software. | ||||
| 
 | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
| THE SOFTWARE. | ||||
| --> | ||||
| 
 | ||||
| <template> | ||||
|     <div :class="`column ${half ? 'is-half' : 'is-full'} is-full-mobile is-full-tablet`"> | ||||
|         <h3 v-html="name"></h3> | ||||
|         <pre><code class="language-docker" v-html="conf"></code></pre> | ||||
|     </div> | ||||
| </template> | ||||
| 
 | ||||
| <script> | ||||
|     import Prism from 'prismjs'; | ||||
|     import 'prismjs/components/prism-docker'; | ||||
| 
 | ||||
|     export default { | ||||
|         name: 'DockerPrism', | ||||
|         props: { | ||||
|             name: String, | ||||
|             conf: String, | ||||
|             half: Boolean, | ||||
|         }, | ||||
|         mounted() { | ||||
|             console.info(`Highlighting ${this.$props.name}...`); | ||||
|             Prism.highlightAllUnder(this.$el); | ||||
|         }, | ||||
|     }; | ||||
| </script> | ||||
|  | @ -0,0 +1,50 @@ | |||
| <!-- | ||||
| Copyright 2020 DigitalOcean | ||||
| 
 | ||||
| This code is licensed under the MIT License. | ||||
| You may obtain a copy of the License at | ||||
| https://github.com/digitalocean/nginxconfig.io/blob/master/LICENSE or https://mit-license.org/ | ||||
| 
 | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions : | ||||
| 
 | ||||
| The above copyright notice and this permission notice shall be included in | ||||
| all copies or substantial portions of the Software. | ||||
| 
 | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
| THE SOFTWARE. | ||||
| --> | ||||
| 
 | ||||
| <template> | ||||
|     <div :class="`column ${half ? 'is-half' : 'is-full'} is-full-mobile is-full-tablet`"> | ||||
|         <h3 v-html="name"></h3> | ||||
|         <pre><code class="language-yaml" v-html="conf"></code></pre> | ||||
|     </div> | ||||
| </template> | ||||
| 
 | ||||
| <script> | ||||
|     import Prism from 'prismjs'; | ||||
|     import 'prismjs/components/prism-yaml'; | ||||
| 
 | ||||
|     export default { | ||||
|         name: 'YamlPrism', | ||||
|         props: { | ||||
|             name: String, | ||||
|             conf: String, | ||||
|             half: Boolean, | ||||
|         }, | ||||
|         mounted() { | ||||
|             console.info(`Highlighting ${this.$props.name}...`); | ||||
|             Prism.highlightAllUnder(this.$el); | ||||
|         }, | ||||
|     }; | ||||
| </script> | ||||
|  | @ -25,7 +25,6 @@ THE SOFTWARE. | |||
| */ | ||||
| 
 | ||||
| const path = require('path'); | ||||
| const { LimitChunkCountPlugin } = require('webpack').optimize; | ||||
| const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); | ||||
| const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin'); | ||||
| 
 | ||||
|  | @ -37,7 +36,6 @@ module.exports = { | |||
|     configureWebpack: { | ||||
|         node: false, // Disable Node.js polyfills (Buffer etc.) -- This will be default in Webpack 5
 | ||||
|         plugins: [ | ||||
|             new LimitChunkCountPlugin({ maxChunks: 1 }), // Generate a single CSS & JS file for easy embedding
 | ||||
|             process.argv.includes('--analyze') && new BundleAnalyzerPlugin(), | ||||
|             process.argv.includes('--analyze') && new DuplicatePackageCheckerPlugin(), | ||||
|         ].filter(x => !!x), | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Alex Howes
						Alex Howes