@take-out/scripts 0.0.30 → 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 +3 -3
- package/src/env-update.ts +45 -8
- package/src/helpers/env-load.ts +1 -1
- package/src/helpers/run.ts +27 -9
- package/src/typecheck.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/scripts",
|
|
3
|
-
"version": "0.0.
|
|
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": "
|
|
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.
|
|
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
|
|
43
|
-
|
|
53
|
+
const indent = ` `
|
|
44
54
|
const envSection = Object.keys(envVars)
|
|
45
|
-
.map((key) => `${
|
|
55
|
+
.map((key) => `${indent}${key}: \${{ secrets.${key} }}`)
|
|
46
56
|
.join('\n')
|
|
47
57
|
|
|
48
|
-
const newDeployYml = deployYml
|
|
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
|
-
|
|
155
|
+
updateDockerCompose()
|
|
119
156
|
console.info('✅ All files updated successfully')
|
|
120
157
|
} catch (error: any) {
|
|
121
158
|
console.error('❌ Update failed:', error.message)
|
package/src/helpers/env-load.ts
CHANGED
|
@@ -17,7 +17,7 @@ export async function loadEnv(
|
|
|
17
17
|
if (options?.optional?.includes(key)) {
|
|
18
18
|
continue
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (typeof Environment[key as keyof typeof Environment] === 'undefined') {
|
|
21
21
|
console.warn(`Missing key: ${key}`)
|
|
22
22
|
}
|
|
23
23
|
}
|
package/src/helpers/run.ts
CHANGED
|
@@ -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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
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
|
@@ -18,5 +18,5 @@ if (process.env.LAZY_TYPECHECK) {
|
|
|
18
18
|
if (useTsgo) {
|
|
19
19
|
await run(`bun tsgo --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
|
|
20
20
|
} else {
|
|
21
|
-
await run(`tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
|
|
21
|
+
await run(`bun x tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
|
|
22
22
|
}
|