From 2f760748a3a2cab9fe616ab0392df625b47bab44 Mon Sep 17 00:00:00 2001 From: POPPIN-FUMI Date: Wed, 6 Mar 2024 16:08:45 +0100 Subject: [PATCH 1/3] Update - getSQLs --- common/runDiscordChangeLog.ts | 4 +- packages/cli/package.json | 12 +-- packages/cli/src/cli/ai/mode/prismaMode.ts | 19 +++- packages/cli/src/lib/files/getFunctions.ts | 20 ++-- packages/cli/src/lib/files/getSQLs.ts | 20 ++-- .../src/lib/files/sortDirsByLastModified.ts | 14 +++ packages/cli/tests/file.test.ts | 1 + pnpm-lock.yaml | 102 ++++++++++++------ 8 files changed, 132 insertions(+), 60 deletions(-) create mode 100644 packages/cli/src/lib/files/sortDirsByLastModified.ts diff --git a/common/runDiscordChangeLog.ts b/common/runDiscordChangeLog.ts index 2753ab9f..f5cea3db 100644 --- a/common/runDiscordChangeLog.ts +++ b/common/runDiscordChangeLog.ts @@ -1,7 +1,5 @@ import { discordChangeLog } from '@skeet-framework/discord-utils' -import dotenv from 'dotenv' - -dotenv.config() +require('dotenv').config() const REPO_NAME = 'elsoul/skeet' diff --git a/packages/cli/package.json b/packages/cli/package.json index 5f48fadb..6155863c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -52,7 +52,6 @@ "cli-spinner": "0.2.10", "cli-table3": "0.6.3", "commander": "12.0.0", - "dotenv": "16.4.1", "dotenv-cli": "7.3.0", "i18n": "0.15.1", "inquirer": "9.2.14", @@ -60,29 +59,24 @@ }, "devDependencies": { "@changesets/cli": "2.27.1", - "@skeet-framework/discord-utils": "0.4.0", - "@skeet-framework/firestore": "2.5.1", + "@skeet-framework/discord-utils": "workspace:*", + "@skeet-framework/firestore": "workspace:*", "@stdlib/string-percent-encode": "0.1.1", "@types/cli-spinner": "0.2.3", "@types/i18n": "0.13.10", "@types/inquirer": "9.0.7", - "@types/jest": "29.5.12", "@types/node": "20.11.16", "@types/prompt": "1.1.8", "@types/semver": "7.5.6", "@typescript-eslint/eslint-plugin": "6.21.0", "@typescript-eslint/parser": "6.21.0", - "babel-loader": "9.1.3", "copyfiles": "2.4.1", "esbuild": "0.20.0", - "esbuild-plugin-alias-path": "^2.0.2", "eslint": "8.56.0", "eslint-config-prettier": "9.1.0", "nodemon": "3.0.3", "prettier": "3.2.5", - "ts-loader": "9.5.1", - "tsconfig-paths": "4.2.0", - "tsx": "^4.7.1", + "tsx": "4.7.1", "typescript": "5.3.3", "vite-tsconfig-paths": "4.3.1", "vitest": "1.3.0", diff --git a/packages/cli/src/cli/ai/mode/prismaMode.ts b/packages/cli/src/cli/ai/mode/prismaMode.ts index 5757b21a..de625a99 100644 --- a/packages/cli/src/cli/ai/mode/prismaMode.ts +++ b/packages/cli/src/cli/ai/mode/prismaMode.ts @@ -1,4 +1,3 @@ -import { PRISMA_SCHEMA_PATH } from '@/index' import chalk from 'chalk' import { promptUser } from '../ai' import { spawnSync } from 'child_process' @@ -8,6 +7,13 @@ import inquirer from 'inquirer' import { yesOrNo } from './yesOrNoMode' import { AiLog } from '../aiLog' import { SkeetAIOptions } from '..' +import { getSQLs } from '@/lib/files/getSQLs' +import { prismaPrompt } from '../skeetai/prisma/prompt' + +type PrismaOptions = { + modelPath: string + input: string +} export const prismaMode = async (config: SkeetAIOptions, logger: AiLog) => { const log = logger.text() as SkeetLog @@ -23,14 +29,21 @@ export const prismaMode = async (config: SkeetAIOptions, logger: AiLog) => { log.prismaMode.example2 + '\n\n' + chalk.green(log.common.you + ':') - logger.addJson(SkeetRole.AI, inputMessage, SkeetAiMode.Firestore, model) - const answer = await inquirer.prompt([ + + const answer = await inquirer.prompt([ + { + type: 'list', + name: 'modelPath', + message: 'Select Model', + choices: await getSQLs(), + }, { type: 'input', name: 'input', message: inputMessage, }, ]) + const firstAiContent = await prismaPrompt(answer.modelPath) const prismaSchema = (await skeetAi.prisma(answer.input)) as string console.log( diff --git a/packages/cli/src/lib/files/getFunctions.ts b/packages/cli/src/lib/files/getFunctions.ts index 7f9416f1..c39fb2a1 100644 --- a/packages/cli/src/lib/files/getFunctions.ts +++ b/packages/cli/src/lib/files/getFunctions.ts @@ -1,12 +1,20 @@ import { mkdir, readdir } from 'fs/promises' import path from 'path' +import { sortDirsByLastModified } from './sortDirsByLastModified' export const getFunctions = async () => { - const functionsDir = path.join(process.cwd(), 'functions') - if (!functionsDir) { - await mkdir(functionsDir) + try { + const dir = path.join(process.cwd(), 'functions') + if (!dir) { + await mkdir(dir) + } + const sqlDirs = (await readdir(dir)).map((dirName) => + path.join(dir, dirName), + ) + const result = await sortDirsByLastModified(sqlDirs) + return result + } catch (error) { + console.log('getFunctions:', error) + return [''] } - console.log(functionsDir) - const functions = await readdir(functionsDir) - return functions } diff --git a/packages/cli/src/lib/files/getSQLs.ts b/packages/cli/src/lib/files/getSQLs.ts index 8f6d046a..e23142dc 100644 --- a/packages/cli/src/lib/files/getSQLs.ts +++ b/packages/cli/src/lib/files/getSQLs.ts @@ -1,12 +1,20 @@ import { mkdir, readdir } from 'fs/promises' import path from 'path' +import { sortDirsByLastModified } from './sortDirsByLastModified' export const getSQLs = async () => { - const dir = path.join(process.cwd(), 'sql') - if (!dir) { - await mkdir(dir) + try { + const dir = path.join(process.cwd(), 'sql') + if (!dir) { + await mkdir(dir) + } + const sqlDirs = (await readdir(dir)).map((dirName) => + path.join(dir, dirName), + ) + const result = await sortDirsByLastModified(sqlDirs) + return result + } catch (error) { + console.log('Error getting SQL directories:', error) + return [''] } - console.log(dir) - const apps = await readdir(dir) - return apps } diff --git a/packages/cli/src/lib/files/sortDirsByLastModified.ts b/packages/cli/src/lib/files/sortDirsByLastModified.ts new file mode 100644 index 00000000..2c902a61 --- /dev/null +++ b/packages/cli/src/lib/files/sortDirsByLastModified.ts @@ -0,0 +1,14 @@ +import { getDirectoryLastModified } from './getDirectoryLastModified' + +export const sortDirsByLastModified = async (dirs: string[]) => { + const dirsWithStats = [] + for await (const dir of dirs) { + const lastModified = await getDirectoryLastModified(dir) + dirsWithStats.push({ name: dir, mtime: lastModified }) + } + + // Sort by last modified date + dirsWithStats.sort((a, b) => b.mtime.getTime() - a.mtime.getTime()) + const dirNames = dirsWithStats.map((dir) => dir.name.split('/').pop()) + return dirNames as string[] +} diff --git a/packages/cli/tests/file.test.ts b/packages/cli/tests/file.test.ts index 5e6ccea0..8144f744 100644 --- a/packages/cli/tests/file.test.ts +++ b/packages/cli/tests/file.test.ts @@ -14,6 +14,7 @@ describe('Method: getFunctions/getSQLs', () => { it('should return SQL Apps array', async () => { const functions = await getSQLs() + console.log(functions) // return SQL App Name array expect(functions).toBeInstanceOf(Array) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 92d50f98..eeca5257 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -160,9 +160,6 @@ importers: commander: specifier: 12.0.0 version: 12.0.0 - dotenv: - specifier: 16.4.1 - version: 16.4.1 dotenv-cli: specifier: 7.3.0 version: 7.3.0 @@ -180,10 +177,10 @@ importers: specifier: 2.27.1 version: 2.27.1 '@skeet-framework/discord-utils': - specifier: 0.4.0 + specifier: workspace:* version: link:../discord-utils '@skeet-framework/firestore': - specifier: 2.5.1 + specifier: workspace:* version: link:../firestore '@stdlib/string-percent-encode': specifier: 0.1.1 @@ -197,9 +194,6 @@ importers: '@types/inquirer': specifier: 9.0.7 version: 9.0.7 - '@types/jest': - specifier: 29.5.12 - version: 29.5.12 '@types/node': specifier: 20.11.16 version: 20.11.16 @@ -215,18 +209,12 @@ importers: '@typescript-eslint/parser': specifier: 6.21.0 version: 6.21.0(eslint@8.56.0)(typescript@5.3.3) - babel-loader: - specifier: 9.1.3 - version: 9.1.3(@babel/core@7.24.0)(webpack@5.90.3) copyfiles: specifier: 2.4.1 version: 2.4.1 esbuild: specifier: 0.20.0 version: 0.20.0 - esbuild-plugin-alias-path: - specifier: ^2.0.2 - version: 2.0.2(esbuild@0.20.0) eslint: specifier: 8.56.0 version: 8.56.0 @@ -239,14 +227,8 @@ importers: prettier: specifier: 3.2.5 version: 3.2.5 - ts-loader: - specifier: 9.5.1 - version: 9.5.1(typescript@5.3.3)(webpack@5.90.3) - tsconfig-paths: - specifier: 4.2.0 - version: 4.2.0 tsx: - specifier: ^4.7.1 + specifier: 4.7.1 version: 4.7.1 typescript: specifier: 5.3.3 @@ -6048,7 +6030,7 @@ packages: '@babel/core': 7.24.0 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.90.3(esbuild@0.20.0) + webpack: 5.90.3(esbuild@0.20.1) dev: true /babel-plugin-istanbul@6.1.1: @@ -7654,17 +7636,6 @@ packages: es6-promise: 4.2.8 dev: false - /esbuild-plugin-alias-path@2.0.2(esbuild@0.20.0): - resolution: {integrity: sha512-YK8H9bzx6/CG6YBV11XjoNLjRhNZP0Ta4xZ3ATHhPn7pN8ljQGg+zne4d47DpIzF8/sX2qM+xQWev0CvaD2rSQ==} - peerDependencies: - esbuild: '>= 0.14.0' - dependencies: - esbuild: 0.20.0 - find-up: 5.0.0 - fs-extra: 10.1.0 - jsonfile: 6.1.0 - dev: true - /esbuild-plugin-alias-path@2.0.2(esbuild@0.20.1): resolution: {integrity: sha512-YK8H9bzx6/CG6YBV11XjoNLjRhNZP0Ta4xZ3ATHhPn7pN8ljQGg+zne4d47DpIzF8/sX2qM+xQWev0CvaD2rSQ==} peerDependencies: @@ -15110,6 +15081,31 @@ packages: webpack: 5.90.3(esbuild@0.20.0) dev: true + /terser-webpack-plugin@5.3.10(esbuild@0.20.1)(webpack@5.90.3): + resolution: {integrity: sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==} + engines: {node: '>= 10.13.0'} + peerDependencies: + '@swc/core': '*' + esbuild: '*' + uglify-js: '*' + webpack: ^5.1.0 + peerDependenciesMeta: + '@swc/core': + optional: true + esbuild: + optional: true + uglify-js: + optional: true + dependencies: + '@jridgewell/trace-mapping': 0.3.25 + esbuild: 0.20.1 + jest-worker: 27.5.1 + schema-utils: 3.3.0 + serialize-javascript: 6.0.2 + terser: 5.28.1 + webpack: 5.90.3(esbuild@0.20.1) + dev: true + /terser@5.28.1: resolution: {integrity: sha512-wM+bZp54v/E9eRRGXb5ZFDvinrJIOaTapx3WUokyVGZu5ucVCK55zEgGd5Dl2fSr3jUo5sDiERErUWLY6QPFyA==} engines: {node: '>=10'} @@ -16644,6 +16640,46 @@ packages: - uglify-js dev: true + /webpack@5.90.3(esbuild@0.20.1): + resolution: {integrity: sha512-h6uDYlWCctQRuXBs1oYpVe6sFcWedl0dpcVaTf/YF67J9bKvwJajFulMVSYKHrksMB3I/pIagRzDxwxkebuzKA==} + engines: {node: '>=10.13.0'} + hasBin: true + peerDependencies: + webpack-cli: '*' + peerDependenciesMeta: + webpack-cli: + optional: true + dependencies: + '@types/eslint-scope': 3.7.7 + '@types/estree': 1.0.5 + '@webassemblyjs/ast': 1.11.6 + '@webassemblyjs/wasm-edit': 1.11.6 + '@webassemblyjs/wasm-parser': 1.11.6 + acorn: 8.11.3 + acorn-import-assertions: 1.9.0(acorn@8.11.3) + browserslist: 4.23.0 + chrome-trace-event: 1.0.3 + enhanced-resolve: 5.15.1 + es-module-lexer: 1.4.1 + eslint-scope: 5.1.1 + events: 3.3.0 + glob-to-regexp: 0.4.1 + graceful-fs: 4.2.11 + json-parse-even-better-errors: 2.3.1 + loader-runner: 4.3.0 + mime-types: 2.1.35 + neo-async: 2.6.2 + schema-utils: 3.3.0 + tapable: 2.2.1 + terser-webpack-plugin: 5.3.10(esbuild@0.20.1)(webpack@5.90.3) + watchpack: 2.4.0 + webpack-sources: 3.2.3 + transitivePeerDependencies: + - '@swc/core' + - esbuild + - uglify-js + dev: true + /websocket-driver@0.7.4: resolution: {integrity: sha512-b17KeDIQVjvb0ssuSDF2cYXSg2iztliJ4B9WdsuB6J952qCPKmnVq4DyW5motImXHDC1cBT/1UezrJVsKw5zjg==} engines: {node: '>=0.8.0'} From 7bfa08afb705bfa5d15c1af853e1387106450d1c Mon Sep 17 00:00:00 2001 From: POPPIN-FUMI Date: Fri, 8 Mar 2024 09:08:52 +0100 Subject: [PATCH 2/3] ai --- packages/cli/src/cli/ai/ai.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/cli/src/cli/ai/ai.ts b/packages/cli/src/cli/ai/ai.ts index c358ea22..0ae42720 100644 --- a/packages/cli/src/cli/ai/ai.ts +++ b/packages/cli/src/cli/ai/ai.ts @@ -100,11 +100,6 @@ export async function promptUser( // } const skeetPrompt = skeetAiPrompt('en') - await chat( - skeetPrompt.context, - skeetPrompt.examples, - userInput.input, - aiOptions.ai, - ) + await chat(skeetPrompt.context, skeetPrompt.examples, userInput.input) await promptUser(aiOptions, logger) } From c6a95ea6f2a9ceb723daa0022e4aed57a5adae4a Mon Sep 17 00:00:00 2001 From: POPPIN-FUMI Date: Mon, 11 Mar 2024 14:07:13 +0100 Subject: [PATCH 3/3] mkdir if no dir --- packages/cli/src/lib/files/getAllApps.ts | 5 +++++ packages/cli/src/lib/files/getFunctions.ts | 2 +- packages/cli/src/lib/files/getSQLs.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/lib/files/getAllApps.ts b/packages/cli/src/lib/files/getAllApps.ts index a749da6b..4884c140 100644 --- a/packages/cli/src/lib/files/getAllApps.ts +++ b/packages/cli/src/lib/files/getAllApps.ts @@ -1,6 +1,8 @@ +import { mkdir } from 'fs/promises' import { getDirectoryLastModified } from './getDirectoryLastModified' import { getFunctions } from './getFunctions' import { getSQLs } from './getSQLs' +import path from 'path' export const getAllApps = async () => { try { @@ -8,6 +10,9 @@ export const getAllApps = async () => { const dirs = (await getFunctions()).map((dir) => `functions/${dir}`) const sqls = (await getSQLs()).map((dir) => `sql/${dir}`) dirs.push('webapp') + if (!path.join(process.cwd(), 'webapp')) { + await mkdir('webapp', { recursive: true }) + } dirs.push(...sqls) for (const dir of dirs) { const name = dir diff --git a/packages/cli/src/lib/files/getFunctions.ts b/packages/cli/src/lib/files/getFunctions.ts index c39fb2a1..1be44c60 100644 --- a/packages/cli/src/lib/files/getFunctions.ts +++ b/packages/cli/src/lib/files/getFunctions.ts @@ -6,7 +6,7 @@ export const getFunctions = async () => { try { const dir = path.join(process.cwd(), 'functions') if (!dir) { - await mkdir(dir) + await mkdir(dir, { recursive: true }) } const sqlDirs = (await readdir(dir)).map((dirName) => path.join(dir, dirName), diff --git a/packages/cli/src/lib/files/getSQLs.ts b/packages/cli/src/lib/files/getSQLs.ts index e23142dc..b8d17564 100644 --- a/packages/cli/src/lib/files/getSQLs.ts +++ b/packages/cli/src/lib/files/getSQLs.ts @@ -6,7 +6,7 @@ export const getSQLs = async () => { try { const dir = path.join(process.cwd(), 'sql') if (!dir) { - await mkdir(dir) + await mkdir(dir, { recursive: true }) } const sqlDirs = (await readdir(dir)).map((dirName) => path.join(dir, dirName),