@take-out/scripts 0.0.99 → 0.1.0

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.99",
3
+ "version": "0.1.0",
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.0.99",
32
+ "@take-out/helpers": "0.1.0",
33
33
  "picocolors": "^1.1.1"
34
34
  },
35
35
  "peerDependencies": {
package/src/env-update.ts CHANGED
@@ -75,13 +75,10 @@ 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(([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
- })
78
+ .map(
79
+ ([key, value]) =>
80
+ `export const ${key} = ensureEnv('${key}'${typeof value === 'string' ? `, ${JSON.stringify(value)}` : ''})`
81
+ )
85
82
  .join('\n')
86
83
 
87
84
  const newEnvServer = envServer.replace(
@@ -3,8 +3,10 @@ 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'
6
7
 
7
8
  export async function getTestEnv() {
9
+ const zeroVersion = getZeroVersion()
8
10
  const dockerHost = getDockerHost()
9
11
  const devEnv = await loadEnv('development')
10
12
  const envPath =
@@ -29,6 +31,7 @@ export async function getTestEnv() {
29
31
  ZERO_LOG_LEVEL: 'warn',
30
32
  }),
31
33
  DO_NOT_TRACK: '1',
34
+ ZERO_VERSION: zeroVersion,
32
35
  ZERO_MUTATE_URL: `http://${dockerHost}:${appPort}/api/zero/push`,
33
36
  ZERO_QUERY_URL: `http://${dockerHost}:${appPort}/api/zero/pull`,
34
37
  ZERO_UPSTREAM_DB: `${dockerDbBase}/postgres`,
@@ -5,6 +5,8 @@ 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
+
8
10
  // skip in CI environments
9
11
  if (process.env.CI === 'true') {
10
12
  console.info('Skipping bootstrap in CI environment')
@@ -12,6 +14,7 @@ await cmd`sync auto-generated env vars to local .env file`.run(async ({ path })
12
14
  }
13
15
 
14
16
  const ENV_PATH = path.join(process.cwd(), '.env')
17
+ const ENV_TEMPLATE_PATH = path.join(process.cwd(), '.env.template')
15
18
  const ENV_BACKUP_PATH = path.join(process.cwd(), '.env.backup')
16
19
  const ENV_TEMP_PATH = path.join(process.cwd(), '.env.tmp')
17
20
 
@@ -19,44 +22,47 @@ await cmd`sync auto-generated env vars to local .env file`.run(async ({ path })
19
22
  const BEGIN_MARKER = '# ---- BEGIN AUTO-GENERATED (DO NOT EDIT) ----'
20
23
  const END_MARKER = '# ---- END AUTO-GENERATED ----'
21
24
 
22
- function getAutoGeneratedContent(): string {
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>
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
+ }
26
30
 
27
- if (!envVars || typeof envVars !== 'object') {
28
- console.warn('No env section found in package.json')
29
- return ''
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
30
38
  }
39
+ }
31
40
 
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)
41
+ function getAutoGeneratedContent(): string {
42
+ const zeroVersion = getZeroVersion()
43
+ if (!zeroVersion) {
44
+ console.warn('Could not determine Zero version')
45
+ return ''
49
46
  }
50
47
 
51
- lines.push(END_MARKER)
48
+ const lines = [
49
+ BEGIN_MARKER,
50
+ `# Generated at: ${new Date().toISOString()}`,
51
+ `ZERO_VERSION=${zeroVersion}`,
52
+ END_MARKER,
53
+ ]
54
+
52
55
  return lines.join('\n')
53
56
  }
54
57
 
55
58
  function updateEnvFile(): void {
56
59
  // ensure .env exists
57
60
  if (!fs.existsSync(ENV_PATH)) {
58
- fs.writeFileSync(ENV_PATH, '')
59
- console.info('Created empty .env file')
61
+ const created = createEnvFromTemplate()
62
+ if (!created && !fs.existsSync(ENV_PATH)) {
63
+ fs.writeFileSync(ENV_PATH, '')
64
+ console.info('Created empty .env file')
65
+ }
60
66
  }
61
67
 
62
68
  try {