Skip to content

Commit 27260e3

Browse files
authored
Feat/inline delivery mode (#22)
* feat(publish): support inline Webflow delivery * chore: release v1.3.0
1 parent 332d73a commit 27260e3

16 files changed

Lines changed: 527 additions & 108 deletions

File tree

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Example:
7272
"repositoryName": "your-repo",
7373
"packageManager": "bun",
7474
"assetBranch": "wfkit-dist",
75+
"deliveryMode": "cdn",
7576
"buildDir": "dist/assets",
7677
"devHost": "localhost",
7778
"devPort": 5173,
@@ -204,6 +205,22 @@ This flow:
204205
3. updates the Webflow custom code
205206
4. republishes the site
206207

208+
By default, production publish uses `deliveryMode: "cdn"` and points Webflow at the artifact branch through jsDelivr.
209+
210+
If you want to skip jsDelivr and write the built module code back into Webflow as managed inline scripts, run:
211+
212+
```bash
213+
wfkit publish --env prod --delivery inline
214+
```
215+
216+
Or set this once in `wfkit.json`:
217+
218+
```json
219+
{
220+
"deliveryMode": "inline"
221+
}
222+
```
223+
207224
If you want to preview the publish plan without changing GitHub or Webflow, run:
208225

209226
```bash
@@ -246,8 +263,8 @@ That extended flow:
246263

247264
1. writes the migrated local files
248265
2. builds the project
249-
3. pushes the artifact branch
250-
4. updates Webflow to the new jsDelivr URLs
266+
3. if `deliveryMode` is `cdn`, pushes the artifact branch
267+
4. updates Webflow using either jsDelivr URLs or managed inline scripts
251268

252269
## Release the CLI
253270

@@ -372,6 +389,7 @@ Options:
372389
- `--dev-port` Local dev server port for legacy `dev` mode
373390
- `--dev-host` Local dev server host for legacy `dev` mode
374391
- `--custom-commit` Custom Git commit message for the asset branch publish
392+
- `--delivery` Production delivery mode: `cdn` or `inline`
375393
- `--asset-branch` Git branch used for published build artifacts and jsDelivr URLs
376394
- `--build-dir` Build output directory
377395
- `--notify` Show a desktop notification and play a sound when finished
@@ -400,11 +418,17 @@ Options:
400418
- `--force` Overwrite existing generated migration targets
401419
- `--publish` After writing local files, build assets, push the artifact branch, and update Webflow
402420
- `--custom-commit` Custom Git commit message for the generated migration publish
421+
- `--delivery` Delivery mode for `--publish`: `cdn` or `inline`
403422
- `--asset-branch` Git branch used for published build artifacts and jsDelivr URLs
404423
- `--build-dir` Build output directory
405424
- `--notify` Show a desktop notification and play a sound when finished
406425

407-
`wfkit publish` always publishes only the built files in `buildDir` to the asset branch. `wfkit migrate --publish` uses that same artifact-only flow. Neither command commits or pushes your working tree source files.
426+
`wfkit publish` and `wfkit migrate --publish` support two delivery modes:
427+
428+
- `cdn`: publish only the built files in `buildDir` to the asset branch, then point Webflow at jsDelivr
429+
- `inline`: build self-contained bundles and write them back into Webflow as managed inline module scripts
430+
431+
Neither command commits or pushes your working tree source files.
408432

409433
### `wfkit update`
410434

cmd/wfkit/app_commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func buildMigrateCommand() *cli.Command {
6060
&cli.BoolFlag{Name: "dry-run", Usage: "Show what would be migrated without writing files or updating Webflow"},
6161
&cli.BoolFlag{Name: "publish", Usage: "After writing local files, build assets, push the artifact branch, and update Webflow"},
6262
&cli.StringFlag{Name: "custom-commit", Value: "Migrate Webflow page code via wfkit", Usage: "Custom commit message"},
63+
&cli.StringFlag{Name: "delivery", Value: "cdn", Usage: "Delivery mode for --publish: cdn or inline"},
6364
&cli.StringFlag{Name: "asset-branch", Value: "wfkit-dist", Usage: "Git branch used for published build artifacts and jsDelivr URLs"},
6465
&cli.StringFlag{Name: "branch", Hidden: true, Usage: "Deprecated alias for --asset-branch"},
6566
&cli.StringFlag{Name: "build-dir", Value: "dist/assets", Usage: "Build directory"},
@@ -81,6 +82,7 @@ func buildPublishCommand() *cli.Command {
8182
&cli.IntFlag{Name: "dev-port", Value: 5173, Usage: "Local dev server port (dev mode)"},
8283
&cli.StringFlag{Name: "dev-host", Value: "localhost", Usage: "Local dev server host (dev mode)"},
8384
&cli.StringFlag{Name: "custom-commit", Value: "Auto publish from wfkit tool", Usage: "Custom commit message"},
85+
&cli.StringFlag{Name: "delivery", Value: "cdn", Usage: "Production delivery mode: cdn or inline"},
8486
&cli.StringFlag{Name: "asset-branch", Value: "wfkit-dist", Usage: "Git branch used for published build artifacts and jsDelivr URLs"},
8587
&cli.StringFlag{Name: "branch", Hidden: true, Usage: "Deprecated alias for --asset-branch"},
8688
&cli.StringFlag{Name: "build-dir", Value: "dist/assets", Usage: "Build directory"},

cmd/wfkit/cli_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ func resolveAssetBranchFlag(c *cli.Context, fallback string) string {
5656
return c.String("asset-branch")
5757
}
5858

59+
func resolveDeliveryModeFlag(c *cli.Context, fallback string) string {
60+
if c.IsSet("delivery") {
61+
return c.String("delivery")
62+
}
63+
if fallback != "" {
64+
return fallback
65+
}
66+
return "cdn"
67+
}
68+
5969
func resolveIntFlag(c *cli.Context, name string, fallback int) int {
6070
if c.IsSet(name) {
6171
return c.Int(name)

cmd/wfkit/migrate_flow.go

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ func (f *migrateFlow) run() error {
3737
}
3838

3939
f.printHeader()
40-
printMigrateTimeline(f.dryRun(), f.shouldPublish(), false, false, false, false, false, false, false)
40+
printMigrateTimeline(f.dryRun(), f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), false, false, false, false, false, false, false)
4141

4242
if err := f.authenticate(); err != nil {
4343
return err
4444
}
45-
printMigrateTimeline(f.dryRun(), f.shouldPublish(), true, false, false, false, false, false, false)
45+
printMigrateTimeline(f.dryRun(), f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, false, false, false, false, false, false)
4646

4747
if err := f.loadPages(); err != nil {
4848
return err
4949
}
50-
printMigrateTimeline(f.dryRun(), f.shouldPublish(), true, true, false, false, false, false, false)
50+
printMigrateTimeline(f.dryRun(), f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, false, false, false, false, false)
5151

5252
if err := f.loadGlobalCode(); err != nil {
5353
return err
5454
}
55-
printMigrateTimeline(f.dryRun(), f.shouldPublish(), true, true, true, false, false, false, false)
55+
printMigrateTimeline(f.dryRun(), f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, false, false, false, false)
5656

5757
if err := f.planMigration(); err != nil {
5858
return err
@@ -66,14 +66,14 @@ func (f *migrateFlow) run() error {
6666

6767
if f.dryRun() {
6868
utils.CPrint("Dry run mode: no files or Webflow code were changed", "yellow")
69-
printMigrateTimeline(true, f.shouldPublish(), true, true, true, false, false, false, false)
69+
printMigrateTimeline(true, f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, false, false, false, false)
7070
return nil
7171
}
7272

7373
if err := f.writeFiles(); err != nil {
7474
return err
7575
}
76-
printMigrateTimeline(false, f.shouldPublish(), true, true, true, true, false, false, false)
76+
printMigrateTimeline(false, f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, true, false, false, false)
7777

7878
if !f.shouldPublish() {
7979
f.printSuccess()
@@ -83,12 +83,14 @@ func (f *migrateFlow) run() error {
8383
if err := f.buildAssets(); err != nil {
8484
return err
8585
}
86-
printMigrateTimeline(false, true, true, true, true, true, true, false, false)
86+
printMigrateTimeline(false, f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, true, true, false, false)
8787

88-
if err := f.pushGit(); err != nil {
89-
return err
88+
if f.shouldPushAssets() {
89+
if err := f.pushGit(); err != nil {
90+
return err
91+
}
9092
}
91-
printMigrateTimeline(false, true, true, true, true, true, true, true, false)
93+
printMigrateTimeline(false, f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, true, true, f.shouldPushAssets(), false)
9294

9395
if err := f.publish(); err != nil {
9496
return err
@@ -106,7 +108,7 @@ func (f *migrateFlow) loadConfig() error {
106108
if cfg.AppName == "" {
107109
return fmt.Errorf("missing appName configuration in wfkit.json")
108110
}
109-
if f.shouldPublish() {
111+
if f.shouldPublish() && f.delivery() == "cdn" {
110112
if err := cfg.ValidatePublish(); err != nil {
111113
return err
112114
}
@@ -116,6 +118,7 @@ func (f *migrateFlow) loadConfig() error {
116118
f.pagesDir = resolveStringFlag(f.cliContext, "pages-dir", "src/pages")
117119
f.args = map[string]interface{}{
118120
"env": "prod",
121+
"delivery": resolveDeliveryModeFlag(f.cliContext, cfg.DeliveryMode),
119122
"asset-branch": resolveAssetBranchFlag(f.cliContext, cfg.AssetBranch),
120123
"build-dir": resolveStringFlag(f.cliContext, "build-dir", cfg.BuildDir),
121124
"custom-commit": f.cliContext.String("custom-commit"),
@@ -189,6 +192,20 @@ func (f *migrateFlow) writeFiles() error {
189192

190193
func (f *migrateFlow) buildAssets() error {
191194
utils.CPrint("Building migrated pages...", "cyan")
195+
if f.delivery() == "inline" {
196+
if err := build.RunProjectBuild(f.args["build-dir"].(string), f.config.PackageManager); err != nil {
197+
return fmt.Errorf("build failed after migration: %w", err)
198+
}
199+
inlineBundles, err := build.BuildInlineBundles(f.args["build-dir"].(string), f.config.PackageManager)
200+
if err != nil {
201+
return fmt.Errorf("inline bundle build failed after migration: %w", err)
202+
}
203+
f.args["inline-global"] = inlineBundles.Global
204+
f.args["inline-pages"] = inlineBundles.Pages
205+
utils.CPrint("Build successful, inline bundles are ready for Webflow", "green")
206+
return nil
207+
}
208+
192209
scriptURL, err := build.DoBuild(f.args, f.config.GitHubUser, f.config.RepositoryName, f.config.PackageManager)
193210
if err != nil {
194211
return fmt.Errorf("build failed after migration: %w", err)
@@ -243,15 +260,16 @@ func (f *migrateFlow) publish() error {
243260
func (f *migrateFlow) printSuccess() {
244261
if f.shouldPublish() {
245262
printMigrationPublishResult(f.result)
246-
printMigrateTimeline(false, true, true, true, true, true, true, true, f.result.Published)
263+
printMigrateTimeline(false, f.shouldPublish(), f.shouldPushAssets(), f.shouldPublish(), true, true, true, true, true, f.shouldPushAssets(), f.result.Published)
247264

248265
notifySuccess(f.args["notify"].(bool), "wfkit migrate completed", "Webflow code migration finished successfully.")
249266

250267
utils.PrintSuccessScreen(
251268
"Migration completed",
252-
"Legacy Webflow code has been moved into local files and published via jsDelivr.",
269+
"Legacy Webflow code has been moved into local files and published back to Webflow.",
253270
[]utils.SummaryMetric{
254271
{Label: "Pages updated", Value: fmt.Sprintf("%d", f.result.UpdatedPages), Tone: "success"},
272+
{Label: "Delivery", Value: f.delivery(), Tone: "info"},
255273
{Label: "Published", Value: map[bool]string{true: "yes", false: "no"}[f.result.Published], Tone: "info"},
256274
},
257275
"git status",
@@ -260,7 +278,7 @@ func (f *migrateFlow) printSuccess() {
260278
return
261279
}
262280

263-
printMigrateTimeline(false, false, true, true, true, true, false, false, false)
281+
printMigrateTimeline(false, false, false, false, true, true, true, true, false, false, false)
264282
notifySuccess(f.args["notify"].(bool), "wfkit migrate completed", "Webflow code migration files were written locally.")
265283
utils.PrintSuccessScreen(
266284
"Migration completed",
@@ -281,3 +299,11 @@ func (f *migrateFlow) dryRun() bool {
281299
func (f *migrateFlow) shouldPublish() bool {
282300
return f.cliContext.Bool("publish")
283301
}
302+
303+
func (f *migrateFlow) delivery() string {
304+
return f.args["delivery"].(string)
305+
}
306+
307+
func (f *migrateFlow) shouldPushAssets() bool {
308+
return f.shouldPublish() && f.delivery() == "cdn"
309+
}

0 commit comments

Comments
 (0)