Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
support for ignore flag (fix for #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
goya committed Sep 13, 2018
1 parent 6906374 commit cd3b81f
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/commands/helpers/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/commands/new.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/commands/update.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion lib/commands/usage/new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Add a new app from the specified repository, directory or file
Properties:

phonegap, android-phonegap, ios-phonegap, winphone-phonegap, hydrates, share,
tag, debug, private, android-key, windows-key, ios-key, winphone-key
tag, debug, private, android-key, windows-key, ios-key, winphone-key, ignore

The ignore flag allows you to specify directories or files that should NOT
be uploaded. It supports the glob format (https://git-scm.com/docs/gitignore)
and can be specified multiple times.

Options:

Expand Down
6 changes: 5 additions & 1 deletion lib/commands/usage/update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ directory or file
Properties:

phonegap, android-phonegap, ios-phonegap, winphone-phonegap, hydrates, share,
tag, debug, private, android-key, windows-key, ios-key, winphone-key
tag, debug, private, android-key, windows-key, ios-key, winphone-key, ignore

The ignore flag allows you to specify directories or files that should NOT
be uploaded. It supports the glob format (https://git-scm.com/docs/gitignore)
and can be specified multiple times.

Options:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgb-cli",
"version": "1.0.4-dev",
"version": "1.1.0",
"description": "nodeJS CLI to PhoneGap Build",
"keywords": [
"PhoneGap",
Expand Down Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"easy-utf8-table": "^0.2.0",
"pgb-api": "^1.0.5",
"pgb-api": "^1.1.1",
"visualwidth": "^0.1.0"
}
}
17 changes: 17 additions & 0 deletions src/commands/helpers/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const payload = require('./payload')
const merge = require('../../util/misc').merge
const path = require('path')
const fs = require('fs')

module.exports.getData = (repoOrFile) => {
let data = { keys: {} }

if (repoOrFile) {
try {
let file = path.resolve(path.join(repoOrFile, '.pgbrc'))
pgb.opts.variables = merge(JSON.parse(fs.readFileSync(file, 'utf8')), pgb.opts.variables)
pgb.debug(`reading ${file}`)
} catch (e) {
if (e.name === 'SyntaxError') {
throw new Error('invalid json in .pgbrc file')
}
}
}

payload.addVariables(
data, 'hydrates', 'share', 'tag', 'debug', 'private', 'pull', 'zip', 'android-phonegap:android_phonegap_version',
'winphone-phonegap:winphone_phonegap_version', 'ios-phonegap:ios_phonegap_version', 'phonegap:phonegap_version'
Expand All @@ -12,5 +27,7 @@ module.exports.getData = (repoOrFile) => {
data.keys, 'android-key:android', 'windows-key:windows', 'ios-key:ios', 'winphone-key:winphone'
)

data.ignore = pgb.opts.variables.ignore || []

return data
}
3 changes: 2 additions & 1 deletion src/commands/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module.exports = () => {
has.args(1)

let progress = BindProgress()
let repoOrFile = pgb.opts.commands[1]

return pgb.api.addApp(pgb.opts.commands[1], appHelper.getData())
return pgb.api.addApp(repoOrFile, appHelper.getData(repoOrFile))
.then(app => {
pgb.print(`app ${pgb.colours.bold(app.id)} added`)
return wait(app).then((app) => pgb.print({ bare: app.id, json: app }))
Expand Down
3 changes: 2 additions & 1 deletion src/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module.exports = () => {
let id = has.id(pgb.opts.commands[1])

let progress = BindProgress()
let repoOrFile = pgb.opts.commands[2]

return pgb.api.updateApp(id, pgb.opts.commands[2], appHelper.getData())
return pgb.api.updateApp(id, repoOrFile, appHelper.getData(repoOrFile))
.then((app) => {
pgb.print(`app ${pgb.colours.bold(app.id)} updated`)
return wait(app).then((app) =>
Expand Down
6 changes: 5 additions & 1 deletion src/commands/usage/new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Add a new app from the specified repository, directory or file
Properties:

phonegap, android-phonegap, ios-phonegap, winphone-phonegap, hydrates, share,
tag, debug, private, android-key, windows-key, ios-key, winphone-key
tag, debug, private, android-key, windows-key, ios-key, winphone-key, ignore

The ignore flag allows you to specify directories or files that should NOT
be uploaded. It supports the glob format (https://git-scm.com/docs/gitignore)
and can be specified multiple times.

Options:

Expand Down
6 changes: 5 additions & 1 deletion src/commands/usage/update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ directory or file
Properties:

phonegap, android-phonegap, ios-phonegap, winphone-phonegap, hydrates, share,
tag, debug, private, android-key, windows-key, ios-key, winphone-key
tag, debug, private, android-key, windows-key, ios-key, winphone-key, ignore

The ignore flag allows you to specify directories or files that should NOT
be uploaded. It supports the glob format (https://git-scm.com/docs/gitignore)
and can be specified multiple times.

Options:

Expand Down
23 changes: 19 additions & 4 deletions test/commands/helpers/app.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
const app = require('../../../src/commands/helpers/app.js')
const fs = require('fs')

describe('app', () => {
beforeEach(() => {
global.pgb = { opts: { variables: {} } }
})

test('should format platforms', () => {
test('should be a function', () => {
expect(app.getData).toBeInstanceOf(Function)
})

test('should return empty object with no variables', () =>
expect(app.getData()).toEqual({ keys: {} })
expect(app.getData()).toEqual({ keys: {}, ignore: [] })
)

test('should not fail if config file not found', () =>
expect(app.getData('not_found')).toEqual({ keys: {}, ignore: [] })
)

test('should throw error on bad json', () => {
fs.writeFileSync('/.pgbrc', 'not json')
expect(() => app.getData('/')).toThrow('invalid json in .pgbrc file')
})

test('should get variables from file', () => {
fs.writeFileSync('/.pgbrc', '{ "private": true }')
expect(app.getData('/')).toEqual({ 'ignore': [], 'keys': {}, 'private': true })
})

test('should attach whitelisted variables to object', () => {
global.pgb.opts.variables = { share: true, foo: 'bar', 'android-key': 12 }
expect(app.getData()).toEqual({ share: true, keys: { android: 12 } })
global.pgb.opts.variables = { share: true, foo: 'bar', 'android-key': 12, ignore: [ 'node_modules' ] }
expect(app.getData()).toEqual({ share: true, keys: { android: 12 }, ignore: [ 'node_modules' ] })
})
})
2 changes: 1 addition & 1 deletion test/commands/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('new', () => {
.then(command)
.then(() => {
expect(pgb.print).toBeCalledWith('app 12 added')
expect(pgb.api.addApp).toBeCalledWith('org/repo', { 'hydrates': true, 'keys': {} })
expect(pgb.api.addApp).toBeCalledWith('org/repo', { 'hydrates': true, 'keys': {}, ignore: [] })
expect(BindTransfer).toBeCalled()
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('update', () => {
.then(command)
.then(() => {
expect(pgb.print).toBeCalledWith('app 12 updated')
expect(pgb.api.updateApp).toBeCalledWith('12', 'org/repo', { 'hydrates': true, 'keys': {} })
expect(pgb.api.updateApp).toBeCalledWith('12', 'org/repo', { 'hydrates': true, 'keys': {}, ignore: [] })
expect(BindTransfer).toBeCalled()
})
})
Expand Down

0 comments on commit cd3b81f

Please sign in to comment.