Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code-changelog): init #467

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
519 changes: 519 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ packageExtensions:
'ink-link@*':
dependencies:
react: '*'
'@conventional-changelog/git-client@*':
dependencies:
conventional-changelog-writer: '*'
conventional-commits-parser: '*'
conventional-commits-filter: '*'

plugins:
- path: yarn/plugin-pnp-patch/bundles/@yarnpkg/plugin-pnp-patch.cjs
Expand Down
36 changes: 36 additions & 0 deletions code/code-changelog/package.json
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"
}
}
92 changes: 92 additions & 0 deletions code/code-changelog/src/changelog.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

View workflow job for this annotation

GitHub Actions / Lint

(no-console): Unexpected console statement.

Unexpected console statement.
Raw output
  29 |       lernaPackage: `${packageName}`,
  30 |       tagPrefix,
> 31 |       debug: debug ? console.debug : undefined,
     |                      ^
  32 |       preset: 'angular',
  33 |       append: true,
  34 |       releaseCount,
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

View workflow job for this annotation

GitHub Actions / Lint

(no-return-await): Redundant use of `await` on a return value.

Redundant use of `await` on a return value.
Raw output
  44 |
  45 |     if (file) {
> 46 |       return await this.generateToFile(config, path)
     |              ^
  47 |     }
  48 |
  49 |     return this.generateToStdOut(config)

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

View workflow job for this annotation

GitHub Actions / Lint

(@typescript-eslint/no-unsafe-call): Unsafe call of a(n) `any` typed value.

Unsafe call of a(n) `any` typed value.
Raw output
  56 |
  57 |     changelogStream.on('data', (record) => {
> 58 |       newChangelog += record.toString()
     |                       ^
  59 |     })
  60 |
  61 |     return newChangelog

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

View workflow job for this annotation

GitHub Actions / Lint

(@typescript-eslint/no-unsafe-call): Unsafe call of a(n) `any` typed value.

Unsafe call of a(n) `any` typed value.
Raw output
  69 |     const changelogStream = conventionalChangelog(config)
  70 |     changelogStream.on('data', (record) => {
> 71 |       newChangelog += record.toString()
     |                       ^
  72 |     })
  73 |
  74 |     changelogStream.on('end', () => {

changelogStream.on('end', () => {
let existingData = ''

try {
existingData = readFileSync(outFile, 'utf8')
} catch (error) {

Check failure on line 79 in code/code-changelog/src/changelog.ts

View workflow job for this annotation

GitHub Actions / Lint

(n/no-sync): Unexpected sync method: 'readFileSync'.

Unexpected sync method: 'readFileSync'.
Raw output
  76 |
  77 |       try {
> 78 |         existingData = readFileSync(outFile, 'utf8')
     |                        ^
  79 |       } catch (error) {
  80 |         if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') throw error
  81 |       }
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

View workflow job for this annotation

GitHub Actions / Lint

(n/no-sync): Unexpected sync method: 'writeFileSync'.

Unexpected sync method: 'writeFileSync'.
Raw output
  85 |         updatedData += `\n${existingData}`
  86 |       }
> 87 |       writeFileSync(outFile, updatedData)
     |       ^
  88 |     })
  89 |
  90 |     return ''

return ''
}
}
1 change: 1 addition & 0 deletions code/code-changelog/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './changelog.js'
4 changes: 2 additions & 2 deletions code/code-commit/src/commit.linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { test } from 'node:test'
import { CommitLinter } from './commit.linter.js'

test('should lint valid commit', async () => {
const { valid } = await new CommitLinter().lint('feat(common): init')
const { valid } = await new CommitLinter({}).lint('feat(common): init')

assert.ok(valid)
})

test('should lint invalid commit', async () => {
const { valid, errors } = await new CommitLinter().lint('invalid')
const { valid, errors } = await new CommitLinter({}).lint('invalid')

assert.ok(!valid)
assert.equal(errors.at(0)?.name, 'subject-empty')
Expand Down
Loading
Loading