Repository: maizzle/framework (js)

Issue:
Plaintext doesn't seem to be outputting
- Maizzle Version: ^2.1.0
- Node.js Version: 10.19.0

I followed along with the documentation to enable plaintext output on template creation via Front matter and it doesn't seem to generate the txt files to go along with the generated html.

Pull request description:
fix(generators): read plaintext option correctly from template config
Fixes #299

Patch:
diff --git a/src/generators/output/to-disk.js b/src/generators/output/to-disk.js
index 438f1bd..4bbbfb7 100644
--- a/src/generators/output/to-disk.js
+++ b/src/generators/output/to-disk.js
@@ -63,7 +63,7 @@ module.exports = async (env, spinner, config) => {
             .then(async ({html, config}) => {
               const destination = config.permalink || file
 
-              if (templateConfig.plaintext) {
+              if (config.plaintext) {
                 await Plaintext.prepare(html, destination, config)
                   .then(async ({target, plaintext}) => {
                     await fs.outputFile(target, plaintext)
@@ -126,5 +126,5 @@ module.exports = async (env, spinner, config) => {
     await config.events.afterBuild(files)
   }
 
-  return parsed
+  return files
 }


Test patch:
diff --git a/test/test-todisk.js b/test/test-todisk.js
index d64fe9d..9e02d61 100644
--- a/test/test-todisk.js
+++ b/test/test-todisk.js
@@ -51,7 +51,7 @@ test('outputs files at the correct location', async t => {
   })
 
   t.true(fs.pathExistsSync(t.context.folder))
-  t.is(files.length, 2)
+  t.is(files.length, 3)
 })
 
 test('outputs files at the correct location if multiple template sources are used', async t => {
@@ -76,7 +76,7 @@ test('outputs files at the correct location if multiple template sources are use
   })
 
   t.true(fs.pathExistsSync(t.context.folder))
-  t.is(files.length, 3)
+  t.is(files.length, 4)
 })
 
 test('processes all files in the `filetypes` option', async t => {
@@ -115,25 +115,25 @@ test('outputs files with the correct extension', async t => {
 })
 
 test('outputs plaintext files if option is enabled', async t => {
-  await Maizzle.build('production', {
+  const files = await Maizzle.build('production', {
     fail: 'silent',
     build: {
       templates: {
         source: 'test/stubs/plaintext',
         destination: {
           path: t.context.folder
-        },
-        plaintext: true
+        }
       }
-    }
+    },
+    plaintext: true
   })
 
-  const plaintext = fs.readdirSync(t.context.folder).filter(file => file.includes('.txt'))
-  const html = fs.readdirSync(t.context.folder).filter(file => file.includes('.html'))
-  const plaintextContent = await fs.readFile(`${t.context.folder}/${plaintext[0]}`, 'utf8')
-  const htmlContent = await fs.readFile(`${t.context.folder}/${html[0]}`, 'utf8')
+  const plaintext = files.filter(file => file.includes('.txt'))
+  const html = files.filter(file => file.includes('.html'))
+  const plaintextContent = await fs.readFile(plaintext[0], 'utf8')
+  const htmlContent = await fs.readFile(html[0], 'utf8')
 
-  t.is(plaintext.length, 1)
+  t.is(plaintext[0], `${t.context.folder}/plaintext.txt`)
   t.is(plaintextContent, 'Show in HTML\nShow in plaintext')
   t.is(htmlContent, '<div>Show in HTML</div>\n\n')
 })