feat(core): option to specify the database path

Fixes #216
pull/224/head
Romain 3 years ago
parent b9ffb2d630
commit 0f42dc8f85

@ -325,6 +325,12 @@ const OPTIONS = {
normalize: true
},
'database-file': {
group: 'Misc options:',
description: 'Path to the database file',
normalize: true
},
'log': {
group: 'Misc options:',
description: 'Print a detailed text log',
@ -411,9 +417,15 @@ exports.get = (args) => {
// This means we can process the camelCase version only after that
const opts = _.omitBy(parsedOptions, (value, key) => key.indexOf('-') >= 0)
// Make input/output folder absolute paths
// Default database file
if (!opts.databaseFile) {
opts.databaseFile = path.join(opts.output, 'thumbsup.db')
}
// Better to work with absolute paths
opts.input = path.resolve(opts.input)
opts.output = path.resolve(opts.output)
opts.databaseFile = path.resolve(opts.databaseFile)
// By default, use relative links to the input folder
if (opts.downloadLinkPrefix) opts.linkPrefix = opts.downloadLinkPrefix

@ -1,7 +1,6 @@
#!/usr/bin/env node
const fs = require('fs-extra')
const path = require('path')
const moment = require('moment')
const Analytics = require('./analytics')
const dependencies = require('./dependencies')
@ -20,8 +19,7 @@ require('./log').init(opts.log, opts.output)
const index = require('../src/index')
// If this is the first run, display a welcome message
const indexPath = path.join(opts.output, 'thumbsup.db')
const firstRun = fs.existsSync(indexPath) === false
const firstRun = fs.existsSync(opts.databaseFile) === false
if (firstRun) {
console.log(`${messages.GREETING()}\n`)
}

@ -12,13 +12,12 @@ const AlbumMapper = require('../input/album-mapper')
const Metadata = require('../model/metadata')
const File = require('../model/file')
const Observable = require('zen-observable')
const path = require('path')
const Picasa = require('../input/picasa')
exports.run = function (opts, callback) {
return new Observable(observer => {
const picasaReader = new Picasa()
const index = new Index(path.join(opts.output, 'thumbsup.db'))
const index = new Index(opts.databaseFile)
const emitter = index.update(opts.input, opts)
const files = []

@ -1,4 +1,5 @@
const path = require('path')
const process = require('process')
const should = require('should/as-function')
const options = require('../../bin/options.js')
@ -89,6 +90,24 @@ describe('options', function () {
should(opts.gmArgs).eql(['-equalize', '-modulate 120'])
})
})
describe('misc', () => {
describe('database file path', () => {
it('defaults to the output folder', () => {
const opts = options.get(BASE_ARGS)
should(opts.databaseFile).eql(path.resolve('website/thumbsup.db'))
})
it('can be overridden with a relative url', () => {
const args = BASE_ARGS.concat(['--database-file', 'album.db'])
const opts = options.get(args)
should(opts.databaseFile).eql(path.join(process.cwd(), 'album.db'))
})
it('can be overridden with an absolute url', () => {
const args = BASE_ARGS.concat(['--database-file', '/media/album.db'])
const opts = options.get(args)
should(opts.databaseFile).eql('/media/album.db')
})
})
})
describe('deprecated', () => {
it('--original-photos false', () => {
const args = BASE_ARGS.concat(['--original-photos false'])

Loading…
Cancel
Save