Skip to content

Commit f505b81

Browse files
committed
add workflow for npm package release, modify few files
1 parent cce906c commit f505b81

File tree

11 files changed

+90
-57
lines changed

11 files changed

+90
-57
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Node.js Package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: 20
15+
- run: npm ci
16+
- run: npm test
17+
18+
publish-gpr:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
permissions:
22+
packages: write
23+
contents: read
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 20
29+
registry-url: https://npm.pkg.github.com/
30+
- run: npm ci
31+
- run: npm publish
32+
env:
33+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ Begin by
3636

3737
You can re-use this for whatever you want or to build something cool with it.
3838

39+
- Using the `Get class` to fetch data.<br/>
40+
For instance, fetching `posts` from `jsonplaceholder api`
41+
42+
```js
43+
let posts = new Get("posts").api()
44+
```
45+
46+
this fetches posts from jsonplaceholder api. The `api()` accepts 1 optional argument which is your endpoint query. For instance, fetching a single post with an `id` of `50`
47+
48+
```js
49+
let post = new Get("posts").api("?id=50")
50+
```
51+
or programmatically:
52+
53+
```js
54+
let id = value // dynamic value
55+
let post = new Get("posts").api(`?id=${value}`)
56+
```
57+
3958
## License
4059

4160
Licensed under the MIT license.
61+
62+
## Documentation
63+
64+
Coming soon

dist/index.es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'react';

dist/index.esm.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'react';

dist/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
require('react');
4+

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"description": "Customizable Components that can make calls to many endpoints and api handling the logical aspect while you just decide the data to be fetched and how it should be consumed",
77
"main": "/dist/index.js",
88
"scripts": {
9-
"build": "rollup -c",
10-
"prebuild": "rimraf src && rimraf dist"
9+
"build": "rollup -c"
1110
},
1211
"repository": {
1312
"type": "git",

rollup.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {babel} from "@rollup/plugin-babel"
22
import postcss from "rollup-plugin-postcss"
3-
import filesize from "rollup-plugin-filesize"
3+
// import filesize from "rollup-plugin-filesize"
44
import external from "rollup-plugin-peer-deps-external"
55
import resolve from "@rollup/plugin-node-resolve"
6-
import {terser} from "@rollup/plugin-terser"
6+
// import {terser} from "@rollup/plugin-terser"
77

88
const config={
9-
input: "/src/index.js",
9+
input: "src/index.jsx",
1010
output:[
1111
{
1212
file: 'dist/index.esm.js',
@@ -32,7 +32,7 @@ const config={
3232
}),
3333
external(),
3434
resolve(),
35-
terser(),
35+
// terser(),
3636
postcss({
3737
plugins:[],
3838
minimize:true

src/components/Get/Get.jsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/components/Get/index.jsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/hooks/providers/useGetProvider.jsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/index.jsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
import Get from "./components/Get/Get";
2-
import { useGetProvider } from "./hooks/providers/useGetProvider";
1+
import { useState } from "react";
32

4-
const App = () =>{
5-
return(
6-
<useGetProvider>
7-
<Get/>
8-
</useGetProvider>
9-
)
3+
function Get(input){
4+
this.input = input
5+
this.response;
6+
this.data;
7+
}
8+
9+
Get.prototype.api = async function (endpoint=""){
10+
const [fetch, setFetch] = useState()
11+
if(this.input == "posts"){
12+
if(endpoint == ""){
13+
this.response = await fetch(`https://jsonplaceholder.typicode.com/${this.input}`)
14+
this.data = this.response.json().then(result=>{
15+
setFetch(result)
16+
})
17+
}else{
18+
this.response = await fetch(`https://jsonplaceholder.typicode.com/${this.input}/${endpoint}`)
19+
this.data = this.response.json().then(result=>{
20+
setFetch(result)
21+
})
22+
}
23+
}
24+
return fetch
1025
}

0 commit comments

Comments
 (0)