standard-changelog 3.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.
package/README.md CHANGED
@@ -48,7 +48,7 @@ $ standard-changelog --help
48
48
 
49
49
  ## API
50
50
 
51
- See the [conventional-changelog](https://github.com/ajoslin/conventional-changelog) docs with the angular preset.
51
+ See the [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) docs with the angular preset.
52
52
 
53
53
  ## License
54
54
 
@@ -1,14 +1,32 @@
1
1
  #!/usr/bin/env node
2
- 'use strict'
3
- const addStream = require('add-stream')
4
- const chalk = require('chalk')
5
- const standardChangelog = require('./')
6
- const fs = require('fs')
7
- const meow = require('meow')
8
- const tempfile = require('tempfile')
9
- const resolve = require('path').resolve
10
- const Readable = require('stream').Readable
11
- const rimraf = require('rimraf')
2
+ import { createWriteStream } from 'fs'
3
+ import {
4
+ readFile,
5
+ writeFile
6
+ } from 'fs/promises'
7
+ import pc from 'picocolors'
8
+ import meow from 'meow'
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
+ }
20
+
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
+ })
29
+ }
12
30
 
13
31
  const cli = meow(`
14
32
  Usage
@@ -28,55 +46,56 @@ const cli = meow(`
28
46
  -l, --lerna-package Generate a changelog for a specific lerna package (:pkg-name@1.0.0)
29
47
  --commit-path Generate a changelog scoped to a specific directory
30
48
  `, {
49
+ importMeta: import.meta,
31
50
  booleanDefault: undefined,
32
51
  flags: {
33
52
  infile: {
34
- alias: 'i',
53
+ shortFlag: 'i',
35
54
  default: 'CHANGELOG.md',
36
55
  type: 'string'
37
56
  },
38
57
  help: {
39
- alias: 'h'
58
+ shortFlag: 'h'
40
59
  },
41
60
  outfile: {
42
- alias: 'o',
61
+ shortFlag: 'o',
43
62
  type: 'string'
44
63
  },
45
- 'same-file': {
46
- alias: 's',
64
+ sameFile: {
65
+ shortFlag: 's',
47
66
  default: true,
48
67
  type: 'boolean'
49
68
  },
50
69
  preset: {
51
- alias: 'p',
70
+ shortFlag: 'p',
52
71
  type: 'string'
53
72
  },
54
73
  pkg: {
55
- alias: 'k',
74
+ shortFlag: 'k',
56
75
  type: 'string'
57
76
  },
58
77
  append: {
59
- alias: 'a',
78
+ shortFlag: 'a',
60
79
  type: 'boolean'
61
80
  },
62
- 'release-count': {
63
- alias: 'r',
81
+ releaseCount: {
82
+ shortFlag: 'r',
64
83
  type: 'number'
65
84
  },
66
85
  verbose: {
67
- alias: 'v',
86
+ shortFlag: 'v',
68
87
  type: 'boolean'
69
88
  },
70
89
  context: {
71
- alias: 'c',
90
+ shortFlag: 'c',
72
91
  type: 'string'
73
92
  },
74
- 'first-release': {
75
- alias: 'f',
93
+ firstRelease: {
94
+ shortFlag: 'f',
76
95
  type: 'boolean'
77
96
  },
78
- 'lerna-package': {
79
- alias: 'l',
97
+ lernaPackage: {
98
+ shortFlag: 'l',
80
99
  type: 'string'
81
100
  }
82
101
  }
@@ -94,8 +113,8 @@ const options = {
94
113
  pkg: {
95
114
  path: flags.pkg
96
115
  },
97
- append: append,
98
- releaseCount: releaseCount,
116
+ append,
117
+ releaseCount,
99
118
  lernaPackage: flags.lernaPackage
100
119
  }
101
120
 
@@ -105,61 +124,39 @@ if (flags.verbose) {
105
124
 
106
125
  let templateContext
107
126
 
108
- function outputError (err) {
109
- if (flags.verbose) {
110
- console.error(chalk.grey(err.stack))
111
- } else {
112
- console.error(chalk.red(err.toString()))
113
- }
114
- process.exit(1)
115
- }
116
-
117
127
  try {
118
128
  if (flags.context) {
119
- templateContext = require(resolve(process.cwd(), flags.context))
129
+ templateContext = JSON.parse(await readFile(flags.context, 'utf8'))
120
130
  }
121
131
  } catch (err) {
122
- outputError(err)
132
+ printError(err)
123
133
  }
124
134
 
125
135
  const changelogStream = standardChangelog(options, templateContext, flags.commitPath ? { path: flags.commitPath } : {})
126
- .on('error', function (err) {
127
- outputError(err)
128
- })
129
136
 
130
- standardChangelog.createIfMissing(infile)
131
-
132
- let readStream = null
133
- if (releaseCount !== 0) {
134
- readStream = fs.createReadStream(infile)
135
- .on('error', function (err) {
136
- outputError(err)
137
- })
138
- } else {
139
- readStream = new Readable()
140
- readStream.push(null)
141
- }
137
+ await createIfMissing(infile)
142
138
 
143
139
  if (options.append) {
144
- changelogStream
145
- .pipe(fs.createWriteStream(outfile, {
146
- flags: 'a'
147
- }))
148
- .on('finish', function () {
149
- standardChangelog.checkpoint('appended changes to %s', [outfile])
150
- })
140
+ await waitStreamFinish(
141
+ changelogStream
142
+ .pipe(createWriteStream(outfile, {
143
+ flags: 'a'
144
+ }))
145
+ )
146
+
147
+ checkpoint('appended changes to %s', [outfile])
151
148
  } else {
152
- const tmp = tempfile()
153
-
154
- changelogStream
155
- .pipe(addStream(readStream))
156
- .pipe(fs.createWriteStream(tmp))
157
- .on('finish', function () {
158
- fs.createReadStream(tmp)
159
- .pipe(fs.createWriteStream(outfile))
160
- .on('finish', function () {
161
- standardChangelog.checkpoint('output changes to %s', [outfile])
162
- rimraf.sync(tmp)
163
- })
164
- })
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])
165
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,34 +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 accessSync = require('fs-access').sync
7
- const chalk = require('chalk')
8
- const figures = require('figures')
9
- const sprintf = require('sprintf-js').sprintf
5
+ const { tick } = require('./figures')
10
6
 
11
7
  function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts, writerOpts) {
12
8
  options = options || {}
13
9
  options.config = angular
10
+
14
11
  return conventionalChangelogCore(options, context, gitRawCommitsOpts, parserOpts, writerOpts)
15
12
  }
16
13
 
17
- conventionalChangelog.createIfMissing = function (infile) {
14
+ async function createIfMissing (infile) {
18
15
  try {
19
- accessSync(infile, fs.F_OK)
16
+ await fs.access(infile, fs.F_OK)
20
17
  } catch (err) {
21
18
  if (err.code === 'ENOENT') {
22
- conventionalChangelog.checkpoint('created %s', [infile])
23
- fs.writeFileSync(infile, '\n', 'utf-8')
19
+ checkpoint('created %s', [infile])
20
+ await fs.writeFile(infile, '\n', 'utf-8')
24
21
  }
25
22
  }
26
23
  }
27
24
 
28
- conventionalChangelog.checkpoint = function (msg, args) {
29
- console.info(chalk.green(figures.tick) + ' ' + sprintf(msg, args.map(function (arg) {
30
- return chalk.bold(arg)
31
- })))
25
+ function checkpoint (msg, args) {
26
+ console.info(`${pc.green(tick)} ${msg}`, ...args.map(arg => pc.bold(arg)))
32
27
  }
33
28
 
34
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": "3.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"
@@ -19,26 +19,18 @@
19
19
  ],
20
20
  "license": "MIT",
21
21
  "engines": {
22
- "node": ">=14"
22
+ "node": ">=16"
23
23
  },
24
24
  "files": [
25
25
  "index.js",
26
- "cli.js"
26
+ "figures.js",
27
+ "cli.mjs"
27
28
  ],
28
29
  "dependencies": {
29
- "add-stream": "^1.0.0",
30
- "chalk": "^4.1.2",
31
- "conventional-changelog-angular": "^6.0.0",
32
- "conventional-changelog-core": "^5.0.0",
33
- "figures": "^3.2.0",
34
- "fs-access": "^1.0.1",
35
- "meow": "^8.1.2",
36
- "rimraf": "^3.0.2",
37
- "sprintf-js": "^1.1.2",
38
- "tempfile": "^3.0.0"
30
+ "meow": "^12.0.1",
31
+ "picocolors": "^1.0.0",
32
+ "conventional-changelog-angular": "^7.0.0",
33
+ "conventional-changelog-core": "^7.0.0"
39
34
  },
40
- "bin": "cli.js",
41
- "scripts": {
42
- "test-windows": "echo 'make work on windows'"
43
- }
35
+ "bin": "cli.mjs"
44
36
  }