Extend Project Init Script with Feature Toggles#704
Draft
Adi-ty wants to merge 8 commits into
Draft
Conversation
… details Rewrite bin/init.js on the @rtcamp/wp-tooling TTY UI kit (text/confirm/spinner/ style) as a single-process, mode-detecting flow: first run scaffolds + renames, later runs open the feature manager (re-runnable via `npm run init`). - Fix the PHP namespace rename: rtCamp\Theme\Elementary renames across PHP, composer.json (psr-4 + Tests), docs and config (single + JSON-escaped forms). - Configurable theme details: declining confirmation opens a per-field edit loop (name, version, text domain, namespace, prefix, package), looping until confirmed; the chosen version is applied to style.css + package.json. - Persist the full project identity to .wp-tooling.json for reuse by scaffolds. - Tailwind is an opt-in feature; webpack loads GenerateTailwindThemePlugin only when features.tailwind is set. - Declare the @rtcamp/wp-tooling devDependency (linked locally until published).
Extend the search-replace with targeted tokens for the starter's bare- "elementary" identifiers the compound tokens missed: block marker class / pattern slug, Interactivity store namespace, image size, browser-sync handle, ThemeOptions prefix/section/slug/label, and the "Theme Elementary" title. Source-repo URLs and the elementary.local example domains are left as-is.
Replace installHusky() with @rtcamp/wp-tooling/hooks installHooks({ force: true }):
writes pre-commit (runs lint:staged) and commit-msg (Conventional Commits) hooks
directly into .git/hooks, drops the husky devDependency and the .husky/ dir, and
points `prepare` at `wp-tooling install-hooks || true` so hooks reinstall on a
fresh clone (guarded so non-git/CI installs don't fail).
…keep tab indent - Invalid CLI arguments now exit 1 instead of 0. - Declining git initialization no longer prompts to install git hooks (hooks need a repo). - JSON writers (package.json, composer.json, .wp-tooling.json) preserve tab indentation and a final newline per .editorconfig, instead of reformatting the files to 2-space.
…nals - Pass record:true to the feature manager when install is skipped so feature deps land in package.json on first run (pairs with wp-tooling's opt-in --record-deps semantics). - Normalize namespaces (collapse doubled, strip leading/trailing backslashes) so composer-escaped input cannot produce invalid PHP. - Rename themes/elementary example paths; drop starter-repo repository/bugs/homepage from package.json during cleanup. - Persist cssDir in .wp-tooling.json for config:cssDir discovery. - Replace getRoot() with a ROOT constant, extract updateJsonFile/ replaceInFile helpers, pass keepGit explicitly instead of module state, run git with cwd, skip symlinks in the rename walk, surface feature-manager error details.
…ary and harden init against destructive and malformed input
Author
|
Depends on: https://github.com/rtCamp/wp-tooling/pull/30 |
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
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.
Description
Rewrites the theme init script (
bin/init.js) into a modular, re-runnable setup + feature manager built on@rtcamp/wp-tooling. The first run scaffolds and renames the starter theme and persists its identity; later runs jump straight to a feature manager, so optional features (e.g. Tailwind) can be toggled on or off any time withnpm run init.Technical Details
Two modes, detected via
.wp-tooling.json:composer dump-autoload→ persist identity → pick optional features → optional git + git hooks → first-run cleanup.Key changes
@rtcamp/wp-tooling/uiTTY kit (text/confirm/spinner/style) — replaces rawreadlinecallbacks and hand-rolled ANSI codes.style.css(Version:header) andpackage.json(version) — new behaviour..wp-tooling.json(name, version, textDomain, namespace, packageName, functionPrefix, cssClassPrefix, constantPrefix, cssDir, features). Reusable by any scaffold viadiscover_from: "config:<key>".rtCamp\Theme\Elementary) plus cleanup of remaining bare-elementaryidentifiers; repo URLs /elementary.localexamples are intentionally preserved.@rtcamp/wp-toolinginstallHooks()(pre-commit lint + commit-msg Conventional Commits) straight into.git/hooks/— replaces Husky (nohuskydep, no.husky/).prepareis set towp-tooling install-hooks || trueso hooks reinstall after a fresh clone.@rtcamp/wp-tooling/features; the Tailwind scaffold is bundled in@rtcamp/wp-tooling(so it's shared across consumers) — the theme-localbin/scaffolds/setup/tailwind/is removed.webpack.config.jslazily gates@rtcamp/tailwind-configbehindfeatures.tailwind, so themes that opt out never need it installed.bin/init.js+.wp-tooling.json(so the feature manager stays re-runnable) and drops theprepare → npm run initauto-trigger sonpm installno longer re-runs init.applyThemeNameskips its own file —init.jsholds the search tokens verbatim and is now kept, so without this it would corrupt its own replacement table.Checklist
(Acceptance criteria from #639 — verified via end-to-end smoke testing across default / custom-identity / Tailwind-toggle / edge-case runs.)
npm run initscaffold flow works end-to-end with TTY promptsstyle.cssVersion:andpackage.jsonversionreflect the chosen version.wp-tooling.jsonwritten with full identity;discover_from: "config:<key>"resolvesbin/scaffolds/setup/tailwind/removed (bundled scaffold used instead)npm run lint:stagedon commitnpm run init --cleanworks standalonebin/init.jsis not self-corrupted during the rename passScreenshots
N/A — CLI-only change.
To-do
@rtcamp/wp-toolingchange (feature-toggle layer +discover_fromresolvers) first.@rtcamp/wp-tooling(a devDependency of this theme) and@rtcamp/tailwind-config(added to the theme only when the Tailwind feature is enabled, with peerstailwindcss+@tailwindcss/postcss). Bump both to their published versions once available.Fixes/Covers issue
Fixes #639