Skip to content

Commit

Permalink
refactor: set printWidth 100
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed May 3, 2023
1 parent 59ee387 commit 20fee9a
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 363 deletions.
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"frourio",
"typescript"
],
"prettier": {
"printWidth": 100,
"semi": false,
"trailingComma": "none",
"singleQuote": true
},
"dependencies": {
"@aspida/axios": "^1.11.0",
"@aspida/swr": "^1.11.0",
Expand Down
18 changes: 3 additions & 15 deletions scripts/build-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ interface Params {
const omitImportNodeNSPlugin: Plugin = {
name: 'omit-import-node-ns',
setup(build) {
build.onResolve({ filter: /^node:/ }, (args) => {
return {
path: args.path.slice(5),
external: true
}
})
build.onResolve({ filter: /^node:/ }, (args) => ({ path: args.path.slice(5), external: true }))
}
}

Expand Down Expand Up @@ -50,20 +45,13 @@ const main = async ({ from, to, watch, prod, target, server }: Params) => {
minify: true,
keepNames: true,
jsx: server ? undefined : 'transform',
define: {
'process.env.NODE_ENV': prod ? '"production"' : '"development"'
},
define: { 'process.env.NODE_ENV': prod ? '"production"' : '"development"' },
sourcemap: 'inline',
bundle: true,
outfile: toPath,
entryPoints: [fromPath],
watch: watchOptions,
plugins: [
omitImportNodeNSPlugin,
nodeExternalsPlugin({
allowList: []
})
]
plugins: [omitImportNodeNSPlugin, nodeExternalsPlugin({ allowList: [] })]
})
}

Expand Down
4 changes: 1 addition & 3 deletions server/api/answers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export default defineController(({ appendLogging, clientReady }) => ({
for (let i = 0; i < 600; i++) {
await new Promise((resolve) => setTimeout(resolve, 1000))
try {
const client = axios.create({
baseURL: `http://localhost:${serverPort}/api`
})
const client = axios.create({ baseURL: `http://localhost:${serverPort}/api` })
const res = await client.get('tasks')
if (res.status === 200) {
clientReady()
Expand Down
21 changes: 4 additions & 17 deletions server/api/dbConnection/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ export default defineController(() => ({
return { status: 200, body: { enabled: true } }
}

const templateCtx = answersToTemplateContext({
...answers,
serverPort: 0,
clientPort: 0
})
const templateCtx = answersToTemplateContext({ ...answers, serverPort: 0, clientPort: 0 })

if (
templateCtx.dbHost !== '127.0.0.1' &&
templateCtx.dbHost !== 'localhost'
) {
if (templateCtx.dbHost !== '127.0.0.1' && templateCtx.dbHost !== 'localhost') {
return {
status: 200,
body: {
Expand All @@ -44,10 +37,7 @@ export default defineController(() => ({
}

if (answers.db === 'mysql') {
const conn = await mariadb.createConnection({
...config,
allowPublicKeyRetrieval: true
})
const conn = await mariadb.createConnection({ ...config, allowPublicKeyRetrieval: true })

await conn.query(`CREATE DATABASE IF NOT EXISTS ${templateCtx.dbName}`)

Expand All @@ -67,10 +57,7 @@ export default defineController(() => ({

return { status: 200, body: { enabled: true } }
} catch (e) {
return {
status: 200,
body: { enabled: false, err: e instanceof Error ? e.message : '' }
}
return { status: 200, body: { enabled: false, err: e instanceof Error ? e.message : '' } }
}
}
}))
11 changes: 3 additions & 8 deletions server/api/localPath/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ import path from 'path'
export default defineController(() => ({
post: async ({ body: { path: relativePath } }) => {
const absPath = path.resolve(process.cwd(), relativePath)
const body = {
absPath,
canContinue: canContinueOnPath(await getPathStatus(absPath))
}
return {
status: 200,
body
}
const body = { absPath, canContinue: canContinueOnPath(await getPathStatus(absPath)) }

return { status: 200, body }
}
}))
41 changes: 11 additions & 30 deletions server/common/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,11 @@ export const cfaPrompts: Prompt[] = [
name: `${db}Db${what}` as PromptName,
message: (ans: Answers) => {
if (ans.orm === 'prisma') {
return `dev DB ${typeormEnv}: server/prisma/.env API_DATABASE_URL (${getPrismaDbUrl(
{
...ans,
[`${db}Db${what}`]: (ans as any)[`${db}Db${what}`] || 'HERE',
[`${db}DbPass`]: (ans as any)[`${db}DbPass`]
? '***'
: what === 'Pass'
? 'HERE'
: ''
}
)}) =`
return `dev DB ${typeormEnv}: server/prisma/.env API_DATABASE_URL (${getPrismaDbUrl({
...ans,
[`${db}Db${what}`]: (ans as any)[`${db}Db${what}`] || 'HERE',
[`${db}DbPass`]: (ans as any)[`${db}DbPass`] ? '***' : what === 'Pass' ? 'HERE' : ''
})}) =`
} else {
return `dev DB: server/.env TYEPORM_${typeormEnv} =`
}
Expand Down Expand Up @@ -345,8 +339,7 @@ export const cfaPrompts: Prompt[] = [
`- **API_DATABASE_URL**: ${
(
{
sqlite:
'Production URL for SQLite. e.g. `file:///mnt/efs-data/db.sqlite`',
sqlite: 'Production URL for SQLite. e.g. `file:///mnt/efs-data/db.sqlite`',
mysql:
'Production URL for MySQL. e.g. `mysql://mysql-instance1.123456789012.us-east-1.rds.amazonaws.com:3306`',
postgresql:
Expand Down Expand Up @@ -456,9 +449,7 @@ export const cfaPrompts: Prompt[] = [
'### Deploy to Vercel',
'',
'1. Visit [vercel.com](https://vercel.com) and create new project.',
'2. Set **BUILD COMMAND** to `' +
ans.pm +
' run build:client`.',
'2. Set **BUILD COMMAND** to `' + ans.pm + ' run build:client`.',
'3. Add environment variables **API_BASE_PATH** and **API_ORIGIN**.'
].join('\n')
}
Expand All @@ -478,9 +469,7 @@ export const cfaPrompts: Prompt[] = [
'1. Visit [app.netlify.com](https://app.netlify.com) and create new project.',
'2. Go to **Site Settings** > **Build & Deploy**',
' a. Set **Repository** to your remote repository',
' b. Set **Build command** to `' +
ans.pm +
' run build:client`',
' b. Set **Build command** to `' + ans.pm + ' run build:client`',
' c. Set **Publish directory** to `out/`',
'3. Go to **Site Settings** > **Build & Deploy** > **Environment**',
' a. Add environment variables **API_ORIGIN** and **API_BASE_PATH**.'
Expand Down Expand Up @@ -550,15 +539,10 @@ export const cfaPrompts: Prompt[] = [
]

/* eslint-disable @typescript-eslint/no-explicit-any */
export const calculatePrompts = (
answers: Answers,
target: any = cfaPrompts
): any => {
export const calculatePrompts = (answers: Answers, target: any = cfaPrompts): any => {
if (target === null) return target
if (Array.isArray(target)) {
return target
.map((e: any) => calculatePrompts(answers, e))
.filter((e: any) => e !== undefined)
return target.map((e: any) => calculatePrompts(answers, e)).filter((e: any) => e !== undefined)
}
if (typeof target === 'object') {
const res: any = {}
Expand Down Expand Up @@ -635,10 +619,7 @@ export const isAnswersValid = (answers: Answers) => {
if (valid !== undefined) return valid

if (el.type === 'list') {
return (
(el.choices.filter((choice) => choice.value === value)[0]?.disabled ??
false) === false
)
return (el.choices.filter((choice) => choice.value === value)[0]?.disabled ?? false) === false
}

if (el.type === 'input') {
Expand Down
7 changes: 1 addition & 6 deletions server/common/template-context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Answers,
CommonDbInfo,
getCommonDbInfo,
getPrismaDbUrl
} from './prompts'
import { Answers, CommonDbInfo, getCommonDbInfo, getPrismaDbUrl } from './prompts'

// This is something like `computed value`.
// Additional keys should not include the same key on Answers.
Expand Down
17 changes: 4 additions & 13 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,17 @@ const basePath = '/api'

const fastify = Fastify()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fastify.register(FastifyStatic, {
root: path.join(__dirname, '../../out')
})
await fastify.register(FastifyInject, {
dir,
logging,
ready
})
fastify.register(FastifyStatic, { root: path.join(__dirname, '../../out') })
await fastify.register(FastifyInject, { dir, logging, ready })
if (process.env.NODE_ENV === 'development') {
fastify
// eslint-disable-next-line @typescript-eslint/no-var-requires
.register(require('@fastify/nextjs'), {
dev: true,
conf: {
env: {
NEXT_PUBLIC_SERVER_PORT: port
}
}
conf: { env: { NEXT_PUBLIC_SERVER_PORT: port } }
})
.after(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(fastify as any).next('/')
})
}
Expand Down
12 changes: 3 additions & 9 deletions server/plugins/fastify-inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ export interface FastifyInjectOptions {
}

const fastifyInject: FastifyPluginCallback<FastifyInjectOptions> = fp(
(
fastify: FastifyInstance,
options: FastifyInjectOptions,
next: () => void
) => {
(fastify: FastifyInstance, options: FastifyInjectOptions, next: () => void) => {
fastify.decorateRequest('dir', { getter: () => options.dir })
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fastify.decorate('appendLogging', (data: any) => {
options.logging.push(data)
})
Expand All @@ -34,10 +31,7 @@ const fastifyInject: FastifyPluginCallback<FastifyInjectOptions> = fp(
})
next()
},
{
fastify: '>=3',
name: 'fastify-winston-logger'
}
{ fastify: '>=3', name: 'fastify-winston-logger' }
)

export default fastifyInject
17 changes: 4 additions & 13 deletions server/service/__tests__/package-json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { convertListToJson } from '../package-json'

describe('convertListToJson', () => {
const deps = {
frourio: 'v1.0.0',
aspida: 'v1.0.0',
'@types/node': 'v1.0.0'
}
const deps = { frourio: 'v1.0.0', aspida: 'v1.0.0', '@types/node': 'v1.0.0' }

it('[frourio], indent=" "', () => {
expect(convertListToJson(deps, ['frourio'], ' ')).toMatch(
/^ {2}"frourio": "v.*"$/
)
expect(convertListToJson(deps, ['frourio'], ' ')).toMatch(/^ {2}"frourio": "v.*"$/)
})
it('[frourio, aspida, frourio, frourio, @types/node], indent=" "', () => {
expect(
convertListToJson(
deps,
['frourio', 'aspida', 'frourio', 'frourio', '@types/node'],
' '
)
convertListToJson(deps, ['frourio', 'aspida', 'frourio', 'frourio', '@types/node'], ' ')
).toMatch(/^ "@types\/node": "v.*",\n "aspida": "v.*",\n "frourio": "v.*"$/)
})
})
Loading

0 comments on commit 20fee9a

Please sign in to comment.