Skip to content

Cordova support, Code-push App Name , Update dependencies #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
npm-debug.log
lib/
coverage/
.nyc*
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The following environment variables are needed to configure the CLI:

## Example usage

### React Native

In your `.travis.yml` file:

```yml
Expand All @@ -35,3 +37,17 @@ node_js:
script:
- code-push-travis
```

### Cordova

In your `.travis.yml` file:

```yml
language: node_js

node_js:
- 6

script:
- code-push-travis -f cordova
```
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "code-push-travis-cli",
"version": "1.2.0",
"description": "Automatic ci deploy of react-native app with code-push",
"description": "Automatic ci deploy of react-native and cordova app with code-push",
"main": "lib/index.js",
"bin": {
"code-push-travis": "./lib/bin/index.js"
},
"scripts": {
"build": "babel src --out-dir lib",
"clean": "rimraf lib coverage",
"coverage": "NODE_ENV=test NODE_PATH=src babel-node $(npm bin)/isparta cover node_modules/mocha/bin/_mocha -- --recursive",
"coverage": "NODE_ENV=test NODE_PATH=src nyc --reporter=lcov --require babel-register mocha --require test/setup.js --recursive test",
"dev": "npm test -- --watch",
"lint": "eslint src test",
"test": "env NODE_ENV=test env NODE_PATH=src mocha --compilers js:babel-core/register --recursive test",
"test": "env NODE_ENV=test env NODE_PATH=src mocha --require babel-register --recursive test",
"prepublish": "npm run clean && npm run build"
},
"keywords": [
"code-push",
"deploy",
"ci",
"travis-ci",
"react-native"
"react-native",
"cordova"
],
"author": "Davide Bianchi <davide.bianchi@mondora.com>",
"repository": {
Expand All @@ -34,21 +35,21 @@
"devDependencies": {
"babel-cli": "^6.16.0",
"babel-core": "^6.17.0",
"babel-eslint": "^7.0.0",
"babel-eslint": "^8.0.1",
"babel-plugin-rewire": "^1.0.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"chai": "^3.5.0",
"codecov": "^1.0.1",
"eslint": "^3.7.0",
"isparta": "^4.0.0",
"chai": "^4.1.2",
"codecov": "^3.0.0",
"eslint": "^4.9.0",
"lodash.omit": "^4.5.0",
"mocha": "^3.1.0",
"sinon": "^1.17.6",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"sinon": "^4.0.1",
"sinon-chai": "^2.8.0"
},
"dependencies": {
"code-push-cli": "^1.12.6-beta",
"yargs": "^6.0.0"
"code-push-cli": "^2.1.1-beta",
"yargs": "^10.0.3"
}
}
19 changes: 18 additions & 1 deletion src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const argv = yargs
.option("dev", {
alias: "development",
default: false,
describe: "This specifies whether to generate a unminified, development JS bundle",
describe: "This specifies whether to generate a unminified, development JS bundle ( This parameter will be ignored if the framework is cordova)",
type: "boolean"
})
.option("m", {
Expand All @@ -41,13 +41,30 @@ const argv = yargs
describe: "Check if you want your push is mandatory",
type: "boolean"
})
.option("na", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

na option is not an auto-explanatory alias, so it could be only nameAndroid without alias? The same is for ni and nameIos

alias: "nameAndroid",
describe: "app name for Android registered on code-push",
type: "string"
})
.option("ni", {
alias: "nameIos",
describe: "app name for Ios registered on code-push",
type: "string"
})
.option("platform", {
alias: "platforms",
default: ["android", "ios"],
describe: "Platform to push [ios or android]",
choices: ["android", "ios"],
type: "array"
})
.option("f", {
alias: "framework",
default: "reactnative",
describe: "Framework used to create the Mobile Application",
choices: ["reactnative", "cordova"],
type: "string"
})
.option("tag", {
// TODO: change default to true when major version upgrade
default: false,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import codepushLogin from "./steps/login";
import codepushReleaseReact from "./steps/release-react";
import codePushRelease from "./steps/release-react";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name should be modified, maybe in release.js, because it is also for cordova release

import codepushLogout from "./steps/logout";

export default function codePushTravis (argv) {
Expand All @@ -8,7 +8,7 @@ export default function codePushTravis (argv) {
) && process.env.TRAVIS_PULL_REQUEST === "false") {
const pkg = require(`${process.env.TRAVIS_BUILD_DIR}/package.json`);
codepushLogin();
argv.platforms.forEach(platform => codepushReleaseReact(argv, platform, pkg));
argv.platforms.forEach(platform => codePushRelease(argv, platform, pkg));
codepushLogout();
}
}
29 changes: 19 additions & 10 deletions src/steps/release-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@ function targetBinary (targetBinary) {
return targetBinary ? `-t "${targetBinary}"` : "";
}

function appName (pkgName, platform) {
function appName (pkgName, platform, argv) {

if (argv.na && platform === "android") {
return `"${argv.na}"`;
}

if (argv.ni && platform === "ios") {
return `"${argv.ni}"`;
}

return `"${pkgName}-${platform}"`;
}

function reactNativeRelease (argv, platform, pkg) {
function codePushFrameworkRelease (argv, platform, pkg) {
return [
"code-push",
"release-react",
appName(pkg.name, platform),
(!argv.framework || argv.framework === "reactnative") ? "release-react" : "release-cordova",
appName(pkg.name, platform, argv),
platform,
`-d "${argv.deploymentName}"`,
`--des "${argv.description}"`,
`--dev ${argv.development}`,
(!argv.framework || argv.framework === "reactnative") ? `--dev ${argv.development}` : "",
`-m ${argv.mandatory}`,
targetBinary(argv.targetBinary)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be transform as the line of the development option, to mantain uniformity of the codebase

].join(" ");
}

function reactNativeReleaseStatus (pkgName, platform) {
function codePushFrameworkReleaseStatus (argv, pkgName, platform) {
return [
"code-push",
"deployment",
"list",
appName(pkgName, platform)
appName(pkgName, platform, argv)
].join(" ");
}

export default function codepushReleaseReact (argv, platform, pkg) {
execSync(reactNativeRelease(argv, platform, pkg), {stdio: [0, 1, 2]});
execSync(reactNativeReleaseStatus(pkg.name, platform), {stdio: [0, 1, 2]});
export default function codePushRelease (argv, platform, pkg) {
execSync(codePushFrameworkRelease(argv, platform, pkg), {stdio: [0, 1, 2]});
execSync(codePushFrameworkReleaseStatus(argv, pkg.name, platform), {stdio: [0, 1, 2]});
}
30 changes: 15 additions & 15 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ describe("`codePushTravis` function", () => {

const codepushLogin = sinon.spy();
const codepushLogout = sinon.spy();
const codepushReleaseReact = sinon.spy();
const codePushRelease = sinon.spy();

before(() => {
codePushTravis.__Rewire__("codepushLogin", codepushLogin);
codePushTravis.__Rewire__("codepushLogout", codepushLogout);
codePushTravis.__Rewire__("codepushReleaseReact", codepushReleaseReact);
codePushTravis.__Rewire__("codePushRelease", codePushRelease);
});

beforeEach(() => {
process.env = omit(process.env, ["TRAVIS_PULL_REQUEST", "TRAVIS_BRANCH", "TRAVIS_BUILD_DIR", "TRAVIS_TAG"]);
codepushLogin.reset();
codepushLogout.reset();
codepushReleaseReact.reset();
codePushRelease.reset();
});

after(() => {
process.env = omit(process.env, ["TRAVIS_PULL_REQUEST", "TRAVIS_BRANCH", "TRAVIS_BUILD_DIR", "TRAVIS_TAG"]);
codePushTravis.__ResetDependency__("codepushLogin");
codePushTravis.__ResetDependency__("codepushLogout");
codePushTravis.__ResetDependency__("codepushReleaseReact");
codePushTravis.__ResetDependency__("codePushRelease");
});

it("skip all functions [CASE: `TRAVIS_PULL_REQUEST` is true]", () => {
Expand All @@ -38,7 +38,7 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(0);
expect(codepushReleaseReact).to.have.callCount(0);
expect(codePushRelease).to.have.callCount(0);
expect(codepushLogout).to.have.callCount(0);
});

Expand All @@ -50,7 +50,7 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(0);
expect(codepushReleaseReact).to.have.callCount(0);
expect(codePushRelease).to.have.callCount(0);
expect(codepushLogout).to.have.callCount(0);
});

Expand All @@ -64,7 +64,7 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(0);
expect(codepushReleaseReact).to.have.callCount(0);
expect(codePushRelease).to.have.callCount(0);
expect(codepushLogout).to.have.callCount(0);
});

Expand All @@ -78,8 +78,8 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(1);
expect(codepushReleaseReact).to.have.callCount(1);
expect(codepushReleaseReact).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codePushRelease).to.have.callCount(1);
expect(codePushRelease).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codepushLogout).to.have.callCount(1);
});

Expand All @@ -93,9 +93,9 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(1);
expect(codepushReleaseReact).to.have.callCount(2);
expect(codepushReleaseReact.firstCall).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codepushReleaseReact.secondCall).to.have.been.calledWithExactly(argv, "ios", pkg);
expect(codePushRelease).to.have.callCount(2);
expect(codePushRelease.firstCall).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codePushRelease.secondCall).to.have.been.calledWithExactly(argv, "ios", pkg);
expect(codepushLogout).to.have.callCount(1);
});

Expand All @@ -110,9 +110,9 @@ describe("`codePushTravis` function", () => {
};
codePushTravis(argv);
expect(codepushLogin).to.have.callCount(1);
expect(codepushReleaseReact).to.have.callCount(2);
expect(codepushReleaseReact.firstCall).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codepushReleaseReact.secondCall).to.have.been.calledWithExactly(argv, "ios", pkg);
expect(codePushRelease).to.have.callCount(2);
expect(codePushRelease.firstCall).to.have.been.calledWithExactly(argv, "android", pkg);
expect(codePushRelease.secondCall).to.have.been.calledWithExactly(argv, "ios", pkg);
expect(codepushLogout).to.have.callCount(1);
});

Expand Down
Loading