Repository navigation
feat: create new project based on templates - #160
felipesantos2 wants to merge 7 commits into
Conversation
|
Hi @felipesantos2, thanks for the PR! We only merge features once they're in all three apps, so this also needs the Mac and Linux UI. Happy to keep it open until those are added, by you or someone else. :) |
|
Ok, I'll take care of the Linux version first and then look into what needs to be done for Mac. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
onairmarc
left a comment
There was a problem hiding this comment.
windows daemon tests are failing
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved creation conflicts and concurrency races can leave projects partially configured, replace existing directories, and overwrite concurrent site or settings changes.
5 open issues
Allow the newly created parked site during parent-folder conflict checks · New Publish projects with an atomic no-replace operation · New Register the site against the latest config under the mutation lock · New Preserve creation errors through refresh and gate selection on success · New Show template-loading errors to the user · New
What changed in this PR
Adds template-based project creation to Flock, addressing issue #150 with configurable starters, optional database setup, and automatic site linking.
Changes:
- Adds
flock app create, shared creation logic, and API endpoints backed by customizableapps.conftemplates. - Adds New App dialogs and client support on Windows, macOS, and Linux.
- Adds creation and client tests, CLI documentation, and Linux development instructions.
| File | Description |
|---|---|
windows/Flock.Tray/Settings/SitesPane.xaml.cs |
Adds the creation dialog and progress handling. |
windows/Flock.Tray/Settings/SitesPane.xaml |
Adds New App buttons and progress indicators. |
windows/Flock.Tray/Features/Sites/SitesService.cs |
Connects template loading and creation to UI operations. |
windows/Flock.Kit/Models.cs |
Adds template response models. |
windows/Flock.Kit/FlockClient.cs |
Adds template and creation API calls. |
windows/Flock.Kit.Tests/ClientTests.cs |
Tests requests, payloads, and creation timeout. |
README.md |
Expands Linux build, test, and run instructions. |
macos/Tests/FlockKitTests/ClientTests.swift |
Tests template loading and creation requests. |
macos/Sources/FlockUI/Settings/SitesPane.swift |
Adds the New App sheet and creation flow. |
macos/Sources/FlockKit/Models.swift |
Adds template and creation request models. |
macos/Sources/FlockKit/Client.swift |
Adds template and creation API calls. |
linux/src/panes/sites.rs |
Adds the creation dialog, progress, and helper tests. |
linux/src/api.rs |
Adds API methods, models, and serialization tests. |
internal/cli/root.go |
Registers the app command. |
internal/cli/passthrough_linux_test.go |
Checks app commands bypass PHP passthrough. |
internal/cli/app.go |
Implements flock app create and its options. |
internal/cli/app_test.go |
Tests creation, validation, conflicts, and database handling. |
internal/apps/apps.go |
Implements templates, project creation, and WordPress configuration. |
internal/apps/apps.conf |
Defines blank, PHP, and WordPress templates. |
internal/apps/apps_test.go |
Tests template parsing, overrides, and WordPress configuration. |
internal/api/appsapi.go |
Exposes template listing and project creation endpoints. |
internal/api/appsapi_test.go |
Tests endpoint success and rejection cases. |
internal/api/api.go |
Registers the application endpoints. |
docs/cli.md |
Documents creation commands and template customization. |
Review effort: Balanced
| return err | ||
| } | ||
| _ = os.Chmod(tmpDir, 0o755) | ||
| if err := os.Rename(tmpDir, path); err != nil { |
| if err := s.cfg.Upsert(site); err != nil { | ||
| return err | ||
| } | ||
| if err := s.commit(ctx, cmd.ErrOrStderr()); err != nil { |
Allow SaveSite to overwrite the parked entry discovered at the newly created path while still rejecting linked sites or entries at other paths, and add a parked-parent test.
Reload config.json after template download/setup before checking conflicts and committing, avoiding overwriting concurrent changes.
Return a success boolean from SettingsStore.perform and preserve any mutation error after refresh(), gating New App selection on that outcome.
Catch AppTemplatesAsync failures in NewAppAsync and show a ContentDialog instead of failing silently.
There was a problem hiding this comment.
🟡 Changes recommended
An unresolved critical race can overwrite an existing destination directory, while additional findings identify incorrect URL previews, leaked widgets, unsaved settings, and overlapping app-creation dialogs.
7 open issues
Register the site against the latest config under the mutation lock Publish projects with an atomic no-replace operation Compare parked directories by file identity · New Mark app creation busy before loading templates · New Break widget signal-handler reference cycles · New Prevent stale template responses from reopening the sheet · New Normalize the preview hostname like the created site · New
3 resolved since last review
Review effort: Balanced
| if existing, ok := latest.FindSite(site.Name); ok && (!existing.Parked || filepath.Clean(existing.Path) != filepath.Clean(site.Path)) { | ||
| return fmt.Errorf("project created at %s, but a site named %q already exists", site.Path, site.Name) | ||
| } |
| let this = self.clone(); | ||
| glib::spawn_future_local(async move { | ||
| let templates = match gio::spawn_blocking(|| Client.app_templates()).await.expect("templates request") { | ||
| Ok(list) if !list.is_empty() => list, | ||
| Err(Error::Server { status: 404, .. }) | Ok(_) => default_app_templates(), | ||
| Err(e) => { | ||
| report(&this.banner, Some(e.to_string())); | ||
| return; | ||
| } | ||
| }; | ||
| this.show_new_app_dialog(templates); | ||
| }); |
| let (name, folder, template_row) = (name.clone(), folder.clone(), template_row.clone()); | ||
| let (db_row, db_service_row, secured_row) = (db_row.clone(), db_service_row.clone(), secured_row.clone()); | ||
| let tld = tld.clone(); | ||
| move || { | ||
| let Some(dialog) = weak.upgrade() else { return }; |
| guard !creatingAppState.wrappedValue else { return } | ||
| Task { |
| var scheme = securedCheck.IsChecked == true ? "https" : "http"; | ||
| preview.Text = dialog.IsPrimaryButtonEnabled | ||
| ? $"{Path.Combine(rawFolder, rawName)} → {scheme}://{rawName.ToLowerInvariant().Replace(' ', '-')}.{tld}" |
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by active moderate issues: Windows-invalid and device-reserved names remain accepted, and the Windows preview can display a hostname different from the one created; the scope discrepancy is also unresolved.
9 open issues
Register the site against the latest config under the mutation lock Publish projects with an atomic no-replace operation Reject Windows-invalid folder names and reserved device names · New Normalize the preview hostname like the created site Prevent stale template responses from reopening the sheet Break widget signal-handler reference cycles Mark app creation busy before loading templates Compare parked directories by file identity Align the PR description with the added macOS and Linux flows · New
Review effort: Lite
| if folder == "" || folder == "." || folder == ".." || | ||
| strings.ContainsAny(folder, `/\:`) || strings.TrimSpace(folder) != folder || | ||
| strings.HasSuffix(folder, ".") || name == "" || len(name) > 63 { |
| Button("New App…") { openNewAppSheet() } | ||
| .disabled(creatingAppState.wrappedValue) | ||
| .help("Create a new project from a template and link it as a site") |
…Windows Tested and verified with the full Go test suite on Windows (PowerShell): - Increase freePort retry limit from 20 to 500 in daemon and web tests so sequential ephemeral TCP port allocation can step past 100-port Hyper-V/WSL excluded UDP/TCP port ranges on Windows. - Close the done channel in startDaemon and increase readiness timeout to 15s to prevent cleanup deadlocks on early daemon exit and false timeouts when netstat/tasklist run under parallel test load on Windows. - Call requireSymlinks(t) in TestCloneTreeCopiesFilesModesAndSymlinks so the test skips cleanly on Windows when Developer Mode or admin privileges are not enabled. - Register t.Cleanup(m.StopAll) in TestManagerRunsOneSetupPerWorktreeAndJoinsIt so worktree log files are closed before TempDir removal on Windows.



Quick Create Project (Windows-first)
Issue #150
Added a quick way to start new projects in Flock from both the terminal and the Windows app, inspired by Laragon's simplicity. Instead of hardcoding project setups, templates live in a plain
apps.conffile that's easy to extend or customize.From the terminal (
flock app create)flock app create my-app-- creates a starter PHP project (index.php) and linksmy-app.testflock app create my-app --type blank-- creates an empty folder and links itflock app create my-app --type wordpress-- downloads and extracts WordPress, creates a database in your running MySQL or MariaDB, fills inwp-config.php, and links the siteflock app create my-app --type wordpress --db-service mariadb-- lets you pick MySQL or MariaDB explicitly (also supports--db,--php, and--secure)You can add new templates or override download links without rebuilding by placing an
apps.conffile in Flock's data folder (%AppData%\Flock\apps.confon Windows).From the Windows app
Pending: UI for Mac and Linux
Personal Note:
Please review the DIFF, and let me know if you have any questions.