Skip to content

Commit

Permalink
🔥 init
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Mao authored and stevemao committed Aug 12, 2015
0 parents commit 9f46d78
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: objective-c
before_script:
- xo
script: 'curl -s https://raw.githubusercontent.com/atom/ci/master/build-package.sh | sh'
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0 - First Release
* Every feature added
* Every bug fixed
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2015 <Your name here>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Atom conventional-changelog package

> Generate a changelog or make a new GitHub release from git metadata.
![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif)

## Install

```
$ apm install conventional-changelog
```

Or Settings → Install → Search for `conventional-changelog`


## License

MIT © [Steve Mao](https://github.com/stevemao)
103 changes: 103 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use babel'
import conventionalChangelog from 'conventional-changelog';
import conventionalCommitsDetector from 'conventional-commits-detector';
import conventionalGithubReleaser from 'conventional-github-releaser';
import concatStream from 'concat-stream';
import loophole from 'loophole';
import path from 'path';

function chdirToRepo() {
const editor = atom.workspace.getActiveTextEditor();

if (!editor) {
return;
}

const file = editor.getURI();

// hack
process.chdir(path.dirname(file));
}

function getConfigs() {
return [{
preset: atom.config.get('conventional-changelog.preset'),
append: atom.config.get('conventional-changelog.append'),
releaseCount: atom.config.get('conventional-changelog.releaseCount')
}];
}

function changelog() {
chdirToRepo();

const editor = atom.workspace.getActiveTextEditor();
let text = editor.getText();

loophole.allowUnsafeNewFunctionAsync((done) => {
let configs = getConfigs();
let opts = configs[0];

return conventionalChangelog(...configs)
.on('error', function(err) {
err.message = 'Error in conventional-changelog: ' + err.message;
console.error(err);
atom.beep();
})
.pipe(concatStream((data) => {
data = data.toString();

if (opts.releaseCount === 0) {
text = data;
} else if (opts.append) {
text = text + data;
} else if (!opts.append) {
text = data + text;
}

editor.setText(text);
done();
}));
});
}

function githubRelease() {
chdirToRepo();

loophole.allowUnsafeNewFunctionAsync((done) => {
return conventionalGithubReleaser({
type: 'token'
}, ...getConfigs(), (err, data) => {
if (err) {
err.message = 'Error in conventional-github-releaser: ' + err.message;
console.error(err);
atom.beep();
}

console.log(data);
done();
});
});
}

export let config = {
preset: {
type: 'string',
description: 'A set of options of a popular project so you don\'t have to define everything in options, context, gitRawCommitsOpts, parserOpts or writerOpts manually.',
default: 'angular'
},
append: {
type: 'boolean',
description: 'Should the log be appended.',
default: false
},
releaseCount: {
type: 'number',
description: 'How many releases of changelog you want to generate.',
default: 1
}
};

export let activate = () => {
atom.commands.add('atom-workspace', 'conventional-changelog:changelog', changelog);
atom.commands.add('atom-workspace', 'conventional-changelog:githubRelease', githubRelease);
};
12 changes: 12 additions & 0 deletions keymaps/conventional-changelog.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
# execute.
#
# Below is a basic keybinding which registers on all platforms by applying to
# the root workspace element.

# For more detailed documentation see
# https://atom.io/docs/latest/behind-atom-keymaps-in-depth
'atom-workspace':
'ctrl-alt-c': 'conventional-changelog:changelog'
'ctrl-alt-g': 'conventional-changelog:githubRelease'
19 changes: 19 additions & 0 deletions menus/conventional-changelog.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details
'menu': [
{
'label': 'Packages'
'submenu': [
'label': 'Conventional Changelog'
'submenu': [
{
'label': 'Generate Changelog'
'command': 'conventional-changelog:changelog'
}
{
'label': 'Make GitHub release(s)'
'command': 'conventional-changelog:githubRelease'
}
]
]
}
]
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "conventional-changelog",
"version": "0.0.0",
"description": "Generate a changelog or make a new GitHub release from git metadata",
"keywords": [
"conventional-github-releaser",
"github",
"gh",
"release",
"releases",
"conventional-changelog",
"conventional",
"changelog",
"log"
],
"private": true,
"repository": "https://github.com/stevemao/atom-conventional-changelog",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {
"concat-stream": "^1.5.0",
"conventional-changelog": "^0.3.0",
"conventional-commits-detector": "^0.1.0",
"conventional-github-releaser": "^0.3.0",
"loophole": "git://github.com/stevemao/loophole.git"
}
}
62 changes: 62 additions & 0 deletions spec/conventional-changelog-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
AtomConventionalChangelog = require '../'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.

describe "AtomConventionalChangelog", ->
[workspaceElement, activationPromise] = []

beforeEach ->
workspaceElement = atom.views.getView(atom.workspace)
activationPromise = atom.packages.activatePackage('atom-conventional-changelog')

describe "when the atom-conventional-changelog:toggle event is triggered", ->
it "hides and shows the modal panel", ->
# Before the activation event the view is not on the DOM, and no panel
# has been created
expect(workspaceElement.querySelector('.atom-conventional-changelog')).not.toExist()

# This is an activation event, triggering it will cause the package to be
# activated.
atom.commands.dispatch workspaceElement, 'atom-conventional-changelog:toggle'

waitsForPromise ->
activationPromise

runs ->
expect(workspaceElement.querySelector('.atom-conventional-changelog')).toExist()

atomConventionalChangelogElement = workspaceElement.querySelector('.atom-conventional-changelog')
expect(atomConventionalChangelogElement).toExist()

atomConventionalChangelogPanel = atom.workspace.panelForItem(atomConventionalChangelogElement)
expect(atomConventionalChangelogPanel.isVisible()).toBe true
atom.commands.dispatch workspaceElement, 'atom-conventional-changelog:toggle'
expect(atomConventionalChangelogPanel.isVisible()).toBe false

it "hides and shows the view", ->
# This test shows you an integration test testing at the view level.

# Attaching the workspaceElement to the DOM is required to allow the
# `toBeVisible()` matchers to work. Anything testing visibility or focus
# requires that the workspaceElement is on the DOM. Tests that attach the
# workspaceElement to the DOM are generally slower than those off DOM.
jasmine.attachToDOM(workspaceElement)

expect(workspaceElement.querySelector('.atom-conventional-changelog')).not.toExist()

# This is an activation event, triggering it causes the package to be
# activated.
atom.commands.dispatch workspaceElement, 'atom-conventional-changelog:toggle'

waitsForPromise ->
activationPromise

runs ->
# Now we can test for view visibility
atomConventionalChangelogElement = workspaceElement.querySelector('.atom-conventional-changelog')
expect(atomConventionalChangelogElement).toBeVisible()
atom.commands.dispatch workspaceElement, 'atom-conventional-changelog:toggle'
expect(atomConventionalChangelogElement).not.toBeVisible()

0 comments on commit 9f46d78

Please sign in to comment.