Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Sep 26, 2015
0 parents commit e6442fa
Show file tree
Hide file tree
Showing 11 changed files with 271 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 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
node_modules
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
git:
depth: 1
branches:
except: /^v\d/
language: node_js
node_js: stable
after_script:
- npm install istanbul-coveralls
- npm run-script coverage
- node node_modules/.bin/istanbul-coveralls
notifications:
email: false
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# installed-pod-regex

[![NPM version](https://img.shields.io/npm/v/installed-pod-regex.svg)](https://www.npmjs.com/package/installed-pod-regex)
[![Build Status](https://travis-ci.org/shinnn/installed-pod-regex.svg?branch=master)](https://travis-ci.org/shinnn/installed-pod-regex)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/installed-pod-regex.svg)](https://coveralls.io/r/shinnn/installed-pod-regex)
[![devDependency Status](https://david-dm.org/shinnn/installed-pod-regex/dev-status.svg)](https://david-dm.org/shinnn/installed-pod-regex#info=devDependencies)

Create a [regular expression](http://www.ecma-international.org/ecma-262/5.1/#sec-15.10) object that matches the newly installed [Pod](https://cocoapods.org/) list generated with [CocoaPods installation commands](https://guides.cocoapods.org/terminal/commands.html#group_installation)

```javascript
const stdout = `
Using colored 1.2
Installing rouge 1.10.1
Installing xcjobs 0.2.2 (was 0.1.2)
`;

stdout.match(installedPodRegex());
//=> ['Installing rouge 1.10.1', 'Installing xcjobs 0.2.2 (was 0.1.2)']
```

## Installation

### Package managers

#### [npm](https://www.npmjs.com/)

```
npm install installed-pod-regex
```

#### [bower](http://bower.io/)

```
bower install installed-pod-regex
```

### Standalone

[Download the script file directly.](https://raw.githubusercontent.com/shinnn/installed-pod-regex/master/browser.js)

## API

### installedPodRegex()

Return: [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance with `g` and `m` flags

```javascript
const stdout = `
Installing rouge 1.10.1
Installing xcjobs 0.2.2 (was 0.1.2)
`;

const regex = installedPodRegex();

regex.exec(stdout);
//=> ['Installing rouge 1.10.1', 'rouge', '1.10.1', undefined]

// The last item of matching result would be a previous version (if available)
regex.exec(stdout);
//=> ['Installing xcjobs 0.2.2 (was 0.1.2)', 'xcjobs', '0.2.2', '0.1.2']

regex.exec(stdout);
//=> null
```

## License

[The Unlicense](./LICENSE)
37 changes: 37 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "installed-pod-regex",
"version": "1.0.0",
"description": "Create a regex that matches the newly installed Pod list generated with CocoaPods installation commands",
"keywords": [
"cocoapods",
"pod",
"pods",
"version",
"install",
"installed",
"installing",
"update",
"list",
"regex",
"regexp",
"match",
"detect"
],
"main": "browser.js",
"moduleType": "globals",
"homepage": "https://github.com/shinnn/installed-pod-regex",
"repository": {
"type": "git",
"url": "git://github.com/shinnn/installed-pod-regex.git"
},
"authors": [
"Shinnosuke Watanabe (https://github.com/shinnn)"
],
"license": "Unlicense",
"ignore": [
"**/.*",
"*.js",
"*.json",
"node_modules"
]
}
5 changes: 5 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window.installedPodRegex = function installedPodRegex() {
'use strict';
// https://github.com/CocoaPods/CocoaPods/blob/0.39.0/lib/cocoapods/installer.rb#L301
return /^Installing ([^\.\s\/][^\s\/]*) (\d\S+)(?: \(was (\d\S+)\))?$/gm;
};
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function installedPodRegex() {
'use strict';
// https://github.com/CocoaPods/CocoaPods/blob/0.39.0/lib/cocoapods/installer.rb#L301
return /^Installing ([^\.\s\/][^\s\/]*) (\d\S+)(?: \(was (\d\S+)\))?$/gm;
};
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "installed-pod-regex",
"version": "1.0.0",
"description": "Create a regex that matches the newly installed Pod list generated with CocoaPods installation commands",
"repository": "shinnn/installed-pod-regex",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"pretest": "eslint --config @shinnn/node --env browser browser.js index.js test.js",
"test": "node --strong_mode --throw-deprecation --track-heap-objects test.js | tap-spec",
"coverage": "node --strong_mode node_modules/.bin/istanbul cover test.js"
},
"license": "Unlicense",
"files": [
"index.js"
],
"keywords": [
"cocoapods",
"pod",
"pods",
"version",
"install",
"installed",
"installing",
"update",
"list",
"regex",
"regexp",
"match",
"detect",
"client-side",
"browser"
],
"devDependencies": {
"@shinnn/eslint-config-node": "^1.0.1",
"eslint": "^1.7.3",
"istanbul": "^0.4.0",
"tap-spec": "^4.1.0",
"tape": "^4.2.2"
}
}
65 changes: 65 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strong';

const test = require('tape');

const fixture = `
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Using colored 1.2
Installing rouge 1.10.1
Installing xcjobs 0.2.2 (was 0.1.2)
`;

function runTest(description, installedPodRegex) {
test(description, t => {
t.plan(7);

t.equal(installedPodRegex.name, 'installedPodRegex', 'should have a function name.');

const regex = installedPodRegex();

t.deepEqual(
Array.from(regex.exec(fixture)),
['Installing rouge 1.10.1', 'rouge', '1.10.1', undefined],
'should return a regex that detects currently installing Pods from the output of installation command.'
);

t.deepEqual(
Array.from(regex.exec(fixture)),
['Installing xcjobs 0.2.2 (was 0.1.2)', 'xcjobs', '0.2.2', '0.1.2'],
'should return a regex that detects the previous versions of currently installing Pods.'
);

t.strictEqual(
installedPodRegex().exec('Installing .rouge 1.10.1'),
null,
'should return a regex that doesn\'t match the line with a dot-first Pod name.'
);

t.strictEqual(
installedPodRegex().exec('Installing ro/uge 1.10.1'),
null,
'should return a regex that doesn\'t match the line with a Pod name including `/`.'
);

t.strictEqual(
installedPodRegex().exec('Installing r ouge 1.10.1'),
null,
'should return a regex that doesn\'t match the line with a Pod name including white spaces.'
);

t.strictEqual(
installedPodRegex().exec('Installing rouge 1.1 0.4'),
null,
'should return a regex that doesn\'t match the line with an invalid version number.'
);
});
}

runTest('require(\'installed-pod-regex\')', require('.'));

global.window = {};
require(`./${require('./bower.json').main}`);

runTest('window.installedPodRegex', global.window.installedPodRegex);

0 comments on commit e6442fa

Please sign in to comment.