Comparing version 0.1.1 to 0.2.0
56
index.js
@@ -7,5 +7,11 @@ 'use strict'; | ||
path = require('path'), | ||
os = require('os'), | ||
fs = require('fs'), | ||
fsAtomic = require('fs-atomic'), | ||
buildRoot = 'build'; | ||
function makeBuildPath(data) { | ||
return path.join(buildRoot, data.branch, data.version); | ||
} | ||
function getBuildData(known) { | ||
@@ -18,5 +24,10 @@ | ||
known.version || readPkgUp().then((data) => { | ||
if (!data || !data.pkg) { | ||
throw new TypeError( | ||
'Unable to determine the project version' | ||
); | ||
} | ||
return data.pkg.version; | ||
}) | ||
]).then(function (data) { | ||
]).then((data) => { | ||
return { | ||
@@ -31,12 +42,8 @@ branch : data[0], | ||
return getBuildData(known).then((data) => { | ||
const | ||
branch = data.branch, | ||
version = data.version; | ||
return path.join(buildRoot, branch, version); | ||
return makeBuildPath(data); | ||
}); | ||
} | ||
function link() { | ||
return getBuildData().then((data) => { | ||
function link(known) { | ||
return getBuildData(known).then((data) => { | ||
const | ||
@@ -47,12 +54,32 @@ branch = data.branch, | ||
return fsAtomic.symlink(version, branchLatestPath) | ||
.then(() => { | ||
return fsAtomic.symlink(branchLatestPath, 'latest-build'); | ||
}); | ||
}); | ||
} | ||
function prepare(known) { | ||
return getBuildData(known).then((data) => { | ||
return new Promise((resolve) => { | ||
fs.symlink(version, branchLatestPath, (err) => { | ||
const prefix = path.join(os.tmpdir(), '/'); | ||
fs.mkdtemp(prefix, (err, tempPath) => { | ||
if (err) { | ||
throw err; | ||
} | ||
fs.symlink(branchLatestPath, 'latest-build', (err) => { | ||
if (err) { | ||
throw err; | ||
resolve({ | ||
path : tempPath, | ||
finalize : () => { | ||
return (new Promise((resolve) => { | ||
const newPath = makeBuildPath(data); | ||
fs.rename(tempPath, newPath, (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
resolve(); | ||
}); | ||
})).then(() => { | ||
return link(data); | ||
}); | ||
} | ||
resolve(); | ||
}); | ||
@@ -68,3 +95,4 @@ }); | ||
get : get, | ||
link | ||
link, | ||
prepare | ||
}; |
{ | ||
"name": "build-dir", | ||
"version": "0.1.1", | ||
"description": "Get a place to put your build", | ||
"homepage": "https://github.com/solladay/build-dir", | ||
"version": "0.2.0", | ||
"description": "Get a place to put your build.", | ||
"homepage": "https://github.com/sholladay/build-dir", | ||
"main": "index.js", | ||
@@ -27,3 +27,4 @@ "author": { | ||
"dependencies": { | ||
"branch-name": "0.1.2", | ||
"branch-name": "0.1.3", | ||
"fs-atomic": "0.1.0", | ||
"read-pkg-up": "1.0.1" | ||
@@ -30,0 +31,0 @@ }, |
@@ -29,3 +29,3 @@ # build-dir | ||
buildDir.get().then((dirPath) => { | ||
console.log(dirPath); | ||
console.log('Build directory:', dirPath); | ||
}); | ||
@@ -37,7 +37,21 @@ ```` | ||
buildDir.link().then(() => { | ||
// latest-build now points to build/<branch>/latest, | ||
// which in turn points to build/<branch>/<version> | ||
console.log('Linking complete.') | ||
// latest-build -> build/<branch>/latest -> build/<branch>/<version> | ||
}); | ||
```` | ||
Let us manage the lifecycle steps for you. | ||
````javascript | ||
buildDir.prepare().then((dir) => { | ||
// Put stuff in here: | ||
console.log('Temp dir:', dir.path); | ||
// ... some time later ... | ||
// Move the temp dir to its permanent home and set up | ||
// latest links. | ||
return dir.finalize(); | ||
}); | ||
```` | ||
## Contributing | ||
@@ -44,0 +58,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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
21224
83
2
68
3
2
+ Addedfs-atomic@0.1.0
+ Addedbranch-name@0.1.3(transitive)
+ Addedfs-atomic@0.1.0(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedtempfile@1.1.1(transitive)
+ Addeduuid@2.0.3(transitive)
- Removedbranch-name@0.1.2(transitive)
Updatedbranch-name@0.1.3