@fluid-app/fluid-cli-theme-dev 0.1.521 → 0.1.522
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/README.md +33 -0
- package/dist/index.mjs +292 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -161,6 +161,39 @@ fluid theme pull --resolve remote # Auto-resolve conflicts to the server's
|
|
|
161
161
|
|
|
162
162
|
By default, conflicting edits (changed locally _and_ on the server since the last sync) are written with git-style conflict markers for you to resolve. For non-interactive use, `--resolve local` keeps your side of each conflicting hunk and `--resolve remote` takes the server's; before any auto-resolution overwrites local content, the pre-merge working tree is committed to the theme's shadow history (`.fluid-theme/repo`) so the discarded side stays restorable.
|
|
163
163
|
|
|
164
|
+
### `fluid theme widget`
|
|
165
|
+
|
|
166
|
+
Customize a Fluid native widget (`{% section 'fluid://native/widgets/<key>' %}`)
|
|
167
|
+
through the theme's own copy of it. The copy replaces the widget at every
|
|
168
|
+
placement in the theme, the same copy the visual builder makes when a widget is
|
|
169
|
+
dropped:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
fluid theme widget copy acct # Make the copy and pull it into fluid_native_acct/ (asks first on the live theme)
|
|
173
|
+
fluid theme widget copy acct --yes # Same, without the live-theme confirmation
|
|
174
|
+
fluid theme widget reset acct # Delete the copy and its fluid_native_acct/ folder (asks first)
|
|
175
|
+
fluid theme widget reset acct --yes # Same, without the confirmation
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
A copy keeps the template type of Fluid's original, so it is pulled into
|
|
179
|
+
`sections/fluid_native_<key>/` for a widget that is still a section and into
|
|
180
|
+
`widgets/fluid_native_<key>/` for one stored as a widget. `reset` deletes the
|
|
181
|
+
theme's copy of either type and removes both folders.
|
|
182
|
+
|
|
183
|
+
Both commands act on the theme in `.fluid-theme.json` unless `--theme <id>` is
|
|
184
|
+
passed, then run an ordinary `fluid theme pull` of that theme so the sync
|
|
185
|
+
baseline matches the server. The pull also brings down any other changes made
|
|
186
|
+
to the theme since the last pull.
|
|
187
|
+
|
|
188
|
+
On the live (active) theme a copy or reset changes what members see as soon as
|
|
189
|
+
it is made, so `copy` asks before it makes the copy there and `reset` says the
|
|
190
|
+
theme is live in its confirmation. `--yes` skips both prompts.
|
|
191
|
+
|
|
192
|
+
Do not create `sections/fluid_native_<key>/` or `widgets/fluid_native_<key>/`
|
|
193
|
+
by hand: without a copy of that type, a push makes it a plain template that
|
|
194
|
+
replaces nothing, and every placement keeps rendering Fluid's original.
|
|
195
|
+
`fluid theme push` warns about such folders.
|
|
196
|
+
|
|
164
197
|
### `fluid theme init`
|
|
165
198
|
|
|
166
199
|
Scaffold a new theme from the base template:
|
package/dist/index.mjs
CHANGED
|
@@ -610,6 +610,26 @@ async function validateMemberDestination(address, themeId, path) {
|
|
|
610
610
|
//#endregion
|
|
611
611
|
//#region ../../api-clients/themes/src/namespaces/v0.ts
|
|
612
612
|
/**
|
|
613
|
+
* Lists all theme templates
|
|
614
|
+
* Lists the templates available to a theme: the theme's own templates, global templates it has not overridden, and — when you filter by `themeable_type` — active templates from installed droplets. Requires a company admin user or company API token with the `application_themes` view permission. The list is not paginated.
|
|
615
|
+
*
|
|
616
|
+
* @param client - Fetch client instance
|
|
617
|
+
* @param [params] - params
|
|
618
|
+
*/
|
|
619
|
+
async function listThemeTemplates(client, params) {
|
|
620
|
+
return client.get(`/api/application_theme_templates`, params);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Deletes a theme template
|
|
624
|
+
* Deletes a template, along with any region rules that point at it. If it was the default for its type, another template is promoted to default. Requires the `application_themes` update permission. Global templates, droplet-provided templates, and page types managed by a dedicated endpoint are refused with 403; a template still referenced elsewhere returns 409.
|
|
625
|
+
*
|
|
626
|
+
* @param client - Fetch client instance
|
|
627
|
+
* @param id - id
|
|
628
|
+
*/
|
|
629
|
+
async function deleteThemeTemplate(client, id) {
|
|
630
|
+
return client.delete(`/api/application_theme_templates/${id}`);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
613
633
|
* List application themes
|
|
614
634
|
* Get all application themes with optional filters
|
|
615
635
|
*
|
|
@@ -5500,7 +5520,161 @@ async function requestSyncActor(api, timeoutMs) {
|
|
|
5500
5520
|
}
|
|
5501
5521
|
}
|
|
5502
5522
|
//#endregion
|
|
5523
|
+
//#region src/theme/native-widgets.ts
|
|
5524
|
+
/**
|
|
5525
|
+
* A theme's own copies of Fluid native widgets.
|
|
5526
|
+
*
|
|
5527
|
+
* A member page places a native widget by URI
|
|
5528
|
+
* (`{% section 'fluid://native/widgets/<key>' %}`), and Fluid owns the
|
|
5529
|
+
* template behind it: a global template named `fluid_native_<key>`. A theme
|
|
5530
|
+
* customizes one through its own COPY, made by
|
|
5531
|
+
* `POST /api/v202604/themes/:id/native-widget-copies`: a theme template of
|
|
5532
|
+
* the same name that replaces the widget at every placement in that theme.
|
|
5533
|
+
* Deleting the copy as a template returns the theme to Fluid's original.
|
|
5534
|
+
*
|
|
5535
|
+
* The copy keeps its original's template type. Fluid's originals are
|
|
5536
|
+
* `sections` today and are moving to the `widgets` type, and Rails reads a
|
|
5537
|
+
* copy of either type, so a theme can hold `sections/fluid_native_<key>/`,
|
|
5538
|
+
* `widgets/fluid_native_<key>/`, or both. Everything here handles both.
|
|
5539
|
+
*
|
|
5540
|
+
* A `fluid_native_<key>/` folder pushed to a theme without a copy of that
|
|
5541
|
+
* type becomes a plain template that replaces nothing, so the copy is always
|
|
5542
|
+
* made on the server before its files are edited locally.
|
|
5543
|
+
*/
|
|
5544
|
+
/** The template types a native widget and its copy can have. */
|
|
5545
|
+
const NATIVE_WIDGET_TYPES = ["sections", "widgets"];
|
|
5546
|
+
const NAME_PREFIX = "fluid_native_";
|
|
5547
|
+
/** Catalog keys are short lowercase slugs (`acct`, `sales_goal`). Anything
|
|
5548
|
+
* else is not a widget and must never reach a path or an API URL. */
|
|
5549
|
+
const NATIVE_WIDGET_KEY_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
5550
|
+
function isNativeWidgetKey(key) {
|
|
5551
|
+
return NATIVE_WIDGET_KEY_RE.test(key);
|
|
5552
|
+
}
|
|
5553
|
+
function isNativeWidgetType(type) {
|
|
5554
|
+
return NATIVE_WIDGET_TYPES.includes(type);
|
|
5555
|
+
}
|
|
5556
|
+
/** The folder a widget's copy of `type` is pulled into, relative to the
|
|
5557
|
+
* theme root. */
|
|
5558
|
+
function nativeWidgetFolder(key, type = "sections") {
|
|
5559
|
+
return `${type}/${NAME_PREFIX}${key}`;
|
|
5560
|
+
}
|
|
5561
|
+
/** The folder a copy is pulled into. A copy that does not state its type
|
|
5562
|
+
* is the older `sections` kind. */
|
|
5563
|
+
function copyFolder(key, copy) {
|
|
5564
|
+
return nativeWidgetFolder(key, isNativeWidgetType(copy.themeable_type) ? copy.themeable_type : "sections");
|
|
5565
|
+
}
|
|
5566
|
+
/**
|
|
5567
|
+
* Make the theme's copy of a native widget, or return the copy it already
|
|
5568
|
+
* has. Rails answers 201 for a new copy and 200 for an existing one, so a
|
|
5569
|
+
* repeat call is safe.
|
|
5570
|
+
*/
|
|
5571
|
+
async function copyNativeWidget(api, themeId, key) {
|
|
5572
|
+
return (await api.request(`/api/v202604/themes/${themeId}/native-widget-copies`, {
|
|
5573
|
+
method: "POST",
|
|
5574
|
+
body: { native_widget_key: key }
|
|
5575
|
+
})).template;
|
|
5576
|
+
}
|
|
5577
|
+
/**
|
|
5578
|
+
* The theme's copies of native widgets, by widget key, of either template
|
|
5579
|
+
* type. A key normally has one copy; it has two only when the theme holds
|
|
5580
|
+
* both a `sections` and a `widgets` copy.
|
|
5581
|
+
*/
|
|
5582
|
+
async function listNativeWidgetCopies(api, themeId, query = NAME_PREFIX) {
|
|
5583
|
+
const listed = await Promise.all(NATIVE_WIDGET_TYPES.map(async (type) => {
|
|
5584
|
+
return ((await listThemeTemplates(api, {
|
|
5585
|
+
application_theme_id: themeId,
|
|
5586
|
+
themeable_type: type,
|
|
5587
|
+
query
|
|
5588
|
+
}))?.templates ?? []).map((template) => template ? {
|
|
5589
|
+
...template,
|
|
5590
|
+
themeable_type: type
|
|
5591
|
+
} : template);
|
|
5592
|
+
}));
|
|
5593
|
+
const copies = /* @__PURE__ */ new Map();
|
|
5594
|
+
for (const template of listed.flat()) {
|
|
5595
|
+
const key = template?.customized_native_widget_key;
|
|
5596
|
+
if (template && key && template.name === `${NAME_PREFIX}${key}`) copies.set(key, [...copies.get(key) ?? [], template]);
|
|
5597
|
+
}
|
|
5598
|
+
return copies;
|
|
5599
|
+
}
|
|
5600
|
+
/** The `sections/fluid_native_<key>/` and `widgets/fluid_native_<key>/`
|
|
5601
|
+
* folders in the theme, sorted by folder. */
|
|
5602
|
+
function localNativeWidgets(themeRoot) {
|
|
5603
|
+
const found = /* @__PURE__ */ new Map();
|
|
5604
|
+
for (const file of themeRoot.files()) {
|
|
5605
|
+
const match = /^(sections|widgets)\/fluid_native_([^/]+)\//.exec(file.relativePath);
|
|
5606
|
+
if (!match || !isNativeWidgetKey(match[2])) continue;
|
|
5607
|
+
const widget = {
|
|
5608
|
+
key: match[2],
|
|
5609
|
+
type: match[1]
|
|
5610
|
+
};
|
|
5611
|
+
found.set(nativeWidgetFolder(widget.key, widget.type), widget);
|
|
5612
|
+
}
|
|
5613
|
+
return [...found.keys()].sort().map((folder) => found.get(folder));
|
|
5614
|
+
}
|
|
5615
|
+
/**
|
|
5616
|
+
* Local `fluid_native_<key>/` folders the theme has no copy of that type
|
|
5617
|
+
* for. Pushing one makes a plain template that never replaces the widget.
|
|
5618
|
+
*/
|
|
5619
|
+
async function uncopiedNativeWidgets(api, themeId, themeRoot) {
|
|
5620
|
+
const local = localNativeWidgets(themeRoot);
|
|
5621
|
+
if (local.length === 0) return [];
|
|
5622
|
+
const copies = await listNativeWidgetCopies(api, themeId);
|
|
5623
|
+
return local.filter(({ key, type }) => !(copies.get(key) ?? []).some((copy) => copyFolder(key, copy) === nativeWidgetFolder(key, type)));
|
|
5624
|
+
}
|
|
5625
|
+
/** One line per uncopied folder, telling the person how to make its copy. */
|
|
5626
|
+
function uncopiedNativeWidgetWarning(widgets) {
|
|
5627
|
+
return ["Native widget folders without a theme copy:", ...widgets.map(({ key, type }) => ` ${nativeWidgetFolder(key, type)}/ has no copy on this theme; run \`fluid theme widget copy ${key}\` first, or it is pushed as a plain ${type === "widgets" ? "widget" : "section"} that does not replace the widget.`)].join("\n");
|
|
5628
|
+
}
|
|
5629
|
+
/**
|
|
5630
|
+
* Return a native widget to Fluid's original: delete every copy the theme
|
|
5631
|
+
* has of it, then remove its `sections/` and `widgets/` folders. A copy that
|
|
5632
|
+
* is already gone (404) is not an error; any other refusal stops the reset
|
|
5633
|
+
* before a local folder is touched.
|
|
5634
|
+
*/
|
|
5635
|
+
async function resetNativeWidget(api, themeRoot, key, copies) {
|
|
5636
|
+
let deletedCopies = 0;
|
|
5637
|
+
for (const copy of copies) {
|
|
5638
|
+
if (copy.id == null) continue;
|
|
5639
|
+
try {
|
|
5640
|
+
await deleteThemeTemplate(api, copy.id);
|
|
5641
|
+
deletedCopies += 1;
|
|
5642
|
+
} catch (error) {
|
|
5643
|
+
if (!(error instanceof ApiError && error.status === 404)) throw error;
|
|
5644
|
+
}
|
|
5645
|
+
}
|
|
5646
|
+
const removedFolders = [];
|
|
5647
|
+
for (const type of NATIVE_WIDGET_TYPES) {
|
|
5648
|
+
const folder = nativeWidgetFolder(key, type);
|
|
5649
|
+
const absolute = join(themeRoot.root, folder);
|
|
5650
|
+
if (!existsSync(absolute)) continue;
|
|
5651
|
+
rmSync(absolute, {
|
|
5652
|
+
recursive: true,
|
|
5653
|
+
force: true
|
|
5654
|
+
});
|
|
5655
|
+
removedFolders.push(folder);
|
|
5656
|
+
}
|
|
5657
|
+
return {
|
|
5658
|
+
deletedCopies,
|
|
5659
|
+
removedFolders
|
|
5660
|
+
};
|
|
5661
|
+
}
|
|
5662
|
+
//#endregion
|
|
5503
5663
|
//#region src/commands/push.ts
|
|
5664
|
+
/**
|
|
5665
|
+
* Warn about `sections/` or `widgets/` `fluid_native_<key>/` folders the
|
|
5666
|
+
* theme has no copy of that type for: pushed, each becomes a plain template
|
|
5667
|
+
* that never replaces the widget. Only a warning, so a failed lookup never
|
|
5668
|
+
* stops the push.
|
|
5669
|
+
*/
|
|
5670
|
+
async function warnUncopiedNativeWidgets(api, themeId, themeRoot) {
|
|
5671
|
+
try {
|
|
5672
|
+
const uncopied = await uncopiedNativeWidgets(api, themeId, themeRoot);
|
|
5673
|
+
if (uncopied.length > 0) console.warn(chalk.yellow(uncopiedNativeWidgetWarning(uncopied)));
|
|
5674
|
+
} catch (error) {
|
|
5675
|
+
console.warn(chalk.yellow(` Could not check native widget copies: ${formatError(error)}`));
|
|
5676
|
+
}
|
|
5677
|
+
}
|
|
5504
5678
|
function createPushCommand() {
|
|
5505
5679
|
return new Command("push").description("Push local theme files to a remote theme").option("-t, --theme <name-or-id>", "Theme name or ID to push to").option("-n, --nodelete", "Do not delete remote files missing locally").option("-f, --force", "Skip local Liquid validation and the server-side merge check").option("-p, --publish", "Publish the theme after pushing").option("-u, --unpublished", "Create a new unpublished theme and push to it").option("--auto-baseline", "When no local baseline exists, record the server's current state as the baseline and push only what differs locally (never modifies local files, never deletes server-only files)").option("--root <path>", "Theme root directory", ".").action(async (opts) => {
|
|
5506
5680
|
requireToken();
|
|
@@ -5538,6 +5712,7 @@ function createPushCommand() {
|
|
|
5538
5712
|
theme = (await getApplicationTheme(api, config.themeId)).application_theme;
|
|
5539
5713
|
if (theme.status === "development") console.warn(chalk.yellow(` ${theme.name} (#${theme.id}) is a development theme: a scratch copy made by \`fluid theme dev\`, not a theme your storefront serves. This push updates only that copy. To update the real theme, run \`fluid theme pull -t <theme-id>\` here to bind the project to it, or pass --theme.`));
|
|
5540
5714
|
} else theme = await selectTheme(api, "Select a theme to push to");
|
|
5715
|
+
await warnUncopiedNativeWidgets(api, theme.id, themeRoot);
|
|
5541
5716
|
if (config && !mayBindTheme(config, theme)) {
|
|
5542
5717
|
const own = getDevTheme(devThemeKey(config.company, themeRoot.root));
|
|
5543
5718
|
if (own?.id !== theme.id) {
|
|
@@ -12878,6 +13053,7 @@ function resolveThemeId(opts) {
|
|
|
12878
13053
|
if (!config) throw new Error("No .fluid-theme.json here. Run `fluid theme pull` to bind this project to a theme, or pass --theme <id>.");
|
|
12879
13054
|
return config.themeId;
|
|
12880
13055
|
}
|
|
13056
|
+
/** The theme root: --root, else the theme root the workspace resolves from cwd. */
|
|
12881
13057
|
function resolveRoot(root) {
|
|
12882
13058
|
if (root !== ".") return root;
|
|
12883
13059
|
const workspace = findWorkspace();
|
|
@@ -12897,7 +13073,7 @@ function stagingJson(status) {
|
|
|
12897
13073
|
operation: status.operation
|
|
12898
13074
|
};
|
|
12899
13075
|
}
|
|
12900
|
-
async function run(opts, action) {
|
|
13076
|
+
async function run$1(opts, action) {
|
|
12901
13077
|
try {
|
|
12902
13078
|
await action();
|
|
12903
13079
|
} catch (error) {
|
|
@@ -12929,26 +13105,26 @@ function report(status, json) {
|
|
|
12929
13105
|
console.log(describeStaging(status));
|
|
12930
13106
|
if (status.branch?.preview_url) console.log(`Preview: ${chalk.cyan(status.branch.preview_url)}`);
|
|
12931
13107
|
}
|
|
12932
|
-
function withThemeOptions(command) {
|
|
13108
|
+
function withThemeOptions$1(command) {
|
|
12933
13109
|
return command.option("-t, --theme <id>", "Production theme ID (defaults to .fluid-theme.json)").option("--root <path>", "Theme root directory", ".").option("--json", "Emit JSON");
|
|
12934
13110
|
}
|
|
12935
13111
|
function createStagingCommand() {
|
|
12936
|
-
const status = withThemeOptions(new Command("status").description("Show the theme's staging branch and its preview link")).action((opts) => run(opts, async () => {
|
|
13112
|
+
const status = withThemeOptions$1(new Command("status").description("Show the theme's staging branch and its preview link")).action((opts) => run$1(opts, async () => {
|
|
12937
13113
|
requireToken();
|
|
12938
13114
|
report(await readStagingStatus(createApiClient(), resolveThemeId(opts)), opts.json);
|
|
12939
13115
|
}));
|
|
12940
|
-
const request = withThemeOptions(new Command("request").description("Create the theme's staging branch (or follow the one being created)")).action((opts) => run(opts, async () => {
|
|
13116
|
+
const request = withThemeOptions$1(new Command("request").description("Create the theme's staging branch (or follow the one being created)")).action((opts) => run$1(opts, async () => {
|
|
12941
13117
|
requireToken();
|
|
12942
13118
|
report(await ensureStaging(createApiClient(), resolveThemeId(opts)), opts.json);
|
|
12943
13119
|
}));
|
|
12944
|
-
const wait = withThemeOptions(new Command("wait").description("Wait until staging is ready or has failed")).option("--timeout <seconds>", "Give up after this many seconds", "600").action((opts) => run(opts, async () => {
|
|
13120
|
+
const wait = withThemeOptions$1(new Command("wait").description("Wait until staging is ready or has failed")).option("--timeout <seconds>", "Give up after this many seconds", "600").action((opts) => run$1(opts, async () => {
|
|
12945
13121
|
requireToken();
|
|
12946
13122
|
const timeoutMs = Number(opts.timeout) * 1e3;
|
|
12947
13123
|
const settled = await waitForStaging(createApiClient(), resolveThemeId(opts), { timeoutMs });
|
|
12948
13124
|
report(settled, opts.json);
|
|
12949
13125
|
if (settled.branch?.state !== "ready") process.exitCode = 1;
|
|
12950
13126
|
}));
|
|
12951
|
-
const publish = withThemeOptions(new Command("publish").description("Publish this directory's theme files to staging; production is not touched")).action((opts) => run(opts, async () => {
|
|
13127
|
+
const publish = withThemeOptions$1(new Command("publish").description("Publish this directory's theme files to staging; production is not touched")).action((opts) => run$1(opts, async () => {
|
|
12952
13128
|
requireToken();
|
|
12953
13129
|
const root = new ThemeRoot(resolveRoot(opts.root));
|
|
12954
13130
|
if (!root.isValid()) throw new Error(`'${root.root}' does not look like a theme directory.`);
|
|
@@ -12964,9 +13140,117 @@ function createStagingCommand() {
|
|
|
12964
13140
|
return new Command("staging").description("Use the theme's staging branch, previewed by a signed link (needs branch environments)").addCommand(status).addCommand(request).addCommand(wait).addCommand(publish);
|
|
12965
13141
|
}
|
|
12966
13142
|
//#endregion
|
|
13143
|
+
//#region src/commands/widget.ts
|
|
13144
|
+
function requireKey(key) {
|
|
13145
|
+
if (!isNativeWidgetKey(key)) throw new Error(`"${key}" is not a native widget key (lowercase letters, digits, "_" and "-").`);
|
|
13146
|
+
}
|
|
13147
|
+
/**
|
|
13148
|
+
* The theme a widget command changes, once it is known that the follow-up
|
|
13149
|
+
* pull may write it into `root`. A development theme that is not the one
|
|
13150
|
+
* this directory is bound to is refused here, before anything changes, the
|
|
13151
|
+
* same way `fluid theme pull` refuses it; otherwise the copy or reset would
|
|
13152
|
+
* land on that theme and its pull would then stop, leaving this directory
|
|
13153
|
+
* out of step with both.
|
|
13154
|
+
*/
|
|
13155
|
+
async function targetTheme(api, themeId, root) {
|
|
13156
|
+
const { application_theme: theme } = await getApplicationTheme(api, themeId);
|
|
13157
|
+
const config = readThemeConfig(root);
|
|
13158
|
+
if (config && !mayBindTheme(config, theme)) throw new Error(developmentThemeRefusal(config, theme));
|
|
13159
|
+
return theme;
|
|
13160
|
+
}
|
|
13161
|
+
/**
|
|
13162
|
+
* True when the theme is the company's live (published) theme, the one its
|
|
13163
|
+
* storefront and members are served. A copy or reset there changes what
|
|
13164
|
+
* members see at once.
|
|
13165
|
+
*/
|
|
13166
|
+
function isLiveTheme(theme) {
|
|
13167
|
+
return theme.status === "active";
|
|
13168
|
+
}
|
|
13169
|
+
const LIVE_THEME_NOTE = "It is the live theme, so members see the change immediately.";
|
|
13170
|
+
/** Ask the person at the terminal; anything but a yes declines. */
|
|
13171
|
+
async function confirm(message) {
|
|
13172
|
+
const { confirmed } = await prompts({
|
|
13173
|
+
type: "confirm",
|
|
13174
|
+
name: "confirmed",
|
|
13175
|
+
message,
|
|
13176
|
+
initial: false
|
|
13177
|
+
}, { onCancel: () => process.exit(130) });
|
|
13178
|
+
return confirmed === true;
|
|
13179
|
+
}
|
|
13180
|
+
/**
|
|
13181
|
+
* An ordinary `fluid theme pull` of the theme into the checkout. It brings
|
|
13182
|
+
* the copy's files down AND records them in the sync baseline, so the next
|
|
13183
|
+
* push neither refuses as "server has changed" nor treats the files as new.
|
|
13184
|
+
*/
|
|
13185
|
+
async function pullTheme(themeId, root) {
|
|
13186
|
+
await createPullCommand().parseAsync([
|
|
13187
|
+
"--yes",
|
|
13188
|
+
"-t",
|
|
13189
|
+
String(themeId),
|
|
13190
|
+
"--root",
|
|
13191
|
+
root
|
|
13192
|
+
], { from: "user" });
|
|
13193
|
+
}
|
|
13194
|
+
async function run(action) {
|
|
13195
|
+
try {
|
|
13196
|
+
await action();
|
|
13197
|
+
} catch (error) {
|
|
13198
|
+
console.error(chalk.red(formatError(error)));
|
|
13199
|
+
process.exitCode = 1;
|
|
13200
|
+
}
|
|
13201
|
+
}
|
|
13202
|
+
function withThemeOptions(command) {
|
|
13203
|
+
return command.option("-t, --theme <id>", "Theme ID to change (defaults to .fluid-theme.json)").option("--root <path>", "Theme root directory", ".").option("-y, --yes", "Skip confirmation prompt");
|
|
13204
|
+
}
|
|
13205
|
+
function createWidgetCommand() {
|
|
13206
|
+
const copy = withThemeOptions(new Command("copy").argument("<key>", "Native widget key, such as acct").description("Make the theme's copy of a native widget and pull it into fluid_native_<key>/ (asks first on the live theme)")).action((key, opts) => run(async () => {
|
|
13207
|
+
requireKey(key);
|
|
13208
|
+
requireToken();
|
|
13209
|
+
const root = resolveRoot(opts.root);
|
|
13210
|
+
const themeId = resolveThemeId(opts);
|
|
13211
|
+
const api = createApiClient();
|
|
13212
|
+
const theme = await targetTheme(api, themeId, root);
|
|
13213
|
+
if (!opts.yes && isLiveTheme(theme)) {
|
|
13214
|
+
if (!await confirm(`Copy ${key} on theme #${themeId}? ${LIVE_THEME_NOTE} The copy replaces Fluid's ${key} at every placement on it.`)) {
|
|
13215
|
+
console.log("Aborted.");
|
|
13216
|
+
return;
|
|
13217
|
+
}
|
|
13218
|
+
}
|
|
13219
|
+
const template = await copyNativeWidget(api, themeId, key);
|
|
13220
|
+
console.log(`Theme #${themeId} has its copy of ${chalk.bold(key)} (template #${template.id}). Pulling it into ${copyFolder(key, template)}/…`);
|
|
13221
|
+
await pullTheme(themeId, root);
|
|
13222
|
+
}));
|
|
13223
|
+
const reset = withThemeOptions(new Command("reset").argument("<key>", "Native widget key, such as acct").description("Delete the theme's copy of a native widget and remove its fluid_native_<key>/ folder")).action((key, opts) => run(async () => {
|
|
13224
|
+
requireKey(key);
|
|
13225
|
+
requireToken();
|
|
13226
|
+
const root = resolveRoot(opts.root);
|
|
13227
|
+
const themeId = resolveThemeId(opts);
|
|
13228
|
+
const api = createApiClient();
|
|
13229
|
+
const theme = await targetTheme(api, themeId, root);
|
|
13230
|
+
const copies = (await listNativeWidgetCopies(api, themeId, `fluid_native_${key}`)).get(key) ?? [];
|
|
13231
|
+
const folders = NATIVE_WIDGET_TYPES.map((type) => nativeWidgetFolder(key, type)).filter((folder) => existsSync(join(root, folder)));
|
|
13232
|
+
if (copies.length === 0 && folders.length === 0) {
|
|
13233
|
+
console.log(`Theme #${themeId} has no copy of ${key}, and there is no ${nativeWidgetFolder(key)}/ or ${nativeWidgetFolder(key, "widgets")}/ here. Nothing to reset.`);
|
|
13234
|
+
return;
|
|
13235
|
+
}
|
|
13236
|
+
if (!opts.yes) {
|
|
13237
|
+
const live = copies.length > 0 && isLiveTheme(theme) ? ` ${LIVE_THEME_NOTE}` : "";
|
|
13238
|
+
if (!await confirm(`Reset ${key} to Fluid's original? This deletes ${[copies.length > 0 && `theme #${themeId}'s copy`, ...folders.map((folder) => `${folder}/`)].filter(Boolean).join(" and ")}, including your changes.${live}`)) {
|
|
13239
|
+
console.log("Aborted.");
|
|
13240
|
+
return;
|
|
13241
|
+
}
|
|
13242
|
+
}
|
|
13243
|
+
const outcome = await resetNativeWidget(api, new ThemeRoot(root), key, copies);
|
|
13244
|
+
const done = [outcome.deletedCopies > 0 && `deleted theme #${themeId}'s copy`, ...outcome.removedFolders.map((folder) => `removed ${folder}/`)].filter(Boolean);
|
|
13245
|
+
console.log(`Reset ${chalk.bold(key)}: ${done.join(" and ") || "nothing left to remove"}.`);
|
|
13246
|
+
await pullTheme(themeId, root);
|
|
13247
|
+
}));
|
|
13248
|
+
return new Command("widget").description("Customize Fluid native widgets through the theme's own copy of each").addCommand(copy).addCommand(reset);
|
|
13249
|
+
}
|
|
13250
|
+
//#endregion
|
|
12967
13251
|
//#region src/commands/theme.ts
|
|
12968
13252
|
function registerThemeCommand(ctx) {
|
|
12969
|
-
const cmd = new Command("theme").description("Theme developer workflow — dev server, push, pull, lint, init, skills, crawl, compare");
|
|
13253
|
+
const cmd = new Command("theme").description("Theme developer workflow — dev server, push, pull, lint, init, skills, crawl, compare, widget");
|
|
12970
13254
|
cmd.addCommand(createDevCommand());
|
|
12971
13255
|
cmd.addCommand(createPushCommand());
|
|
12972
13256
|
cmd.addCommand(createPullCommand());
|
|
@@ -12977,6 +13261,7 @@ function registerThemeCommand(ctx) {
|
|
|
12977
13261
|
cmd.addCommand(createCrawlCommand());
|
|
12978
13262
|
cmd.addCommand(createCompareCommand());
|
|
12979
13263
|
cmd.addCommand(createStagingCommand());
|
|
13264
|
+
cmd.addCommand(createWidgetCommand());
|
|
12980
13265
|
ctx.program.addCommand(cmd);
|
|
12981
13266
|
}
|
|
12982
13267
|
//#endregion
|