-
Notifications
You must be signed in to change notification settings - Fork 724
feat: template based init script #3517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Migrated template system from .tmpl extensions to real file extensions with unified __VAR__ substitution syntax (previously {{VAR}}). Changes: - Updated substitution regex in src/utils.ts to use __VAR__ format - Modified src/init.ts to process all text files instead of only .tmpl - Renamed all .tmpl files to use actual extensions (.ts, .tsx, .json) - Updated all template files to use __VAR__ syntax - Updated tests to reflect new syntax and file extensions - Updated DESIGN.md with new conventions Benefits: - Proper syntax highlighting in all template files - Editor auto-formatting and type checking now work - Simpler processing logic without special extension handling - Consistent variable syntax across all file types All 45 tests passing.
eaee5e5
to
a7529d5
Compare
Replaced by #3524 |
marvinhagemeister
pushed a commit
that referenced
this pull request
Oct 6, 2025
Supersedes earlier attempt -> #3517 This is now ready for review. The major upside and motivation for this template based approach is that it is now possible to view what gets generated in the repository as actual valid files including syntax highlighting and formatting. Previously those files where just strings inside the old `init` script, which is IMHO a nightmare for maintainability. The approach for this template system is loosely based on Vite's `create-vite`, which also includes (redundant) templates inside the repository, see here -> https://github.com/vitejs/vite/tree/main/packages/create-vite Included in the tests are compatibility checks against the current `@fresh/[email protected]`, those can get removed at a later point when the templates start to diverge. They are only included for demonstration purposes, that this new implementation generates 100% identical output. This means that the first PR after this got included, which modifies the templates so the output differs from the old `init` script, also needs to include: ```shell rm packages/init/tests/compatibility_test.ts ``` Since this is a rather large PR, it may be more approachable to view the branch directly -> https://github.com/fry69/fresh/tree/fry69/refactor-init-template-rename/packages/init Generated PR message below: --- Replaces inline string-based project generation with file-based templates for improved maintainability and extensibility. ### Architecture **Template structure:** - `assets/template/` - Complete project templates (vite, vite-tailwind, builder, builder-tailwind) - `assets/variants/` - Additive overlays (docker, vscode, vscode-tailwind) - `assets/base/` - Common files synced across template variants Templates use `__VARIABLE__` syntax for substitution (project name, dependency versions). Files with `__` prefix are renamed to `.` prefix during generation (e.g., `__gitignore` → .gitignore). **Template selection logic:** ``` Base: vite|vite-tailwind|builder|builder-tailwind Variants: +docker, +vscode, +vscode-tailwind ``` ### Maintenance workflow Edit shared files in `assets/base/vite/` or `assets/base/builder/`, then run `deno task sync` to propagate changes to template variants. Template-specific files (deno.json, vite.config.ts, styles.css) are never overwritten. ### Version resolution Matches existing behavior: only Fresh core version is fetched from JSR, all other dependencies use fixed versions updated by release scripts. ### Testing 55 tests covering: - Unit tests for core functionality - Integration tests (project generation, builds, dev servers) - CLI argument parsing - Compatibility tests verifying output matches v2.0.9 (pre-refactor baseline) - Template sync workflow ### Breaking changes None. CLI interface and programmatic API remain identical. Package publishes to same `@fresh/init` scope at JSR. ### Documentation - README.md - User-facing usage documentation - DESIGN.md - Maintainer documentation (architecture, template maintenance, development setup)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor: File-based template system for init
Replaces inline string templates with file-based templates in
packages/init-templates/
.Changes
assets/template/
directoryassets/base/{vite,builder}
, synced viasync_templates.ts
__FRESH_VERSION__
-> Latest Fresh version@std/expect
See README.md and DESIGN.md for more details.
Since this is a rather large PR due to all the templates involved, I recommend take a look via the file browser branch view here -> https://github.com/fry69/fresh/tree/fry69/refactor-init-template/packages/init-templates