@take-out/scripts 0.6.10 → 0.6.12

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/env-update.ts +28 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.6.10",
3
+ "version": "0.6.12",
4
4
  "type": "module",
5
5
  "main": "./src/cmd.ts",
6
6
  "sideEffects": false,
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@clack/prompts": "^0.8.2",
32
- "@take-out/helpers": "0.6.10",
33
- "@take-out/run": "0.6.10",
32
+ "@take-out/helpers": "0.6.12",
33
+ "@take-out/run": "0.6.12",
34
34
  "picocolors": "^1.1.1"
35
35
  }
36
36
  }
package/src/env-update.ts CHANGED
@@ -164,13 +164,25 @@ await cmd`sync environment variables from src/env.ts to matching files`
164
164
  // .env auto-generated section markers
165
165
  const dotenvSectionStart = '# ---- BEGIN AUTO-GENERATED (DO NOT EDIT) ----'
166
166
  const dotenvSectionEnd = '# ---- END AUTO-GENERATED ----'
167
+ const typescriptArrayStart = '// 🔒 env array start - generated by "bun env:update"'
168
+ const typescriptArrayEnd = '// 🔒 env array end - generated by "bun env:update"'
167
169
 
168
- type Strategy = 'yaml-markers' | 'dotenv-section' | 'dotenv-inline'
170
+ type Strategy =
171
+ | 'yaml-markers'
172
+ | 'dotenv-section'
173
+ | 'dotenv-inline'
174
+ | 'typescript-array-markers'
169
175
 
170
176
  function detectStrategy(filePath: string, content: string): Strategy | null {
171
177
  if (content.includes(yamlStart) && content.includes(yamlEnd)) {
172
178
  return 'yaml-markers'
173
179
  }
180
+ if (
181
+ content.includes(typescriptArrayStart) &&
182
+ content.includes(typescriptArrayEnd)
183
+ ) {
184
+ return 'typescript-array-markers'
185
+ }
174
186
  const basename = path.basename(filePath)
175
187
  if (basename === '.env') {
176
188
  return 'dotenv-section'
@@ -275,10 +287,25 @@ await cmd`sync environment variables from src/env.ts to matching files`
275
287
  return result
276
288
  }
277
289
 
290
+ function applyTypescriptArrayMarkers(_filePath: string, content: string): string {
291
+ const markerMatch = content.match(
292
+ new RegExp(`^(\\s*)${escapeRegExp(typescriptArrayStart)}`, 'm'),
293
+ )
294
+ const indent = markerMatch?.[1] || ' '
295
+ const envLines = entries.map(({ key }) => `${indent}'${key}',`).join('\n')
296
+ return replaceMarkerSection(
297
+ content,
298
+ typescriptArrayStart,
299
+ typescriptArrayEnd,
300
+ envLines,
301
+ )
302
+ }
303
+
278
304
  const strategies: Record<Strategy, (filePath: string, content: string) => string> = {
279
305
  'yaml-markers': applyYamlMarkers,
280
306
  'dotenv-section': applyDotenvSection,
281
307
  'dotenv-inline': applyDotenvInline,
308
+ 'typescript-array-markers': applyTypescriptArrayMarkers,
282
309
  }
283
310
 
284
311
  let updated = 0