Skip to content

Commit

Permalink
feat(js): new version facade functions
Browse files Browse the repository at this point in the history
`majorVersion`, `untilMinorVersion`, `untilPatchVersion`, and `fullVersion`.
  • Loading branch information
jjangga0214 committed Nov 6, 2023
1 parent e00a85d commit 5ba82bb
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/js-version-facades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@haetae/javascript': patch
---

Add new functions `majorVersion`, `untilMinorVersion`, `untilPatchVersion`, and `fullVersion`.
72 changes: 72 additions & 0 deletions packages/docs/pages/apis/javascript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,78 @@ export default configure({
```
</TokenLinkCode>

### `majorVersion`

A [Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) for the major version from [`version()`](#version).

**Implementation**

<TokenLinkCode tokens={['version', 'VersionOptions']}>
```ts
async function majorVersion(
packageName: string,
options: VersionOptions = {},
): Promise<number> {
const { major } = await version(packageName, options)
return major
}
```
</TokenLinkCode>

### `untilMinorVersion`

A [Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) for the until-minor(`x.y`) version of [`version()`](#version).

**Implementation**

<TokenLinkCode tokens={['version', 'VersionOptions']}>
```ts
async function untilMinorVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { untilMinor } = await version(packageName, options)
return untilMinor
}
```
</TokenLinkCode>

### `untilPatchVersion`

A [Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) for the until-patch(`x.y.z`) version from [`version()`](#version).

**Implementation**

<TokenLinkCode tokens={['version', 'VersionOptions']}>
```ts
async function untilPatchVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { untilPatch } = await version(packageName, options)
return untilPatch
}
```
</TokenLinkCode>

### `fullVersion`

A [Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) for the full version from [`version()`](#version).

**Implementation**

<TokenLinkCode tokens={['version', 'VersionOptions']}>
```ts
async function fullVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { value } = await version(packageName, options)
return value
}
```
</TokenLinkCode>

### `GraphOptions`

An argument interface for [`graph`](#graph).
Expand Down
12 changes: 6 additions & 6 deletions packages/docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ For instance, let's change the config to this.
'configure': './apis/haetae#configure',
'pkg': './apis/haetae#pkg',
'.hash': './apis/utils#hash',
'.version': './apis/javascript#version',
'.majorVersion': './apis/javascript#majorversion',
'.branch': './apis/git#branch',
}}>
```js filename="haetae.config.js" showLineNumbers
Expand All @@ -545,7 +545,7 @@ export default configure({
return {
NODE_ENV: process.env.NODE_ENV,
jestConfig: await utils.hash(['jest.config.js']),
jest: (await js.version('jest')).major,
jest: await js.majorVersion('jest'),
branch: await git.branch(),
os: process.platform,
node: semver.major(process.version),
Expand Down Expand Up @@ -1516,7 +1516,7 @@ haetaeConfig: await utils.hash(
```
</TokenLinkCode>
Evaluated `env` is passed from each command's `env` to upper levels.
Evaluated `env` object is propagated to upper levels.
<TokenLinkCode tokens={{
'configure': './apis/haetae#configure',
Expand All @@ -1527,15 +1527,15 @@ import { configure } from 'haetae'

export default configure({
env: async (env) => {
// Evaluated `env` from each command
// Env from each command
assert(env.hello === 'world')
return {
...env,
hi: 'there',
}
},
recordData: async (data, { env }) => {
// Evaluated `env` from root env
// Eenv from RootEnv
assert(env.hi === 'there')
assert(env.hello === 'world')
// ...
Expand All @@ -1544,7 +1544,7 @@ export default configure({
myCommand: {
env: { hello: 'world' },,
run: async ({ env }) => {
// Evaluated `env` of "myCommand"
// Env from "myCommand"
assert(env.hello === 'world')
// ...
}
Expand Down
32 changes: 32 additions & 0 deletions packages/js/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,35 @@ export async function version(
return parseVersion(await versionFromYarnBerry(packageName, { rootDir }))
}
}

export async function majorVersion(
packageName: string,
options: VersionOptions = {},
): Promise<number> {
const { major } = await version(packageName, options)
return major
}

export async function untilMinorVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { untilMinor } = await version(packageName, options)
return untilMinor
}

export async function untilPatchVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { untilPatch } = await version(packageName, options)
return untilPatch
}

export async function fullVersion(
packageName: string,
options: VersionOptions = {},
): Promise<string> {
const { value } = await version(packageName, options)
return value
}

1 comment on commit 5ba82bb

@vercel
Copy link

@vercel vercel bot commented on 5ba82bb Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

haetae – ./

haetae-git-main-jjangga0214.vercel.app
haetae-mu.vercel.app
haetae-jjangga0214.vercel.app

Please sign in to comment.