Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Dec 17, 2017
1 parent 9cb4c1d commit 1cceeb6
Show file tree
Hide file tree
Showing 14 changed files with 572 additions and 2 deletions.
131 changes: 131 additions & 0 deletions .gitignore
@@ -0,0 +1,131 @@

# Created by https://www.gitignore.io/api/macos,windows,linux,node

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/macos,windows,linux,node

package-lock.json
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
26 changes: 26 additions & 0 deletions .travis.yml
@@ -0,0 +1,26 @@
language: node_js
services:
- docker
notifications:
email: false
node_js:
- 9
- 8

# Trigger a push build on master and greenkeeper branches + PRs build on every branches
# Avoid double build on PRs (See https://github.com/travis-ci/travis-ci/issues/1147)
branches:
only:
- master
- /^greenkeeper.*$/

# Retry install on fail to avoid failing a build on network/disk/external errors
install:
- travis_retry npm install

script:
- npm run test

after_success:
- npm run codecov
- npm run semantic-release
1 change: 1 addition & 0 deletions .yarnrc
@@ -0,0 +1 @@
--install.no-lockfile true
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Contributors

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.
58 changes: 56 additions & 2 deletions README.md
@@ -1,2 +1,56 @@
# changelog
Set of semantic-release plugins for creating or updating a changelog file
# @semantic-release/changelog

Set of [semantic-release](https://github.com/semantic-release/semantic-release) plugins for creating or updating a changelog file.

[![Travis](https://img.shields.io/travis/semantic-release/changelog.svg)](https://travis-ci.org/semantic-release/changelog)
[![Codecov](https://img.shields.io/codecov/c/github/semantic-release/changelog.svg)](https://codecov.io/gh/semantic-release/changelog)
[![Greenkeeper badge](https://badges.greenkeeper.io/semantic-release/changelog.svg)](https://greenkeeper.io/)

## verifyConditions

Verify the `changelogFile` option configuration.

## publish

Create or update the changelog file in the local project repository.

## Configuration

### Options

| Options | Description | Default |
|-----------------|-----------------------------|----------------|
| `changelogFile` | File path of the changelog. | `CHANGELOG.md` |

### Usage

Options can be set within the plugin definition in the `semantic-release` configuration file:

```json
{
"release": {
"publish": [
{
"path": "@semantic-release/changelog",
"changelogFile": "docs/changelog.md",
},
"@semantic-release/git"
]
}
}
```

**It's recommended to use this plugin with the [git](https://github.com/semantic-release/git) plugin, so the changelog file will be committed to the Git repository and available on subsequent builds in order to be updated.**

**When using with the [npm](https://github.com/semantic-release/npm) plugin and/or the [git](https://github.com/semantic-release/git) plugin the `changelog` plugin must be called first in order to create or update the changelog file, so it can be included in the npm package and committed to the Git repository.**

To use with the [npm](https://github.com/semantic-release/npm), [git](https://github.com/semantic-release/git) and [condition-travis](https://github.com/semantic-release/condition-travis) plugins:

```json
{
"release": {
"verifyConditions": ["@semantic-release/condition-travis", "@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git"],
"publish": ["@semantic-release/changelog", "@semantic-release/npm", "@semantic-release/git"]
}
}
```
29 changes: 29 additions & 0 deletions index.js
@@ -0,0 +1,29 @@
const {castArray} = require('lodash');
const verifyChangelog = require('./lib/verify');
const publishChangelog = require('./lib/publish');

let verified;

async function verifyConditions(pluginConfig, {options}) {
// If the Changelog publish plugin is used and has `changelogFile` configured, validate them now in order to prevent any release if the configuration is wrong
if (options.publish) {
const publishPlugin = castArray(options.publish).find(
config => config.path && config.path === '@semantic-release/changelog'
);
if (publishPlugin && publishPlugin.changelogFile) {
pluginConfig.changelogFile = publishPlugin.changelogFile;
}
}
await verifyChangelog(pluginConfig);
verified = true;
}

async function publish(pluginConfig, {nextRelease: {notes}, logger}) {
if (!verified) {
await verifyChangelog(pluginConfig);
verified = true;
}
await publishChangelog(pluginConfig, notes, logger);
}

module.exports = {verifyConditions, publish};
18 changes: 18 additions & 0 deletions lib/publish.js
@@ -0,0 +1,18 @@
const {readFile, writeFile, ensureFile} = require('fs-extra');
const resolveConfig = require('./resolve-config');

module.exports = async (pluginConfig, notes, logger) => {
const {changelogFile} = resolveConfig(pluginConfig);

if (notes) {
await ensureFile(changelogFile);
const currentFile = (await readFile(changelogFile)).toString().trim();

if (currentFile) {
logger.log('Update %s', changelogFile);
} else {
logger.log('Create %s', changelogFile);
}
await writeFile(changelogFile, `${notes.trim()}\n${currentFile ? `\n${currentFile}\n` : ''}`);
}
};
5 changes: 5 additions & 0 deletions lib/resolve-config.js
@@ -0,0 +1,5 @@
const {isUndefined} = require('lodash');

module.exports = ({changelogFile}) => ({
changelogFile: isUndefined(changelogFile) ? 'CHANGELOG.md' : changelogFile,
});
14 changes: 14 additions & 0 deletions lib/verify.js
@@ -0,0 +1,14 @@
const {isString, isUndefined} = require('lodash');
const SemanticReleaseError = require('@semantic-release/error');
const resolveConfig = require('./resolve-config');

module.exports = pluginConfig => {
const {changelogFile} = resolveConfig(pluginConfig);

if (!isUndefined(changelogFile) && !(isString(changelogFile) && changelogFile.trim())) {
throw new SemanticReleaseError(
'The "changelogFile" options, if defined, must be a non empty String.',
'EINVALIDCHANGELOGFILE'
);
}
};

0 comments on commit 1cceeb6

Please sign in to comment.