Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Aug 18, 2023
0 parents commit 92ef0d6
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelogrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@lobehub/lint').changelog;
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@lobehub/lint').commitlint;
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/lambda/
/scripts
/config
.history
public
dist
.umi
mock
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('@lobehub/lint').eslint;

module.exports = config;
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release CI
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install deps
run: pnpm install

- name: Test
run: pnpm run test

- name: release
run: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test
on: [push]

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install deps
run: pnpm install

- name: Test and coverage
run: pnpm run test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
**/node_modules
# roadhog-api-doc ignore
/src/utils/request-temp.js
_roadhog-api-doc

# production
/dist
/.vscode

# misc
.DS_Store
npm-debug.log*
yarn-error.log

/coverage
.idea
package-lock.json
*bak
.vscode

# visual studio code
.history
*.log
functions/*
.temp/**

# umi
.umi
.umi-production

# screenshot
screenshot
.firebase
.eslintcache

build

.env

.vercel
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install lint-staged
11 changes: 11 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lockfile=false
resolution-mode=highest
public-hoist-pattern[]=*@umijs/lint*
public-hoist-pattern[]=*changelog*
public-hoist-pattern[]=*commitlint*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*postcss*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=*remark*
public-hoist-pattern[]=*semantic-release*
public-hoist-pattern[]=*stylelint*
23 changes: 23 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**/*.svg
**/*.ejs
.umi
.umi-production
/dist
.dockerignore
.DS_Store
.eslintignore
*.png
*.toml
docker
.editorconfig
Dockerfile*
.gitignore
.prettierignore
LICENSE
.eslintcache
*.lock
yarn-error.log
.history
CNAME
/build
/public
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@lobehub/lint').prettier;
1 change: 1 addition & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@lobehub/lint').semanticRelease;
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<a name="readme-top"></a>

# Changelog

## Version&nbsp;1.0.0

<sup>Released on **2023-08-17**</sup>

#### ♻ Code Refactoring

- **misc**: 按照接口模式重构.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: 按照接口模式重构 ([0e66e76](https://github.com/lobehub/chat-plugin-real-time-weather/commit/0e66e76))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 LobeHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# LobeChat Plugin RealTime Weather

[![Coverage][coverage]][codecov-url] ![Test CI status][test-ci]

[test-ci]: https://github.com/lobehub/chat-plugin-market/workflows/Test/badge.svg
[coverage]: https://codecov.io/gh/arvinxx/vercel-serverless-api-template/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/arvinxx/vercel-serverless-api-template/branch/master

LobeChat Plugin RealTime Weather
33 changes: 33 additions & 0 deletions api/v1/_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Response, WeatherParams, WeatherResult } from '../../type';

const weatherBaseURL = 'https://restapi.amap.com/v3/weather/weatherInfo';

const citySearchURL = 'https://restapi.amap.com/v3/config/district';

const KEY = process.env.GAODE_WEATHER_KEY;

const fetchCityCode = async (keywords: string): Promise<string> => {
const URL = `${citySearchURL}?keywords=${keywords}&subdistrict=0&extensions=base&key=${KEY}`;
const res = await fetch(URL);

const data = await res.json();
console.log(data);

return data.districts[0].adcode;
};

const fetchWeather = async ({
city,
extensions = 'all',
}: WeatherParams): Promise<WeatherResult> => {
const cityCode = await fetchCityCode(city);

const URL = `${weatherBaseURL}?city=${cityCode}&extensions=${extensions}&key=${KEY}`;
const res = await fetch(URL);

const data: Response = await res.json();

return data.forecasts;
};

export default fetchWeather;
16 changes: 16 additions & 0 deletions api/v1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { WeatherParams } from '../../type';
import fetchWeather from './_utils';

export const config = {
runtime: 'edge',
};

export default async (req: Request) => {
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 });

const args = (await req.json()) as WeatherParams;

const result = await fetchWeather(args);

return new Response(JSON.stringify(result));
};
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "chat-plugin-real-time-weather",
"version": "1.0.0",
"private": true,
"description": "Lobe Chat Plugin Market",
"repository": "https://github.com/lobehub/chat-plugin-real-time-weather.git",
"scripts": {
"ci": "npm run lint && npm run type-check",
"lint": "npm run lint:js && npm run lint:prettier",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx ./api",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx ./api",
"lint:prettier": "prettier --check \"api/**/*\" --end-of-line auto",
"prepare": "husky install",
"prettier": "prettier -c --write \"api/**/*\"",
"release": "semantic-release",
"start": "vercel dev",
"test": "vitest --passWithNoTests",
"test:coverage": "vitest --coverage --passWithNoTests",
"type-check": "tsc --noEmit"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
"**/*.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write"
]
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 10"
],
"devDependencies": {
"@lobehub/lint": "latest",
"@vercel/node": "^2",
"@vitest/coverage-v8": "latest",
"commitlint": "^17",
"cross-env": "^7",
"eslint": "^8",
"husky": "^8",
"lint-staged": "^13",
"prettier": "^2",
"semantic-release": "^21",
"typescript": "^5",
"vercel": "^31.2.3",
"vitest": "latest"
}
}
10 changes: 10 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Lobe Chat Realtime Weather</title>
</head>
<body>

</body>
</html>
17 changes: 17 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES5",
"lib": ["esnext", "DOM"],
"sourceMap": true,
"baseUrl": ".",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"strict": true
},
"include": ["types", "api"]
}
Loading

0 comments on commit 92ef0d6

Please sign in to comment.