npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svn-project-root

v0.1.0

Published

Get the root url for your svn project

Downloads

362

Readme

SVN Project Root

Get the root url for your svn project

Usage

svn-project-root

This module exports a function which asynchronously determines the project root for your svn repository.

var doSomethingWithRoot = function(err, root) {
  // Handle error, do something with root
};

var getRoot = require('svn-project-root');

getRoot(doSomethingWithRoot);

// CWD not in the project you care about? You can pass directory path as
// thefirst parameter.
var otherProjectFldr = '/other/project/folder';
getRoot(otherProjectFldr, doSomethingWithRoot);

svn-project-root#sync

The synchronous flavor of the above method. This may throw an error if for example there is a problem parsing your project's package.json or if the project in question is not an svn repository.

var getRoot = require('svn-project-root')
  , otherProjectFldr = '/other/project/folder'
  , projectRoot;

try {
  projectRoot = getRoot.sync();
} catch(err) {
  // boo!
}

// or

try {
  projectRoot = getRoot.sync(otherProjectFldr);
} catch(err) {
  // boo!
}

// Do something with root

svn-project-root#normalize

Our method for normalizing svn urls is also exported. If you already have a svn url handy and just want to get the project root from that url the method may satisfy your needs.

Usernames and passwords will be stripped away and the url will be chopped down to just before trunk|branches|tags start.

var uglyUrl = 'https://[email protected]/fldr/branches/assets/scripts'
  , normalize = require('svn-project-root').normalize;
console.log(normalize(uglyUrl));
// --> 'https://svnhub.com/fldr'

Usage Examples

var getRoot = require('svn-project-root');

// Optionally specify a start directory as first param, defaults to
process.cwd(). Directory // must be above your package.json or inside a svn repo
getRoot(function(err, url) {
  if(err) {
    // Whoops!
  }
  // Do something with url
});

try {
  // Optionally you may pass a directory
  var url = getRoot.sync();
} catch(err) {
  // Whoops!
}
// Do something with url

var grossSvnUrl = 'http://[email protected]/fldr/branches/featureXYZ'
  , prettyUrl = getRoot.normalize(grossSvnUrl);
console.log(prettyUrl);
// --> 'http://foobar.com/fldr'

Limitations

Assumption: Sane folder names

This module assumes your svn project directory structure looks like:

/
  /<arbitrary-folders>
    /<root>
      /trunk
      /branches
      /tags

The root or your project is assumed to be the parent directory of the first occurrence of trunk|branches|root, if you structure your repo such that it's svn url looks like https://svnhub.com/trunk/trunk/trunk/branches/foo you may have problems. I.e. please do not name repo ancestors trunk|branches|tags.

Assumption: First valid package.json is the one you want

svn-project-root will grab your repo url from the repository.url field in the first package.json it sees in the passed directory (defaults to process.cwd()) or any of its ancestors where the following is true:

  • repository.type is set and equals 'svn'
  • repository.url is set

Tests

Tests are run with grunt and mocha.

grunt test

License

MIT