diff --git a/packages/cli/package.json b/packages/cli/package.json index ab095a7..ce1a846 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "graphql-editor-cli", - "version": "0.8.9", + "version": "0.9.0", "description": "GraphQL -> anything. Use GraphQL as your source of truth. GraphQL Editor Official CLI.", "main": "lib/api.js", "author": "Artur Czemiel", @@ -36,7 +36,7 @@ "eslint-plugin-prettier": "^4.2.1", "impuddle": "0.0.2", "prettier": "^2.7.1", - "ttypescript": "^1.5.13", + "ttypescript": "^1.5.15", "typescript": "^4.8.3", "typescript-transform-paths": "^3.3.1" }, @@ -69,6 +69,7 @@ "run-async": "^2.4.1", "stucco-js": "^0.10.18", "ts-node": "^10.9.1", + "ttsc": "^0.3.1", "yargs": "^17.5.1" } } diff --git a/packages/cli/src/commands/common/dev.ts b/packages/cli/src/commands/common/dev.ts index 2b9538f..c6e20a2 100644 --- a/packages/cli/src/commands/common/dev.ts +++ b/packages/cli/src/commands/common/dev.ts @@ -9,12 +9,38 @@ import { getEnvFile } from '@/common/envs.js'; let killing = false; let changingFile = false; +const MAX_NEST = 10; + +const traverseDirToRoot = (iteration: number) => { + const execDir = process.cwd().split('/'); + let finalPath = ''; + for (let index = 0; index < execDir.length - iteration; index++) { + finalPath += execDir[index]; + } + return finalPath[1] === '/' ? finalPath.substring(1) : finalPath; +}; + +const tryRunStuccoWithDynamicPath = async () => { + for (let index = 0; index < MAX_NEST; index++) { + const basePath = traverseDirToRoot(index); + if (basePath.length === 0) { + break; + } + try { + const { onCloseStucco, onCreateStucco } = await stuccoRun({ + basePath: basePath, + schemaPath: path.join(process.cwd(), DEPLOY_FILE), + configPath: path.join(process.cwd(), STUCCO_FILE), + }); + return { onCloseStucco, onCreateStucco }; + } catch (e) {} + } + throw new Error('cannot find stucco binary'); +}; export const CommandDev = async () => { - const { onCloseStucco, onCreateStucco } = await stuccoRun({ - schemaPath: path.join(process.cwd(), DEPLOY_FILE), - configPath: path.join(process.cwd(), STUCCO_FILE), - }); + const { onCloseStucco, onCreateStucco } = await tryRunStuccoWithDynamicPath(); + const tsServer = typescriptServer({ searchPath: './', onCreate: async () => {