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

fix: Generate YAML safely by js-yaml #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/generators/docs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const yaml = require('js-yaml');
const BasicGenerator = require('../../BasicGenerator');


class Generator extends BasicGenerator {
prompting() {
const prompts = [
Expand Down Expand Up @@ -32,7 +34,10 @@ class Generator extends BasicGenerator {

writing() {
this.writeFiles({
context: this.prompts,
context: {
toYAML: obj => yaml.safeDump(obj),
...this.prompts
},
filterFiles: () => {
return true;
}
Expand Down
35 changes: 22 additions & 13 deletions lib/generators/docs/templates/docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
---
home: true
heroImage: https://v1.vuepress.vuejs.org/hero.png
tagline: <%= description %>
actionText: Quick Start →
actionLink: /guide/
features:
- title: Feature 1 Title
details: Feature 1 Description
- title: Feature 2 Title
details: Feature 2 Description
- title: Feature 3 Title
details: Feature 3 Description
footer: Made by <%= author %> with ❤️
<%-
toYAML({
home: true,
heroImage: 'https://v1.vuepress.vuejs.org/hero.png',
tagline: description,
actionText: 'Quick Start →',
actionLink: '/guide/',
features: [
{
title: 'Feature 1 Title',
details: 'Feature 1 Description'
},{
title: 'Feature 2 Title',
details: 'Feature 2 Description'
},{
title: 'Feature 3 Title',
details: 'Feature 3 Description'
}
],
footer: `Made by ${author} with ❤️`
})
%>
---
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"fs-extra": "^8.0.1",
"glob": "^7.1.4",
"inquirer": "^6.2.1",
"js-yaml": "^3.14.0",
"mkdirp": "^0.5.1",
"prettier": "^1.17.0",
"semver": "^6.1.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,7 @@ jest-validate@^23.5.0:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

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