Skip to content

Commit

Permalink
Add support for --silent
Browse files Browse the repository at this point in the history
Adds support for running xstate-cli in silent mode. Still prints errors.
  • Loading branch information
gkiely authored Nov 19, 2022
1 parent 6736930 commit 2dc8743
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/cli/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const handleError = (uri: string, e: any) => {
}
};

const writeToFiles = async (uriArray: string[]) => {
const writeToFiles = async (uriArray: string[], silent = false) => {
/**
* TODO - implement pretty readout
*/
Expand Down Expand Up @@ -74,7 +74,9 @@ const writeToFiles = async (uriArray: string[]) => {
filePath: uri,
event,
});
console.log(`${uri} - success`);
if(!silent){
console.log(`${uri} - success`);
}
} catch (e) {
handleError(uri, e);
}
Expand All @@ -87,14 +89,15 @@ program
.description("Generate TypeScript types from XState machines")
.argument("<files>", "The files to target, expressed as a glob pattern")
.option("-w, --watch", "Run the typegen in watch mode")
.action(async (filesPattern: string, opts: { watch?: boolean }) => {
.option("-s, --silent", "Run the typegen in silent mode")
.action(async (filesPattern: string, opts: { watch?: boolean; silent?: boolean }) => {
if (opts.watch) {
// TODO: implement per path queuing to avoid tasks related to the same file from overlapping their execution
const processFile = (path: string) => {
if (path.endsWith(".typegen.ts")) {
return;
}
writeToFiles([path]);
writeToFiles([path], opts.silent);
};
// TODO: handle removals
watch(filesPattern, { awaitWriteFinish: true })
Expand All @@ -108,7 +111,7 @@ program
if (path.endsWith(".typegen.ts")) {
return;
}
tasks.push(writeToFiles([path]));
tasks.push(writeToFiles([path], opts.silent));
})
.on("ready", async () => {
await Promise.all(tasks);
Expand Down

0 comments on commit 2dc8743

Please # to comment.