Skip to content

Commit 9d96954

Browse files
rexxarsbjoerge
authored andcommitted
[core] Skip system documents when exporting a dataset (#120)
1 parent cf8b00e commit 9d96954

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/@sanity/core/src/commands/dataset/exportDatasetCommand.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import path from 'path'
22
import fsp from 'fs-promise'
3+
import split from 'split2'
34
import prettyMs from 'pretty-ms'
45
import streamDataset from '../../actions/dataset/streamDataset'
6+
import skipSystemDocuments from '../../util/skipSystemDocuments'
57

68
export default {
79
name: 'export',
@@ -44,6 +46,8 @@ export default {
4446
const startTime = Date.now()
4547

4648
streamDataset(client, dataset)
49+
.pipe(split())
50+
.pipe(skipSystemDocuments)
4751
.pipe(outputPath ? fsp.createWriteStream(outputPath) : process.stdout)
4852
.on('error', err => output.error(err))
4953
.on('close', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const through2 = require('through2')
2+
3+
const parseJson = json => {
4+
try {
5+
return JSON.parse(json)
6+
} catch (err) {
7+
return null
8+
}
9+
}
10+
11+
const isSystemDocument = doc => doc && doc._id && doc._id.indexOf('_.') === 0
12+
13+
module.exports = through2((line, enc, callback) => {
14+
const doc = parseJson(line)
15+
16+
if (isSystemDocument(doc)) {
17+
return callback()
18+
}
19+
20+
return callback(null, `${line}\n`)
21+
})

0 commit comments

Comments
 (0)