Skip to content

Commit

Permalink
allow jspm init to work outside of package.json folder itself (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Nov 14, 2014
1 parent 041abf0 commit cd92fb1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lib/config/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
});
}
Expand Down

0 comments on commit cd92fb1

Please sign in to comment.