From 521db8b462da3bbc12c8bc09b700d8b27479a06e Mon Sep 17 00:00:00 2001 From: Joel Kuzmarski Date: Sun, 9 Apr 2017 17:26:25 -0500 Subject: [PATCH 1/3] Add support for file: syntax --- build/static_dist.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/build/static_dist.js b/build/static_dist.js index ae7c765..6d9f5ff 100644 --- a/build/static_dist.js +++ b/build/static_dist.js @@ -112,12 +112,28 @@ function addPackages(siteConfig, buildFolder) { return readFile(path.join(fullBuildFolderPath, "package.json")).then(function(packageContents){ var json = JSON.parse(packageContents); + var filePathedDeps = siteConfig.html.dependencies; + + for(var depName in siteConfig.html.dependencies) { + var possibleFilePath = siteConfig.dependencies[depName]; + + if (_.startsWith(possibleFilePath,'file:')) { + try { + var absDir = path.resolve(possibleFilePath.substr(5)); + if(fs.statSync(absDir).isDirectory()) { + filePathedDeps[depName] = absDir; + } + } catch(err) { + // skip bad path + } + } + } - json.dependencies = _.assign(json.dependencies || {},siteConfig.html.dependencies); + json.dependencies = _.assign(json.dependencies || {},filePathedDeps); return writeFile( path.join(fullBuildFolderPath, "package.json"), JSON.stringify(json) ).then(function(){ - var deps = _.map(siteConfig.html.dependencies, function(version, packageName){ + var deps = _.map(filePathedDeps, function(version, packageName){ return '"'+packageName+'": callIfFunction( require("'+packageName+'") )'; }); From adde3485dd49e7cbfc4b9db2129c35eebede18ab Mon Sep 17 00:00:00 2001 From: Joel Kuzmarski Date: Mon, 10 Apr 2017 04:26:48 -0500 Subject: [PATCH 2/3] Remove unnecessary path resolve Not needed now that bit-docs makes all file: paths absolute: https://github.com/bit-docs/bit-docs/pull/26 --- build/static_dist.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/build/static_dist.js b/build/static_dist.js index 6d9f5ff..3b7a28d 100644 --- a/build/static_dist.js +++ b/build/static_dist.js @@ -118,14 +118,7 @@ function addPackages(siteConfig, buildFolder) { var possibleFilePath = siteConfig.dependencies[depName]; if (_.startsWith(possibleFilePath,'file:')) { - try { - var absDir = path.resolve(possibleFilePath.substr(5)); - if(fs.statSync(absDir).isDirectory()) { - filePathedDeps[depName] = absDir; - } - } catch(err) { - // skip bad path - } + filePathedDeps[depName] = possibleFilePath; } } From 8be8b34412181b9f2ce1ea0a232c81cf07c48a93 Mon Sep 17 00:00:00 2001 From: Joel Kuzmarski Date: Wed, 12 Apr 2017 17:22:13 -0500 Subject: [PATCH 3/3] Use JavaScript startsWith instead of lodash --- build/static_dist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/static_dist.js b/build/static_dist.js index 3b7a28d..7f0a27b 100644 --- a/build/static_dist.js +++ b/build/static_dist.js @@ -117,7 +117,7 @@ function addPackages(siteConfig, buildFolder) { for(var depName in siteConfig.html.dependencies) { var possibleFilePath = siteConfig.dependencies[depName]; - if (_.startsWith(possibleFilePath,'file:')) { + if (possibleFilePath.startsWith('file:')) { filePathedDeps[depName] = possibleFilePath; } }