Skip to content

Commit

Permalink
✨ Add Cargo preset (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamaq01 committed Dec 16, 2020
1 parent d2ee43d commit ceab8dc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/gitmoji-changelog-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"semver": "^5.6.0",
"semver-compare": "^1.0.0",
"simple-git": "^1.113.0",
"toml": "^3.0.0",
"yargs": "^12.0.1"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gitmoji-changelog-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ yargs
}, execute('update'))

.option('format', { default: 'markdown', desc: 'changelog format (markdown, json)' })
.option('preset', { default: 'node', desc: 'define preset mode', choices: ['node', 'generic', 'maven'] })
.option('preset', { default: 'node', desc: 'define preset mode', choices: ['node', 'generic', 'maven', 'cargo'] })
.option('output', { desc: 'output changelog file' })
.option('group-similar-commits', { desc: '[⚗️ - beta] try to group similar commits', default: false })
.option('author', { default: false, desc: 'add the author in changelog lines' })
Expand Down
29 changes: 29 additions & 0 deletions packages/gitmoji-changelog-cli/src/presets/cargo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const toml = require('toml')
const fs = require('fs')

module.exports = async () => {
try {
const cargoPromise = new Promise((resolve, reject) => {
try {
resolve(toml.parse(fs.readFileSync('Cargo.toml', 'utf-8')))
} catch (err) {
reject(err)
}
})

const {
package: {
name,
version,
description,
},
} = await cargoPromise
return {
name: name,
version: version,
description: description,
}
} catch (e) {
return null
}
}
9 changes: 9 additions & 0 deletions packages/gitmoji-changelog-documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ _This workflow is related to the `node` preset but can be adapted to your own te
- node (default preset)
- generic
- maven
- cargo

Didn't see the preset you need in the list? Consider adding it. Presets are stored in a [presets](https://github.com/frinyvonnick/gitmoji-changelog/blob/master/packages/gitmoji-changelog-cli/src/presets) folder in the `cli` package.

Expand Down Expand Up @@ -147,6 +148,14 @@ The maven preset looks for 4 properties in you `pom.xml`:
- version
- description

#### Cargo

The cargo preset looks for 3 properties in your `Cargo.toml`:

- name
- version
- description

### Add a preset

A preset need to export a function. When called this function must return three mandatory information about the project in which the cli has been called. The name of the project, a short description of it and its current version.
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6873,6 +6873,11 @@ toidentifier@1.0.0:
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==

toml@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==

tough-cookie@^2.3.3, tough-cookie@^2.3.4:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"
Expand Down

0 comments on commit ceab8dc

Please sign in to comment.