Skip to content

Commit

Permalink
Merge pull request #4 from HanJaemEo/api-initial
Browse files Browse the repository at this point in the history
feat: ✨ (api) api をセットアップした
  • Loading branch information
ReoHakase authored Mar 15, 2024
2 parents b777aa8 + 83544e2 commit bfc9dbc
Show file tree
Hide file tree
Showing 16 changed files with 1,279 additions and 27 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/api_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: API Deploy

on:
push:
branches:
- main

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
# The action will look for `volta.node` first. If `volta.node` isn't defined, then it will look for `engines.node`
# Refer: https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#node-version-file
node-version-file: 'package.json'

- name: Setup PNPM
uses: pnpm/action-setup@v3.0.0
id: pnpm-install
with:
# Version of pnpm to install:
# Optional when there is a packageManager field in the package.json.
# Refer: https://github.com/pnpm/action-setup#inputs
run_install: false

- name: Get PNPM store
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
name: Setup PNPM cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-store-

- name: Install
run: pnpm install --frozen-lockfile

- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
packageManager: pnpm
workingDirectory: ./apps/api/
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
9 changes: 9 additions & 0 deletions apps/api/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: ['custom-node'],
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
};
11 changes: 11 additions & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
dist
.wrangler
.dev.vars
.env

# Change them to your taste:
package-lock.json
yarn.lock
pnpm-lock.yaml
bun.lockb
8 changes: 8 additions & 0 deletions apps/api/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by lint-staged to run linting and formatting on staged files

const path = require('path');

module.exports = {
'**/*.{js,jsx,cjs,mjs,ts,tsx}': 'pnpm --filter api exec eslint',
'**/*.{js,jsx,cjs,mjs,ts,tsx,md,html,css,json,yaml,yml}': 'pnpm --filter api exec prettier --check',
};
10 changes: 10 additions & 0 deletions apps/api/app/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { showRoutes } from 'hono/dev';
import { createApp } from 'honox/server';

const app = createApp();

app.get('/', (c) => c.text('Hello HonoX!'));

showRoutes(app);

export default app;
28 changes: 28 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "api",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "wrangler dev ./dist/server.js",
"deploy": "pnpm build && wrangler deploy ./dist/server.js",
"lint": "eslint .",
"format:check": "prettier --check .",
"format:fix": "prettier --write ."
},
"dependencies": {
"hono": "4.1.0",
"honox": "0.1.8",
"zod": "3.22.4"
},
"devDependencies": {
"@cloudflare/workers-types": "4.20240314.0",
"eslint-config-custom-node": "workspace:*",
"tsconfig": "workspace:*",
"vite": "5.1.6",
"vitest": "1.4.0",
"wrangler": "3.34.2"
}
}
18 changes: 18 additions & 0 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"lib": ["ESNext"],
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
},
"rootDir": "./",
"types": ["@cloudflare/workers-types"]
},
"include": ["**/*.ts", "**/*.*js"],
"exclude": ["node_modules"]
}
14 changes: 14 additions & 0 deletions apps/api/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import honox from 'honox/vite';
import { defineConfig } from 'vite';

export default defineConfig({
build: {
rollupOptions: {
input: {
server: './app/server.ts',
},
},
ssr: true,
},
plugins: [honox({ entry: './app/server.ts' })],
});
8 changes: 8 additions & 0 deletions apps/api/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
},
});
18 changes: 18 additions & 0 deletions apps/api/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name = "api"
compatibility_date = "2023-12-01"

# [vars]
# MY_VAR = "my-variable"

# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"

# [[d1_databases]]
# binding = "DB"
# database_name = "my-database"
# database_id = ""
5 changes: 5 additions & 0 deletions packages/eslint-config-custom-node/.lintstagedrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file is used by lint-staged to run linting and formatting on staged files

module.exports = {
'**/*.{js,jsx,ts,tsx,md,html,css,json,yaml,yml}': 'pnpm prettier --ignore-unknown --check',
};
48 changes: 48 additions & 0 deletions packages/eslint-config-custom-node/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file `.prettierignore` must be placed in each apps and packages directory.

# =============================================================================
# Inherited from `.gitignore`
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# =============================================================================

# dependencies
node_modules
.pnp
.pnp.js
.pnpm-store

# testing
coverage

# next.js
.next/
out/
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

# =============================================================================
# Unique to `.prettierignore` config
# =============================================================================

# Generated PNPM files
# Since renovate automatically updates these files, we don't want to format them
package.json
pnpm-lock.yaml
39 changes: 39 additions & 0 deletions packages/eslint-config-custom-node/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
$schema: 'https://json.schemastore.org/eslintrc',
extends: ['custom'],
parser: '@typescript-eslint/parser',
rules: {
'@typescript-eslint/consistent-type-imports': [
'error',
{
fixStyle: 'inline-type-imports',
},
],
'class-methods-use-this': 'off',
'dot-notation': 'off',
'no-empty-function': 'off',
'no-nested-ternary': 'off',
'no-useless-constructor': 'off',
},
overrides: [
{
files: ['./*'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'import/no-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'import/prefer-default-export': 'off',
},
},
{
files: ['./*.*js'],
extends: ['plugin:@typescript-eslint/disable-type-checked'],
},
],
settings: {
'import/resolver': {
typescript: {},
},
},
};
17 changes: 17 additions & 0 deletions packages/eslint-config-custom-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "eslint-config-custom-node",
"version": "0.0.0",
"main": "index.cjs",
"type": "commonjs",
"license": "MIT",
"scripts": {
"format:check": "prettier --check .",
"format:fix": "prettier --write ."
},
"dependencies": {
"eslint-config-custom": "workspace:*"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'turbo',
'prettier',
],
plugins: ['@typescript-eslint', 'import', 'prettier'],
parser: '@typescript-eslint/parser',
ignorePatterns: ['.turbo', 'node_modules', 'dist', '**/*.js', '**/*.mjs', '**/*.jsx', 'tsup.config.ts'],
rules: {
Expand Down
Loading

0 comments on commit bfc9dbc

Please sign in to comment.