Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
feat: initial implementation
  • Loading branch information
Michael M committed Feb 19, 2022
1 parent c0730c9 commit fac48dd
Show file tree
Hide file tree
Showing 20 changed files with 3,515 additions and 594 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2022 Public JS
Copyright 2018 Conventional Changelog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getJestProjects } = require('@nrwl/jest');

module.exports = {
projects: getJestProjects(),
projects: getJestProjects(),
};
3,609 changes: 3,046 additions & 563 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
},
"private": true,
"dependencies": {
"conventional-changelog": "^3.0.0",
"dateformat": "^4.6.0",
"git-semver-tags": "^4.0.0",
"got": "^11.0.0",
"meow": "^9.0.0",
"q": "^1.5.1",
"semver": "^7.0.0",
"semver-regex": "^3.0.0",
"standard-version": "^9.0.0",
"through2": "^4.0.2",
"tslib": "^2.0.0"
},
"devDependencies": {
Expand All @@ -31,8 +41,14 @@
"@nrwl/nx-cloud": "latest",
"@nrwl/tao": "13.8.3",
"@nrwl/workspace": "13.8.3",
"@types/conventional-changelog": "^3.1.1",
"@types/dateformat": "^5.0.0",
"@types/git-semver-tags": "^4.1.1",
"@types/jest": "27.0.2",
"@types/node": "16.11.7",
"@types/q": "^1.5.5",
"@types/semver": "^7.3.9",
"@types/through2": "^2.0.36",
"@typescript-eslint/eslint-plugin": "~5.10.0",
"@typescript-eslint/parser": "~5.10.0",
"eslint": "~8.7.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/cc-github-releaser/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022 Public JS
Copyright 2018 Conventional Changelog

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 3 additions & 5 deletions packages/cc-github-releaser/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# cc-github-releaser
# @public-js/cc-github-releaser

This library was generated with [Nx](https://nx.dev).
---

## Running unit tests

Run `nx test cc-github-releaser` to execute the unit tests via [Jest](https://jestjs.io).
TODO: add project description
24 changes: 12 additions & 12 deletions packages/cc-github-releaser/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = {
displayName: 'cc-github-releaser',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
displayName: 'cc-github-releaser',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/cc-github-releaser',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/cc-github-releaser',
};
42 changes: 41 additions & 1 deletion packages/cc-github-releaser/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
{
"name": "@public-js/cc-github-releaser",
"version": "0.0.0"
"version": "0.0.0",
"description": "",
"bin": {
"cc-github-releaser": "./src/cc-github-releaser.js"
},
"dependencies": {
"conventional-changelog": ">=2.0.0 <4.0.0",
"dateformat": "^4.0.0",
"git-semver-tags": ">=2.0.0 <5.0.0",
"got": ">=8.0.0 <12.0.0",
"meow": ">=7.0.0 <10.0.0",
"q": "^1.4.1",
"semver": ">=5.0.0 <8.0.0",
"semver-regex": ">=2.0.0 <4.0.0",
"through2": ">=2.0.0 <5.0.0"
},
"peerDependencies": {
"standard-version": ">=8.0.0"
},
"peerDependenciesMeta": {
"standard-version": {
"optional": true
}
},
"license": "MIT",
"author": "Public JS <public-js@muffin.blue> (https://github.com/public-js/public-js)",
"repository": "https://github.com/public-js/cc-github-releaser",
"homepage": "https://github.com/public-js/cc-github-releaser",
"keywords": [
"conventional-github-releaser",
"github",
"release",
"releases",
"conventional-changelog",
"conventional",
"changelog",
"log"
],
"engines": {
"node": ">=10.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/cc-github-releaser/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"outputPath": "dist/packages/cc-github-releaser",
"tsConfig": "packages/cc-github-releaser/tsconfig.lib.json",
"packageJson": "packages/cc-github-releaser/package.json",
"main": "packages/cc-github-releaser/src/index.ts",
"main": "packages/cc-github-releaser/src/cc-github-releaser.ts",
"assets": ["packages/cc-github-releaser/README.md", "LICENSE"]
}
},
Expand Down
7 changes: 7 additions & 0 deletions packages/cc-github-releaser/src/_/spec-only.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { testFn } from './spec-only';

describe('spec only', () => {
it('testFn should return null', () => {
expect(testFn()).toBeNull();
});
});
1 change: 1 addition & 0 deletions packages/cc-github-releaser/src/_/spec-only.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const testFn = () => null;
133 changes: 133 additions & 0 deletions packages/cc-github-releaser/src/cc-github-releaser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env node

import ccGithubReleaser from './runner';
import { ChangelogOpts, GitRawCommitsOpts, ImportedConfig, ParserOpts, TemplateContext, WriterOpts } from './types';
import meow from 'meow';
import { resolve } from 'path';

const cli = meow({
help: `
Usage conventional-github-releaser
Example conventional-github-releaser -p angular
Options
-t, --token Your GitHub auth token
-p, --preset Name of the preset you want to use. Must be one of the following:
angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint
Default: angular
-k, --pkg A filepath of where your package.json is located
Default is the closest package.json from cwd
-r, --releases How many releases to be generated from the latest
If 0, the whole changelog will be regenerated and
the output file will be overwritten
Default: 1
-f, --prefix Release name prefix
Default: ''
-n, --config A filepath of your config script
-c, --context A filepath of a javascript that is used to define template variables
-d, --draft Publish a draft release
Default: false
`,
flags: {
token: {
alias: 't',
default:
process.env['GITHUB_TOKEN'] ||
process.env['GH_TOKEN'] ||
process.env['CONVENTIONAL_GITHUB_RELEASER_TOKEN'] ||
'_',
type: 'string',
},
preset: {
alias: 'p',
default: 'angular',
type: 'string',
},
pkg: {
alias: 'k',
type: 'string',
},
releases: {
alias: 'r',
default: 1,
type: 'number',
},
prefix: {
alias: 'f',
type: 'string',
},
config: {
alias: 'n',
type: 'string',
},
context: {
alias: 'c',
type: 'string',
},
draft: {
alias: 'd',
default: false,
type: 'boolean',
},
},
});

let config: ImportedConfig = {};
let context: TemplateContext | undefined;
let gitRawCommitsOpts: GitRawCommitsOpts | undefined;
let parserOpts: ParserOpts | undefined;
let writerOpts: WriterOpts | undefined;

try {
if (cli.flags.context) {
context = require(resolve(process.cwd(), cli.flags.context));
}
if (cli.flags.config) {
config = require(resolve(process.cwd(), cli.flags.config));
}
if (config.gitRawCommitsOpts) {
gitRawCommitsOpts = config.gitRawCommitsOpts;
}
if (config.parserOpts) {
parserOpts = config.parserOpts;
}
if (config.writerOpts) {
writerOpts = config.writerOpts;
}
} catch (err) {
console.error('Failed to get file:', err);
process.exit(1);
}

const changelogOpts: ChangelogOpts = {
preset: cli.flags.preset,
pkg: { path: cli.flags.pkg },
releaseCount: cli.flags.releases,
releasePrefix: cli.flags.prefix,
draft: cli.flags.draft,
};

ccGithubReleaser({
token: cli.flags.token,
changelogOpts,
context,
gitRawCommitsOpts,
parserOpts,
writerOpts,
userCb: function (err, data) {
if (err) {
console.error(err.toString());
process.exit(1);
}
// if (flags.verbose) {
// console.log(data)
// }
},
});
62 changes: 62 additions & 0 deletions packages/cc-github-releaser/src/got-wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import got, { CancelableRequest, Got, GotReturn, HandlerFunction, Options, Response } from 'got';

type GotResponseExt<T> = GotReturn & CancelableRequest<Response<T>>;
const create: () => Got = <T = unknown>() =>
got.extend({
prefixUrl: process.env['GITHUB_ENDPOINT'] || 'https://api.github.com',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'cc-github-releaser',
},
responseType: 'json',
context: { token: process.env['GITHUB_TOKEN'] },
handlers: [
(options: Options, next: (options: Options) => Promise<GotResponseExt<T>>) => {
// Authorization
if (options.context?.token && !options.headers.authorization) {
options.headers.authorization = `token ${options.context.token}`;
}
if (options.context?.accept) {
options.headers.accept = options.context.accept as string;
}

options.json = options.body as unknown as Record<string, unknown>;
delete options.body;

if (options.isStream) {
return next(options);
}

return (async (): Promise<Response<T>> => {
try {
return (await next(options)) as Response<T>;
} catch (error) {
const { response } = error;
// Rate limit for errors
if (response) {
error.statusCode = response.statusCode;
}
if (response?.body) {
error.body = response.body;
}
if (error.code === 'ERR_NON_2XX_3XX_RESPONSE') {
return error;
}
// Nicer errors
if (response?.body) {
error.name = 'GitHubError';
error.message = `${response.body.message} (${response.statusCode})`;
}
throw error;
}
})();
},
] as HandlerFunction[],
});

type GotOptions = Required<Pick<Options, 'method'>> & {
body?: Record<string, unknown> | Options['body'];
context?: Options['context'];
};
type GotType = <T = unknown>(methodPath: string, options: GotOptions) => Promise<Response<T>>;
export default create() as GotType;
1 change: 0 additions & 1 deletion packages/cc-github-releaser/src/index.ts

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/cc-github-releaser/src/lib/cc-github-releaser.ts

This file was deleted.

Loading

0 comments on commit fac48dd

Please sign in to comment.