@take-out/scripts 0.0.70 → 0.0.72
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 +1 -1
- package/src/release.ts +153 -33
package/package.json
CHANGED
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
return curVersion
|
|
48
|
-
}
|
|
54
|
+
async function mainRelease() {
|
|
55
|
+
const curVersion = fs.readJSONSync('./packages/helpers/package.json').version
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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,101 @@ 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
|
+
|
|
309
|
+
// check if there are commits after the last sync commit
|
|
310
|
+
const log = (await $`git -C ${onZeroGithub} log --oneline --format=%s`.text()).trim()
|
|
311
|
+
const commits = log.split('\n')
|
|
312
|
+
const lastSyncIdx = commits.findIndex((c) => c.startsWith('sync: from takeout'))
|
|
313
|
+
|
|
314
|
+
// no commits before sync, or first commit is a sync = nothing to pull in
|
|
315
|
+
if (lastSyncIdx <= 0) {
|
|
316
|
+
console.info(' ← on-zero: no new github commits to sync in')
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const newCommits = commits.slice(0, lastSyncIdx).filter((c) => !c.match(/^v\d+\.\d+\.\d+/))
|
|
321
|
+
if (!newCommits.length) {
|
|
322
|
+
console.info(' ← on-zero: no new github commits to sync in')
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
console.info(` ← on-zero: syncing ${newCommits.length} commits from github`)
|
|
327
|
+
for (const c of newCommits) console.info(` ${c}`)
|
|
328
|
+
|
|
329
|
+
if (dryRun) {
|
|
330
|
+
console.info(' [dry-run] would copy src from github')
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
await fs.copy(join(onZeroGithub, 'src'), join(onZeroTakeout, 'src'), { overwrite: true })
|
|
335
|
+
|
|
336
|
+
const status = (await $`git status --porcelain`.text()).trim()
|
|
337
|
+
if (status) {
|
|
338
|
+
await $`git add packages/on-zero`
|
|
339
|
+
await $`git commit -m "on-zero: sync from github"`
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async function syncOnZeroOut(version: string) {
|
|
344
|
+
if (!(await fs.pathExists(onZeroGithub))) return
|
|
345
|
+
console.info(' → on-zero: syncing out to github')
|
|
346
|
+
|
|
347
|
+
// copy src files from takeout to github
|
|
348
|
+
await fs.copy(join(onZeroTakeout, 'src'), join(onZeroGithub, 'src'), {
|
|
349
|
+
overwrite: true,
|
|
350
|
+
})
|
|
351
|
+
await fs.copy(join(onZeroTakeout, 'cli.cjs'), join(onZeroGithub, 'cli.cjs'))
|
|
352
|
+
await fs.copy(join(onZeroTakeout, 'tsconfig.json'), join(onZeroGithub, 'tsconfig.json'))
|
|
353
|
+
|
|
354
|
+
// update package.json preserving github-specific fields
|
|
355
|
+
const takeoutPkg = await fs.readJSON(join(onZeroTakeout, 'package.json'))
|
|
356
|
+
const githubPkg = await fs.readJSON(join(onZeroGithub, 'package.json'))
|
|
357
|
+
const convertDeps = (deps: Record<string, string>) =>
|
|
358
|
+
Object.fromEntries(
|
|
359
|
+
Object.entries(deps || {}).map(([k, v]) => [
|
|
360
|
+
k,
|
|
361
|
+
v.startsWith('workspace:') ? `^${version}` : v,
|
|
362
|
+
])
|
|
363
|
+
)
|
|
364
|
+
await fs.writeJSON(
|
|
365
|
+
join(onZeroGithub, 'package.json'),
|
|
366
|
+
{
|
|
367
|
+
...takeoutPkg,
|
|
368
|
+
files: githubPkg.files,
|
|
369
|
+
repository: githubPkg.repository,
|
|
370
|
+
homepage: githubPkg.homepage,
|
|
371
|
+
bugs: githubPkg.bugs,
|
|
372
|
+
dependencies: convertDeps(takeoutPkg.dependencies),
|
|
373
|
+
devDependencies: convertDeps(takeoutPkg.devDependencies),
|
|
374
|
+
},
|
|
375
|
+
{ spaces: 2 }
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
// commit and push
|
|
379
|
+
const status = (await $`git -C ${onZeroGithub} status --porcelain`.text()).trim()
|
|
380
|
+
if (!status) return
|
|
381
|
+
|
|
382
|
+
if (dryRun) {
|
|
383
|
+
console.info(` [dry-run] would push: sync: from takeout v${version}`)
|
|
384
|
+
await $`git -C ${onZeroGithub} checkout -- .`
|
|
385
|
+
return
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
await $`git -C ${onZeroGithub} add -A`
|
|
389
|
+
await $`git -C ${onZeroGithub} commit -m ${'sync: from takeout v' + version}`
|
|
390
|
+
await $`git -C ${onZeroGithub} push origin main`
|
|
391
|
+
}
|
|
392
|
+
|
|
271
393
|
async function getWorkspacePackages() {
|
|
272
394
|
// read workspaces from root package.json
|
|
273
395
|
const rootPackageJson = await fs.readJSON(join(process.cwd(), 'package.json'))
|
|
@@ -332,5 +454,3 @@ async function loadPackageJsons(packagePaths: { name: string; location: string }
|
|
|
332
454
|
|
|
333
455
|
return { allPackageJsons, publishablePackages }
|
|
334
456
|
}
|
|
335
|
-
|
|
336
|
-
main()
|