Skip to content

Commit

Permalink
[refactor] transform .execute() from Recursion to Iteration (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Sep 2, 2024
1 parent 8e2d022 commit 0497d47
Show file tree
Hide file tree
Showing 15 changed files with 7,596 additions and 121 deletions.
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
"parserOptions": {
"sourceType": "module"
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"]
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-explicit-any": "warn"
}
}
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI & CD
on:
push:
tags:
- v*
jobs:
Build-and-Publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
cache: pnpm
- name: Install Dependencies
run: pnpm i --frozen-lockfile

- name: Build & Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Update document
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: ./docs
personal_token: ${{ secrets.GITHUB_TOKEN }}
force_orphan: true
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Node.JS
node_modules/
package-lock.json
yarn.lock

# Building
dist/
.rts2_cache_*/
docs/

# IDE
.vscode/
.vscode/settings.json
.idea/

# Online platform
.github/

# OS
.DS_Store
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run build
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
test/
.rts2_cache_*/
docs/
.travis.yml
.vscode/
.husky/
.github/
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provenance = true
auto-install-peers = false
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Jest",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
20 changes: 10 additions & 10 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

**Middleware** framework based on [Async Generator][1] & [TypeScript][2], inspired by [Koa 2][3].

[![NPM Dependency](https://david-dm.org/TechQuery/onion-stack.svg)][4]
[![Build Status](https://travis-ci.com/TechQuery/onion-stack.svg?branch=master)][5]
[![NPM Dependency](https://img.shields.io/librariesio/github/TechQuery/onion-stack.svg)][4]
[![CI & CD](https://github.com/TechQuery/onion-stack/actions/workflows/main.yml/badge.svg)][5]
[![](https://data.jsdelivr.com/v1/package/npm/onion-stack/badge?style=rounded)][6]

[![NPM](https://nodei.co/npm/onion-stack.png?downloads=true&downloadRank=true&stars=true)][7]

## Example

```JavaScript
```javascript
import OnionStack from 'onion-stack';

const list = [ ];
const list = [];

const stack = new OnionStack(
function*() {
function* () {
list.push(1);

yield;
Expand All @@ -27,7 +27,7 @@ const stack = new OnionStack(

list.push(3);
},
async function*() {
async function* () {
await delay(0.1);

list.push(4);
Expand All @@ -36,20 +36,20 @@ const stack = new OnionStack(

list.push(5);
},
function() {
function () {
list.push(6);
}
);

stack.execute().then(() => console.log( list )); // [1, 4, 6, 5, 2]
stack.execute().then(() => console.log(list)); // [1, 4, 6, 5, 2]
```

[More cases](https://github.com/TechQuery/onion-stack/tree/master/test)

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#Iterating_over_async_generators
[2]: https://www.typescriptlang.org
[3]: https://koajs.com
[4]: https://david-dm.org/TechQuery/onion-stack
[5]: https://travis-ci.com/TechQuery/onion-stack
[4]: https://libraries.io/npm/onion-stack
[5]: https://github.com/TechQuery/onion-stack/actions/workflows/main.yml
[6]: https://www.jsdelivr.com/package/npm/onion-stack
[7]: https://nodei.co/npm/onion-stack/
66 changes: 27 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "onion-stack",
"version": "0.3.1",
"version": "0.3.2",
"description": "Middleware framework based on Async Generator of ECMAScript 2018, inspired by Koa 2",
"keywords": [
"middleware",
Expand All @@ -24,59 +24,47 @@
"main": "dist/onion-stack.umd.js",
"module": "dist/onion-stack.js",
"scripts": {
"prepare": "husky",
"lint": "lint-staged",
"pack-docs": "typedoc --name \"Onion Stack\" --out docs/ source/",
"build": "rm -rf dist/ && microbundle --name=OnionStack && npm run pack-docs",
"pack-docs": "rm -rf docs/ && typedoc source/",
"pack-dist": "rm -rf dist/ && microbundle --name=OnionStack",
"build": "npm run pack-dist && npm run pack-docs",
"debug": "node --inspect node_modules/jest/bin/jest --runInBand",
"test": "lint-staged && jest",
"prepublishOnly": "npm test && npm run build",
"help": "npm run pack-docs && open-cli docs/index.html"
},
"lint-staged": {
"*.{md,json,yml}": [
"prettier --write",
"git add"
],
"*.{md,json,yml}": "prettier --write",
"*.ts": [
"prettier --write",
"eslint --fix",
"git add"
"eslint --fix"
]
},
"husky": {
"hooks": {
"pre-commit": "npm test",
"pre-push": "npm run build"
}
},
"devDependencies": {
"@types/jest": "^24.0.23",
"@typescript-eslint/parser": "^2.8.0",
"eslint": "^6.7.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",
"husky": "^3.1.0",
"jest": "^24.9.0",
"lint-staged": "^9.4.3",
"microbundle": "^0.11.0",
"open-cli": "^5.0.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"typedoc": "^0.15.3",
"typescript": "^3.7.2"
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"husky": "^9.1.5",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"microbundle": "^0.15.1",
"open-cli": "^8.0.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typedoc": "^0.26.6",
"typedoc-plugin-mdn-links": "^3.2.11",
"typescript": "^5.5.4"
},
"prettier": {
"tabWidth": 4,
"singleQuote": true
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid",
"tabWidth": 4
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testRegex": "/test/.*\\.(test|spec)?\\.ts$",
"moduleFileExtensions": [
"js",
"ts",
"json"
]
"preset": "ts-jest"
}
}
Loading

0 comments on commit 0497d47

Please sign in to comment.