44//
55// See http://www.w3.org/TR/rdfa-syntax/ etc
66//
7-
87const $rdf = require ( '../../lib' )
9- var fs = require ( 'fs' )
8+ const fs = require ( 'fs' )
9+ const nock = require ( 'nock' )
1010
11- var kb = $rdf . graph ( )
12- var fetcher = $rdf . fetcher ( kb )
11+ const kb = $rdf . graph ( )
12+ const fetcher = $rdf . fetcher ( kb )
1313
1414var contentType = 'text/turtle'
15- var base = 'file://' + process . cwd ( ) + '/'
16- var uri
17- var targetDocument = $rdf . sym ( base + 'stdin' ) // defaul URI of test data
15+ var base = 'http://localhost/'
16+ var server
17+ var fileName
18+ var targetDocument // = $rdf.sym(base + 'stdin') // defaul URI of test data
19+
20+ var inDocument
21+ var outDocument
1822
1923var check = function ( ok , message , status ) {
2024 if ( ! ok ) {
@@ -50,7 +54,6 @@ var stackString = function (e) {
5054 return str
5155}
5256
53-
5457var exitMessage = function ( message ) {
5558 console . log ( message )
5659 process . exit ( 4 )
@@ -78,19 +81,24 @@ var doNext = function (remaining) {
7881 break
7982
8083 case '-in' :
81- targetDocument = $rdf . sym ( $rdf . uri . join ( right , base ) )
82- // console.log("Document is " + targetDocument)
83- fetcher . nowOrWhenFetched ( targetDocument , { } , function ( ok , body , xhr ) {
84+ let targetUri = $rdf . uri . join ( right , base )
85+ inDocument = $rdf . sym ( targetUri )
86+ let docContents = fs . readFileSync ( right , 'utf8' )
87+
88+ server = nock ( 'http://localhost' ) . get ( '/' + right ) . reply ( 200 , docContents )
89+
90+ fetcher . nowOrWhenFetched ( inDocument , { } , function ( ok , body , xhr ) {
8491 check ( ok , body , xhr ? xhr . status : undefined )
85- console . log ( 'Loaded ' + targetDocument )
92+ // console.log(kb.statementsMatching().map(ea => ea.toString() + ' why:' + ea.why) )
8693 doNext ( remaining )
8794 } ) ; // target, kb, base, contentType, callback
8895 return // STOP processing at this level
8996
9097 case '-out' :
9198 try {
9299 var options = { flags : 'z' } // Only applies to RDF/XML
93- var out = $rdf . serialize ( targetDocument , kb , targetDocument . uri , contentType , undefined , options )
100+
101+ var out = $rdf . serialize ( inDocument , kb , inDocument . uri , contentType , undefined , options )
94102 } catch ( e ) {
95103 exitMessage ( 'Error in serializer: ' + e + stackString ( e ) )
96104 }
@@ -99,11 +107,12 @@ var doNext = function (remaining) {
99107 doNext ( remaining )
100108 return
101109 }
102- doc = $rdf . sym ( $rdf . uri . join ( right , base ) )
103- if ( doc . uri . slice ( 0 , 7 ) !== 'file://' ) {
104- exitMessage ( 'Can only write files just now, sorry: ' + doc . uri )
105- }
106- var fileName = doc . uri . slice ( 7 ) //
110+ // doc = $rdf.sym($rdf.uri.join(right, base))
111+ // if (doc.uri.slice(0, 7) !== 'file://') {
112+ // exitMessage('Can only write files just now, sorry: ' + doc.uri)
113+ // }
114+ fileName = right
115+
107116 fs . writeFile ( fileName , out , function ( err ) {
108117 if ( err ) {
109118 exitMessage ( 'Error writing file <' + right + '> :' + err )
@@ -120,10 +129,11 @@ var doNext = function (remaining) {
120129 } catch ( e ) {
121130 exitMessage ( 'Error in serializer: ' + e + stackString ( e ) )
122131 }
123- if ( doc . uri . slice ( 0 , 7 ) !== 'file://' ) {
124- exitMessage ( 'Can only write files just now, sorry: ' + doc . uri )
125- }
126- var fileName = doc . uri . slice ( 7 ) //
132+ // if (doc.uri.slice(0, 7) !== 'file://') {
133+ // exitMessage('Can only write files just now, sorry: ' + doc.uri)
134+ // }
135+ // fileName = doc.uri.slice(7) //
136+ fileName = doc . uri . split ( '/' ) [ doc . uri . length - 1 ]
127137 fs . writeFile ( fileName , out , function ( err ) {
128138 if ( err ) {
129139 exitMessage ( 'Error writing file <' + right + '> :' + err )
0 commit comments