@take-out/scripts 0.0.69 → 0.0.71

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 (3) hide show
  1. package/package.json +3 -3
  2. package/src/release.ts +137 -33
  3. package/src/up.ts +10 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "type": "module",
5
5
  "main": "./src/run.ts",
6
6
  "sideEffects": false,
@@ -28,9 +28,9 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@take-out/helpers": "0.0.68"
31
+ "@take-out/helpers": "0.0.69"
32
32
  },
33
33
  "devDependencies": {
34
- "vxrn": "*1.4.10"
34
+ "vxrn": "1.4.10-1770207233041"
35
35
  }
36
36
  }
package/src/release.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { tmpdir } from 'node:os'
1
+ import { homedir, tmpdir } from 'node:os'
2
2
  import path, { join } from 'node:path'
3
3
 
4
4
  // note! this is an helper script used by tamagui team for publishing the takeout packages
5
5
  // you can delete this from your own app
6
6
 
7
7
  import { run } from '@take-out/scripts/helpers/run'
8
+ import { $ } from 'bun'
8
9
  import fs, { writeJSON } from 'fs-extra'
9
10
  import pMap from 'p-map'
10
11
 
@@ -13,6 +14,10 @@ process.setMaxListeners(50)
13
14
  process.stderr.setMaxListeners(50)
14
15
  process.stdout.setMaxListeners(50)
15
16
 
17
+ // on-zero sync paths
18
+ const onZeroGithub = join(homedir(), 'github', 'on-zero')
19
+ const onZeroTakeout = join(process.cwd(), 'packages', 'on-zero')
20
+
16
21
  // for failed publishes that need to re-run
17
22
  const reRun = process.argv.includes('--rerun')
18
23
  const rePublish = reRun || process.argv.includes('--republish')
@@ -33,44 +38,61 @@ const skipTest =
33
38
  const skipBuild = finish || rePublish || process.argv.includes('--skip-build')
34
39
  const dryRun = process.argv.includes('--dry-run')
35
40
  const tamaguiGitUser = process.argv.includes('--tamagui-git-user')
41
+ const syncOnZeroOnly = process.argv.includes('--sync-on-zero')
42
+ const skipOnZeroSync = process.argv.includes('--skip-on-zero-sync')
36
43
 
37
- const curVersion = fs.readJSONSync('./packages/helpers/package.json').version
38
-
39
- // must specify version (unless republishing):
40
- if (!rePublish && !skipVersion && !shouldPatch && !shouldMinor && !shouldMajor) {
41
- console.error(`Must specify one of --patch, --minor, or --major`)
42
- process.exit(1)
44
+ // handle --sync-on-zero standalone mode
45
+ if (syncOnZeroOnly) {
46
+ syncOnZero().catch((err) => {
47
+ console.error('sync failed:', err)
48
+ process.exit(1)
49
+ })
50
+ } else {
51
+ mainRelease()
43
52
  }
44
53
 
45
- const nextVersion = (() => {
46
- if (rePublish || skipVersion) {
47
- return curVersion
48
- }
54
+ async function mainRelease() {
55
+ const curVersion = fs.readJSONSync('./packages/helpers/package.json').version
49
56
 
50
- if (canary) {
51
- return `${curVersion.replace(/(-\d+)+$/, '')}-${Date.now()}`
57
+ // must specify version (unless republishing):
58
+ if (!rePublish && !skipVersion && !shouldPatch && !shouldMinor && !shouldMajor) {
59
+ console.error(`Must specify one of --patch, --minor, or --major`)
60
+ process.exit(1)
52
61
  }
53
62
 
54
- const curMajor = +curVersion.split('.')[0] || 0
55
- const curMinor = +curVersion.split('.')[1] || 0
56
- const patchAndCanary = curVersion.split('.')[2]
57
- const [curPatch] = patchAndCanary.split('-')
58
- const patchVersion = shouldPatch ? +curPatch + 1 : 0
59
- const minorVersion = curMinor + (shouldMinor ? 1 : 0)
60
- const majorVersion = curMajor + (shouldMajor ? 1 : 0)
61
- const next = `${majorVersion}.${minorVersion}.${patchVersion}`
62
-
63
- return next
64
- })()
65
-
66
- if (!skipVersion) {
67
- console.info(` 🚀 Releasing:`)
68
- console.info(' Current:', curVersion)
69
- console.info(` Next: ${nextVersion}`)
70
- }
63
+ const nextVersion = (() => {
64
+ if (rePublish || skipVersion) {
65
+ return curVersion
66
+ }
67
+
68
+ if (canary) {
69
+ return `${curVersion.replace(/(-\d+)+$/, '')}-${Date.now()}`
70
+ }
71
+
72
+ const curMajor = +curVersion.split('.')[0] || 0
73
+ const curMinor = +curVersion.split('.')[1] || 0
74
+ const patchAndCanary = curVersion.split('.')[2]
75
+ const [curPatch] = patchAndCanary.split('-')
76
+ const patchVersion = shouldPatch ? +curPatch + 1 : 0
77
+ const minorVersion = curMinor + (shouldMinor ? 1 : 0)
78
+ const majorVersion = curMajor + (shouldMajor ? 1 : 0)
79
+ const next = `${majorVersion}.${minorVersion}.${patchVersion}`
80
+
81
+ return next
82
+ })()
83
+
84
+ if (!skipVersion) {
85
+ console.info(` 🚀 Releasing:`)
86
+ console.info(' Current:', curVersion)
87
+ console.info(` Next: ${nextVersion}`)
88
+ }
71
89
 
72
- async function main() {
73
90
  try {
91
+ // sync on-zero IN (before release)
92
+ if (!skipOnZeroSync && !finish && !rePublish) {
93
+ await syncOnZeroIn()
94
+ }
95
+
74
96
  // ensure we are up to date
75
97
  // ensure we are on main
76
98
  if (!canary) {
@@ -259,6 +281,11 @@ async function main() {
259
281
  console.info(`✅ Pushed and versioned\n`)
260
282
  }
261
283
  }
284
+
285
+ // sync on-zero OUT (after release)
286
+ if (!skipOnZeroSync) {
287
+ await syncOnZeroOut(nextVersion)
288
+ }
262
289
  }
263
290
 
264
291
  console.info(`✅ Done\n`)
@@ -268,6 +295,85 @@ async function main() {
268
295
  }
269
296
  }
270
297
 
298
+ // sync on-zero: copy src from github to takeout, then takeout to github after release
299
+ async function syncOnZero() {
300
+ if (!(await fs.pathExists(onZeroGithub))) return
301
+ const pkg = await fs.readJSON(join(onZeroTakeout, 'package.json'))
302
+ await syncOnZeroIn()
303
+ await syncOnZeroOut(pkg.version)
304
+ }
305
+
306
+ async function syncOnZeroIn() {
307
+ if (!(await fs.pathExists(onZeroGithub))) return
308
+ console.info(' ← on-zero: syncing in from github')
309
+
310
+ if (dryRun) {
311
+ console.info(' [dry-run] would copy src from github')
312
+ return
313
+ }
314
+
315
+ // copy src files from github to takeout (github is source of truth for direct edits)
316
+ await fs.copy(join(onZeroGithub, 'src'), join(onZeroTakeout, 'src'), {
317
+ overwrite: true,
318
+ })
319
+
320
+ const status = (await $`git status --porcelain`.text()).trim()
321
+ if (status) {
322
+ await $`git add packages/on-zero`
323
+ await $`git commit -m "on-zero: sync from github"`
324
+ }
325
+ }
326
+
327
+ async function syncOnZeroOut(version: string) {
328
+ if (!(await fs.pathExists(onZeroGithub))) return
329
+ console.info(' → on-zero: syncing out to github')
330
+
331
+ // copy src files from takeout to github
332
+ await fs.copy(join(onZeroTakeout, 'src'), join(onZeroGithub, 'src'), {
333
+ overwrite: true,
334
+ })
335
+ await fs.copy(join(onZeroTakeout, 'cli.cjs'), join(onZeroGithub, 'cli.cjs'))
336
+ await fs.copy(join(onZeroTakeout, 'tsconfig.json'), join(onZeroGithub, 'tsconfig.json'))
337
+
338
+ // update package.json preserving github-specific fields
339
+ const takeoutPkg = await fs.readJSON(join(onZeroTakeout, 'package.json'))
340
+ const githubPkg = await fs.readJSON(join(onZeroGithub, 'package.json'))
341
+ const convertDeps = (deps: Record<string, string>) =>
342
+ Object.fromEntries(
343
+ Object.entries(deps || {}).map(([k, v]) => [
344
+ k,
345
+ v.startsWith('workspace:') ? `^${version}` : v,
346
+ ])
347
+ )
348
+ await fs.writeJSON(
349
+ join(onZeroGithub, 'package.json'),
350
+ {
351
+ ...takeoutPkg,
352
+ files: githubPkg.files,
353
+ repository: githubPkg.repository,
354
+ homepage: githubPkg.homepage,
355
+ bugs: githubPkg.bugs,
356
+ dependencies: convertDeps(takeoutPkg.dependencies),
357
+ devDependencies: convertDeps(takeoutPkg.devDependencies),
358
+ },
359
+ { spaces: 2 }
360
+ )
361
+
362
+ // commit and push
363
+ const status = (await $`git -C ${onZeroGithub} status --porcelain`.text()).trim()
364
+ if (!status) return
365
+
366
+ if (dryRun) {
367
+ console.info(` [dry-run] would push: sync: from takeout v${version}`)
368
+ await $`git -C ${onZeroGithub} checkout -- .`
369
+ return
370
+ }
371
+
372
+ await $`git -C ${onZeroGithub} add -A`
373
+ await $`git -C ${onZeroGithub} commit -m ${'sync: from takeout v' + version}`
374
+ await $`git -C ${onZeroGithub} push origin main`
375
+ }
376
+
271
377
  async function getWorkspacePackages() {
272
378
  // read workspaces from root package.json
273
379
  const rootPackageJson = await fs.readJSON(join(process.cwd(), 'package.json'))
@@ -332,5 +438,3 @@ async function loadPackageJsons(packagePaths: { name: string; location: string }
332
438
 
333
439
  return { allPackageJsons, publishablePackages }
334
440
  }
335
-
336
- main()
package/src/up.ts CHANGED
@@ -200,11 +200,16 @@ function updatePackageJsonVersions(
200
200
  if (pkg in depsObject && !depsObject[pkg].startsWith('workspace:')) {
201
201
  const newVersion = versionMap.get(pkg)
202
202
  if (newVersion) {
203
- const currentVersion = depsObject[pkg]
204
- // preserve version prefix (^, ~, >=, etc) or use exact if none
205
- const prefixMatch = currentVersion.match(/^([^\d]*)/)
206
- const prefix = prefixMatch?.[1] || ''
207
- depsObject[pkg] = `${prefix}${newVersion}`
203
+ // for tagged versions (canary, rc, etc), use exact version (no prefix)
204
+ // otherwise preserve version prefix (^, ~, >=, etc)
205
+ if (globalTag) {
206
+ depsObject[pkg] = newVersion
207
+ } else {
208
+ const currentVersion = depsObject[pkg]
209
+ const prefixMatch = currentVersion.match(/^([^\d]*)/)
210
+ const prefix = prefixMatch?.[1] || ''
211
+ depsObject[pkg] = `${prefix}${newVersion}`
212
+ }
208
213
  updatedCount++
209
214
  }
210
215
  }