-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to biiif v1.0.0, deprecated generateThumbs
- Loading branch information
Showing
4 changed files
with
488 additions
and
768 deletions.
There are no files selected for viewing
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
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
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); | ||
} | ||
}); | ||
}); | ||
} |
Oops, something went wrong.