@take-out/scripts 0.0.38 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@take-out/helpers": "0.0.38"
27
+ "@take-out/helpers": "0.0.40"
28
28
  },
29
29
  "devDependencies": {
30
30
  "vxrn": "*"
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * @description Bootstrap project workspace and build initial packages. This is
5
+ * mostly important for Takeout starter kit itself.
6
+ */
7
+
8
+ import { existsSync, mkdirSync, readFileSync, symlinkSync } from 'node:fs'
9
+ import { exists } from 'node:fs/promises'
10
+ import { join } from 'node:path'
11
+
12
+ import { $ } from 'bun'
13
+
14
+ const hasPackages = await exists(`./packages`)
15
+
16
+ // only run once:
17
+ if (!(await exists(`./node_modules/.bin/tko`))) {
18
+ if (hasPackages) {
19
+ symlinkBins()
20
+ }
21
+ }
22
+
23
+ // check if critical packages are built - both helpers and takeout are needed for tko to work
24
+ if (hasPackages) {
25
+ const needsBuild =
26
+ !(await exists(`./packages/helpers/dist`)) ||
27
+ !(await exists(`./packages/takeout/dist/esm`))
28
+
29
+ if (needsBuild) {
30
+ // build helpers first as other packages depend on it
31
+ await $`cd packages/helpers && bun run build`
32
+
33
+ // then build all other packages in parallel
34
+ await $`bun ./packages/scripts/src/run.ts build --no-root`
35
+ }
36
+ }
37
+
38
+ // show welcome message if not onboarded
39
+ checkAndShowWelcome()
40
+
41
+ function checkAndShowWelcome(cwd: string = process.cwd()): void {
42
+ try {
43
+ const packagePath = join(cwd, 'package.json')
44
+ const pkg = JSON.parse(readFileSync(packagePath, 'utf-8'))
45
+
46
+ if (pkg.takeout?.onboarded === false) {
47
+ console.info()
48
+ console.info(`
49
+ ████████╗ █████╗ ██╗ ██╗███████╗ ██████╗ ██╗ ██╗████████╗
50
+ ╚══██╔══╝██╔══██╗██║ ██╔╝██╔════╝██╔═══██╗██║ ██║╚══██╔══╝
51
+ ██║ ███████║█████╔╝ █████╗ ██║ ██║██║ ██║ ██║
52
+ ██║ ██╔══██║██╔═██╗ ██╔══╝ ██║ ██║██║ ██║ ██║
53
+ ██║ ██║ ██║██║ ██╗███████╗╚██████╔╝╚██████╔╝ ██║
54
+ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝
55
+ 麵 碼 飯
56
+ `)
57
+ console.info()
58
+ console.info(' welcome to takeout! 🥡')
59
+ console.info()
60
+ console.info(' run \x1b[32mbun onboard\x1b[0m to get things set up')
61
+ console.info()
62
+ }
63
+ } catch {
64
+ // silently fail if package.json doesn't exist or is malformed
65
+ }
66
+ }
67
+
68
+ function symlinkBins() {
69
+ // workaround for https://github.com/oven-sh/bun/issues/19782
70
+ // bun doesn't create symlinks for workspace packages properly
71
+ const packagesWithCLI = [
72
+ { name: 'takeout', cliFile: 'cli.mjs', alias: 'tko' },
73
+ { name: 'postgres', cliFile: 'cli.cjs' },
74
+ ]
75
+
76
+ const binDir = join(process.cwd(), 'node_modules', '.bin')
77
+
78
+ if (!existsSync(binDir)) {
79
+ mkdirSync(binDir, { recursive: true })
80
+ }
81
+
82
+ for (const pkg of packagesWithCLI) {
83
+ const binPath = join(binDir, pkg.name)
84
+ const sourcePath = join(process.cwd(), 'packages', pkg.name, pkg.cliFile)
85
+ symlinkTo(sourcePath, binPath)
86
+
87
+ if (pkg.alias) {
88
+ const aliasPath = join(binDir, pkg.alias)
89
+ // create alias symlink pointing to the source
90
+ symlinkTo(sourcePath, aliasPath)
91
+ }
92
+ }
93
+
94
+ // helper function to create symlink with existence check
95
+ function symlinkTo(source: string, target: string): void {
96
+ if (existsSync(target)) {
97
+ console.info(`✓ Symlink already exists: ${target}`)
98
+ return
99
+ }
100
+
101
+ symlinkSync(source, target)
102
+ console.info(`→ Created symlink: ${source} ⇢ ${target}`)
103
+ }
104
+ }
package/src/run.ts CHANGED
@@ -46,10 +46,21 @@ const noRoot = args.includes('--no-root')
46
46
  const runBun = args.includes('--bun')
47
47
  const watch = args.includes('--watch') // just attempts to restart a failed process up to MAX_RESTARTS times
48
48
 
49
+ // parse --stdin=<script-name> to specify which script receives keyboard input
50
+ // if not specified, defaults to the last script in the list
51
+ const stdinArg = args.find((arg) => arg.startsWith('--stdin='))
52
+ const stdinScript = stdinArg
53
+ ? stdinArg.replace('--stdin=', '')
54
+ : (runCommands[runCommands.length - 1] ?? null)
55
+
49
56
  // Collect additional flags and arguments to forward to sub-commands
50
57
  const forwardArgs = args.filter(
51
58
  (arg) =>
52
- arg.startsWith('--') && arg !== '--no-root' && arg !== '--bun' && arg !== '--watch'
59
+ arg.startsWith('--') &&
60
+ arg !== '--no-root' &&
61
+ arg !== '--bun' &&
62
+ arg !== '--watch' &&
63
+ !arg.startsWith('--stdin=')
53
64
  )
54
65
 
55
66
  // Get the list of scripts already being run by a parent process
@@ -227,8 +238,9 @@ const runScript = async (
227
238
  // Combine parent running scripts with current scripts to prevent recursion
228
239
  const allRunningScripts = [...parentRunningScripts, ...runCommands].join(',')
229
240
 
241
+ const shouldInheritStdin = name === stdinScript
230
242
  const proc = spawn('bun', runArgs, {
231
- stdio: ['pipe', 'pipe', 'pipe'],
243
+ stdio: [shouldInheritStdin ? 'inherit' : 'pipe', 'pipe', 'pipe'],
232
244
  shell: false,
233
245
  env: {
234
246
  ...process.env,
@@ -245,7 +257,7 @@ const runScript = async (
245
257
  processes.push(proc)
246
258
  addChildProcess(proc)
247
259
 
248
- proc.stdout.on('data', (data) => {
260
+ proc.stdout!.on('data', (data) => {
249
261
  if (getIsExiting()) return // prevent output during cleanup
250
262
  const lines = data.toString().split('\n')
251
263
  for (const line of lines) {
@@ -253,7 +265,7 @@ const runScript = async (
253
265
  }
254
266
  })
255
267
 
256
- proc.stderr.on('data', (data) => {
268
+ proc.stderr!.on('data', (data) => {
257
269
  const dataStr = data.toString()
258
270
  stderrBuffer += dataStr
259
271
 
File without changes