Skip to content

Commit

Permalink
feat: skip file output
Browse files Browse the repository at this point in the history
skip file output with settings.output as false
  • Loading branch information
klaytonfaria committed Mar 30, 2022
1 parent 2c97872 commit e15175d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
14 changes: 8 additions & 6 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ const build = options => {
const transformData = transformDataPlugin(settings)
const serveData = serveDataPlugin(settings)

const distFolder = path.resolve(
options.cwd,
options.dist.replace(/(.*\/).*\.json$/, '$1')
)
if (!fs.existsSync(distFolder)) {
fs.mkdirSync(distFolder, { recursive: true })
if (options.dist) {
const distFolder = path.resolve(
options.cwd,
options.dist.replace(/(.*\/).*\.json$/, '$1')
)
if (!fs.existsSync(distFolder)) {
fs.mkdirSync(distFolder, { recursive: true })
}
}

const ignorePattern = options.ignore
Expand Down
26 changes: 16 additions & 10 deletions lib/plugins/write-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ const plugin = settings => {
* @param done
*/
return function writeJson (files, metalsmith, done) {
const data = {
app: settings,
data: files.data || []
}
if (settings.dist) {
const data = {
app: settings,
data: files.data || []
}

data.app.version = pkg ? pkg.version : 'n/a'
data.app.version = pkg ? pkg.version : 'n/a'

json.writeFileSync(settings.dist, data, { spaces: 2 }, err => {
cli.fatal(err)
})
json.writeFileSync(settings.dist, data, { spaces: 2 }, err => {
cli.fatal(err)
})
}

if (settings.display) {
cli.info(`Total files: ${Object.keys(files).length}`)
cli.info(`Output file created on: ${settings.dist}`)
cli.info(`Total files: ${Object.keys(files).filter(file => file !== 'data').length}`)
if (settings.dist) {
cli.info(`Output file created on: ${settings.dist}`)
} else {
cli.info(`Output file creation skipped. Settings Value: ${settings.dist}`)
}
cli.ok('Markdown to json process has been finished!')
}

Expand Down
2 changes: 1 addition & 1 deletion stubs/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SETTINGS = {
src: './example/',
filePattern: '**/*.md',
ignore: '*(icon|input)*',
dist: 'build/example/output.json',
dist: false,
metadata: false,
deterministicOrder: true
}
Expand Down

0 comments on commit e15175d

Please sign in to comment.