-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportAuthors.mjs
More file actions
33 lines (25 loc) · 913 Bytes
/
exportAuthors.mjs
File metadata and controls
33 lines (25 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import '@babel/polyfill'
import dotenv from 'dotenv'
import sanityClient from '@sanity/client'
import { writeToPath } from '@fast-csv/format';
import path from 'path'
dotenv.config()
const client = sanityClient({
apiVersion: process.env.SANITY_API_VERSION,
dataset: process.env.SANITY_DATASET,
projectId: process.env.SANITY_PROJECT_ID,
token: process.env.SANITY_ACCESS_TOKEN,
useCdn: false // We can't use the CDN for writing
})
const authorQuery = '*[_type == "author"] { name } | order(name asc)'
const downloadAuthors = async () => {
const authors = await client.fetch(authorQuery)
return authors.map(author => [author.name])
}
const main = async () => {
const allAuthors = await downloadAuthors()
writeToPath(path.resolve('authors.csv'), allAuthors)
.on('error', err => console.error(err))
.on('finish', () => console.log('Done writing.'));
}
main()