create-grist-widget 0.2.20 → 0.2.22

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.20",
3
+ "version": "0.2.22",
4
4
  "description": "Scaffold a new Grist custom widget from the grist-widget-sdk Vite template",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -5,6 +5,12 @@ name: Deploy widget to GitHub Pages
5
5
  # /<repo>/v<version>/ + mutable /<repo>/latest/.
6
6
  # Rebuilt only when package.json's version has no v<version> dir yet, so
7
7
  # re-pushing main without a version bump is a no-op deploy.
8
+ # A push that *creates* the main ref (github.event.created) -- fired by
9
+ # GitHub's "Use this template" copying this repo onto a brand-new ref --
10
+ # is skipped entirely instead: it would otherwise publish whatever
11
+ # boilerplate version package.json happens to have checked in and
12
+ # permanently spend the first-release override before anyone's done
13
+ # real work.
8
14
  # - push to dev -> dev channel: mutable /<repo>/dev/
9
15
  # with version.json + a self-reload snippet, for live review inside Grist.
10
16
  #
@@ -91,7 +97,8 @@ jobs:
91
97
  --site site --repo "$REPO_NAME" \
92
98
  --event "${{ github.event_name }}" \
93
99
  --ref "${{ github.ref }}" \
94
- ${{ github.event.inputs.force == 'true' && '--force' || '' }})
100
+ ${{ github.event.inputs.force == 'true' && '--force' || '' }} \
101
+ ${{ github.event.created == true && '--created' || '' }})
95
102
  echo "Plan: $PLAN"
96
103
  node -e '
97
104
  const p = JSON.parse(process.argv[1]);
@@ -111,6 +111,13 @@ automatically.
111
111
  > only ever apply before your *first* genuine release — once one exists,
112
112
  > they're permanently a no-op, so it's still safest to never manually
113
113
  > re-seed `gh-pages` again after that point.
114
+ >
115
+ > "Use this template" also immediately fires this workflow once on its own,
116
+ > the moment the repo is created — before you've cloned it, let alone
117
+ > changed anything. That run is recognized (GitHub marks it as the push
118
+ > that *created* the `main` ref) and skipped entirely: nothing gets
119
+ > published, and it doesn't count as your first release, so the `0.0.1`
120
+ > override above still applies in full once you actually push real changes.
114
121
 
115
122
  **One-time setup** (the workflow can't do this part for you):
116
123
 
@@ -19,10 +19,13 @@
19
19
  //
20
20
  // Subcommands:
21
21
  // plan --site <dir> --repo <name> --event <push|workflow_dispatch>
22
- // --ref <ref> [--force]
22
+ // --ref <ref> [--force] [--created]
23
23
  // Prints JSON { context: "release"|"dev", version?, base, skip }.
24
24
  // Release is skipped when v<version> already exists on gh-pages
25
25
  // (idempotence: re-pushing main without a version bump is a no-op).
26
+ // --created (github.event.created off a push event) additionally skips
27
+ // unconditionally, without consuming the first-release version override
28
+ // -- see plan()'s own comment.
26
29
  //
27
30
  // place --site <dir> --repo <name> --channel <release|dev>
28
31
  // [--version <v>] --dist <dir> --sha <sha> [--ref <ref>]
@@ -101,7 +104,7 @@ function hasGenuineRelease(siteDir, repo) {
101
104
  * genuinely published by this repo before (unless force), so re-pushing main
102
105
  * without a version bump is a no-op.
103
106
  */
104
- export function plan(siteDir, repo, event, ref, { force = false } = {}) {
107
+ export function plan(siteDir, repo, event, ref, { force = false, created = false } = {}) {
105
108
  const isRelease = event === "workflow_dispatch" || ref === "refs/heads/main" || ref === "main"
106
109
  if (!isRelease) {
107
110
  return { context: "dev", base: basePathFor(repo, "dev") }
@@ -118,6 +121,28 @@ export function plan(siteDir, repo, event, ref, { force = false } = {}) {
118
121
  const version = firstRelease ? "0.0.1" : pkg.version
119
122
  if (!version) throw new Error("package.json has no version")
120
123
  const versionDir = join(siteDir, `v${version}`)
124
+ // GitHub's "Use this template" copies the source repo's main branch onto a
125
+ // brand-new ref, which fires this same push-to-main event itself --
126
+ // before anyone has done any real work. Without this check, that event
127
+ // would consume the first-release override above on whatever unmodified
128
+ // boilerplate happens to be checked in, so the widget's *actual* first
129
+ // release (once someone merges real content) no longer counts as
130
+ // firstRelease and publishes under that boilerplate's version verbatim
131
+ // instead of a clean 0.0.1 -- found live (a monorepo widget moved into its
132
+ // own repo this way published its real first release as "v0.2.21").
133
+ // Skipping this event entirely (never placing anything, never touching
134
+ // gh-pages) keeps hasGenuineRelease() false, so the override survives
135
+ // intact for whenever a real release actually happens.
136
+ if (created && event === "push") {
137
+ return {
138
+ context: "release",
139
+ version,
140
+ base: basePathFor(repo, "release", version),
141
+ skip: true,
142
+ reason: "ref-created",
143
+ firstRelease,
144
+ }
145
+ }
121
146
  const exists = isGenuineRelease(versionDir, repo)
122
147
  return {
123
148
  context: "release",
@@ -151,6 +176,12 @@ export function selfReloadSnippet(sha) {
151
176
  }
152
177
  } catch (e) { /* transient offline / 404 during publish: keep polling */ }
153
178
  }
179
+ check(); // don't wait a full POLL_MS for the first check -- a plain
180
+ // (non-cache-busted) request for this very page can hit a stale
181
+ // CDN-cached index.html referencing JS assets a newer deploy
182
+ // already deleted, producing a blank/black screen until this
183
+ // fires; found live, waiting the full interval left that
184
+ // black screen up for ~5s on a fresh visit.
154
185
  setInterval(check, POLL_MS);
155
186
  })();
156
187
  </script>`
@@ -376,7 +407,10 @@ function main() {
376
407
 
377
408
  switch (cmd) {
378
409
  case "plan": {
379
- const result = plan(args.site, args.repo, args.event, args.ref, { force: !!args.force })
410
+ const result = plan(args.site, args.repo, args.event, args.ref, {
411
+ force: !!args.force,
412
+ created: !!args.created,
413
+ })
380
414
  process.stdout.write(JSON.stringify(result))
381
415
  break
382
416
  }