Skip to content

Commit

Permalink
refactor: consolidate CI workflows and enhance publishing process for…
Browse files Browse the repository at this point in the history
… JSR and NPM
  • Loading branch information
myty committed Nov 5, 2024
1 parent b09c987 commit 3a87b17
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 62 deletions.
44 changes: 41 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: CI
name: CI/CD

on: [push]

jobs:
build:
name: Build, lint, and test on Deno
integrate:
name: Format, Lint, Test

runs-on: ubuntu-latest

Expand All @@ -25,3 +25,41 @@ jobs:

- name: Deno Test
run: deno test

publish:
name: Publish to JSR and NPM
needs: [integrate]
if: startsWith(github.event.ref, 'refs/tags/v')

runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Publish package to JSR
run: |
deno run -A ./scripts/prep-jsr.ts ${{ github.ref }}
deno publish --allow-dirty
- name: build npm package
run: deno run -A ./scripts/build_npm.ts ${{ github.ref }}

- uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: publish npm package
run: |
cd npm
npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41 changes: 0 additions & 41 deletions .github/workflows/publish.yml

This file was deleted.

20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# Introduction

The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a `with` method to the record class.
Built on `immer`, immutable recorda are class factories for immutable types.

## Deno

```typescript
import {
ImmutableConstructor,
ImmutableRecord,
ImmutableWith,
} from "https://deno.land/x/simple-immutable-record/mod.ts";
```

## Node

```sh
npm install simple-immutable-record
deno add jsr:@myty/immutable-record
```

or
## Node

```sh
yarn add simple-immutable-record
npm install @myty/immutable-record
```

## Usage

```typescript
import { ImmutableConstructor, ImmutableRecord, ImmutableWith } from "@myty/immutable-record";

interface TestDataInterface {
testNumber: number;
testString: string;
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@myty/immutable-record",
"description": "The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a with method to the record class.",
"description": "Built on immer, immutable recorda are class factories for immutable types.",
"exports": "./mod.ts",
"lint": {
"rules": {
Expand Down
3 changes: 1 addition & 2 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ async function start() {
package: {
name: "@myty/immutable-record",
version: Deno.args[0].substring("refs/tags/v".length),
description:
"The sole purpose of this immutable record is to simply act as a class factory for immutable types. For this particular implementation, it piggybacks off of immer and adds a with method to the record class.",
description: "Built on immer, immutable recorda are class factories for immutable types.",
license: "MIT",
author: "Michael Tyson",
engines: {
Expand Down
18 changes: 17 additions & 1 deletion src/immutable-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@ import { enableMapSet, immerable, Immutable, produce } from "immer";

enableMapSet();

/**
* immutable record interface
*/
export interface ImmutableWith<T> {
/**
* Returns a new object if values changed
*/
with: (values: Partial<Immutable<T>>) => this;
}

/**
* Represents a constructor for an immutable object
*/
export type ImmutableConstructor<T> = new (
value?: Partial<Immutable<T>>,
) => Immutable<T> & ImmutableWith<T>;

/**
* Class factory to create an immutable record
* @param defaultValues Default values
* @param processor Processor for values
*/
export function ImmutableRecord<T>(
defaultValues: T | Immutable<T>,
processor?: (values: Partial<Immutable<T>>) => Partial<Immutable<T>>,
): ImmutableConstructor<T> {
const classProcessor = processor ?? ((value: Partial<Immutable<T>>) => value);

/**
* Immutable record class
*/
class ImmutableRecordClass implements ImmutableWith<T> {
[immerable] = true;

Expand Down Expand Up @@ -44,7 +61,6 @@ export function ImmutableRecord<T>(
(prev as any)[key] = (values as any)[key];
}
});
``;
});
}
}
Expand Down

0 comments on commit 3a87b17

Please sign in to comment.