create-grist-widget 0.2.16 → 0.2.17

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": "create-grist-widget",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "Scaffold a new Grist custom widget from the grist-widget-sdk Vite template",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -91,13 +91,16 @@ automatically.
91
91
  > it doesn't run any of the CLI's own setup (renaming `package.json`,
92
92
  > titles, etc.), and it won't reset `package.json`'s `version` back to a
93
93
  > fresh `0.0.1` for you. Do both by hand before your first real release.
94
- > Also **never manually seed/copy `gh-pages` content** from another repo
95
- > (e.g. to get Pages showing something immediately) — each `v<version>/`
96
- > is only recognized as a genuine prior release if it carries a
94
+ > If you also checked **"Include all branches"** (to get `gh-pages`/Pages
95
+ > already set up, no manual Settings step), your first real release
96
+ > automatically clears out every leftover `v<version>/` it finds — a
97
+ > `v<version>/` only counts as a genuine prior release once it carries a
97
98
  > `showcase-meta.json` naming *this* repo (written by this pipeline's own
98
- > `place` step); anything else is treated as unpublished and safely
99
- > rebuilt over, but it's simpler to just let the workflow create
100
- > `gh-pages` itself (it does, as an orphan branch, on its first real run).
99
+ > `place` step), so on a repo with no genuine releases yet, everything
100
+ > else is provably inherited noise and gets safely wiped on your first
101
+ > push to `main`. That cleanup only ever runs before your *first* genuine
102
+ > release — once one exists, it's permanently a no-op, so it's still safest
103
+ > to never manually re-seed `gh-pages` again after that point.
101
104
 
102
105
  **One-time setup** (the workflow can't do this part for you):
103
106
 
@@ -177,6 +177,29 @@ function replaceDir(dest, srcDist) {
177
177
  cpSync(srcDist, dest, { recursive: true })
178
178
  }
179
179
 
180
+ /**
181
+ * If this repo has never genuinely published a release before (no
182
+ * v<version>/ directory whose showcase-meta.json matches this repo), any
183
+ * v<version>/ directories present are provably inherited noise -- e.g. from
184
+ * copying this template repo including its gh-pages branch (GitHub's "Use
185
+ * this template" -> "Include all branches"). Safe to clear them all before
186
+ * placing this repo's actual first release: there is no ambiguity, since a
187
+ * repo with zero genuine releases can't have any of its own history to lose.
188
+ * Never touches dev/, latest/, or site-root files. Once a genuine release
189
+ * exists for this repo, buildVersionsManifest is non-empty and this is
190
+ * permanently a no-op.
191
+ */
192
+ export function cleanupForeignVersionsIfFirstRelease(siteDir, repo) {
193
+ if (buildVersionsManifest(siteDir, repo).length > 0) return { cleaned: [] }
194
+ const cleaned = []
195
+ for (const name of existsSync(siteDir) ? readdirSync(siteDir) : []) {
196
+ if (!/^v\d+\.\d+\.\d+/.test(name)) continue
197
+ rmSync(join(siteDir, name), { recursive: true, force: true })
198
+ cleaned.push(name)
199
+ }
200
+ return { cleaned }
201
+ }
202
+
180
203
  /** Place a freshly built dist into the gh-pages tree. */
181
204
  export function placeTarget({ siteDir, channel, version, distDir, sha, ref, repo }) {
182
205
  if (!existsSync(distDir)) throw new Error(`dist not found: ${distDir}`)
@@ -202,6 +225,7 @@ export function placeTarget({ siteDir, channel, version, distDir, sha, ref, repo
202
225
  // exactly like latest/ reusing it: the asset URLs it references (under
203
226
  // v<version>/assets/) already exist from the versionDir placement above,
204
227
  // so nothing 404s.
228
+ cleanupForeignVersionsIfFirstRelease(siteDir, repo)
205
229
  const versionDir = join(siteDir, `v${version}`)
206
230
  replaceDir(versionDir, distDir)
207
231
  writeFileSync(