-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@atls/code-changelog", | ||
"version": "0.0.0", | ||
"license": "BSD-3-Clause", | ||
"type": "module", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": "./src/index.ts" | ||
}, | ||
"main": "src/index.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "yarn library build", | ||
"prepack": "yarn run build", | ||
"postpack": "rm -rf dist" | ||
}, | ||
"dependencies": { | ||
"@types/conventional-changelog": "3.1.5", | ||
"conventional-changelog": "6.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { Options } from 'conventional-changelog' | ||
|
||
import { readFileSync } from 'node:fs' | ||
import { writeFileSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
|
||
import conventionalChangelog from 'conventional-changelog' | ||
|
||
interface GenerateOptions { | ||
packageName: string | ||
path: string | ||
debug?: boolean | ||
tagPrefix?: string | ||
version?: string | ||
file?: boolean | ||
releaseCount?: number | ||
} | ||
|
||
export class Changelog { | ||
async generate({ | ||
path, | ||
packageName, | ||
debug, | ||
tagPrefix, | ||
file, | ||
releaseCount, | ||
}: GenerateOptions): Promise<string> { | ||
const config: Options = { | ||
lernaPackage: `${packageName}`, | ||
tagPrefix, | ||
debug: debug ? console.debug : undefined, | ||
preset: 'angular', | ||
Check warning on line 32 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(no-console): Unexpected console statement.
Raw output
|
||
append: true, | ||
releaseCount, | ||
pkg: { | ||
path: join(path, 'package.json'), | ||
}, | ||
config: { | ||
gitRawCommitsOpts: { | ||
path, | ||
}, | ||
}, | ||
} | ||
|
||
if (file) { | ||
return await this.generateToFile(config, path) | ||
} | ||
Check failure on line 47 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(no-return-await): Redundant use of `await` on a return value.
Raw output
|
||
|
||
return this.generateToStdOut(config) | ||
} | ||
|
||
private generateToStdOut(config: Options): string { | ||
const changelogStream = conventionalChangelog(config) | ||
|
||
let newChangelog = '' | ||
|
||
changelogStream.on('data', (record) => { | ||
newChangelog += record.toString() | ||
}) | ||
Check failure on line 59 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(@typescript-eslint/no-unsafe-call): Unsafe call of a(n) `any` typed value.
Raw output
|
||
|
||
return newChangelog | ||
} | ||
|
||
private async generateToFile(config: Options, path: string): Promise<string> { | ||
const outFile = join(path, 'CHANGELOG.md') | ||
|
||
let newChangelog = '' | ||
|
||
const changelogStream = conventionalChangelog(config) | ||
changelogStream.on('data', (record) => { | ||
newChangelog += record.toString() | ||
}) | ||
Check failure on line 72 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(@typescript-eslint/no-unsafe-call): Unsafe call of a(n) `any` typed value.
Raw output
|
||
|
||
changelogStream.on('end', () => { | ||
let existingData = '' | ||
|
||
try { | ||
existingData = readFileSync(outFile, 'utf8') | ||
} catch (error) { | ||
Check failure on line 79 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(n/no-sync): Unexpected sync method: 'readFileSync'.
Raw output
|
||
if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') throw error | ||
} | ||
|
||
let updatedData = newChangelog | ||
if (existingData) { | ||
updatedData += `\n${existingData}` | ||
} | ||
writeFileSync(outFile, updatedData) | ||
}) | ||
Check failure on line 88 in code/code-changelog/src/changelog.ts GitHub Actions / Lint(n/no-sync): Unexpected sync method: 'writeFileSync'.
Raw output
|
||
|
||
return '' | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './changelog.js' |