Skip to content

Commit

Permalink
feat: add npmpage + an example on how to use the library
Browse files Browse the repository at this point in the history
  • Loading branch information
ZimGil committed Apr 2, 2019
2 parents b6883f1 + 90cca6f commit 7ccb0ea
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 17 deletions.
84 changes: 68 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ Install this package as a dev dependency:
npm install --save-dev @kibibit/announce-it
```

We also recommend adding a dedicated script in your `package.json` file:
```js
// ...
"scripts": {
// ...
"announce": "announce-it"
}
// ...
```

## How to use
Intended to run after a new release in your continues integration

Expand All @@ -49,29 +39,91 @@ You have to create a [Developer Account on Twitter](https://developer.twitter.co
* Create an App
* From your apps list go to your app Details
* Select the `Keys and tokens` tab
* Use these Token as environment variables in this fashion:
* You'll need all 4 variables available in that page:
* API key
* API secret key
* Access token
* Access token secret


### As a command line tool
- You can add a dedicated script in your `package.json` file:
```js
// ...
"scripts": {
// ...
"announce": "announce-it"
}
// ...
```
- If installed as a project dependency, you can run with npx:
```bash
# should be ran inside your project
# npx
npx announce-it

# directly
./node_modules/.bin/announce-it
```
- If installed globally, you can run it from within any node package with
the correct setup

### As a node module

```typescript
import { KbAnnounceIt, PackageDetails } from '@kibibit/announce-it';

const announceIt = new KbAnnounceIt({
accessTokenKey: 'TWITTER_ACCESS_KEY',
accessTokenSecret: 'TWITTER_ACCESS_SECRET',
consumerKey: 'TWITTER_CONSUMER_KEY',
consumerSecret: 'TWITTER_CONSUMER_SECRET'
});

const myPackage: PackageDetails = require('./package');

// get generated tweet
const tweet: string = announceIt.generateTweet(myPackage);

console.log('going to tweet: ', tweet);

// publish tweet to twitter
announceIt.announceRelease(myPackage);

```

* Use these Token as environment variables in this fashion:
* `CONSUMER_KEY` = API key
* `CONSUMER_SECRET` = API secret key
* `ACCESS_TOKEN_KEY` = Access token
* `ACCESS_TOKEN_SECRET` = Access token secret


### Using Templates
### Defining your Templates
Inside your `package.json` file, add an `announcements` object with `tweet` property.

You can then create your own tweet message template that will be posted to twitter.

```javascript
{
"name": "my-package",
"version": "2.4.3",
// ...
"announcements": {
"tweet": "Version <%= version %> of <%= package %> is live! <%= npmpage %>"
},
}
```

The tweet template is generated with [Lodash template](https://lodash.com/docs/4.17.11#template).

You can use these variables:
* Package name: `<%= package %>`
* Version number: `<%= version %>`
* Package description: `<%= description %>`
* Package author: `<%= author %>`
* Homepage link: `<%= homepage%>`

#### Example:
`Version <%= version %> of <%= package %> is live! check it out <%=homepage %>`
* Homepage link: `<%= homepage %>`
* Package page on npm: `<%= npmpage %>`

## Contributing

Expand Down
18 changes: 18 additions & 0 deletions examples/as-a-node-module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { KbAnnounceIt, PackageDetails } from '@kibibit/announce-it';

const announceIt = new KbAnnounceIt({
accessTokenKey: 'TWITTER_ACCESS_KEY',
accessTokenSecret: 'TWITTER_ACCESS_SECRET',
consumerKey: 'TWITTER_CONSUMER_KEY',
consumerSecret: 'TWITTER_CONSUMER_SECRET'
});

const myPackage: PackageDetails = require('./package');

// get generated tweet
const tweet: string = announceIt.generateTweet(myPackage);

console.log('going to publish this tweet!', tweet);

// publish tweet to twitter
announceIt.announceRelease(myPackage);
17 changes: 17 additions & 0 deletions examples/as-a-node-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "as-a-node-module",
"version": "1.0.0",
"description": "this is an example for using announce it as a node module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "k1b1b0t",
"license": "ISC",
"announcements": {
"tweet": "Version <%= version %> of <%= package %> is live! check it out <%=homepage %>"
},
"dependencies": {
"@kibibit/announce-it": "file:../.."
}
}
3 changes: 2 additions & 1 deletion src/announce-it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export class KbAnnounceIt {
version: packageDetails.version,
description: packageDetails.description,
author: packageDetails.author,
homepage: packageDetails.homepage
homepage: packageDetails.homepage,
npmpage: `https://www.npmjs.com/package/${ packageDetails.name }/v/${ packageDetails.version }`
});
}
}

0 comments on commit 7ccb0ea

Please sign in to comment.