Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

プロジェクト作成 #303

Merged
merged 30 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1215927
Project setup
na2na-p Nov 11, 2023
6c71faa
ESM対応
na2na-p Nov 11, 2023
c328ebf
末尾改行
na2na-p Nov 11, 2023
63727d9
Schemaにvalidな感じにする
na2na-p Nov 11, 2023
24b453e
ファイル命名規則作っておく
na2na-p Nov 11, 2023
b41ae99
要らんもん消す
na2na-p Nov 13, 2023
5fb0e2f
Slash commandsつかえるようにした
na2na-p Nov 11, 2023
fd86c2a
リファクタリング
na2na-p Nov 11, 2023
d583294
不要なコンストラクタ消す
na2na-p Nov 11, 2023
5c48f2b
説明追記
na2na-p Nov 11, 2023
6065167
readonlyつける
na2na-p Nov 12, 2023
17182d7
Merge pull request #304 from na2na-p/topic/commands
na2na-p Nov 13, 2023
f8bde35
テスト追加
na2na-p Nov 12, 2023
d15a9a3
テスト追加
na2na-p Nov 12, 2023
eb6c97b
カバレッジ吐く
na2na-p Nov 12, 2023
76430ef
カバレッジ稼ぎ
na2na-p Nov 12, 2023
79840a4
テスト増やす
na2na-p Nov 12, 2023
0ed3ff5
エントリポイント修正
na2na-p Nov 12, 2023
39fe48e
依存更新
na2na-p Nov 12, 2023
630cff7
依存関係更新
na2na-p Nov 13, 2023
24d26b7
Merge pull request #305 from na2na-p/topic/test
na2na-p Nov 13, 2023
6896a7c
足回り改修
na2na-p Nov 13, 2023
fd0db26
一階層掘る
na2na-p Nov 13, 2023
0fda77e
CI付ける
na2na-p Nov 13, 2023
5cbb4b4
命名合わせる
na2na-p Nov 13, 2023
9f08e13
eslint設定直した
na2na-p Nov 15, 2023
fbbfbde
イケてる感じにした
na2na-p Nov 15, 2023
d424d4a
保存時アクションの最適化
na2na-p Nov 20, 2023
fca5431
jetbrains勢対応
na2na-p Nov 22, 2023
cb2adf4
改名
na2na-p Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*]
indent_style = tab
indent_size = 2
charset = utf-8
insert_final_newline = true
end_of_line = lf

[*.yml]
indent_style = space
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISCORD_APP_TOKEN=
BOT_NAME=2na2
SET_COMMANDS_TARGET_SERVERS=""
90 changes: 90 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"import",
"@typescript-eslint"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier"
],
"root": true,
"env": {
"node": true,
"jest": true
},
"ignorePatterns": [
".eslintrc.js"
],
"settings": {
"import/resolver": {
"typescript": {}
}
},
"rules": {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
],
"import/no-duplicates": "error",
"import/order": [
"error",
{
"groups": [
"builtin",
"external"
],
"pathGroups": [
{
"pattern": "@/**",
"group": "external",
"position": "after"
}
],
"alphabetize": {
"order": "asc"
},
"newlines-between": "always"
}
],
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports"
}
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "typeAlias",
"format": [
"PascalCase"
]
}
],
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": [
{
"group": [
"./*/**/internal/**/*",
"@/**/internal/**/*",
"../**/internal/**/*",
"@/features/**/internal/**/*"
],
"message": "Do not import internal modules."
}
]
}
],
"object-shorthand": "error"
}
}
30 changes: 30 additions & 0 deletions .github/workflows/cd-for-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CD for PR
on:
pull_request:
branches:
- main
- v3
types:
- opened
- reopened
- synchronize
- ready_for_review
- labeled
- unlabeled

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
prepare:
if: github.event.pull_request.draft == false
timeout-minutes: 60
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
ci:
uses: ./.github/workflows/ci.yml
secrets: inherit
needs: prepare
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI
on: workflow_call

jobs:
Build:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/[email protected]
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build

TypeCheck:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/[email protected]
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: typecheck
run: pnpm tsc --noEmit

Lint:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/[email protected]
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: fmt
run: pnpm fmt
- name: lint
run: pnpm lint

Test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: asdf install
uses: asdf-vm/actions/[email protected]
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: test
run: pnpm test:coverage
env:
TZ: Asia/Tokyo
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
coverage
dist/
.env
.idea
14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"jsxSingleQuote": false,
"printWidth": 80,
"quoteProps": "as-needed",
"rangeStart": 0,
"rangeEnd": 999999,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
24 changes: 24 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"dynamicImport": false,
"decorators": false
},
"target": "esnext",
"loose": false,
"externalHelpers": false,
"keepClassNames": false,
"paths": {
"@/*": [
"src/*"
]
}
},
"module": {
"type": "es6"
},
"minify": false
}
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 20.9.0
pnpm 8.10.5
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.eol": "\n",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always"
},
"cSpell.words": [
"jetdisc",
"swcrc"
]
}
32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const config = JSON.parse(readFileSync(`${__dirname}/.swcrc`, 'utf-8'));

/** @type {import('jest').Config} */
const jestConfig = {
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': ['@swc/jest', { ...config }],
},
setupFiles: ['<rootDir>/setup-global.ts'],
injectGlobals: true,
testEnvironment: 'node',
testTimeout: 200,

testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/dist/'],
modulePathIgnorePatterns: ['<rootDir>/dist/'],

restoreMocks: true,
clearMocks: true,
resetMocks: true,
};

export default jestConfig;
47 changes: 47 additions & 0 deletions loader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { isBuiltin } from 'node:module';
import { dirname } from 'node:path';
import { cwd } from 'node:process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { promisify } from 'node:util';

import resolveCallback from 'resolve/async.js';

const resolveAsync = promisify(resolveCallback);

const baseURL = pathToFileURL(cwd() + '/').href;

/**
* commonjs-extension-resolution-loader
* Originally written by Geoffrey Booth
* Edited and modified by na2na
* https://github.com/nodejs/loaders-test
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
export async function resolve(specifier, context, next) {
const { parentURL = baseURL } = context;

if (isBuiltin(specifier)) {
return next(specifier, context);
}

// `resolveAsync` works with paths, not URLs
if (specifier.startsWith('file://')) {
specifier = fileURLToPath(specifier);
}
const parentPath = fileURLToPath(parentURL);

let url;
try {
const resolution = await resolveAsync(specifier, {
basedir: dirname(parentPath),
extensions: ['.js', '.json', '.node', '.mjs'],
});
url = pathToFileURL(resolution).href;
} catch (error) {
return next(specifier, context, next);
}

return next(url, context);
}
Loading