Commit 9d1a75eb authored by PTSEFTON's avatar PTSEFTON
Browse files

Added -p for partOf

parent 35a8f617
......@@ -44,17 +44,14 @@ program
.action(function(directories) {
dirs = directories;
})
.option("-b, --bag [bag-dir]", "Create Bagit Bag(s) under [bag-dir])")
.option("-n, --no", "No Citation - only applies ith --bag")
.option(
"-z, --zip",
"Create a zipped version of the bag - only applies with --bag"
)
.option("-b, --bag [bag-dir]", "Create Bagit Bag(s) under [bag-dir])")
.option("-z --zip", "Zip the bagged ro-crate (only works with --bag")
.option("-p --partOf [partOf]", "This is part of another RO-Crate, supply the ro-crate-metadata.jsonld path.")
.option("-d, --depth [depth]", "Maximum depth to recurse into directories looking for or creating CATALOG_.xlsx file")
.option("-r, --recurse", "Recurse into directories looking for or creating CATALOG_.xslx files")
.option("-c, --cratescript [cratesript]", "URL of Crate-script directory")
.option("-m, --maxfiles [maxfiles]", `Maximum number of files to itemise per directory (default is ${defaults.max_files_in_dir})`)
.option(
"-u, --url [distro]",
"Distribution URL"
......@@ -109,16 +106,17 @@ else {
})
}
async function generateHTML(metadata_path) {
async function generateHTML(metadataPath) {
// Save an HTML file
console.log("Generating html from: " + metadata_path);
if (!path.isAbsolute(metadata_path)) {
metadata_path = path.join(process.cwd(), metadata_path);
console.log("Generating html from: " + metadataPath);
if (!path.isAbsolute(metadataPath)) {
metadataPath = path.join(process.cwd(), metadataPath);
}
var dir = path.dirname(metadata_path)
var dir = path.dirname(metadataPath)
shell.rm("-rf", path.join(dir, "ro-crate-metadata_files"));
var crate = new ROCrate(JSON.parse(fs.readFileSync(metadata_path)));
var root = crate.getRootDataset();
var crate = new ROCrate(JSON.parse(fs.readFileSync(metadataPath)));
await crate.index();
var root = await crate.getRootDataset();
if (program.url){
// Add dowload info
if (!root["distribution"]) {
......@@ -140,6 +138,29 @@ async function generateHTML(metadata_path) {
crate = new roCrate(crate.getJson());
}
if (program.partOf) {
var parentCrate = new ROCrate(JSON.parse(fs.readFileSync(program.partOf)));
await parentCrate.index();
parentRoot = await parentCrate.getRootDataset();
console.log("PARENT ROOT", parentRoot);
// Inherit metadata
if (!root.datePublished) {
console.log("Inherit")
root.datePublished = parentRoot.datePublished;
}
if (!root.name) {
root.name = "Part of: " + parentRoot.name;
}
if (!root.descripton) {
root.description = "This is a part of: " + parentRoot.name;
}
if (!root.isPartOf && parentRoot.identifier) {
console.log("So here we are")
root.isPartOf = parentRoot.identifier;
}
console.log("ROOT", root)
}
var index_maker = new Index();
index_maker.init(
......@@ -150,9 +171,8 @@ async function generateHTML(metadata_path) {
fs.writeFileSync(path.join(dir, htmlFileName),
await index_maker.make_index_html(program.url, program.cratescript));
if (program.bag) {
// Bag the HTML
// TODO - GET THIS WORKING
var bagger = new Bag();
var dest = path.join(program.bag, path.basename(dir));
......@@ -166,15 +186,14 @@ async function generateHTML(metadata_path) {
metadata_path = path.join(dir, metadata_file_name);
const index = await fs.copyFile(path.join(__dirname, "defaults", "index.html"), path.join(dest, "index.html"));
bagger.update();
}
if (program.zip && program.bag) {
shell.cd(bagger.targetDir);
var zipname = path.join("../", path.basename(bagger.targetDir) + ".zip");
shell.rm("-f", zipname);
shell.exec("zip -r " + zipname + " " + "*");
if (program.zip){
var zipname = path.join(program.bag, path.basename(path.dirname(metadataPath)).replace(" ","_") + ".zip");
console.log('name', zipname)
shell.cd(dir);
shell.rm("-f", `"${zipname}"`);
shell.exec("zip -r " + zipname + " " + "*");
}
}
......
......@@ -78,7 +78,7 @@ module.exports = function() {
this.nested_item_json = [];
if (this.name === "ID") {
this.name = "identifier";
this.is_id = true;
} else if (this.name === "TYPE:") {
this.is_type = true;
} else if (name == "MIME:") {
......@@ -95,7 +95,7 @@ module.exports = function() {
this.name = this.name.substring(5);
this.is_json = true;
}
//Assume what's left of header is a property, and hence starts with lowecase letter
//Assume what's left of header is a property, and hence starts with lowercase letter
this.name = lowercase_first(this.name);
var nest;
if (this.name.endsWith("*")) {
......@@ -124,9 +124,7 @@ module.exports = function() {
this.property_URI = get_RDF_for_column(this.name);
if (this.property_URI == "http://schema.org/identifier") {
this.is_id = true;
}
if (this.property_URI == "http://schema.org/name") {
this.is_name = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment