1- import path from "path"
2- import { fileURLToPath } from "url"
3- import { promises , writeFileSync } from "fs"
41import { newStore , addTurtleToStore , storeToTurtle , sparqlInsertDelete } from "@foerderfunke/sem-ops-utils"
2+ import { promises , writeFileSync , createWriteStream } from "fs"
3+ import { fileURLToPath } from "url"
4+ import { ZipFile } from "yazl"
5+ import path from "path"
56
67const ROOT = path . join ( path . dirname ( fileURLToPath ( import . meta. url ) ) )
78await promises . mkdir ( `${ ROOT } /build` , { recursive : true } )
89
10+ const dfDir = path . join ( ROOT , "datafields" )
11+ const shaclDir = path . join ( ROOT , "shacl" )
12+
913// ----------- def.built.ttl -----------
1014
1115let header = [ "# This file is a generated enriched merge of the following source files:" ]
12- const dfDir = path . join ( ROOT , "datafields" )
1316
1417const defTurtleFiles = [
1518 `${ ROOT } /definitions.ttl` ,
@@ -51,9 +54,9 @@ console.log(`Wrote to ${target}`)
5154
5255header = [ "# This file is a generated merge of the following source files:" ]
5356const shaclDirs = [
54- `${ ROOT } /shacl ` ,
55- `${ ROOT } /shacl /beta` ,
56- `${ ROOT } /shacl /bielefeld`
57+ `${ shaclDir } ` ,
58+ `${ shaclDir } /beta` ,
59+ `${ shaclDir } /bielefeld`
5760]
5861let shaclFiles = [ ]
5962for ( let shaclDir of shaclDirs ) {
@@ -70,3 +73,46 @@ turtle = header.join("\n") + "\n\n" + await storeToTurtle(rpsStore)
7073target = `${ ROOT } /build/rps.built.ttl`
7174writeFileSync ( target , turtle , "utf8" )
7275console . log ( `Wrote to ${ target } ` )
76+
77+ // ----------- foerderfunke-knowledge-base.zip -----------
78+
79+ const zipOutput = `${ ROOT } /build/foerderfunke-knowledge-base.zip`
80+
81+ const defFiles = [
82+ `${ ROOT } /definitions.ttl` ,
83+ `${ ROOT } /materialization.ttl` ,
84+ `${ ROOT } /consistency.ttl`
85+ ]
86+
87+ async function addDirToZip ( zip , dir , zipBasePath = "" ) {
88+ const entries = await promises . readdir ( dir , { withFileTypes : true } )
89+ for ( const entry of entries ) {
90+ const fullPath = path . join ( dir , entry . name )
91+ const zipPath = path . join ( zipBasePath , entry . name )
92+ if ( entry . isDirectory ( ) ) {
93+ await addDirToZip ( zip , fullPath , zipPath )
94+ } else if ( entry . isFile ( ) ) {
95+ zip . addFile ( fullPath , zipPath )
96+ }
97+ }
98+ }
99+
100+ const zip = new ZipFile ( )
101+
102+ const infoTxt = `This ZIP file contains all the semantic definitions from the FörderFunke knowledge-base.\nCreated: ${ new Date ( ) . toISOString ( ) } `
103+ zip . addBuffer ( Buffer . from ( infoTxt , "utf8" ) , "info.txt" )
104+
105+ await addDirToZip ( zip , dfDir , "datafields" )
106+ await addDirToZip ( zip , shaclDir , "shacl" )
107+ for ( const file of defFiles ) zip . addFile ( file , path . basename ( file ) )
108+
109+ zip . end ( )
110+
111+ await new Promise ( ( resolve , reject ) => {
112+ zip . outputStream
113+ . pipe ( createWriteStream ( zipOutput ) )
114+ . on ( "close" , resolve )
115+ . on ( "error" , reject )
116+ } )
117+
118+ console . log ( `Wrote to ${ zipOutput } ` )
0 commit comments