├── .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(``)[1].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(``);
28 | },
29 |
30 | convertTemplate() {
31 | html = pug
32 | .render(findTemplate(), { pretty: true })
33 | .replace(new RegExp('v-else="v-else"', `g`), "v-else")
34 | .replace(new RegExp(">", `g`), ">")
35 | .replace(new RegExp("&", `g`), "&")
36 | .replace(new RegExp(""", `g`), "'");
37 | return html;
38 | },
39 |
40 | saveToFile() {
41 | const formatted = html
42 | .split("\n")
43 | .map(line => ` ${line}`)
44 | .join("\n");
45 |
46 | const data = contents
47 | .replace(findTemplateRaw(), `${formatted}\n`)
48 | .replace(``, "");
49 | fs.writeFileSync(filePath, data);
50 | },
51 | };
52 | };
53 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "env": {
4 | "es6": true,
5 | "node": true
6 | },
7 | "parserOptions": {
8 | "ecmaVersion": 2018
9 | },
10 | "extends": [
11 | "eslint:recommended",
12 | "plugin:prettier/recommended"
13 | ],
14 | "plugins": [
15 | "promise",
16 | "unicorn"
17 | ],
18 | "rules": {
19 | "dot-notation": [
20 | "error"
21 | ],
22 | "eqeqeq": [
23 | "error",
24 | "smart"
25 | ],
26 | "no-console": ["off"],
27 | "no-else-return": [
28 | "error"
29 | ],
30 | "no-extra-bind": [
31 | "error"
32 | ],
33 | "no-extra-label": [
34 | "error"
35 | ],
36 | "no-implicit-coercion": [
37 | "error",
38 | {
39 | "allow": [
40 | "!!"
41 | ]
42 | }
43 | ],
44 | "strict": [
45 | "error",
46 | "global"
47 | ],
48 | "linebreak-style": [
49 | "error",
50 | "unix"
51 | ],
52 | "no-lonely-if": [
53 | "error"
54 | ],
55 | "arrow-body-style": [
56 | "error",
57 | "as-needed"
58 | ],
59 | "no-unused-vars": [
60 | "error",
61 | {
62 | "args": "none"
63 | }
64 | ],
65 | "no-useless-computed-key": [
66 | "error"
67 | ],
68 | "no-useless-rename": [
69 | "error"
70 | ],
71 | "no-var": [
72 | "error"
73 | ],
74 | "prefer-spread": [
75 | "error"
76 | ],
77 | "prefer-template": [
78 | "error"
79 | ],
80 | "prefer-const": [
81 | "warn",
82 | {
83 | "destructuring": "all"
84 | }
85 | ],
86 | "no-empty-function": [
87 | "error"
88 | ],
89 | "vars-on-top": [
90 | "error"
91 | ],
92 | "unicorn/filename-case": [
93 | "warn",
94 | {
95 | "case": "kebabCase"
96 | }
97 | ],
98 | "unicorn/throw-new-error": [
99 | "error"
100 | ],
101 | "unicorn/no-array-instanceof": [
102 | "error"
103 | ],
104 | "unicorn/no-new-buffer": [
105 | "error"
106 | ],
107 | "unicorn/no-hex-escape": [
108 | "error"
109 | ],
110 | "unicorn/prefer-starts-ends-with": [
111 | "warn"
112 | ],
113 | "promise/catch-or-return": [
114 | "error"
115 | ]
116 | }
117 | }
--------------------------------------------------------------------------------