From e3d7111442f34dfaa3ae996a680b1be6cf39a3d3 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 06:49:19 -0700 Subject: [PATCH 1/7] ready to publish --- README.md | 15 +++++++++++---- package.json | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f0dcb33..391b1f5 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ JS challenge by @thdxr on X.com


`n-tuple-array` solution code
-[](./assets/demo-classic.svg) +[](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)

`n-tuple-array` n-tuple-array solution demo
@@ -56,12 +56,13 @@ JS challenge by @thdxr on X.com
## Setup & Usage ```bash -npm install n-tuple-array +npm install @chalu/n-tuple-array ``` ```javascript import { tuplesFromArray } from 'n-tuple-array'; +// some setup const numbers = Array.from({length: 100}, (_, i) => i + 1); const isEven = (item) => { if ( @@ -73,8 +74,14 @@ const isEven = (item) => { return true; }; -for (const triplets of tuplesFromArray({list: numbers, maxItems: 3, match: isEven})) { - console.log(triplets); +// use the lib +const quintetIterator = tuplesFromArray({ + list: numbers, maxItems: 5, match: isEven +}); + +for (const quintet of quintetIterator) { + // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + console.log(quintet); } ``` diff --git a/package.json b/package.json index d98121b..897eb01 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "n-tuple-array", + "name": "@chalu/n-tuple-array", "version": "0.1", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that native arrays provide!", "main": "dist/index.js", From 51add333de5845b97eacb0b26a00b1579e90bbca Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 07:57:16 -0700 Subject: [PATCH 2/7] add CD workflow --- .github/workflows/CD.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/CD.yaml diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml new file mode 100644 index 0000000..8ce8733 --- /dev/null +++ b/.github/workflows/CD.yaml @@ -0,0 +1,24 @@ +name: CD +on: + pull_request: + types: [ closed ] + +jobs: + build-and-test: + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Print ENV + run: | + echo ${ github.event.pull_request.base.ref } + echo ${ github.event.pull_request } + + # - name: Publish to Registry + # uses: JS-DevTools/npm-publish@v3 + # with: + # token: ${{ secrets.NPM_TOKEN }} + \ No newline at end of file From 16d3398acf08593eb0e561490632e0bff52eae05 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 07:58:50 -0700 Subject: [PATCH 3/7] lint only changed TS or JS files --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 897eb01..aa2d186 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "build": "tsc", "prebuild": "rm -rf dist/*", "postbuild": "rm -rf dist/demo/*.d.*", - "lint": "xo", - "lint:fix": "xo --fix", + "lint": "xo $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", + "lint:fix": "xo --fix $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", "test": "jest --runInBand", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", From d0de98d58e799a93706bee0176614f6388607658 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:03:40 -0700 Subject: [PATCH 4/7] fix CD job name --- .github/workflows/CD.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 8ce8733..87083f6 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -4,7 +4,7 @@ on: types: [ closed ] jobs: - build-and-test: + publish-to-registry: if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true runs-on: ubuntu-latest From 83348c4aadee82d7b34f12283c3329a135ef8a2c Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:09:34 -0700 Subject: [PATCH 5/7] run CI only on PR to dev or main --- .github/workflows/CI.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 7a5502b..d355aee 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,9 +1,5 @@ name: CI on: - push: - branches: - - "!main" - - "*" pull_request: branches: - "dev" From 4704b14727a4b3eb6607c13fec488b3246a785fd Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:18:37 -0700 Subject: [PATCH 6/7] Init package publishing (#10) * init * get started with the implementation * allow caller filter in elements with a match function * setup unit tests * add smoke tests for the list parameter * add smoke tests for maxItems param * add smoke tests for the match param * refactor param validation into a separate function * add basic CI workflow * re-add CI workflow file * add catch all branch in CI workflow * try install pnpm before node in CI workflow * attempt display test summary on GHA overview page * add TAP reporter for tests in CI * attempt junit reporter for summary in CI * remove TAP reporter * improve setup for tests * add matchers from jest-extended * add smoke tests * add festures tests * enforce code style with XO * add pre-commit hook to run lint, build, and test scripts * simplify pre-commit script * add built files in dist folder * add docs and samples (#7) * separate commit and push hooks * enable pre/post scripts for pnpm * just use comonjs and have peace of mind :D * configure code style to use practical rules * properly type the iterable and iterator implementation * add demo code * flesh up README.md * Go publish (#9) * ready to publish * add CD workflow * lint only changed TS or JS files * fix CD job name * run CI only on PR to dev or main --- .github/workflows/CD.yaml | 24 ++++++++++++++++++++++++ .github/workflows/CI.yaml | 4 ---- README.md | 15 +++++++++++---- package.json | 6 +++--- 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/CD.yaml diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml new file mode 100644 index 0000000..87083f6 --- /dev/null +++ b/.github/workflows/CD.yaml @@ -0,0 +1,24 @@ +name: CD +on: + pull_request: + types: [ closed ] + +jobs: + publish-to-registry: + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Print ENV + run: | + echo ${ github.event.pull_request.base.ref } + echo ${ github.event.pull_request } + + # - name: Publish to Registry + # uses: JS-DevTools/npm-publish@v3 + # with: + # token: ${{ secrets.NPM_TOKEN }} + \ No newline at end of file diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 7a5502b..d355aee 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,9 +1,5 @@ name: CI on: - push: - branches: - - "!main" - - "*" pull_request: branches: - "dev" diff --git a/README.md b/README.md index f0dcb33..391b1f5 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ JS challenge by @thdxr on X.com


`n-tuple-array` solution code
-[](./assets/demo-classic.svg) +[](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)

`n-tuple-array` n-tuple-array solution demo
@@ -56,12 +56,13 @@ JS challenge by @thdxr on X.com
## Setup & Usage ```bash -npm install n-tuple-array +npm install @chalu/n-tuple-array ``` ```javascript import { tuplesFromArray } from 'n-tuple-array'; +// some setup const numbers = Array.from({length: 100}, (_, i) => i + 1); const isEven = (item) => { if ( @@ -73,8 +74,14 @@ const isEven = (item) => { return true; }; -for (const triplets of tuplesFromArray({list: numbers, maxItems: 3, match: isEven})) { - console.log(triplets); +// use the lib +const quintetIterator = tuplesFromArray({ + list: numbers, maxItems: 5, match: isEven +}); + +for (const quintet of quintetIterator) { + // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + console.log(quintet); } ``` diff --git a/package.json b/package.json index d98121b..aa2d186 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "n-tuple-array", + "name": "@chalu/n-tuple-array", "version": "0.1", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that native arrays provide!", "main": "dist/index.js", @@ -11,8 +11,8 @@ "build": "tsc", "prebuild": "rm -rf dist/*", "postbuild": "rm -rf dist/demo/*.d.*", - "lint": "xo", - "lint:fix": "xo --fix", + "lint": "xo $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", + "lint:fix": "xo --fix $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", "test": "jest --runInBand", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", From d8979e9c8dfdbed2591ee53ad4092cd486544b9f Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:26:19 -0700 Subject: [PATCH 7/7] dry run package publishing --- .github/workflows/CD.yaml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 87083f6..324e1ff 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -12,13 +12,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Print ENV - run: | - echo ${ github.event.pull_request.base.ref } - echo ${ github.event.pull_request } - - # - name: Publish to Registry - # uses: JS-DevTools/npm-publish@v3 - # with: - # token: ${{ secrets.NPM_TOKEN }} + - name: Publish to Registry + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.NPM_TOKEN }} + dry-run: true \ No newline at end of file