fix(themes): resolve built-in theme paths instead of hardcoding node_modules path

The previous method only worked locally inside the repo, but not once the package is published to npm.
Once published, built-in themes are flattened instead of nested.
pull/121/head
Romain 6 years ago
parent ba72015124
commit 37ea6c6ba3

15
package-lock.json generated

@ -4155,6 +4155,21 @@
"integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=",
"dev": true
},
"resolve-pkg": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/resolve-pkg/-/resolve-pkg-1.0.0.tgz",
"integrity": "sha1-4ZoV54rKLhJEYdySsuOUPvk0lNk=",
"requires": {
"resolve-from": "2.0.0"
},
"dependencies": {
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
}
}
},
"resolve-url": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",

@ -54,6 +54,7 @@
"micromatch": "^3.1.10",
"moment": "^2.22.1",
"readdir-enhanced": "^2.2.1",
"resolve-pkg": "^1.0.0",
"through2": "^2.0.3",
"thumbsup-downsize": "^2.1.0",
"url-join": "^4.0.0",

@ -1,9 +1,8 @@
const path = require('path')
const async = require('async')
const resolvePkg = require('resolve-pkg')
const Theme = require('./theme')
const THUMBSUP_PACKAGES = path.join(__dirname, '..', '..', 'node_modules', '@thumbsup')
exports.build = function (rootAlbum, opts, callback) {
// create the base layer assets
// such as shared JS libs, common handlebars helpers, CSS reset...
@ -13,7 +12,7 @@ exports.build = function (rootAlbum, opts, callback) {
})
// then create the actual theme assets
const themeDir = opts.themePath || path.join(THUMBSUP_PACKAGES, `theme-${opts.theme}`)
const themeDir = opts.themePath || localThemePath(opts.theme)
const theme = new Theme(themeDir, opts.output, {
stylesheetName: 'theme.css',
customStylesPath: opts.themeStyle
@ -58,3 +57,11 @@ function createRenderingTasks (theme, album, gallery, breadcrumbs) {
})
return tasks
}
function localThemePath (themeName) {
const local = resolvePkg(`@thumbsup/theme-${themeName}`, {cwd: __dirname})
if (!local) {
throw new Error(`Could not find a built-in theme called ${themeName}`)
}
return local
}

Loading…
Cancel
Save