From cd92fb170e2b638dfb0d3dae4a97fdce6ce8fbef Mon Sep 17 00:00:00 2001 From: guybedford Date: Fri, 14 Nov 2014 17:03:23 +0200 Subject: [PATCH] allow jspm init to work outside of package.json folder itself (#244) --- lib/config/package.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/config/package.js b/lib/config/package.js index efd5c920c..4ea14a04d 100644 --- a/lib/config/package.js +++ b/lib/config/package.js @@ -57,7 +57,7 @@ PackageJSON.prototype.read = function() { return readJSON(this.fileName) .then(function(pjson) { - return checkCreatePackageJSON(pjson); + return checkCreatePackageJSON(pjson, self.fileName); }) .then(function(pjson) { self.originalPjson = pjson; @@ -193,7 +193,9 @@ PackageJSON.prototype.write = function() { } // can take an existing non-jspm package.json -function checkCreatePackageJSON(initialPjson) { +function checkCreatePackageJSON(initialPjson, pjsonPath) { + var baseDir = path.dirname(pjsonPath); + initialPjson = initialPjson || {}; // already jspm-optimized @@ -217,26 +219,31 @@ function checkCreatePackageJSON(initialPjson) { return ui.input('Enter baseURL path', '.'); }) .then(function(baseURL) { - base = baseURL + path.sep; + base = path.relative(process.cwd(), path.resolve(baseURL)); + baseURL = path.relative(baseDir, path.resolve(baseURL)); + if (!base) + base = '.'; + base += path.sep; pjson.directories = pjson.directories || {}; pjson.directories.baseURL = baseURL; return ui.input('Enter project source folder', base + 'lib'); }) .then(function(lib) { pjson.directories = pjson.directories || {}; - pjson.directories.lib = lib; + pjson.directories.lib = path.relative(baseDir, path.resolve(lib)); return ui.input('Enter project built folder (optional)'); }) .then(function(dist) { - pjson.directories.dist = dist; + if (dist) + pjson.directories.dist = path.relative(baseDir, path.resolve(dist)); return ui.input('Enter packages folder', base + 'jspm_packages'); }) .then(function(packages) { - pjson.directories.packages = packages; + pjson.directories.packages = path.relative(baseDir, path.resolve(packages)); return ui.input('Enter config file path', base + 'config.js'); }) .then(function(configFile) { - pjson.configFile = configFile; + pjson.configFile = path.relative(baseDir, path.resolve(configFile)) return initialPjson; }); }