@take-out/scripts 0.1.0 → 0.1.1

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.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./src/run.ts",
6
6
  "sideEffects": false,
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@clack/prompts": "^0.8.2",
32
- "@take-out/helpers": "0.1.0",
32
+ "@take-out/helpers": "0.1.1",
33
33
  "picocolors": "^1.1.1"
34
34
  },
35
35
  "peerDependencies": {
package/src/env-update.ts CHANGED
@@ -75,10 +75,13 @@ await cmd`sync environment variables from package.json to CI and server configs`
75
75
  }
76
76
 
77
77
  const envExports = Object.entries(envVars)
78
- .map(
79
- ([key, value]) =>
80
- `export const ${key} = ensureEnv('${key}'${typeof value === 'string' ? `, ${JSON.stringify(value)}` : ''})`
81
- )
78
+ .map(([key, value]) => {
79
+ // $dep: values have no compile-time default — resolved into .env at runtime
80
+ if (typeof value === 'string' && value.startsWith('$dep:')) {
81
+ return `export const ${key} = ensureEnv('${key}')`
82
+ }
83
+ return `export const ${key} = ensureEnv('${key}'${typeof value === 'string' ? `, ${JSON.stringify(value)}` : ''})`
84
+ })
82
85
  .join('\n')
83
86
 
84
87
  const newEnvServer = envServer.replace(
@@ -3,10 +3,8 @@ import { join } from 'node:path'
3
3
 
4
4
  import { loadEnv } from './env-load'
5
5
  import { getDockerHost } from './get-docker-host'
6
- import { getZeroVersion } from './zero-get-version'
7
6
 
8
7
  export async function getTestEnv() {
9
- const zeroVersion = getZeroVersion()
10
8
  const dockerHost = getDockerHost()
11
9
  const devEnv = await loadEnv('development')
12
10
  const envPath =
@@ -31,7 +29,6 @@ export async function getTestEnv() {
31
29
  ZERO_LOG_LEVEL: 'warn',
32
30
  }),
33
31
  DO_NOT_TRACK: '1',
34
- ZERO_VERSION: zeroVersion,
35
32
  ZERO_MUTATE_URL: `http://${dockerHost}:${appPort}/api/zero/push`,
36
33
  ZERO_QUERY_URL: `http://${dockerHost}:${appPort}/api/zero/pull`,
37
34
  ZERO_UPSTREAM_DB: `${dockerDbBase}/postgres`,
@@ -5,8 +5,6 @@ import fs from 'node:fs'
5
5
  import { cmd } from './cmd'
6
6
 
7
7
  await cmd`sync auto-generated env vars to local .env file`.run(async ({ path }) => {
8
- const { getZeroVersion } = await import('./helpers/zero-get-version')
9
-
10
8
  // skip in CI environments
11
9
  if (process.env.CI === 'true') {
12
10
  console.info('Skipping bootstrap in CI environment')
@@ -14,7 +12,6 @@ await cmd`sync auto-generated env vars to local .env file`.run(async ({ path })
14
12
  }
15
13
 
16
14
  const ENV_PATH = path.join(process.cwd(), '.env')
17
- const ENV_TEMPLATE_PATH = path.join(process.cwd(), '.env.template')
18
15
  const ENV_BACKUP_PATH = path.join(process.cwd(), '.env.backup')
19
16
  const ENV_TEMP_PATH = path.join(process.cwd(), '.env.tmp')
20
17
 
@@ -22,47 +19,44 @@ await cmd`sync auto-generated env vars to local .env file`.run(async ({ path })
22
19
  const BEGIN_MARKER = '# ---- BEGIN AUTO-GENERATED (DO NOT EDIT) ----'
23
20
  const END_MARKER = '# ---- END AUTO-GENERATED ----'
24
21
 
25
- function createEnvFromTemplate(): boolean {
26
- if (!fs.existsSync(ENV_TEMPLATE_PATH)) {
27
- console.info('No .env.template found, skipping .env creation')
28
- return false
29
- }
30
-
31
- try {
32
- fs.copyFileSync(ENV_TEMPLATE_PATH, ENV_PATH)
33
- console.info('Created .env from .env.template')
34
- return true
35
- } catch (error) {
36
- console.error('Failed to create .env from .env.template:', error)
37
- return false
38
- }
39
- }
40
-
41
22
  function getAutoGeneratedContent(): string {
42
- const zeroVersion = getZeroVersion()
43
- if (!zeroVersion) {
44
- console.warn('Could not determine Zero version')
23
+ const packageJsonPath = path.join(process.cwd(), 'package.json')
24
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
25
+ const envVars = packageJson.env as Record<string, boolean | string>
26
+
27
+ if (!envVars || typeof envVars !== 'object') {
28
+ console.warn('No env section found in package.json')
45
29
  return ''
46
30
  }
47
31
 
48
- const lines = [
49
- BEGIN_MARKER,
50
- `# Generated at: ${new Date().toISOString()}`,
51
- `ZERO_VERSION=${zeroVersion}`,
52
- END_MARKER,
53
- ]
32
+ const lines: string[] = [BEGIN_MARKER, `# Generated at: ${new Date().toISOString()}`]
33
+
34
+ for (const [key, value] of Object.entries(envVars)) {
35
+ if (typeof value === 'string' && value.startsWith('$dep:')) {
36
+ // resolve version from dependency
37
+ const depName = value.slice('$dep:'.length)
38
+ const version = packageJson.dependencies?.[depName]?.replace(/^[\^~]/, '')
39
+ if (version) {
40
+ lines.push(`${key}=${version}`)
41
+ } else {
42
+ console.warn(`Could not resolve dependency version for ${depName}`)
43
+ }
44
+ } else if (typeof value === 'string' && value !== '') {
45
+ // non-empty string default
46
+ lines.push(`${key}=${value}`)
47
+ }
48
+ // skip true (required, no default) and "" (no meaningful default)
49
+ }
54
50
 
51
+ lines.push(END_MARKER)
55
52
  return lines.join('\n')
56
53
  }
57
54
 
58
55
  function updateEnvFile(): void {
59
56
  // ensure .env exists
60
57
  if (!fs.existsSync(ENV_PATH)) {
61
- const created = createEnvFromTemplate()
62
- if (!created && !fs.existsSync(ENV_PATH)) {
63
- fs.writeFileSync(ENV_PATH, '')
64
- console.info('Created empty .env file')
65
- }
58
+ fs.writeFileSync(ENV_PATH, '')
59
+ console.info('Created empty .env file')
66
60
  }
67
61
 
68
62
  try {