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.3.1 to 0.4.0

114

index.js
'use strict';
const
path = require('path'),
os = require('os'),
fs = require('fs'),
fsAtomic = require('fs-atomic'),
branchName = require('branch-name'),
readPkgUp = require('read-pkg-up'),
del = require('del'),
buildRoot = 'build';
const path = require('path');
const os = require('os');
const fs = require('fs');
const fsAtomic = require('fs-atomic');
const buildData = require('build-data');
const del = require('del');
function makeBuildPath(data) {
return path.join(buildRoot, data.branch, data.version);
}
const buildPath = (option) => {
return path.join('build', option.branch, option.version);
};
function getBuildData(known) {
const get = (option) => {
return buildData(option).then((data) => {
return buildPath(data);
});
};
known = known || Object.create(null);
const link = (option) => {
return buildData(option).then((data) => {
const { branch, version } = data;
const branchLatestDir = buildPath({
branch,
version : 'latest'
});
return Promise.all([
known.branch || branchName.assumeMaster(),
known.version || readPkgUp().then((data) => {
if (!data || !data.pkg) {
throw new TypeError(
'Unable to determine the project version'
);
}
return data.pkg.version;
})
]).then((data) => {
return {
branch : data[0],
version : data[1]
};
return fsAtomic.symlink(version, branchLatestDir).then(() => {
return fsAtomic.symlink(branchLatestDir, 'latest-build');
});
}
});
};
function get(known) {
return getBuildData(known).then((data) => {
return makeBuildPath(data);
const rename = (oldPath, newPath) => {
return new Promise((resolve, reject) => {
fs.rename(oldPath, newPath, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
}
function link(known) {
return getBuildData(known).then((data) => {
const
branch = data.branch,
version = data.version,
branchLatestPath = path.join(buildRoot, branch, 'latest');
return fsAtomic.symlink(version, branchLatestPath)
.then(() => {
return fsAtomic.symlink(branchLatestPath, 'latest-build');
});
});
}
};
function prepare(known) {
return getBuildData(known).then((data) => {
return new Promise((resolve) => {
const prefix = path.join(os.tmpdir(), '/');
fs.mkdtemp(prefix, (err, tempPath) => {
const prepare = (option) => {
return buildData(option).then((data) => {
return new Promise((resolve, reject) => {
fs.mkdtemp(path.join(os.tmpdir(), '/'), (err, tempPath) => {
if (err) {
throw err;
reject(err);
return;
}
resolve({
path : tempPath,
finalize : () => {
const newPath = makeBuildPath(data);
finalize() {
const newPath = buildPath(data);
return fsAtomic.mkdir(path.dirname(newPath))

@@ -77,10 +64,3 @@ .then(() => {

.then(() => {
return new Promise((resolve) => {
fs.rename(tempPath, newPath, (err) => {
if (err) {
throw err;
}
resolve();
});
});
return rename(tempPath, newPath);
})

@@ -95,10 +75,8 @@ .then(() => {

});
}
};
module.exports = {
// TODO: Use the shorthand syntax here when Node.js upgrades V8
// to a version that does not throw a SyntaxError.
get : get,
get,
link,
prepare
};
{
"name": "build-dir",
"version": "0.3.1",
"version": "0.4.0",
"description": "Get a place to put your build.",

@@ -9,6 +9,7 @@ "homepage": "https://github.com/sholladay/build-dir",

"name": "Seth Holladay",
"url": "http://seth-holladay.com"
"url": "http://seth-holladay.com",
"email": "me@seth-holladay.com"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "xo"
},

@@ -21,4 +22,7 @@ "repository": {

"url": "https://github.com/sholladay/build-dir/issues",
"email": "bugs@seth-holladay.com"
"email": "me@seth-holladay.com"
},
"engines": {
"node": ">=6"
},
"license": "MPL-2.0",

@@ -29,14 +33,21 @@ "files": [

"dependencies": {
"branch-name": "0.1.3",
"build-data": "0.1.0",
"del": "2.2.0",
"fs-atomic": "0.2.0",
"read-pkg-up": "1.0.1"
"fs-atomic": "0.4.0"
},
"devDependencies": {
"eslint-config-tidy": "0.3.0",
"xo": "0.16.0"
},
"keywords": [
"compile",
"build",
"builds",
"dir",
"path",
"tooling"
]
],
"xo": {
"extend": "tidy"
}
}

@@ -1,4 +0,4 @@

# build-dir
# build-dir [![Build status for build-dir on Circle CI.](https://img.shields.io/circleci/project/sholladay/build-dir/master.svg "Circle Build Status")](https://circleci.com/gh/sholladay/build-dir "Build Dir Builds")
> Get a place to put your build
> Get a place to put your build.

@@ -15,5 +15,5 @@ ## Why?

````sh
```sh
npm install build-dir --save
````
```

@@ -23,15 +23,18 @@ ## Usage

Get it into your program.
````javascript
```js
const buildDir = require('build-dir');
````
```
Get a path to use when writing the build.
````javascript
```js
buildDir.get().then((dirPath) => {
console.log('Build directory:', dirPath);
});
````
```
Set up convenient `latest-build` and branch-specific `latest` links.
````javascript
```js
buildDir.link().then(() => {

@@ -41,6 +44,7 @@ console.log('Linking complete.')

});
````
```
Let us manage the lifecycle steps for you.
````javascript
```js
buildDir.prepare().then((dir) => {

@@ -56,16 +60,18 @@ // Put stuff in here:

});
````
```
## Contributing
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.
See our [contributing guidelines](https://github.com/sholladay/build-dir/blob/master/CONTRIBUTING.md "The guidelines for participating in this project.") for more details.
1. [Fork it](https://github.com/sholladay/build-dir/fork).
2. Create your feature branch: `git checkout -b my-new-feature`
2. Make a feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. [Submit a pull request](https://github.com/sholladay/build-dir/compare "Submit code to this repo now for review.").
5. [Submit a pull request](https://github.com/sholladay/build-dir/compare "Submit code to this project for review.").
## License
[MPL-2.0](https://github.com/sholladay/build-dir/blob/master/LICENSE "The license for build-dir.")
[MPL-2.0](https://github.com/sholladay/build-dir/blob/master/LICENSE "The license for build-dir.") © [Seth Holladay](http://seth-holladay.com "Author of build-dir.")
Go make something, dang it.

Sorry, the diff of this file is not supported yet

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