Skip to content

Commit

Permalink
updated to biiif v1.0.0, deprecated generateThumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Apr 29, 2021
1 parent 8f442ca commit bee279f
Show file tree
Hide file tree
Showing 4 changed files with 488 additions and 768 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ Uses [biiif](https://github.com/edsilv/biiif)

The url location of your published collection. All of the IIIF `id` properties are generated using this as the base url.

<!--
### `-g`
Generate thumbnails for images.
-->

### `-v`

Use this virtual name for the root directory instead of its actual one when generating urls.

<!--
### `-s`
Scaffolds the following files (if they don't already exist):
Expand All @@ -33,4 +35,5 @@ Scaffolds the following files (if they don't already exist):
- `index.html` - includes a file explorer to navigate and share the contents of your IIIF collection
- `README.md` - includes a link to index.html
It also creates the folder specified in the `folder` argument.
It also creates the folder specified in the `folder` argument.
-->
64 changes: 1 addition & 63 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,16 @@
#!/usr/bin/env node
const { build } = require('biiif');
const { exec } = require('child_process');
const { join } = require('path');
const fs = require('fs');
const ncp = require('ncp').ncp;
const program = require('commander');
const withErrors = require('./withErrors');

program.arguments('<dir>')
.option('-u, --url <url>', 'The url to use as the base of all ids')
.option('-g, --generate-thumbs', 'Generate thumbnails')
.option('-v, --virtual-name <virtual-name>', 'Use this virtual name for the root directory instead of its actual one when generating urls')
.option('-s, --scaffold-files', 'Scaffold files for github pages, netlify')
.action(withErrors(execCli))
.parse(process.argv);

async function execCli(env, options) {

const dir = program.args[0];

if (program.scaffoldFiles) {
console.log('scaffolding files');

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

ncp.limit = 16;

const scaffoldTarget = './';
const scaffoldFilesPath = join(__dirname, 'scaffold');

ncp(scaffoldFilesPath, scaffoldTarget, {
clobber: false
},
function (err) {
if (err) {
return console.error(err);
}

let url = program.url;

if (url.endsWith('/')) {
url = url.substr(0, url.lastIndexOf('/'));
}

const explorerurl = url.substr(0, url.lastIndexOf('/'));
const manifesturl = url + '/index.json';

// replace [url]
replaceInFile(join(scaffoldTarget, 'README.md'), /\[url\]/g, explorerurl);
replaceInFile(join(scaffoldTarget, 'index.html'), /\[url\]/g, manifesturl);

console.log('finished scaffolding');
});
}

await build(dir, program.url, program.generateThumbs, program.virtualName);

await build(dir, program.url, program.virtualName);
console.log('biiif-cli exit');
}

function replaceInFile(file, replacetarget, replacewith) {
fs.readFile(file, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}

const result = data.replace(replacetarget, replacewith);

fs.writeFile(file, result, 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
});
}
Loading

0 comments on commit bee279f

Please sign in to comment.