standard-changelog 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/cli.mjs +45 -59
  2. package/figures.js +19 -0
  3. package/index.js +12 -14
  4. package/package.json +4 -7
package/cli.mjs CHANGED
@@ -1,23 +1,31 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- createReadStream,
4
- createWriteStream
5
- } from 'fs'
2
+ import { createWriteStream } from 'fs'
6
3
  import {
7
4
  readFile,
8
- rm
5
+ writeFile
9
6
  } from 'fs/promises'
10
- import { resolve } from 'path'
11
- import { pathToFileURL } from 'url'
12
- import { Readable } from 'stream'
13
- import addStream from 'add-stream'
14
7
  import pc from 'picocolors'
15
- import tempfile from 'tempfile'
16
8
  import meow from 'meow'
17
- import standardChangelog from './index.js'
9
+ import standardChangelog, {
10
+ createIfMissing,
11
+ checkpoint
12
+ } from './index.js'
13
+
14
+ function printError (err) {
15
+ if (flags.verbose) {
16
+ console.error(pc.gray(err.stack))
17
+ } else {
18
+ console.error(pc.red(err.toString()))
19
+ }
18
20
 
19
- function relativeResolve (filePath) {
20
- return pathToFileURL(resolve(process.cwd(), filePath))
21
+ process.exit(1)
22
+ }
23
+
24
+ function waitStreamFinish (stream) {
25
+ return new Promise((resolve) => {
26
+ stream.on('finish', resolve)
27
+ stream.on('error', printError)
28
+ })
21
29
  }
22
30
 
23
31
  const cli = meow(`
@@ -116,61 +124,39 @@ if (flags.verbose) {
116
124
 
117
125
  let templateContext
118
126
 
119
- function outputError (err) {
120
- if (flags.verbose) {
121
- console.error(pc.gray(err.stack))
122
- } else {
123
- console.error(pc.red(err.toString()))
124
- }
125
- process.exit(1)
126
- }
127
-
128
127
  try {
129
128
  if (flags.context) {
130
- templateContext = JSON.parse(await readFile(relativeResolve(flags.context), 'utf8'))
129
+ templateContext = JSON.parse(await readFile(flags.context, 'utf8'))
131
130
  }
132
131
  } catch (err) {
133
- outputError(err)
132
+ printError(err)
134
133
  }
135
134
 
136
135
  const changelogStream = standardChangelog(options, templateContext, flags.commitPath ? { path: flags.commitPath } : {})
137
- .on('error', (err) => {
138
- outputError(err)
139
- })
140
-
141
- standardChangelog.createIfMissing(infile)
142
136
 
143
- let readStream = null
144
- if (releaseCount !== 0) {
145
- readStream = createReadStream(infile)
146
- .on('error', (err) => {
147
- outputError(err)
148
- })
149
- } else {
150
- readStream = new Readable()
151
- readStream.push(null)
152
- }
137
+ await createIfMissing(infile)
153
138
 
154
139
  if (options.append) {
155
- changelogStream
156
- .pipe(createWriteStream(outfile, {
157
- flags: 'a'
158
- }))
159
- .on('finish', () => {
160
- standardChangelog.checkpoint('appended changes to %s', [outfile])
161
- })
140
+ await waitStreamFinish(
141
+ changelogStream
142
+ .pipe(createWriteStream(outfile, {
143
+ flags: 'a'
144
+ }))
145
+ )
146
+
147
+ checkpoint('appended changes to %s', [outfile])
162
148
  } else {
163
- const tmp = tempfile()
164
-
165
- changelogStream
166
- .pipe(addStream(readStream))
167
- .pipe(createWriteStream(tmp))
168
- .on('finish', () => {
169
- createReadStream(tmp)
170
- .pipe(createWriteStream(outfile))
171
- .on('finish', () => {
172
- standardChangelog.checkpoint('output changes to %s', [outfile])
173
- rm(tmp, { recursive: true })
174
- })
175
- })
149
+ let changelog = ''
150
+
151
+ for await (const chunk of changelogStream) {
152
+ changelog += chunk.toString()
153
+ }
154
+
155
+ if (releaseCount !== 0) {
156
+ changelog += await readFile(infile, 'utf8')
157
+ }
158
+
159
+ await writeFile(outfile, changelog)
160
+
161
+ checkpoint('output changes to %s', [outfile])
176
162
  }
package/figures.js ADDED
@@ -0,0 +1,19 @@
1
+ function isUnicodeSupported () {
2
+ if (process.platform !== 'win32') {
3
+ return process.env.TERM !== 'linux' // Linux console (kernel)
4
+ }
5
+
6
+ return Boolean(process.env.CI) ||
7
+ Boolean(process.env.WT_SESSION) || // Windows Terminal
8
+ Boolean(process.env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
9
+ process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
10
+ process.env.TERM_PROGRAM === 'Terminus-Sublime' ||
11
+ process.env.TERM_PROGRAM === 'vscode' ||
12
+ process.env.TERM === 'xterm-256color' ||
13
+ process.env.TERM === 'alacritty' ||
14
+ process.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'
15
+ }
16
+
17
+ const tick = isUnicodeSupported() ? '✔' : '√'
18
+
19
+ exports.tick = tick
package/index.js CHANGED
@@ -1,33 +1,31 @@
1
- 'use strict'
2
-
1
+ const fs = require('fs/promises')
2
+ const pc = require('picocolors')
3
3
  const conventionalChangelogCore = require('conventional-changelog-core')
4
4
  const angular = require('conventional-changelog-angular')
5
- const fs = require('fs')
6
- const pc = require('picocolors')
7
- const figures = require('figures')
8
- const sprintf = require('sprintf-js').sprintf
5
+ const { tick } = require('./figures')
9
6
 
10
7
  function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts, writerOpts) {
11
8
  options = options || {}
12
9
  options.config = angular
10
+
13
11
  return conventionalChangelogCore(options, context, gitRawCommitsOpts, parserOpts, writerOpts)
14
12
  }
15
13
 
16
- conventionalChangelog.createIfMissing = function (infile) {
14
+ async function createIfMissing (infile) {
17
15
  try {
18
- fs.accessSync(infile, fs.F_OK)
16
+ await fs.access(infile, fs.F_OK)
19
17
  } catch (err) {
20
18
  if (err.code === 'ENOENT') {
21
- conventionalChangelog.checkpoint('created %s', [infile])
22
- fs.writeFileSync(infile, '\n', 'utf-8')
19
+ checkpoint('created %s', [infile])
20
+ await fs.writeFile(infile, '\n', 'utf-8')
23
21
  }
24
22
  }
25
23
  }
26
24
 
27
- conventionalChangelog.checkpoint = function (msg, args) {
28
- console.info(pc.green(figures.tick) + ' ' + sprintf(msg, args.map(function (arg) {
29
- return pc.bold(arg)
30
- })))
25
+ function checkpoint (msg, args) {
26
+ console.info(`${pc.green(tick)} ${msg}`, ...args.map(arg => pc.bold(arg)))
31
27
  }
32
28
 
33
29
  module.exports = conventionalChangelog
30
+ module.exports.createIfMissing = createIfMissing
31
+ module.exports.checkpoint = checkpoint
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standard-changelog",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Generate a changelog from git metadata with Angular commit convention",
5
5
  "bugs": {
6
6
  "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
@@ -23,17 +23,14 @@
23
23
  },
24
24
  "files": [
25
25
  "index.js",
26
+ "figures.js",
26
27
  "cli.mjs"
27
28
  ],
28
29
  "dependencies": {
29
- "add-stream": "^1.0.0",
30
- "figures": "^3.2.0",
31
30
  "meow": "^12.0.1",
32
31
  "picocolors": "^1.0.0",
33
- "sprintf-js": "^1.1.2",
34
- "tempfile": "^5.0.0",
35
- "conventional-changelog-core": "^6.0.0",
36
- "conventional-changelog-angular": "^7.0.0"
32
+ "conventional-changelog-angular": "^7.0.0",
33
+ "conventional-changelog-core": "^7.0.0"
37
34
  },
38
35
  "bin": "cli.mjs"
39
36
  }