@take-out/scripts 0.0.71 → 0.0.73

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/release.ts +26 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@take-out/scripts",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "type": "module",
5
5
  "main": "./src/run.ts",
6
6
  "sideEffects": false,
package/src/release.ts CHANGED
@@ -305,17 +305,33 @@ async function syncOnZero() {
305
305
 
306
306
  async function syncOnZeroIn() {
307
307
  if (!(await fs.pathExists(onZeroGithub))) return
308
- console.info(' ← on-zero: syncing in from github')
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}`)
309
328
 
310
329
  if (dryRun) {
311
330
  console.info(' [dry-run] would copy src from github')
312
331
  return
313
332
  }
314
333
 
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
- })
334
+ await fs.copy(join(onZeroGithub, 'src'), join(onZeroTakeout, 'src'), { overwrite: true })
319
335
 
320
336
  const status = (await $`git status --porcelain`.text()).trim()
321
337
  if (status) {
@@ -326,12 +342,9 @@ async function syncOnZeroIn() {
326
342
 
327
343
  async function syncOnZeroOut(version: string) {
328
344
  if (!(await fs.pathExists(onZeroGithub))) return
329
- console.info(' → on-zero: syncing out to github')
330
345
 
331
346
  // copy src files from takeout to github
332
- await fs.copy(join(onZeroTakeout, 'src'), join(onZeroGithub, 'src'), {
333
- overwrite: true,
334
- })
347
+ await fs.copy(join(onZeroTakeout, 'src'), join(onZeroGithub, 'src'), { overwrite: true })
335
348
  await fs.copy(join(onZeroTakeout, 'cli.cjs'), join(onZeroGithub, 'cli.cjs'))
336
349
  await fs.copy(join(onZeroTakeout, 'tsconfig.json'), join(onZeroGithub, 'tsconfig.json'))
337
350
 
@@ -340,10 +353,7 @@ async function syncOnZeroOut(version: string) {
340
353
  const githubPkg = await fs.readJSON(join(onZeroGithub, 'package.json'))
341
354
  const convertDeps = (deps: Record<string, string>) =>
342
355
  Object.fromEntries(
343
- Object.entries(deps || {}).map(([k, v]) => [
344
- k,
345
- v.startsWith('workspace:') ? `^${version}` : v,
346
- ])
356
+ Object.entries(deps || {}).map(([k, v]) => [k, v.startsWith('workspace:') ? `^${version}` : v])
347
357
  )
348
358
  await fs.writeJSON(
349
359
  join(onZeroGithub, 'package.json'),
@@ -359,10 +369,12 @@ async function syncOnZeroOut(version: string) {
359
369
  { spaces: 2 }
360
370
  )
361
371
 
362
- // commit and push
372
+ // only commit if there are actual changes
363
373
  const status = (await $`git -C ${onZeroGithub} status --porcelain`.text()).trim()
364
374
  if (!status) return
365
375
 
376
+ console.info(' → on-zero: syncing out to github')
377
+
366
378
  if (dryRun) {
367
379
  console.info(` [dry-run] would push: sync: from takeout v${version}`)
368
380
  await $`git -C ${onZeroGithub} checkout -- .`