Skip to content

Commit

Permalink
make the export functionality more easily runnable as a single command (
Browse files Browse the repository at this point in the history
fixes #4)
  • Loading branch information
jmartin-sul committed Aug 2, 2019
1 parent cf83dcb commit 5d687c2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-transform-runtime",
]
}
3 changes: 3 additions & 0 deletions bin/export
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

npx babel-node src/cli/exportAndSave.js $@
31 changes: 31 additions & 0 deletions src/cli/exportAndSave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2019 Stanford University see LICENSE for license

import sinopiaExporter from '../../package'
import { downloadAllRdfForGroup } from '../getGroupRDF'


const helpText = `
> ./bin/export 'ucdavis'
and you should end up with something like:
$ tree sinopia_export/
sinopia_export/
└── ucdavis_2019-07-26T01:41:00.002Z
├── 0c9895ff-9470-4c70-bee4-b791ee179b34
└── complete.log
each RDF resource will have its own file. complete.log will be written at the end of a successful run.
`


console.debug(`arguments: ${process.argv}`)
console.info(`sinopia_exporter v${sinopiaExporter.version}`)


const groupName = process.argv[2]
if(groupName) {
downloadAllRdfForGroup(groupName)
} else {
console.error(helpText)
}
37 changes: 9 additions & 28 deletions src/getGroupRDF.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright 2019 Stanford University see LICENSE for license

const fs = require('fs');
const path = require('path');
const SinopiaServer = require('sinopia_server')
import fs from 'fs'
import path from 'path'
import config from 'config'
import SinopiaServer from 'sinopia_server'


instance = new SinopiaServer.LDPApi()
instance.apiClient.basePath = 'https://trellis.sinopia.io'
const instance = new SinopiaServer.LDPApi()
instance.apiClient.basePath = config.get('trellis.basePath')
console.info(`Sinopia Server base URL: ${instance.apiClient.basePath}`)


const resourceToName = (uri) => {
Expand Down Expand Up @@ -54,10 +56,10 @@ const saveResourceTextFromServer = async(savePathString, groupName, resourceName
fs.writeFileSync(`${savePathString}/${resourceName}`, (await getResourceTextFromServer(groupName, resourceName)))
}

const downloadAllRdfForGroup = async (groupName) => {
export const downloadAllRdfForGroup = async (groupName) => {
const entityNames = await listGroupRdfEntityNames(groupName)

savePathString = getSavePathString(groupName)
const savePathString = getSavePathString(groupName)
fs.mkdirSync(savePathString)

await Promise.all(entityNames.map((entityName) => saveResourceTextFromServer(savePathString, groupName, entityName)))
Expand All @@ -66,24 +68,3 @@ const downloadAllRdfForGroup = async (groupName) => {
fs.writeFileSync(`${savePathString}/complete.log`, completionMsg)
console.log(completionMsg)
}

/*
TODO: make this something that's usable in a single invocation from the command line.
for now, open a node console, paste the above code in, and then do something like the following:
> downloadPromise = downloadAllRdfForGroup('ucdavis')
and you should end up with something like:
$ tree sinopia_export/
sinopia_export/
└── ucdavis_2019-07-26T01:41:00.002Z
├── 0c9895ff-9470-4c70-bee4-b791ee179b34
└── complete.log
each RDF resource will have its own file. complete.log will be written at the end of a successful run.
also TODO: any error handling at all!
*/


0 comments on commit 5d687c2

Please sign in to comment.