diff --git a/package.json b/package.json index 1e06f94c0..f577da363 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,16 @@ "start": "turbo start", "build": "turbo run build", "build:packages": "turbo run p:build", + "build:apps": "turbo run build --filter='./examples/*' --filter=docs", "build:docs": "turbo run build --filter=docs...", "build:examples": "turbo run build --filter='./examples/*'", "build:examples:expo": "turbo run build --filter=expo-typescript...", "build:examples:next": "turbo run build --filter=next-typescript...", - "dev": "turbo run p:watch dev --parallel --no-cache", + "dev": "node start-dev.js", "dev:packages": "turbo run p:watch", + "dev:apps": "turbo run dev --filter='./examples/*' --filter=docs", "dev:docs": "turbo run dev --filter=docs", - "dev:examples": "turbo run dev --filter=./examples/*", + "dev:examples": "turbo run dev --filter='./examples/*'", "dev:examples:expo": "turbo run dev --filter=expo-typescript", "dev:examples:next": "turbo run dev --filter=next-typescript", "dev:examples:react": "turbo run dev --filter=react-typescript", @@ -47,12 +49,14 @@ "@typescript-eslint/eslint-plugin": "^5.42.0", "@typescript-eslint/parser": "^5.42.0", "babel-plugin-styled-components": "^2.0.7", + "cross-spawn": "^7.0.3", "eslint": "^8.26.0", "eslint-config-next": "^13.0.2", "eslint-config-prettier": "^8.5.0", "eslint-plugin-prettier": "^4.2.1", "eslint-plugin-react": "^7.31.10", "husky": "^8.0.1", + "merge-stream": "^2.0.0", "path-browserify": "^1.0.1", "prettier": "^2.7.1", "pretty-quick": "^3.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 304dbd9ce..ec17a9fc0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,6 +39,9 @@ importers: babel-plugin-styled-components: specifier: ^2.0.7 version: 2.0.7(styled-components@5.3.6) + cross-spawn: + specifier: ^7.0.3 + version: 7.0.3 eslint: specifier: ^8.26.0 version: 8.32.0 @@ -57,6 +60,9 @@ importers: husky: specifier: ^8.0.1 version: 8.0.3 + merge-stream: + specifier: ^2.0.0 + version: 2.0.0 path-browserify: specifier: ^1.0.1 version: 1.0.1 diff --git a/start-dev.js b/start-dev.js new file mode 100644 index 000000000..de6898262 --- /dev/null +++ b/start-dev.js @@ -0,0 +1,48 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const spawn = require("cross-spawn"); +const merge = require("merge-stream"); + +const env = { ...process.env, FORCE_COLOR: true }; + +const devPackages = spawn("pnpm", ["dev:packages"], { + stdio: "pipe", + env, +}); + +const devApps = () => spawn("pnpm", ["dev:apps"], { stdio: "pipe", env }); + +const waitForSuccess = (stream) => { + return new Promise((resolve) => { + stream.on("data", (data) => { + const output = data.toString(); + console.log(output); + if ( + output.includes("info") && + output.includes("waiting for changes...") + ) { + stream.removeAllListeners("data"); + resolve(); + } + }); + }); +}; + +devPackages.stderr.on("data", (data) => { + console.error(data.toString()); +}); + +devPackages.on("exit", (code) => { + console.log(`dev:packages exited with code ${code}`); +}); + +waitForSuccess(devPackages.stdout).then(() => { + const devAppsProcess = devApps(); + const mergedOutput = merge(devPackages.stdout, devAppsProcess.stdout); + mergedOutput.on("data", (data) => { + console.log(data.toString()); + }); + const mergedError = merge(devPackages.stderr, devAppsProcess.stderr); + mergedError.on("data", (data) => { + console.error(data.toString()); + }); +});