From ef42aa530e99a84b587303dc4eb4d16f8225a4f9 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 19 Nov 2018 14:08:49 +0800 Subject: [PATCH] format manifest.json,pages.json --- generator.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/generator.js b/generator.js index 981d9cf..2fd9416 100644 --- a/generator.js +++ b/generator.js @@ -2,6 +2,7 @@ const fs = require('fs') const path = require('path') const isBinary = require('isbinaryfile') +const stripJsonComments = require('strip-json-comments') async function generate(dir, files, base = '') { @@ -16,7 +17,12 @@ async function generate(dir, files, base = '') { if (isBinary.sync(sourcePath)) { files[path.join(base, rawPath)] = fs.readFileSync(sourcePath) // return buffer } else { - files[path.join(base, rawPath)] = fs.readFileSync(sourcePath, 'utf-8') + const content = fs.readFileSync(sourcePath, 'utf-8') + if (sourcePath.indexOf('manifest.json') !== -1 || sourcePath.indexOf('pages.json') !== -1) { + files[path.join(base, rawPath)] = JSON.stringify(JSON.parse(stripJsonComments(content)), null, 2) + } else { + files[path.join(base, rawPath)] = content + } } })