Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// possibly a user defined theme, check if the directory exists
try {
if ((this.theme = require(path.resolve(userThemesPath, this.config.theme)))) {
log.info(`Loaded theme [${this.config.theme}]`)
return
}
} catch (err) {
// noop
}
// possibly a theme installed with npm, test the project root
try {
this.theme = require(path.resolve('node_modules', this.config.theme)) // require.resolve?
} catch (err) {
log.warn(`There was an error during require [${this.config.theme}]`)
log.warn('Using default theme [b-ber-theme-serif]')
log.warn(err.message)
// error loading theme, set to default
this.theme = themes['b-ber-theme-serif']
}
}
log.info(`Loaded theme [${this.config.theme}]`)
return
}
} catch (_) {
// noop
}
// possibly a theme installed with npm, test the project root
try {
set(
this,
'theme',
require(path.resolve('node_modules', this.config.theme)) // eslint-disable-line global-require, import/no-dynamic-require
) // require.resolve?
} catch (err) {
log.warn(`There was an error during require [${this.config.theme}]`)
log.warn('Using default theme [b-ber-theme-serif]')
log.warn(err.message)
// error loading theme, set to default
set(this, 'theme', themes['b-ber-theme-serif'])
}
}
}
} catch (_) {
// noop
}
// possibly a theme installed with npm, test the project root
try {
set(
this,
'theme',
require(path.resolve('node_modules', this.config.theme)) // eslint-disable-line global-require, import/no-dynamic-require
) // require.resolve?
} catch (err) {
log.warn(`There was an error during require [${this.config.theme}]`)
log.warn('Using default theme [b-ber-theme-serif]')
log.warn(err.message)
// error loading theme, set to default
set(this, 'theme', themes['b-ber-theme-serif'])
}
}
return
}
} catch (_) {
// noop
}
// possibly a theme installed with npm, test the project root
try {
set(
this,
'theme',
require(path.resolve('node_modules', this.config.theme)) // eslint-disable-line global-require, import/no-dynamic-require
) // require.resolve?
} catch (err) {
log.warn(`There was an error during require [${this.config.theme}]`)
log.warn('Using default theme [b-ber-theme-serif]')
log.warn(err.message)
// error loading theme, set to default
set(this, 'theme', themes['b-ber-theme-serif'])
}
}
ensureReaderModuleExists() {
try {
this.readerAppPath = path.join(
path.dirname(path.join(require.resolve(this.readerModuleName))),
this.readerModuleDistDir
)
return
} catch (err) {
// module not found using require.resolve, so we check if there's a symlinked version available
log.warn(
`Could not find globally installed module ${this.readerModuleName}`
)
}
const { paths } = module
let modulePath
for (let i = 0; i < paths.length; i++) {
const _path = path.resolve(paths[i], this.readerModuleName)
if (fs.existsSync(_path)) {
modulePath = _path
break
}
}
if (!modulePath) {
log.error(
try {
if ((this.theme = require(path.resolve(userThemesPath, this.config.theme)))) {
log.info(`Loaded theme [${this.config.theme}]`)
return
}
} catch (err) {
// noop
}
// possibly a theme installed with npm, test the project root
try {
this.theme = require(path.resolve('node_modules', this.config.theme)) // require.resolve?
} catch (err) {
log.warn(`There was an error during require [${this.config.theme}]`)
log.warn('Using default theme [b-ber-theme-serif]')
log.warn(err.message)
// error loading theme, set to default
this.theme = themes['b-ber-theme-serif']
}
}
const uglify = contents => {
const result = uglifyJS.minify(contents, uglifyOptions)
if (result.error) throw result.error
if (result.warnings) log.warn(result.warnings)
return result.code
}
const getUserThemes = () => {
const dir = path.resolve(state.config.themes_directory)
if (!fs.existsSync(dir)) {
log.warn(`Themes directory [${path.basename(dir)}] does not exist`)
return []
}
return fs
.readdirSync(dir)
.reduce((acc, curr) => (fs.lstatSync(path.resolve(dir, curr)).isDirectory() ? acc.concat(curr) : acc), [])
}
missing.forEach(name =>
log.warn(
'opf [%s] was not declared in the TOC. Adding [%s] to [%s]',
name,
name,
path.basename(tocFile)
)
)
const uglify = contents => {
const result = uglifyJS.minify(contents, uglifyOptions)
if (result.error) throw result.error
if (result.warnings) log.warn(result.warnings)
return result.code
}