main
1#!/usr/bin/env node
2
3// Copyright 2025 Google LLC
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// https://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17import fs from 'fs-extra'
18import path from 'node:path'
19import minimist from 'minimist'
20
21const root = path.resolve(new URL(import.meta.url).pathname, '../..')
22const copyright = await fs.readFileSync(
23 path.resolve(root, 'test/fixtures/copyright.txt'),
24 'utf8'
25)
26const license = copyright.replace('YEAR', new Date().getFullYear())
27const deps = [
28 'chalk',
29 'depseek',
30 'dotenv',
31 'fetch',
32 'fs',
33 'glob',
34 'minimist',
35 'ps',
36 'which',
37 'yaml',
38]
39const namemap = {
40 dotenv: 'envapi',
41 fs: 'fs-extra',
42 fetch: 'node-fetch-native',
43 glob: 'globby',
44 ps: '@webpod/ps',
45}
46const versions = deps.reduce(
47 (m, name) => {
48 m[name] = fs.readJsonSync(
49 path.resolve(root, 'node_modules', namemap[name] || name, 'package.json')
50 ).version
51 return m
52 },
53 {
54 zx: fs.readJsonSync(path.join(root, 'package.json')).version,
55 }
56)
57
58const argv = minimist(process.argv.slice(2), {
59 default: versions,
60 string: ['zx', ...deps],
61})
62
63delete argv._
64
65const list = JSON.stringify(argv, null, 2)
66 .replaceAll(' "', ' ')
67 .replaceAll('": ', ': ')
68 .replaceAll('"', "'")
69 .replace(/\n}$/, ',\n}')
70
71const versionsTs = `${license}
72export const versions: Record<string, string> = ${list}
73`
74const versionsCjs = `${license}
75module.exports = { versions: ${list}
76`
77
78fs.writeFileSync(path.join(root, 'src/versions.ts'), versionsTs, 'utf8')
79// fs.writeFileSync(path.join(root, 'build/versions.cjs'), versionsCjs, 'utf8')