Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit c4228e2

Browse files
committed
fix: Generate YAML safely by js-yaml
1 parent 296b574 commit c4228e2

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

lib/generators/docs/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const BasicGenerator = require("../../BasicGenerator");
2+
const yaml = require("js-yaml");
23

34
class Generator extends BasicGenerator {
45
prompting() {
@@ -32,7 +33,10 @@ class Generator extends BasicGenerator {
3233

3334
writing() {
3435
this.writeFiles({
35-
context: this.prompts,
36+
context: {
37+
toYAML: obj => yaml.safeDump(obj),
38+
...this.prompts
39+
},
3640
filterFiles: () => {
3741
return true;
3842
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
---
2-
home: true
3-
heroImage: https://v1.vuepress.vuejs.org/hero.png
4-
tagline: <%= description %>
5-
actionText: Quick Start →
6-
actionLink: /guide/
7-
features:
8-
- title: Feature 1 Title
9-
details: Feature 1 Description
10-
- title: Feature 2 Title
11-
details: Feature 2 Description
12-
- title: Feature 3 Title
13-
details: Feature 3 Description
14-
footer: Made by <%= author %> with ❤️
2+
<%-
3+
toYAML({
4+
home: true,
5+
heroImage: 'https://v1.vuepress.vuejs.org/hero.png',
6+
tagline: description,
7+
actionText: 'Quick Start →',
8+
actionLink: '/guide/',
9+
features: [
10+
{
11+
title: 'Feature 1 Title',
12+
details: 'Feature 1 Description'
13+
},{
14+
title: 'Feature 2 Title',
15+
details: 'Feature 2 Description'
16+
},{
17+
title: 'Feature 3 Title',
18+
details: 'Feature 3 Description'
19+
}
20+
],
21+
footer: `Made by ${author} with ❤️`
22+
})
23+
%>
1524
---

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"fs-extra": "^8.0.1",
2626
"glob": "^7.1.4",
2727
"inquirer": "^6.2.1",
28+
"js-yaml": "^3.14.0",
2829
"mkdirp": "^0.5.1",
2930
"prettier": "^1.17.0",
3031
"semver": "^6.1.0",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -2489,7 +2489,7 @@ jest-validate@^23.5.0:
24892489
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
24902490
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
24912491

2492-
js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.9.0:
2492+
js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.14.0, js-yaml@^3.9.0:
24932493
version "3.14.0"
24942494
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
24952495
integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==

0 commit comments

Comments
 (0)