Comparing version 0.0.2 to 0.1.0
61
index.js
@@ -6,15 +6,53 @@ 'use strict'; | ||
readPkgUp = require('read-pkg-up'), | ||
path = require('path'); | ||
path = require('path'), | ||
fs = require('fs'), | ||
buildRoot = 'build'; | ||
function getBuildDir() { | ||
function getBuildData(known) { | ||
known = known || Object.create(null); | ||
return Promise.all([ | ||
readPkgUp(), | ||
branchName.assumeMaster() | ||
]).then(function (data) { | ||
known.branch || branchName.assumeMaster(), | ||
known.version || readPkgUp().then((data) => { | ||
return data.pkg.version; | ||
}) | ||
]).then(function (data) { | ||
return { | ||
branch : data[0], | ||
version : data[1] | ||
}; | ||
}); | ||
} | ||
function get(known) { | ||
return getBuildData(known).then((data) => { | ||
const | ||
branch = data.branch, | ||
version = data.version; | ||
return path.join(buildRoot, branch, version); | ||
}); | ||
} | ||
function link() { | ||
return getBuildData().then((data) => { | ||
const | ||
pkgData = data[0], | ||
currBranch = data[1], | ||
projectVersion = pkgData.pkg.version; | ||
branch = data.branch, | ||
version = data.version, | ||
branchLatestPath = path.join(buildRoot, branch, 'latest'); | ||
return path.join('build', currBranch, projectVersion); | ||
return new Promise((resolve) => { | ||
fs.symlink(version, branchLatestPath, (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
fs.symlink(branchLatestPath, 'latest-build', (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -24,3 +62,6 @@ } | ||
module.exports = { | ||
get : getBuildDir | ||
// TODO: Use the shorthand syntax here when Node.js upgrades V8 | ||
// to a version that does not throw a SyntaxError. | ||
get : get, | ||
link | ||
}; |
{ | ||
"name": "build-dir", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Get a place to put your build", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/solladay/build-dir", |
@@ -28,3 +28,3 @@ # build-dir | ||
````javascript | ||
buildDir.get().then(function (dirPath) { | ||
buildDir.get().then((dirPath) => { | ||
console.log(dirPath); | ||
@@ -34,2 +34,10 @@ }); | ||
Set up convenient `latest-build` and branch-specific `latest` links. | ||
````javascript | ||
buildDir.link().then(() => { | ||
// latest-build now points to build/<branch>/latest, | ||
// which in turn points to build/<branch>/<version> | ||
}); | ||
```` | ||
## Contributing | ||
@@ -36,0 +44,0 @@ See our [contributing guidelines](https://github.com/sholladay/build-dir/blob/master/CONTRIBUTING.md "The guidelines for being involved in this project.") for more details. |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
22534
8
59
54
1