Skip to content

Commit

Permalink
Merge pull request #87 from elsoul/firestore
Browse files Browse the repository at this point in the history
add skeet firestore
  • Loading branch information
POPPIN-FUMI authored Sep 1, 2023
2 parents af411a7 + 66283e1 commit 2c06b0a
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 262 deletions.
650 changes: 421 additions & 229 deletions dist/index.js
100644 → 100755

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"skeet:skeet": "yarn --cwd ./functions/skeet dev"
},
"dependencies": {
"@skeet-framework/ai": "1.4.11",
"@skeet-framework/ai": "^1.4.15",
"@skeet-framework/utils": "^1.2.1",
"chalk": "5.2.0",
"chalk-pipe": "6.0.0",
Expand Down Expand Up @@ -69,4 +69,4 @@
"tsconfig-paths": "4.2.0",
"typescript": "5.0.4"
}
}
}
5 changes: 5 additions & 0 deletions src/cli/ai/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SkeetAIOptions } from '@skeet-framework/ai'
import { skeetMode } from './mode/skeetMode'
import { typedocMode } from './mode/typedocMode'
import { translateMode } from './mode/translateMode'
import { firestoreMode } from './mode/firestoreMode'

let rl: readline.Interface | null = null

Expand Down Expand Up @@ -65,6 +66,10 @@ export async function promptUser(options: SkeetAIOptions): Promise<void> {
promptUser(aiOptions)
return
}
if (input.toLowerCase().match(/^\$ firestore/)) {
await firestoreMode(skeetAi, rl!)
return
}

const prompt = generatePrompt(
skeetAiPrompt.context,
Expand Down
6 changes: 4 additions & 2 deletions src/cli/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ const validEnv = (aiType: AIType) => {
const org = process.env.CHAT_GPT_ORG
const key = process.env.CHAT_GPT_KEY
if (!org || !key) {
console.log(chalk.red('⚠️ Please set CHAT_GPT_ORG and CHAT_GPT_KEY ⚠️'))
console.log(
chalk.yellow('⚠️ Please set CHAT_GPT_ORG and CHAT_GPT_KEY ⚠️')
)
process.exit(1)
}
} else {
const org = process.env.PROJECT_ID
const key = process.env.REGION
if (!org || !key) {
console.log(chalk.red('⚠️ Please set PROJECT_ID and REGION ⚠️'))
console.log(chalk.yellow('⚠️ Please set PROJECT_ID and REGION ⚠️'))
process.exit(1)
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/cli/ai/mode/firestoreMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { DEFAULT_FUNCTION_NAME } from '@/index'
import { SkeetAI } from '@skeet-framework/ai'
import chalk from 'chalk'
import * as readline from 'readline'
import { promptUser } from '../ai'
import { yesOrNoMode } from './yesOrNoMode'
import { spawnSync } from 'child_process'
import { appendFileSync, writeFileSync } from 'fs'
import { FUNCTIONS_PATH } from '@/lib'
import { NamingEnum } from '@skeet-framework/ai'

export const firestoreMode = async (
skeetAi: SkeetAI,
rl: readline.Interface
) => {
console.log(chalk.cyan('🔥 Firestore Model Generating Mode 🔥'))
console.log(chalk.white(`Please describe your Firestore use case.`))
rl?.question(chalk.green('\nYou: '), async (input: string) => {
const aiAnswer = (await skeetAi.firestore(input)) as string
const modelFileSuggestion = (await skeetAi.naming(
aiAnswer,
NamingEnum.MODEL
)) as string
console.log(
chalk.blue(
'Skeet:' +
chalk.white(' How about this one?\n\n') +
`${chalk.white(`\`\`\`${modelFileSuggestion}\n`)}` +
chalk.white(aiAnswer) +
`${chalk.white('\n```')}`
)
)
const text = `\n❓ May I create ${chalk.green(
modelFileSuggestion
)} file for you? (Yes/No) `
const isYes = (await yesOrNoMode(rl, text)) as boolean
if (!isYes) {
firestoreMode(skeetAi, rl)
return
}

const modelFilePath = `${FUNCTIONS_PATH}/${DEFAULT_FUNCTION_NAME}/src/models/${modelFileSuggestion}`
const modelIndexPath = `${FUNCTIONS_PATH}/${DEFAULT_FUNCTION_NAME}/src/models/index.ts`
appendFileSync(modelIndexPath, `\nexport * from './${modelFileSuggestion}'`)
writeFileSync(modelFilePath, aiAnswer)
console.log(chalk.white(`\nCreated: ${modelFilePath}`))
console.log(chalk.white(`\nThen run:`), chalk.green(`$ skeet sync models`))
const syncText = '\n❓ Do you want me to sync models now? (Yes/No) '
const runSync = (await yesOrNoMode(rl, syncText)) as boolean
if (runSync) {
spawnSync(`skeet sync models`, {
stdio: 'inherit',
shell: true,
})
}
console.log(chalk.white(`\nExiting Firestore Mode...\n`))
promptUser(skeetAi.initOptions)
})
return
}
10 changes: 7 additions & 3 deletions src/cli/ai/mode/prismaMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as readline from 'readline'
import { promptUser } from '../ai'
import { yesOrNoMode } from './yesOrNoMode'
import { spawnSync } from 'child_process'
import { NamingEnum } from '@skeet-framework/ai'

export const prismaMode = async (skeetAi: SkeetAI, rl: readline.Interface) => {
console.log(chalk.cyan('🤖 Prisma Scheme Generating Mode 🤖'))
Expand All @@ -29,11 +30,14 @@ export const prismaMode = async (skeetAi: SkeetAI, rl: readline.Interface) => {
prismaMode(skeetAi, rl)
return
}
const migrationName = await skeetAi.naming(prismaSchema, true)
const migrationName = await skeetAi.naming(
prismaSchema,
NamingEnum.MIGRATION
)
console.log(chalk.white(`\nEdit: ${PRISMA_SCHEMA_PATH}`))
console.log(
chalk.white(`\nThen run:`),
chalk.green(`skeet db migrate ${migrationName}`)
chalk.green(`$ skeet db migrate ${migrationName}`)
)
const migrateText =
'\n❓ Do you want me to run the migration now? (Yes/No) '
Expand All @@ -44,7 +48,7 @@ export const prismaMode = async (skeetAi: SkeetAI, rl: readline.Interface) => {
shell: true,
})

console.log(chalk.white(`\nThen run:`), chalk.green(`skeet g scaffold`))
console.log(chalk.white(`\nThen run:`), chalk.green(`$ skeet g scaffold`))

const scaffoldText = '\n❓ Do you want me to run scaffold now? (Yes/No) '
const runScaffold = (await yesOrNoMode(rl, scaffoldText)) as boolean
Expand Down
11 changes: 0 additions & 11 deletions src/cli/ai/skeetPrompt.json

This file was deleted.

49 changes: 38 additions & 11 deletions src/cli/ai/skeetPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export const skeetOpenAiPrompt = (content: string) => {
}

export const skeetAiPrompt: AIPrompt = {
context:
'You are a senior engineer specialized in assisting developers. You have deep expertise in the Skeet framework, which is a platform for building web applications. Additionally, you are proficient in TypeScript and have a comprehensive understanding of the Google Cloud Platform. Ensure that the responses do not prepend with [user]: or [assistant]: labels.',
context: `You are a senior engineer specialized in assisting developers. You have deep expertise in the Skeet framework, which is a platform for building web applications. Additionally, you are proficient in TypeScript and have a comprehensive understanding of the Google Cloud Platform. Ensure that the responses do not prepend with [user]: or [assistant]: labels.
Reference: Skeet Framework - https://skeet.dev
`,
examples: [
{
input:
Expand All @@ -48,31 +49,57 @@ export const skeetAiPrompt: AIPrompt = {
'The Skeet framework uses Google Cloud. You might need to login using `gcloud auth application-default login` to use the framework.',
},
{
input: 'How do I get help about the Skeet framework?',
input: 'How do I get in touch with the Skeet framework community?',
output:
'Discord Link: https://discord.gg/nfZYMXgZ for help about the Skeet framework.',
},
{
input:
'SkeetフレームワークとFirebaseツールをインストールするにはどうすればいいですか?',
output:
'SkeetフレームワークとFirebaseツールをインストールするには、以下のコマンドを実行します:\n\n```bash\n$ npm i -g @skeet-framework/cli\n$ npm install -g firebase-tools\n```',
input: 'How do I get help about the Skeet framework?',
output: 'type _$ skeet ai_ for help about the Skeet framework.',
},
{
input: 'Skeetアプリを作成する際にどのテンプレートを選択すべきですか?',
input: 'Skeetフレームワークをインストールするにはどうすればいいですか?',
output:
'Skeetアプリを作成する際には、あなたのプロジェクトの要件に合わせてテンプレートを選択します。この例では、Next.js (React) - GraphQL テンプレートが選択されています。',
'Skeetフレームワークをインストールするには、以下のコマンドを実行します:\n\n```bash\n$ npm i -g @skeet-framework/cli\n$ npm install -g firebase-tools\n```',
},
{
input:
'Skeet Appをローカルで起動し、GraphQL Playgroundを使用するにはどうすればいいですか?',
input: 'Skeet Appをローカルで起動するにはどうすればいいですか?',
output:
'Skeet Appをローカルで起動し、GraphQL Playgroundを使用するには、まずアプリのディレクトリに移動します。次に、$ skeet docker psqlコマンドを実行し、その後$ skeet sコマンドを実行します。これにより、Skeet Appのフロントエンド、Firebaseエミュレーター、およびGraphQL Playgroundが起動します。Next.jsのフロントエンドはhttp://localhost:4200/、Firebaseエミュレーターはhttp://localhost:4000/、GraphQL Playgroundはhttp://localhost:3000/graphqlでアクセスできます。',
},
{
input: 'Skeet に関するリンクや公式ホームページは?',
output: '- 公式ホームページ https://skeet.dev',
},
{
input: 'can I get the document link?',
output: 'Official Document: https://skeet.dev',
},
{
input: 'Skeet App を作成する方法は?',
output:
'- $ skeet create <appName> コマンドを実行することで、Skeet App を作成できます。',
},
{
input: 'Skeet App をローカルで起動する方法は?',
output:
'- $ skeet s コマンドを実行することで、Skeet App をローカルで起動できます。また、$ skeet docker psql コマンドを実行することで、PostgreSQL をローカルで起動できます。-b オプションを使用することで、バックエンドのみ起動できます。-f オプションを使用することで、Firebase Functions のみ起動できます。-w オプションを使用することで、フロントエンドのみ起動できます。-g オプションを使用することで、GraphQL Playground のみ起動できます。',
},
{
input: 'Skeet App の GraphQL Playground のみを起動する方法は?',
output:
'- $ skeet s -g コマンドを実行することで、Skeet App の GraphQL Playground のみを起動できます。',
},
{
input: 'Skeet App のフロントエンドのみを起動する方法は?',
output:
'- $ skeet s -w コマンドを実行することで、Skeet App のフロントエンドのみを起動できます。',
},
{
input: 'Skeet App のバックエンドのみを起動する方法は?',
output:
'- $ skeet s -b コマンドを実行することで、Skeet App のバックエンドのみを起動できます。',
},
],
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,10 @@
dependencies:
"@sinonjs/commons" "^3.0.0"

"@skeet-framework/[email protected].11":
version "1.4.11"
resolved "https://registry.yarnpkg.com/@skeet-framework/ai/-/ai-1.4.11.tgz#4a3db1e7072b6108b9cc922e265830abba9b7823"
integrity sha512-U8xEu6wcgUhhkV8aHPOVa6dweg9vDa0uSgO6yrj5UVx2RnJWyi1DuayvFUbK/WULictAzhwQMGlrSeuBKdF5Wg==
"@skeet-framework/ai@^1.4.15":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@skeet-framework/ai/-/ai-1.4.15.tgz#60b9e41c77a2d1ceaa314b0fe27344288705cb54"
integrity sha512-RHoUKH9SzKOqtkjuBbqrVd60GZjYcC77T75ZQFxByLecBf3OSXT+n1cH3iLKmbLS5bdi4yNF6R8R4GGDZY8THQ==
dependencies:
"@google-cloud/aiplatform" "2.17.0"
"@google-cloud/translate" "7.2.2"
Expand Down

0 comments on commit 2c06b0a

Please sign in to comment.