File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import path from "path"
2+ import { fileURLToPath } from "url"
3+ import { promises } from "fs"
4+
5+ const ROOT = path . join ( path . dirname ( fileURLToPath ( import . meta. url ) ) )
6+ const shaclDirs = [
7+ `${ ROOT } /shacl` ,
8+ `${ ROOT } /shacl/beta` ,
9+ `${ ROOT } /shacl/bielefeld`
10+ ]
11+ let shaclFiles = [ ]
12+ for ( let shaclDir of shaclDirs ) {
13+ shaclFiles = shaclFiles . concat ( ( await promises . readdir ( shaclDir ) ) . map ( file => `${ shaclDir } /${ file } ` ) . filter ( file => file . endsWith ( ".ttl" ) ) )
14+ }
15+
16+ for ( let file of shaclFiles ) {
17+ // let filename = path.basename(file)
18+ let content = await promises . readFile ( file , "utf8" )
19+ const cls = "sh:PropertyShape"
20+ const regex = new RegExp ( `^([^\\s#;]+)\\s+a\\s+${ cls } \\b` , "gm" )
21+ const matches = [ ... content . matchAll ( regex ) ] . map ( m => m [ 1 ] . trim ( ) )
22+ for ( let match of matches ) {
23+ const hash = Math . random ( ) . toString ( 36 ) . slice ( 2 , 5 )
24+ content = content . split ( match ) . join ( `${ match } _${ hash } ` )
25+ }
26+ await promises . writeFile ( file , content , "utf8" )
27+ }
You can’t perform that action at this time.
0 commit comments