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

chore: add linter #16

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@hono/eslint-config'],
}
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.fixAll.eslint": "explicit"
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"build": "tsx ./build.ts",
"test": "vitest --run",
"prepack": "yarn build",
"release": "np"
"release": "np",
"lint": "eslint --ext js,ts src",
"lint:fix": "eslint --ext js,ts src --fix"
},
"bin": "./bin",
"files": [
Expand All @@ -22,17 +24,20 @@
"registry": "https://registry.npmjs.org"
},
"devDependencies": {
"@hono/eslint-config": "^0.0.2",
"@types/degit": "^2.8.3",
"@types/node": "^18.11.18",
"@types/prompts": "^2.4.2",
"@types/yargs-parser": "^21.0.0",
"degit": "^2.8.4",
"esbuild": "^0.16.17",
"eslint": "^8.55.0",
"kleur": "^4.1.5",
"node-fetch": "^3.3.0",
"np": "^7.6.3",
"prompts": "^2.4.2",
"tsx": "^3.12.2",
"typescript": "^5.3.3",
"vitest": "^0.34.6",
"yargs-parser": "^21.1.1"
}
Expand Down
1 change: 1 addition & 0 deletions src/hook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export class Hook<HookFunction extends (...args: any[]) => any> {
#hookMap: Map<string, HookFunction[]>
constructor() {
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/after-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ afterCreateHook.addHook(
({ projectName, directoryPath }) => {
const wranglerPath = path.join(directoryPath, 'wrangler.toml')
const wrangler = readFileSync(wranglerPath, 'utf-8')
const convertProjectName = projectName.toLowerCase().replaceAll(/[^a-z0-9\-_]/gm, "-")
const convertProjectName = projectName
.toLowerCase()
.replaceAll(/[^a-z0-9\-_]/gm, '-')
const rewritten = wrangler.replaceAll(PROJECT_NAME, convertProjectName)
writeFileSync(wranglerPath, rewritten)
}
Expand Down
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import degit from 'degit'
import fs from 'fs'
import { bold, gray, green } from 'kleur/colors'
import path from 'path'
import degit from 'degit'
import { bold, gray, green } from 'kleur/colors'
import prompts from 'prompts'
import yargsParser from 'yargs-parser'
import { version } from '../package.json'
Expand Down Expand Up @@ -30,28 +30,28 @@ function mkdirp(dir: string) {
async function main() {
console.log(gray(`\ncreate-hono version ${version}`))

let args = yargsParser(process.argv.slice(2))
const args = yargsParser(process.argv.slice(2))

const templateArg = args.template

const templateDirs = await viaContentsApi(config)
const templates: Record<string, { name: string }> = {}

templateDirs.forEach((dir) => {
let template = dir.replace(`${directoryName}/`, '')
const template = dir.replace(`${directoryName}/`, '')
if (!templates[template]) {
templates[template] = {
name: template,
}
}
})
let templateNames = [...Object.values(templates)] as { name: string }[]
const templateNames = [...Object.values(templates)] as { name: string }[]

let target = ''
let projectName = ''
if (args._[0]) {
target = args._[0].toString()
console.log(`${bold(`${green(`✔`)} Using target directory`)} … ${target}`)
console.log(`${bold(`${green('✔')} Using target directory`)} … ${target}`)
projectName = path.basename(target)
} else {
const answer = await prompts({
Expand All @@ -75,6 +75,7 @@ async function main() {
type: 'select',
name: 'template',
message: 'Which template do you want to use?',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
choices: templateNames.map((template: any) => ({
title: template.name,
value: template.name,
Expand Down Expand Up @@ -107,7 +108,7 @@ async function main() {
mkdirp(target)
}

await new Promise((res, rej) => {
await new Promise((res) => {
const emitter = degit(
`${config.user}/${config.repository}/${config.directory}/${templateName}#${config.ref}`,
{
Expand Down
Loading