Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

build-dir

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

build-dir - npm Package Compare versions

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.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc