From f6525124549daf8a903d3326f61eec33a6ce49ee Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Tue, 11 Apr 2023 20:53:24 +0200 Subject: [PATCH] terminate `storybook` on `SIGINT` (#375) --- packages/components/package.json | 3 ++- packages/components/scripts/storybook.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/components/scripts/storybook.js diff --git a/packages/components/package.json b/packages/components/package.json index 12af9790..b86c8683 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -21,7 +21,8 @@ "build:types": "tsc --noEmit false --emitDeclarationOnly || true", "lint": "eslint src", "typecheck": "tsc", - "storybook": "TAMAGUI_TARGET='web' storybook dev -p 3001", + "storybook": "node ./scripts/storybook.js", + "storybook:dev": "TAMAGUI_TARGET='web' storybook dev -p 3001", "storybook:build": "TAMAGUI_TARGET='web' storybook build", "clean": "rimraf node_modules dist .turbo storybook-static" }, diff --git a/packages/components/scripts/storybook.js b/packages/components/scripts/storybook.js new file mode 100644 index 00000000..1e618f92 --- /dev/null +++ b/packages/components/scripts/storybook.js @@ -0,0 +1,17 @@ +#!/usr/bin/node + +// todo: remove after adding `"type": "module",` to `package.json` +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable @typescript-eslint/no-var-requires */ + +const child_process = require('node:child_process') +const process = require('node:process') + +const subprocess = child_process.spawn('yarn', ['storybook:dev'], { + detached: true, + stdio: 'inherit', +}) + +process.once('SIGINT', () => { + process.kill(-subprocess.pid, 'SIGKILL') +})