Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
}
}
34 changes: 30 additions & 4 deletions packages/cli/src/commands/common/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down