Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --silent to @xstate/cli #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!silent){
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more scalable to just pass opts in here? That way we can avoid multiple arguments in the future.

})
.on("ready", async () => {
await Promise.all(tasks);
Expand Down