├── .npmrc ├── .prettierrc.json ├── README.md ├── bin ├── engines │ ├── pug.js │ └── vue.js └── index.js ├── package.json ├── LICENSE ├── .gitignore └── .eslintrc.json /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://registry.npmjs.org/ 2 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "trailingComma": "es5" 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-pug-to-html 2 | convert Vue files from pug templates to html 3 | 4 | Will convert `.pug` files and `.vue` files that have a pug template 5 | 6 | ```shell 7 | npm i -g vue-pug-to-html 8 | cd { your directory of files to convert } 9 | pugToHtml 10 | ``` 11 | 12 | Thats it, converts your pug template to html. 13 | -------------------------------------------------------------------------------- /bin/engines/pug.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const pug = require("pug"); 4 | const fs = require("fs"); 5 | 6 | module.exports = function(filePath) { 7 | const contents = fs.readFileSync(filePath, "utf-8"); 8 | let html = ""; 9 | 10 | return { 11 | name: "pug", 12 | 13 | convertTemplate() { 14 | console.log(filePath, contents); 15 | html = pug.render(contents, { pretty: true }); 16 | return html; 17 | }, 18 | 19 | saveToFile() { 20 | fs.writeFileSync(filePath.replace(".pug", ".html"), html); 21 | }, 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | "use strict"; 4 | 5 | const path = require("path"); 6 | const fs = require("fs"); 7 | const chalk = require("chalk"); 8 | const VueEngine = require("./engines/vue"); 9 | const PugEngine = require("./engines/pug"); 10 | 11 | function _processFile(fileName) { 12 | const filePath = path.join(process.cwd(), fileName); 13 | const engine = filePath.endsWith(".vue") ? VueEngine(filePath) : PugEngine(filePath); 14 | 15 | if (engine.name === "vue" && !engine.hasVueTemplate()) { 16 | console.log(chalk.yellow(`${fileName} does not have a pug template`)); 17 | return; 18 | } 19 | 20 | engine.convertTemplate(); 21 | console.log(chalk.green(`${fileName} converted!!`)); 22 | engine.saveToFile(); 23 | } 24 | 25 | fs.readdirSync(process.cwd()) 26 | .filter(file => file.endsWith(".vue")) 27 | .forEach(_processFile); 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-pug-to-html", 3 | "version": "1.2.1", 4 | "description": "convert vue files templates from pug to html", 5 | "main": "index.js", 6 | "bin": { 7 | "pugToHtml": "bin/index.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/dperrymorrow/vue-pug-to-html.git" 15 | }, 16 | "author": "David Morrow", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/dperrymorrow/vue-pug-to-html/issues" 20 | }, 21 | "homepage": "https://github.com/dperrymorrow/vue-pug-to-html#readme", 22 | "dependencies": { 23 | "chalk": "^2.4.1", 24 | "pug": "^2.0.3" 25 | }, 26 | "devDependencies": { 27 | "eslint": "5.9.0", 28 | "eslint-config-prettier": "3.3.0", 29 | "eslint-plugin-import": "2.14.0", 30 | "eslint-plugin-prettier": "3.0.0", 31 | "eslint-plugin-promise": "4.0.1", 32 | "eslint-plugin-unicorn": "6.0.1", 33 | "prettier": "1.14.3" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 David Morrow 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | .DS_Store 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | *.pid.lock 14 | 15 | # Directory for instrumented libs generated by jscoverage/JSCover 16 | lib-cov 17 | 18 | # Coverage directory used by tools like istanbul 19 | coverage 20 | 21 | # nyc test coverage 22 | .nyc_output 23 | 24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 25 | .grunt 26 | 27 | # Bower dependency directory (https://bower.io/) 28 | bower_components 29 | 30 | # node-waf configuration 31 | .lock-wscript 32 | 33 | # Compiled binary addons (https://nodejs.org/api/addons.html) 34 | build/Release 35 | 36 | # Dependency directories 37 | node_modules/ 38 | jspm_packages/ 39 | 40 | # TypeScript v1 declaration files 41 | typings/ 42 | 43 | # Optional npm cache directory 44 | .npm 45 | 46 | # Optional eslint cache 47 | .eslintcache 48 | 49 | # Optional REPL history 50 | .node_repl_history 51 | 52 | # Output of 'npm pack' 53 | *.tgz 54 | 55 | # Yarn Integrity file 56 | .yarn-integrity 57 | 58 | # dotenv environment variables file 59 | .env 60 | 61 | # next.js build output 62 | .next 63 | -------------------------------------------------------------------------------- /bin/engines/vue.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const pug = require("pug"); 4 | const fs = require("fs"); 5 | 6 | module.exports = function(filePath) { 7 | const contents = fs.readFileSync(filePath, "utf-8"); 8 | let html = ""; 9 | 10 | function findTemplateRaw() { 11 | return contents.split(`")[0]; 12 | } 13 | 14 | function findTemplate() { 15 | let lines = findTemplateRaw() 16 | .split("\n") 17 | .filter(row => row !== ""); 18 | 19 | if (lines[0].startsWith(" ")) lines = lines.map(line => line.replace(" ", "")); 20 | return lines.join("\n"); 21 | } 22 | 23 | return { 24 | name: "vue", 25 | 26 | hasVueTemplate() { 27 | return contents.includes(`