Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ os: linux
stages:
- test
- name: deploy
if: branch = master AND type != pull_request AND tag IS blank
if: (branch = "master" OR branch = "master-lts") AND type != pull_request AND tag IS blank
jobs:
include:
- stage: deploy
script:
- yarn run travis-ssh
- 'git remote set-url origin git@github.com:nativecode-dev/nofrills.git'
- git checkout master
- git checkout $TRAVIS_BRANCH
- 'npm set //registry.npmjs.org/:_authToken "$NPM_TOKEN"'
- yarn run push
after_failure:
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
],
"stream": true,
"useWorkspaces": true,
"version": "2.0.0"
"version": "2.0.1"
}
2 changes: 1 addition & 1 deletion packages/smorgasbord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "@nofrills/smorgasbord",
"private": false,
"types": "./lib/index.d.ts",
"version": "2.0.0",
"version": "2.0.1",
"bugs": {
"url": "https://github.com/nativecode-dev/nofrills/issues"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/smorgasbord/src/Strings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ describe('when using string extensions', () => {
expect(Strings.format(message, ...args)).to.equal(expected)
})

it('should format based on object keys', () => {
const expected = 'The quick brown fox jumped over the test, because test.'
const message = 'The {q} brown fox jumped over the {t}, because {t}.'
const args = { q: 'quick', t: 'test' }
expect(Strings.formatObject(message, args)).to.equal(expected)
})

})

})
22 changes: 16 additions & 6 deletions packages/smorgasbord/src/Strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ const logger: Lincoln = Logger.extend('strings')
export const Strings: Dictionary<any> = {
format: (message: string, ...args: any[]): string => {
logger.debug('format', message, args)
for (let index: number = 0; index < args.length; index++) {
const regex = new RegExp('\\{' + index + '\\}', 'gm')
message = message.replace(regex, args[index])
}
return message
}

return args.reduce((previous, current, index) => {
const regex = new RegExp(`\\{${index}\\}`, 'gm')
return previous.replace(regex, current)
}, message)
},

formatObject: (message: string, object: Dictionary<string>): string => {
const keys = Object.keys(object)
logger.debug('formatObject', message, keys)

return keys.reduce((previous, current, index) => {
const regex = new RegExp(`\\{${current}\\}`, 'igm')
return previous.replace(regex, object[current])
}, message)
},
}
12 changes: 6 additions & 6 deletions push.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

export RELEASE=${RELEASE:="prerelease"}
export TRAVIS_BRANCH=${TRAVIS_BRANCH:="invalid"}
RELEASE=${RELEASE:="prerelease"}
TRAVIS_BRANCH=${TRAVIS_BRANCH:="invalid"}

if [ $TRAVIS_BRANCH = "master" ] && [ $TRAVIS_EVENT_TYPE = "push" ]; then
export RELEASE=major
RELEASE=minor
lerna publish --allow-branch "master" --cd-version $RELEASE --message "$TRAVIS_BRANCH:$RELEASE:%s"
fi

if [ $TRAVIS_BRANCH = "master-lts" ] && [ $TRAVIS_EVENT_TYPE = "push" ]; then
export RELEASE=minor
RELEASE=patch
lerna publish --allow-branch "master-lts" --cd-version $RELEASE --message "$TRAVIS_BRANCH:$RELEASE:%s"
fi

lerna publish --cd-version $RELEASE --message "$TRAVIS_BRANCH:$RELEASE:%s"