Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 8, 2014
0 parents commit c5e1f5a
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
19 changes: 19 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: objective-c
install: brew install node
script:
- npm install
- npm test
20 changes: 20 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node
'use strict';
var bundleId = require('./index');
var input = process.argv[2];

if (!input || process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) {
return console.log('Usage\n bundle-id <bundle name>\n\nExample\n bundle-id Safari\n => com.apple.Safari\n\nReturns the bundle identifier from a bundle name');
}

if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
return console.log(require('./package').version);
}

bundleId(input, function (err, id) {
if (err) {
throw err;
}

console.log(id);
});
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
var execFile = require('child_process').execFile;

module.exports = function (bundleName, cb) {
var script = 'get id of application "' + bundleName + '"';

execFile('osascript', ['-e', script], function (err, stdout) {
if (err) {
return cb(err);
}

cb(err, stdout.trim());
});
};
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "bundle-id",
"version": "0.0.0",
"description": "Get bundle identifier from a bundle name (OS X): Safari => com.apple.Safari",
"license": "MIT",
"bin": {
"bundle-id": "cli.js"
},
"repository": "sindresorhus/bundle-id",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"os": [
"darwin"
],
"scripts": {
"test": "mocha"
},
"files": [
"index.js",
"cli.js"
],
"keywords": [
"osx",
"mac",
"plist",
"applescript",
"bundle",
"bundleid",
"bundlename",
"id",
"identifier",
"CFBundleName",
"CFBundleIdentifier",
"uti",
"cli",
"bin"
],
"devDependencies": {
"mocha": "*"
}
}
46 changes: 46 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# bundle-id [![Build Status](https://travis-ci.org/sindresorhus/bundle-id.png?branch=master)](http://travis-ci.org/sindresorhus/bundle-id)

> Get [bundle identifier](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleIdentifier) from a [bundle name](https://developer.apple.com/library/Mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/plist/info/CFBundleName) (OS X): `Safari` => `com.apple.Safari`
See [bundle-name](https://github.com/sindresorhus/bundle-name) for the reverse.


## Install

```
npm install --save bundle-id
```


## Example

```js
var bundleId = require('bundle-id');

bundleId('Safari', function (err, id) {
console.log(id);
//=> com.apple.Safari
});
```


## CLI

You can also use it as a CLI app by installing it globally:

```
npm install --global bundle-id
```

### Usage

```
bundle-id Safari
```

Which will output `com.apple.Safari`.


## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
var assert = require('assert');
var bundleId = require('./index');

it('should get bundle id from bundle name', function (cb) {
bundleId('Safari', function (err, id) {
console.log('Bundle id:', id);
assert.equal(id, 'com.apple.Safari');
cb();
});
});

0 comments on commit c5e1f5a

Please sign in to comment.