From 688767d415afe4873b9dc97a588d5b779de54e98 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Thu, 1 Feb 2018 07:20:12 -0500 Subject: [PATCH] feat: improve ad hoc theme loading --- dist/verbs/build.js | 25 ++++++++++++++----------- src/verbs/build.coffee | 33 +++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/dist/verbs/build.js b/dist/verbs/build.js index ebebcea..ad70c41 100644 --- a/dist/verbs/build.js +++ b/dist/verbs/build.js @@ -423,19 +423,22 @@ Implementation of the 'build' verb for HackMyResume. */ _verifyTheme = function(themeNameOrPath) { - var exists, tFolder; - tFolder = PATH.join(parsePath(require.resolve('fresh-themes')).dirname, '/themes/', themeNameOrPath); - exists = require('path-exists').sync; - if (!exists(tFolder)) { + var exists, tFolder, themesObj; + themesObj = require('fresh-themes'); + if (_.has(themesObj.themes, themeNameOrPath)) { + tFolder = PATH.join(parsePath(require.resolve('fresh-themes')).dirname, '/themes/', themeNameOrPath); + } else { tFolder = PATH.resolve(themeNameOrPath); - if (!exists(tFolder)) { - return { - fluenterror: HMSTATUS.themeNotFound, - data: _opts.theme - }; - } } - return tFolder; + exists = require('path-exists').sync; + if (exists(tFolder)) { + return tFolder; + } else { + return { + fluenterror: HMSTATUS.themeNotFound, + data: _opts.theme + }; + } }; diff --git a/src/verbs/build.coffee b/src/verbs/build.coffee index 6787e92..e3af122 100644 --- a/src/verbs/build.coffee +++ b/src/verbs/build.coffee @@ -334,17 +334,30 @@ _expand = ( dst, theTheme ) -> Verify the specified theme name/path. ### _verifyTheme = ( themeNameOrPath ) -> - tFolder = PATH.join( - parsePath( require.resolve('fresh-themes') ).dirname, - '/themes/', - themeNameOrPath - ) - exists = require('path-exists').sync - if !exists( tFolder ) + + # First, see if this is one of the predefined FRESH themes. There are only a + # handful of these, but they may change over time, so we need to query + # the official source of truth: the fresh-themes repository, which mounts the + # themes conveniently by name to the module object, and which is embedded + # locally inside the HackMyResume installation. + themesObj = require 'fresh-themes' + if _.has themesObj.themes, themeNameOrPath + tFolder = PATH.join( + parsePath( require.resolve('fresh-themes') ).dirname, + '/themes/', + themeNameOrPath + ) + else + # Otherwsie it's a path to an arbitrary FRESH or JRS theme sitting somewhere + # on the user's system (or, in the future, at a URI). tFolder = PATH.resolve themeNameOrPath - if !exists tFolder - return fluenterror: HMSTATUS.themeNotFound, data: _opts.theme - tFolder + + # In either case, make sure the theme folder exists + exists = require('path-exists').sync + if exists tFolder + tFolder + else + fluenterror: HMSTATUS.themeNotFound, data: _opts.theme