-
-
Save msporny/1fdcb0b98050b849614e1c9fd6a341de to your computer and use it in GitHub Desktop.
DID Spec Registries Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {decode} = require('html-entities'); | |
const fs = require('fs'); | |
const mkdirp = require('mkdirp'); | |
const path = require('path'); | |
const util = require('util'); | |
const exec = util.promisify(require('child_process').exec); | |
// set directories and paths | |
const registryFile = path.join('index.html'); | |
const methodsDir = path.join('methods'); | |
// create directories | |
mkdirp.sync(methodsDir); | |
// analyze DID Methods in index.html and write out individual files | |
(async () => { | |
// search every DID Method | |
const registryHtml = fs.readFileSync(registryFile, 'utf-8'); | |
const didMethodRegex = /<tr>\n.*<td>\n\s+did:(.*):\n.*<\/td>\n.*<td>\s+(.*)\n.*<\/td>\n.*<td>\s+(.*)\n.*<\/td>\n.*<td>\n\s+(.*)\n.*<\/td>\n.*<td>\n\s+(.*)\n.*/g; | |
const didSpecRegex = /<a href="(.*)">.*<\/a>/; | |
const allDidMethods = | |
[...registryHtml.matchAll(didMethodRegex)]; | |
for(const method of allDidMethods) { | |
const name = method[1]; | |
let status = method[2]; | |
const registry = method[3]; | |
const contact = method[4]; | |
const {rubricEvaluation, website, implementation, testSuite} = ''; | |
let specification = method[5].match(didSpecRegex); | |
if(specification === null) { | |
specification = ''; | |
} else { | |
specification = specification[1]; | |
} | |
if(status === 'PROVISIONAL') { | |
status = ''; | |
} | |
const entry = { | |
name, description: '', status, registry, contact, specification, | |
rubricEvaluation: '', website: '', implementation: '', testSuite: '' | |
}; | |
// write entry to disk | |
const methodFile = path.join(methodsDir, name + '.json'); | |
fs.writeFileSync(methodFile, JSON.stringify(entry, null, 2)); | |
// add and commit entry | |
const {stdout1, stderr1} = await exec('git add ' + methodFile); | |
if(stderr1) { throw new Error(stderr); } | |
const {stdout2, stderr2} = await exec(`git commit -m "Convert did:${name} to JSON entry." ${methodFile}`); | |
if(stderr2) { throw new Error(stderr); } | |
console.log(entry); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "did-spec-registries-converter", | |
"version": "0.0.1", | |
"description": "DID Spec Registries conversion command line app", | |
"main": "index.js", | |
"dependencies": { | |
"html-entities": "^2.3.2", | |
"mkdirp": "^0.5.5" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Manu Sporny <msporny@digitalbazaar.com> (https://manu.sporny.org/)", | |
"license": "W3C" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment