Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit e65042d

Browse files
authored
Merge pull request #311 from elsoul/cli
update get dirs
2 parents 4291065 + 66f657b commit e65042d

File tree

10 files changed

+70
-43
lines changed

10 files changed

+70
-43
lines changed

common/runDiscordChangeLog.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { discordChangeLog } from '@skeet-framework/discord-utils'
2-
import dotenv from 'dotenv'
3-
4-
dotenv.config()
2+
require('dotenv').config()
53

64
const REPO_NAME = 'elsoul/skeet'
75

packages/cli/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,15 @@
7575
"babel-loader": "9.1.3",
7676
"copyfiles": "2.4.1",
7777
"esbuild": "0.20.1",
78-
"esbuild-plugin-alias-path": "^2.0.2",
78+
"esbuild-plugin-alias-path": "2.0.2",
7979
"eslint": "8.57.0",
80-
"eslint-config-prettier": "9.1.0",
8180
"nodemon": "3.1.0",
8281
"prettier": "3.2.5",
8382
"ts-loader": "9.5.1",
8483
"tsconfig-paths": "4.2.0",
85-
"tsx": "^4.7.1",
84+
"tsx": "4.7.1",
8685
"typescript": "5.4.2",
87-
"vite": "^5.1.5",
86+
"vite": "5.1.5",
8887
"vite-tsconfig-paths": "4.3.1",
8988
"vitest": "1.3.1"
9089
}

packages/cli/src/cli/ai/ai.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ export async function promptUser(
100100
// }
101101

102102
const skeetPrompt = skeetAiPrompt('en')
103-
await chat(
104-
skeetPrompt.context,
105-
skeetPrompt.examples,
106-
userInput.input,
107-
aiOptions.ai,
108-
)
103+
await chat(skeetPrompt.context, skeetPrompt.examples, userInput.input)
109104
await promptUser(aiOptions, logger)
110105
}

packages/cli/src/cli/ai/mode/prismaMode.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PRISMA_SCHEMA_PATH } from '@/index'
21
import chalk from 'chalk'
32
import { promptUser } from '../ai'
43
import { spawnSync } from 'child_process'
@@ -8,6 +7,13 @@ import inquirer from 'inquirer'
87
import { yesOrNo } from './yesOrNoMode'
98
import { AiLog } from '../aiLog'
109
import { SkeetAIOptions } from '..'
10+
import { getSQLs } from '@/lib/files/getSQLs'
11+
import { prismaPrompt } from '../skeetai/prisma/prompt'
12+
13+
type PrismaOptions = {
14+
modelPath: string
15+
input: string
16+
}
1117

1218
export const prismaMode = async (config: SkeetAIOptions, logger: AiLog) => {
1319
const log = logger.text() as SkeetLog
@@ -23,14 +29,21 @@ export const prismaMode = async (config: SkeetAIOptions, logger: AiLog) => {
2329
log.prismaMode.example2 +
2430
'\n\n' +
2531
chalk.green(log.common.you + ':')
26-
logger.addJson(SkeetRole.AI, inputMessage, SkeetAiMode.Firestore, model)
27-
const answer = await inquirer.prompt([
32+
33+
const answer = await inquirer.prompt<PrismaOptions>([
34+
{
35+
type: 'list',
36+
name: 'modelPath',
37+
message: 'Select Model',
38+
choices: await getSQLs(),
39+
},
2840
{
2941
type: 'input',
3042
name: 'input',
3143
message: inputMessage,
3244
},
3345
])
46+
const firstAiContent = await prismaPrompt(answer.modelPath)
3447

3548
const prismaSchema = (await skeetAi.prisma(answer.input)) as string
3649
console.log(

packages/cli/src/lib/files/getAllApps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync } from '@skeet-framework/utils'
1+
import path from 'path'
22
import { getDirectoryLastModified } from './getDirectoryLastModified'
33
import { getFunctions } from './getFunctions'
44
import { getSQLs } from './getSQLs'
@@ -10,7 +10,7 @@ export const getAllApps = async () => {
1010
const dirs = (await getFunctions()).map((dir) => `functions/${dir}`)
1111
const sqls = (await getSQLs()).map((dir) => `sql/${dir}`)
1212
dirs.push('webapp')
13-
if (await existsSync('webapp')) {
13+
if (!path.join(process.cwd(), 'webapp')) {
1414
await mkdir('webapp', { recursive: true })
1515
}
1616
dirs.push(...sqls)
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { mkdir, readdir } from 'fs/promises'
22
import path from 'path'
3+
import { sortDirsByLastModified } from './sortDirsByLastModified'
34

45
export const getFunctions = async () => {
5-
const functionsDir = path.join(process.cwd(), 'functions')
6-
if (!functionsDir) {
7-
await mkdir(functionsDir, { recursive: true })
6+
try {
7+
const dir = path.join(process.cwd(), 'functions')
8+
if (!dir) {
9+
await mkdir(dir, { recursive: true })
10+
}
11+
const sqlDirs = (await readdir(dir)).map((dirName) =>
12+
path.join(dir, dirName),
13+
)
14+
const result = await sortDirsByLastModified(sqlDirs)
15+
return result
16+
} catch (error) {
17+
console.log('getFunctions:', error)
18+
return ['']
819
}
9-
console.log(functionsDir)
10-
const functions = await readdir(functionsDir)
11-
return functions
1220
}

packages/cli/src/lib/files/getSQLs.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { mkdir, readdir } from 'fs/promises'
22
import path from 'path'
3+
import { sortDirsByLastModified } from './sortDirsByLastModified'
34

45
export const getSQLs = async () => {
5-
const dir = path.join(process.cwd(), 'sql')
6-
if (!dir) {
7-
await mkdir(dir, { recursive: true })
6+
try {
7+
const dir = path.join(process.cwd(), 'sql')
8+
if (!dir) {
9+
await mkdir(dir, { recursive: true })
10+
}
11+
const sqlDirs = (await readdir(dir)).map((dirName) =>
12+
path.join(dir, dirName),
13+
)
14+
const result = await sortDirsByLastModified(sqlDirs)
15+
return result
16+
} catch (error) {
17+
console.log('Error getting SQL directories:', error)
18+
return ['']
819
}
9-
console.log(dir)
10-
const apps = await readdir(dir)
11-
return apps
1220
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { getDirectoryLastModified } from './getDirectoryLastModified'
2+
3+
export const sortDirsByLastModified = async (dirs: string[]) => {
4+
const dirsWithStats = []
5+
for await (const dir of dirs) {
6+
const lastModified = await getDirectoryLastModified(dir)
7+
dirsWithStats.push({ name: dir, mtime: lastModified })
8+
}
9+
10+
// Sort by last modified date
11+
dirsWithStats.sort((a, b) => b.mtime.getTime() - a.mtime.getTime())
12+
const dirNames = dirsWithStats.map((dir) => dir.name.split('/').pop())
13+
return dirNames as string[]
14+
}

packages/cli/tests/file.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Method: getFunctions/getSQLs', () => {
1414

1515
it('should return SQL Apps array', async () => {
1616
const functions = await getSQLs()
17+
console.log(functions)
1718

1819
// return SQL App Name array
1920
expect(functions).toBeInstanceOf(Array)

pnpm-lock.yaml

Lines changed: 4 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)