@take-out/scripts 0.0.29 → 0.0.31

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.29",
3
+ "version": "0.0.31",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -18,13 +18,13 @@
18
18
  "scripts": {
19
19
  "lint": "biome check src",
20
20
  "lint:fix": "biome check --write src",
21
- "typecheck": "TSGO=1 tko run typecheck"
21
+ "typecheck": "tko run typecheck"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@take-out/helpers": "0.0.29"
27
+ "@take-out/helpers": "0.0.31"
28
28
  },
29
29
  "devDependencies": {
30
30
  "vxrn": "*"
package/src/env-update.ts CHANGED
@@ -31,6 +31,17 @@ const yamlEndMarker = `# ${markerEnd}`
31
31
  const jsStartMarker = `// ${markerStart}`
32
32
  const jsEndMarker = `// ${markerEnd}`
33
33
 
34
+ function replaceYamlSection(
35
+ content: string,
36
+ lines: string,
37
+ options: { indent: string }
38
+ ): string {
39
+ return content.replace(
40
+ new RegExp(`${yamlStartMarker}(.|\n)*?${yamlEndMarker}`, 'gm'),
41
+ `${yamlStartMarker}\n${lines}\n${options.indent}${yamlEndMarker}`
42
+ )
43
+ }
44
+
34
45
  function updateDeployYml() {
35
46
  const deployYmlPath = '.github/workflows/ci.yml'
36
47
  let deployYml = readFileSync(deployYmlPath, 'utf-8')
@@ -39,16 +50,12 @@ function updateDeployYml() {
39
50
  throw new Error(`Markers not found in ${deployYmlPath}`)
40
51
  }
41
52
 
42
- const newlines = ` `
43
-
53
+ const indent = ` `
44
54
  const envSection = Object.keys(envVars)
45
- .map((key) => `${newlines}${key}: \${{ secrets.${key} }}`)
55
+ .map((key) => `${indent}${key}: \${{ secrets.${key} }}`)
46
56
  .join('\n')
47
57
 
48
- const newDeployYml = deployYml.replace(
49
- new RegExp(`${yamlStartMarker}(.|\n)*?${yamlEndMarker}`, 'gm'),
50
- `${yamlStartMarker}\n${envSection}\n${newlines}${yamlEndMarker}`
51
- )
58
+ const newDeployYml = replaceYamlSection(deployYml, envSection, { indent })
52
59
 
53
60
  writeFileSync(deployYmlPath, newDeployYml, 'utf-8')
54
61
  console.info('✅ Updated Github workflow')
@@ -111,11 +118,41 @@ function updateEnvServerTs() {
111
118
  // console.info('✅ Updated Dockerfile')
112
119
  // }
113
120
 
121
+ function updateDockerCompose() {
122
+ const dockerComposePath = 'src/uncloud/docker-compose.yml'
123
+
124
+ let dockerCompose = ''
125
+ try {
126
+ dockerCompose = readFileSync(dockerComposePath, 'utf-8')
127
+ } catch (_error) {
128
+ // file doesn't exist, skip
129
+ return
130
+ }
131
+
132
+ if (
133
+ !dockerCompose.includes(yamlStartMarker) ||
134
+ !dockerCompose.includes(yamlEndMarker)
135
+ ) {
136
+ // no markers, skip
137
+ return
138
+ }
139
+
140
+ const indent = ' '
141
+ const envLines = Object.keys(envVars)
142
+ .map((key) => `${indent}- ${key}=\${${key}:-}`)
143
+ .join('\n')
144
+
145
+ const newDockerCompose = replaceYamlSection(dockerCompose, envLines, { indent })
146
+
147
+ writeFileSync(dockerComposePath, newDockerCompose, 'utf-8')
148
+ console.info('✅ Updated docker-compose.yml')
149
+ }
150
+
114
151
  async function updateAll() {
115
152
  try {
116
153
  updateDeployYml()
117
154
  updateEnvServerTs()
118
- // updateDockerfile()
155
+ updateDockerCompose()
119
156
  console.info('✅ All files updated successfully')
120
157
  } catch (error: any) {
121
158
  console.error('❌ Update failed:', error.message)
@@ -17,7 +17,7 @@ export async function loadEnv(
17
17
  if (options?.optional?.includes(key)) {
18
18
  continue
19
19
  }
20
- if (!Environment[key as keyof typeof Environment]) {
20
+ if (typeof Environment[key as keyof typeof Environment] === 'undefined') {
21
21
  console.warn(`Missing key: ${key}`)
22
22
  }
23
23
  }
@@ -1,4 +1,5 @@
1
1
  import type { ChildProcess } from 'node:child_process'
2
+ import { cpus } from 'node:os'
2
3
  import type { Timer } from '@take-out/helpers'
3
4
 
4
5
  export type ProcessType = ChildProcess | Bun.Subprocess
@@ -268,7 +269,8 @@ export async function printTiming<T>(name: string, fn: () => Promise<T>): Promis
268
269
  }
269
270
 
270
271
  export async function runParallel(
271
- tasks: Array<{ name: string; fn: () => Promise<void>; condition?: () => boolean }>
272
+ tasks: Array<{ name: string; fn: () => Promise<void>; condition?: () => boolean }>,
273
+ options?: { maxParallelism?: number }
272
274
  ) {
273
275
  const activeTasks = tasks.filter((task) => !task.condition || task.condition())
274
276
 
@@ -276,27 +278,43 @@ export async function runParallel(
276
278
  return
277
279
  }
278
280
 
281
+ const maxParallelism = options?.maxParallelism ?? cpus().length
279
282
  console.info(`\nStarting parallel tasks: ${activeTasks.map((t) => t.name).join(', ')}`)
283
+ console.info(`Max parallelism: ${maxParallelism}`)
280
284
 
281
285
  const taskStartTime = Date.now()
282
286
 
283
287
  try {
284
- await Promise.all(
285
- activeTasks.map(async (task) => {
286
- const startTime = Date.now()
287
- try {
288
- await task.fn()
288
+ const results: Promise<void>[] = []
289
+ const executing: Set<Promise<void>> = new Set()
290
+
291
+ for (const task of activeTasks) {
292
+ const startTime = Date.now()
293
+ const taskPromise = task.fn().then(
294
+ () => {
289
295
  const duration = Date.now() - startTime
290
296
  console.info(
291
297
  `\x1b[32m✓\x1b[0m task: \x1b[35m${task.name}\x1b[0m completed in \x1b[33m${formatDuration(duration)}\x1b[0m`
292
298
  )
293
- } catch (error) {
299
+ executing.delete(taskPromise)
300
+ },
301
+ (error) => {
294
302
  const duration = Date.now() - startTime
295
303
  console.error(`✗ task: ${task.name} failed after ${formatDuration(duration)}`)
304
+ executing.delete(taskPromise)
296
305
  throw error
297
306
  }
298
- })
299
- )
307
+ )
308
+
309
+ results.push(taskPromise)
310
+ executing.add(taskPromise)
311
+
312
+ if (executing.size >= maxParallelism) {
313
+ await Promise.race(executing)
314
+ }
315
+ }
316
+
317
+ await Promise.all(results)
300
318
 
301
319
  const totalDuration = Date.now() - taskStartTime
302
320
  console.info(
package/src/typecheck.ts CHANGED
@@ -4,13 +4,19 @@
4
4
  * @description Run TypeScript compiler for type checking
5
5
  */
6
6
 
7
+ import { sleep } from '@take-out/helpers'
7
8
  import { run } from '@take-out/scripts/helpers/run'
8
9
 
9
10
  const useTsgo = process.env.TSGO === '1'
10
11
  const args = process.argv.slice(2)
11
12
 
13
+ // hugely cpu intensive, let the dev server start first before using:
14
+ if (process.env.LAZY_TYPECHECK) {
15
+ await sleep(6000)
16
+ }
17
+
12
18
  if (useTsgo) {
13
19
  await run(`bun tsgo --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
14
20
  } else {
15
- await run(`tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
21
+ await run(`bun x tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
16
22
  }
package/src/typescript.ts DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- /**
4
- * @description Run TypeScript compiler for type checking
5
- */
6
-
7
- import { run } from '@take-out/scripts/helpers/run'
8
-
9
- const useTsgo = process.env.TSGO === '1'
10
- const args = process.argv.slice(2)
11
-
12
- if (useTsgo) {
13
- await run(`bun tsgo --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
14
- } else {
15
- await run(`tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
16
- }