Skip to content

Commit

Permalink
Merge pull request #187 from BranchMetrics/feature/gulp
Browse files Browse the repository at this point in the history
Feature/gulp
  • Loading branch information
aaustin authored Aug 8, 2016
2 parents 7e7217b + a78ca64 commit 76cd52b
Show file tree
Hide file tree
Showing 26 changed files with 805 additions and 110 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"parser": "babel-eslint",
"env": { "browser": true },
"rules": {
"quotes": 0,
"strict": 0,
"no-underscore-dangle": 0,
"eqeqeq": 0,
"camelcase": 0,
"consistent-return": 0,
"new-cap": 0
},
"globals": {
"module": true,
"require": false
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ testbed/plugins
testbed/hooks
node_modules
testbed/ul_web_hooks/
.installed
.installed
40 changes: 40 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"fileExtensions": [".js", ".jsx"],
"requireCurlyBraces": [ "if", "else", "for", "while", "do", "try", "catch" ],
"requireSpaceAfterKeywords": [ "if", "else", "for", "while", "do", "switch", "return", "try", "catch" ],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": { "afterTest": true, "beforeConsequent": true, "afterConsequent": true, "beforeAlternate": true },
"requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInAnonymousFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true },
"requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true },
"requireSpacesInFunction": { "beforeOpeningCurlyBrace": true },
"disallowSpacesInFunction": { "beforeOpeningRoundBrace": true },
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"requireSpacesInsideArrayBrackets": "all",
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--", ";"],
"disallowSpaceBeforeBinaryOperators": [ "," ],
"requireSpaceBeforeBinaryOperators": [ "=", "+", "-", "/", "*", "==", "===", "!=", "!==" ],
"requireSpaceAfterBinaryOperators": [ "=", ",", "+", "-", "/", "*", "==", "===", "!=", "!==" ],
"disallowMultipleLineStrings": true,
"validateLineBreaks": "LF",
"disallowMixedSpacesAndTabs": "smart",
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"requireKeywordsOnNewLine": [ "else" ],
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"safeContextKeyword": [ "self" ],
"disallowYodaConditions": true,
"requireSpaceAfterLineComment": true,
"disallowNewlineBeforeBlockStatements": true
}
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- '6'
- '5'
- '4'
before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
script:
- npm run prerelease
after_success:
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
- export $(cat .to_export_back) &> /dev/null
- test $TRAVIS_PULL_REQUEST = false \
&& npm run semantic-release
branches:
only:
- master
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Development Conventions

This document outlines our development processes.

## Pull Requests

All changes to this project should be made in the form of pull requests against master. Use snake-case prefixed by 'feat/' or 'fix/' for features/fixes. Feel free to use any of the commit types listed [here](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#type) as well. Note that when pull requests are merged in they will be automatically released to npm by (Travis CI)[https://travis-ci.org/] and (semantic-release)[https://github.com/semantic-release/semantic-release] so make sure to fully test.

## Commit Messages

Please format your commit messages to match [Angular's Conventions](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines). These messages are parsed using semantic release to determine version numbers so it is important that you stick to them exactly. We recommend using the `npm run commit` script installed in this project to draft conformant messages.

## Linting

The style of all js files in this project are strictly checked using [jscs](http://jscs.info/) and [eslint](http://eslint.org/) before any pull request/release is made. You can manually check your local clone using the `gulp lint` command (don't forget to `nom install -g gulp` if you haven't already). Many problems can be automatically fixed by `gulp jscs-fix`. Don't forget to commit before running jscs-fix in case you end up needing to back out changes.

## Testing

See [tests-harness/README.md](https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/blob/master/tests-harness/README.md) for details on how to run this project's test suite. Please run the test suite before merging any branches.

## Updating IOS dependencies

This project depends on [ios-branch-deep-linking](https://github.com/BranchMetrics/ios-branch-deep-linking). To upgrade that dependency a [release](https://github.com/BranchMetrics/ios-branch-deep-linking/releases) of it run the following script:

```shell
# <tag> is the name of the release. e,g, '0.12.5'
$ src/ios/dependencies/update.sh <tag>
```
5 changes: 0 additions & 5 deletions NPMdeployment.txt

This file was deleted.

147 changes: 147 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
var gulp = require('gulp');
var fs = require('fs');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var eslint = require('gulp-eslint');
var jscs = require('gulp-jscs');

gulp.task('prerelease', [ 'setupNpm', 'babel', 'lint' ]);

// -----------------------------------------------------------------------------
// setup for development use
gulp.task('setupDev', () => {
getDevPluginXML();
setIosNpmOrDev('dev');
})

// setup for npm deployment
gulp.task('setupNpm', () => {
genNpmPluginXML();
setIosNpmOrDev('npm');
});

// generate plugin.xml for use as a cordova plugin
// here we explode the contents of the frameworks
function genNpmPluginXML() {
var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

var files = [];
var root = 'src/ios/dependencies/';
files = files.concat(emitFiles(root + 'Fabric/'));
files = files.concat(emitFiles(root + 'Branch-SDK/'));
files = files.concat(emitFiles(root + 'Branch-SDK/Requests/'));

var newLineIndent = '\n ';
xml = xml.replace('<!--[Branch Framework Reference]-->', newLineIndent
+ files.join(newLineIndent));

fs.writeFileSync('plugin.xml', xml);
};

// generate plugin.xml for local development
// here we reference the frameworks instead of all the files directly
function getDevPluginXML() {
var xml = fs.readFileSync('plugin.template.xml', 'utf-8');

xml = xml.replace('<!--[Branch Framework Reference]-->',
'<framework custom="true" src="src/ios/dependencies/Branch.framework" />');

fs.writeFileSync('plugin.xml', xml);
};

function setIosNpmOrDev(npmOrDev) {
if (npmOrDev === 'npm') {
content = '#define BRANCH_NPM true';
}
else if (npmOrDev === 'dev') {
content = '//empty';
}
else {
throw new Error('expected deployed|local, not ' + deployedOrLocal);
}
fs.writeFileSync('src/ios/BranchNPM.h', content + '\n');
}

// emit array of cordova file references for all .h/.m files in path
function emitFiles(path) {
var ret = [];
for (filename of fs.readdirSync(path)) {
var fileType = null;
if (filename.match(/\.m$/)) {
fileType = 'source';
}
else if (filename.match(/\.h$/) || filename.match(/\.pch$/)) {
fileType = 'header';
}
if (fileType) {
ret.push('<' + fileType + '-file src="' + path + filename + '" />');
}
}
ret.push('');
return ret;
}

// -----------------------------------------------------------------------------
// copy resources and compile es6 from corresponding directories
babelTasks = []; // list of all babel tasks so we can build all of them
function babelize(taskName, dir) {
babelTasks.push(taskName + '-babel');
if (!dir) {
dir = taskName;
}
var srcDir = dir + '.es6/';
var srcPattern = dir + '.es6/**/*.js'
var destDir = dir + '/';
gulp.task(taskName + '-copy', () => {
return gulp.src(srcDir + '**/*.*').pipe(gulp.dest(destDir));
});
gulp.task(taskName + '-babel', [ taskName + '-copy' ], () => {
return gulp.src(srcPattern)
.pipe(sourcemaps.init())
.pipe(babel({
presets: [ 'es2015', 'stage-2' ],
plugins: [ 'transform-runtime' ] // needed for generators etc
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(destDir));
});
}

babelize('hooks');
babelize('www');
babelize('tests');
babelize('testbed', 'testbed/www/js');
gulp.task('babel', babelTasks);

// -----------------------------------------------------------------------------
// linting

gulp.task('lint', [ 'eslint', 'jscs-lint' ]);

var srcs = [
'**/*.js',
'!node_modules/**',
'!testbed/platforms/ios/cordova/node_modules/**'
];

gulp.task('eslint', () => {
return gulp.src(srcs)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

function jscsTask(fix) {
var ret = gulp.src(srcs)
.pipe(jscs({ fix: fix }))
.pipe(jscs.reporter())
.pipe(jscs.reporter('fail'));

if (fix) {
ret.pipe(gulp.dest('.'));
}
return ret;
}

gulp.task('jscs-fix', jscsTask.bind(null, true));
gulp.task('jscs-lint', jscsTask.bind(null, false));
34 changes: 28 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "2.1.10",
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "www/branch.js",
"homepage": "https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK",
"version": "0.0.0-semantic-release",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
"url": "https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK.git"
"url": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking.git"
},
"bugs": {
"url": "https://github.com/BranchMetrics/Cordova-Ionic-PhoneGap-Deferred-Deep-Linking-SDK/issues"
"url": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/issues"
},
"keywords": [
"ecosystem:cordova",
Expand All @@ -30,6 +30,11 @@
"ios"
],
"license": "MIT",
"scripts": {
"prerelease": "gulp prerelease",
"commit": "git-cz",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"dependencies": {
"mkpath": "^1.0.0",
"node-version-compare": "^1.0.1",
Expand All @@ -38,10 +43,27 @@
"xml2js": "^0.4.16"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
"babel-plugin-transform-runtime": "^6.12.0",
"babel-polyfill": "^6.13.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-2": "^6.11.0",
"commitizen": "^2.8.2",
"cz-conventional-changelog": "^1.1.6",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-eslint": "^3.0.1",
"gulp-jscs": "^4.0.0",
"gulp-sourcemaps": "^1.6.0",
"mkpath": "^1.0.0",
"node-version-compare": "^1.0.1",
"plist": "^1.2.0",
"rimraf": "^2.5.2",
"xml2js": "^0.4.16"
"semantic-release": "^4.3.5",
"wd": "^0.4.0"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
}
}
Loading

0 comments on commit 76cd52b

Please sign in to comment.