-
Notifications
You must be signed in to change notification settings - Fork 45
Cli update and typescript conversion wip (new branch name) #69
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
8499c72
6bf24f9
d29ca8e
cbd6dd6
f2aa8bd
d6056d0
200d78d
5e6d029
66bfde6
111683f
c817261
0e57e4b
040beae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import spec from "conventional-changelog-config-spec/versions/2.1.0/schema.json"; | ||
|
||
type Defaults = Readonly< | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
infile: string; | ||
firstRelease: boolean; | ||
sign: boolean; | ||
noVerify: boolean; | ||
commitAll: boolean; | ||
silent: boolean; | ||
tagPrefix: string; | ||
releaseCount: number; | ||
scripts: { | ||
prerelease?: string; | ||
prebump?: string; | ||
postbump?: string; | ||
prechangelog?: string; | ||
postchangelog?: string; | ||
precommit?: string; | ||
postcommit?: string; | ||
pretag?: string; | ||
posttag?: string; | ||
}; | ||
skip: { | ||
bump?: boolean; | ||
changelog?: boolean; | ||
commit?: boolean; | ||
tag?: boolean; | ||
}; | ||
dryRun: boolean; | ||
tagForce: boolean; | ||
gitTagFallback: boolean; | ||
preset: string; | ||
npmPublishHint: string | undefined; | ||
packageFiles: readonly string[]; | ||
bumpFiles: readonly string[]; | ||
} & { | ||
[key in keyof typeof spec.properties]: typeof spec.properties[key]["default"]; | ||
} | ||
>; | ||
|
||
const defaults = { | ||
infile: "CHANGELOG.md", | ||
firstRelease: false, | ||
sign: false, | ||
noVerify: false, | ||
commitAll: false, | ||
silent: false, | ||
tagPrefix: "v", | ||
releaseCount: 1, | ||
scripts: {}, | ||
skip: {}, | ||
dryRun: false, | ||
tagForce: false, | ||
gitTagFallback: true, | ||
preset: require.resolve('conventional-changelog-conventionalcommits'), | ||
npmPublishHint: undefined, | ||
/** | ||
* Sets the default for `header` (provided by the spec) for backwards | ||
* compatibility. This should be removed in the next major version. | ||
*/ | ||
header: | ||
"# Changelog\n\nAll notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.\n", | ||
packageFiles: ["package.json", "bower.json", "manifest.json"], | ||
bumpFiles: [ | ||
"package.json", | ||
"bower.json", | ||
"manifest.json", | ||
"package-lock.json", | ||
"npm-shrinkwrap.json", | ||
], | ||
} as const satisfies Partial<Readonly<Defaults>>; | ||
|
||
/** | ||
* Merge in defaults provided by the spec | ||
*/ | ||
Object.keys(spec.properties).forEach((propertyKey) => { | ||
const k: keyof typeof spec.properties = | ||
propertyKey as keyof typeof spec.properties; | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const property = spec.properties[k]; | ||
// @ts-expect-error - we know that the key exists | ||
defaults[k] = property.default; | ||
}); | ||
|
||
export default defaults as any as Defaults; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { getConfiguration as getConfigFile } from "../configuration"; | ||
import { isin } from "../../type-helpers"; | ||
import type { PrettyPrint } from "../../type-helpers"; | ||
|
||
type Release = "minor" | "major" | "patch"; | ||
type Task = "changelog" | "commit" | "tag"; | ||
type Hook = | ||
| "prerelease" | ||
| "prebump" | ||
| "postbump" | ||
| "prechangelog" | ||
| "postchangelog" | ||
| "precommit" | ||
| "postcommit" | ||
| "pretag" | ||
| "posttag"; | ||
|
||
type TypePrefixes = Array< | ||
( | ||
| { section: string; hidden?: boolean | undefined } | ||
| { hidden: true; section?: string | undefined } | ||
) & { type: string } | ||
>; | ||
|
||
type ConfigFiles = Array< | ||
| string | ||
| { filename: string; type: "json" | "gradle" | "plain-text" } | ||
| { filename: string; updater: string } | ||
>; | ||
|
||
/** | ||
* __THIS SHOULD NOT CHANGE.__ | ||
* @deprecated | ||
* | ||
* The configuration options for `standard-version` as of version 9.5 (The last version prior to the fork; deprecated). | ||
*/ | ||
export type SVConfig = { | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
packageFiles: ConfigFiles; | ||
bumpFiles: ConfigFiles; | ||
releaseAs: Release; | ||
prerelease: string | boolean; | ||
infile: string; | ||
message: string; | ||
firstRelease: boolean; | ||
sign: boolean; | ||
noVerify: boolean; | ||
commitAll: boolean; | ||
silent: boolean; | ||
tagPrefix: string; | ||
scripts: Record<Hook, string>; | ||
skip: Record<Task, string>; | ||
dryRun: boolean; | ||
gitTagFallback: boolean; | ||
path: string; | ||
changelogHeader: string; | ||
preset: string; | ||
lernaPackage: string; | ||
header: string; | ||
types: TypePrefixes; | ||
preMajor: boolean; | ||
commitUrlFormat: string; | ||
compareUrlFormat: string; | ||
issueUrlFormat: string; | ||
userUrlFormat: string; | ||
releaseCommitMessageFormat: string; | ||
issuePrefixes: string[]; | ||
}; | ||
|
||
/** | ||
* The configuration object for commit-and-tag-version, which is a superset of the conventional-changelog-config-spec (as of version 2.1.0) | ||
* This may or may not maintain backwards compatibility with standard-version (as of version 9.5.0). | ||
*/ | ||
export type CatVConfig = PrettyPrint< | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SVConfig & { | ||
npmPublishHint: string; | ||
releaseCount: number; | ||
tagForce: boolean; | ||
} | ||
>; | ||
|
||
/** The configuration options that are not supported by standard-version (as of version 9.5.0). */ | ||
const catVOnlyFeatures = [ | ||
"npmPublishHint", | ||
"releaseCount", | ||
"tagForce", | ||
] as const satisfies ReadonlyArray<Exclude<keyof CatVConfig, keyof SVConfig>>; | ||
|
||
export const getMergedConfig = async ( | ||
cwd?: string | ||
): Promise<Partial<CatVConfig>> => { | ||
const dir = cwd ?? process.cwd(); | ||
const json = (await import("path")).join(dir, "package.json"); | ||
const svConfig: SVConfig = (await import(json))["standard-version"]; | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const catvConfig: CatVConfig = (await import(json))["commit-and-tag-version"]; | ||
|
||
const config: Partial<CatVConfig> = {}; | ||
|
||
if (svConfig) { | ||
for (const key in svConfig) { | ||
// @ts-expect-error - We know this key SHOULD NOT be in svConfig, but we're going to allow it and warn the user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably avoid all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, I don't believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, let's not pollute the global scope 😅 What I mean is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your meaning, but what I'm saying is that - despite how one might expect .filter() and Object.keys() to work - the type of You aren't the only one to expect this behavior, though. I certainly did, as did many others. That's why I bring up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow - ignore me. I feel dumb now! I think I understand what you mean. I've refactored like so:
That about right? |
||
if (catVOnlyFeatures.includes(key)) { | ||
console.warn( | ||
`The "${key}" option is a feature of commit-and-tag-version, and is not supported by standard-version.${"\n"}Please move this option to the 'commit-and-tag-version' key.${"\n"}In a future version, this will throw an error.` | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
if (isin(catvConfig, key)) { | ||
console.warn( | ||
`"standard-version"."${key}" in package.json is being overridden by "commit-and-tag-version"."${key}". in package.json` | ||
); | ||
} | ||
// @ts-expect-error - We know better than TS here. This is valid. | ||
config[key] = svConfig[key]; | ||
} | ||
} | ||
for (const key in catvConfig) { | ||
// @ts-expect-error - We know better than TS here. This is valid. | ||
config[key] = catvConfig[key]; | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const config2 = await getConfigFile(); | ||
helmturner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { ...config, ...config2 }; | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.