@fluid-app/fluid-cli-theme-dev 0.1.599 → 0.1.601
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 +13 -0
- package/dist/index.mjs +188 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -493,6 +493,19 @@ replace the widget.
|
|
|
493
493
|
after publishing, since Fluid may rewrite keys; pull to take staging's
|
|
494
494
|
version.
|
|
495
495
|
|
|
496
|
+
### Promoting staging to live
|
|
497
|
+
|
|
498
|
+
`fluid theme staging promote` copies exactly what staging serves onto the
|
|
499
|
+
live theme, all at once. It lists the files it will write and remove and asks
|
|
500
|
+
first; pass `--yes` to skip the question (JSON mode always needs `--yes`). It
|
|
501
|
+
only promotes when the live theme hasn't changed since staging was based on
|
|
502
|
+
it; otherwise it refuses rather than overwrite that change. Images and other
|
|
503
|
+
binary files are copied to assets the live theme owns.
|
|
504
|
+
|
|
505
|
+
`fluid theme staging undo-promote` puts the live theme back as it was before
|
|
506
|
+
the latest promotion, while the live theme still serves exactly what that
|
|
507
|
+
promotion applied.
|
|
508
|
+
|
|
496
509
|
### Comparing with staging
|
|
497
510
|
|
|
498
511
|
`fluid theme staging compare` reports how this directory's files differ from
|
package/dist/index.mjs
CHANGED
|
@@ -1831,6 +1831,103 @@ function isRecord$5(entry) {
|
|
|
1831
1831
|
return typeof entry === "object" && entry !== null && !Array.isArray(entry);
|
|
1832
1832
|
}
|
|
1833
1833
|
//#endregion
|
|
1834
|
+
//#region ../../platform/theme-schema/src/liquid-blocks.ts
|
|
1835
|
+
const BLOCK_TAGS = new Map([
|
|
1836
|
+
["capture", "endcapture"],
|
|
1837
|
+
["case", "endcase"],
|
|
1838
|
+
["comment", "endcomment"],
|
|
1839
|
+
["for", "endfor"],
|
|
1840
|
+
["form", "endform"],
|
|
1841
|
+
["if", "endif"],
|
|
1842
|
+
["ifchanged", "endifchanged"],
|
|
1843
|
+
["javascript", "endjavascript"],
|
|
1844
|
+
["paginate", "endpaginate"],
|
|
1845
|
+
["raw", "endraw"],
|
|
1846
|
+
["schema", "endschema"],
|
|
1847
|
+
["style", "endstyle"],
|
|
1848
|
+
["stylesheet", "endstylesheet"],
|
|
1849
|
+
["tablerow", "endtablerow"],
|
|
1850
|
+
["unless", "endunless"]
|
|
1851
|
+
]);
|
|
1852
|
+
const CLOSING_TAGS = new Set(BLOCK_TAGS.values());
|
|
1853
|
+
const OPAQUE_BLOCK_TAGS = new Set([
|
|
1854
|
+
"comment",
|
|
1855
|
+
"javascript",
|
|
1856
|
+
"raw",
|
|
1857
|
+
"schema",
|
|
1858
|
+
"style",
|
|
1859
|
+
"stylesheet"
|
|
1860
|
+
]);
|
|
1861
|
+
/**
|
|
1862
|
+
* Find structurally unbalanced Liquid block tags such as an `{% if %}` with
|
|
1863
|
+
* no `{% endif %}`. This intentionally recognizes only established paired
|
|
1864
|
+
* tags; custom and inline tags are ignored rather than guessed at.
|
|
1865
|
+
*
|
|
1866
|
+
* Content inside raw/comment/schema/style/javascript blocks is opaque to
|
|
1867
|
+
* Liquid and therefore skipped until that block's matching close tag. This
|
|
1868
|
+
* prevents CSS, JSON, and examples containing Liquid-looking text from
|
|
1869
|
+
* producing false errors.
|
|
1870
|
+
*/
|
|
1871
|
+
function findLiquidBlockTagDiagnostics(content) {
|
|
1872
|
+
const stack = [];
|
|
1873
|
+
const diagnostics = [];
|
|
1874
|
+
let line = 1;
|
|
1875
|
+
let previousTagIndex = 0;
|
|
1876
|
+
const processTag = (name, tagLine) => {
|
|
1877
|
+
const open = stack.at(-1);
|
|
1878
|
+
if (open && OPAQUE_BLOCK_TAGS.has(open.name)) {
|
|
1879
|
+
if (name === open.expectedClose) stack.pop();
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
const expectedClose = BLOCK_TAGS.get(name);
|
|
1883
|
+
if (expectedClose) {
|
|
1884
|
+
stack.push({
|
|
1885
|
+
name,
|
|
1886
|
+
expectedClose,
|
|
1887
|
+
line: tagLine
|
|
1888
|
+
});
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1891
|
+
if (!CLOSING_TAGS.has(name)) return;
|
|
1892
|
+
if (!open) {
|
|
1893
|
+
diagnostics.push({
|
|
1894
|
+
severity: "error",
|
|
1895
|
+
message: `Unexpected Liquid tag '{% ${name} %}' on line ${tagLine}; there is no open block to close.`
|
|
1896
|
+
});
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1899
|
+
if (name !== open.expectedClose) {
|
|
1900
|
+
diagnostics.push({
|
|
1901
|
+
severity: "error",
|
|
1902
|
+
message: `Mismatched Liquid tag '{% ${name} %}' on line ${tagLine}; '{% ${open.name} %}' from line ${open.line} must close with '{% ${open.expectedClose} %}'.`
|
|
1903
|
+
});
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
stack.pop();
|
|
1907
|
+
};
|
|
1908
|
+
for (const match of content.matchAll(/\{%-?\s*([a-zA-Z_][\w-]*)\b(?:(?!\{%)[\s\S])*?-?%\}/g)) {
|
|
1909
|
+
const name = match[1]?.toLowerCase();
|
|
1910
|
+
if (!name) continue;
|
|
1911
|
+
const index = match.index ?? 0;
|
|
1912
|
+
for (let cursor = previousTagIndex; cursor < index; cursor++) if (content.charCodeAt(cursor) === 10) line += 1;
|
|
1913
|
+
previousTagIndex = index;
|
|
1914
|
+
const open = stack.at(-1);
|
|
1915
|
+
if (name === "liquid" && !(open && OPAQUE_BLOCK_TAGS.has(open.name))) {
|
|
1916
|
+
const statements = match[0].replace(/^\{%-?\s*liquid\b/i, "").replace(/-?%\}$/, "").split("\n");
|
|
1917
|
+
for (const [offset, statement] of statements.entries()) {
|
|
1918
|
+
const statementName = /^\s*([a-zA-Z_][\w-]*)\b/.exec(statement)?.[1];
|
|
1919
|
+
if (!statementName) continue;
|
|
1920
|
+
processTag(statementName.toLowerCase(), line + offset);
|
|
1921
|
+
}
|
|
1922
|
+
} else processTag(name, line);
|
|
1923
|
+
}
|
|
1924
|
+
for (const open of stack.reverse()) diagnostics.push({
|
|
1925
|
+
severity: "error",
|
|
1926
|
+
message: `Unclosed Liquid tag '{% ${open.name} %}' on line ${open.line}; expected '{% ${open.expectedClose} %}'.`
|
|
1927
|
+
});
|
|
1928
|
+
return diagnostics;
|
|
1929
|
+
}
|
|
1930
|
+
//#endregion
|
|
1834
1931
|
//#region src/theme/file.ts
|
|
1835
1932
|
const NON_TEMPLATE_DIRS = new Set([
|
|
1836
1933
|
"sections",
|
|
@@ -4276,101 +4373,6 @@ function hasUnbalancedLiquidDelimiters(content) {
|
|
|
4276
4373
|
}
|
|
4277
4374
|
return unclosedTags > 0 || unclosedOutputs > 0;
|
|
4278
4375
|
}
|
|
4279
|
-
const BLOCK_TAGS = new Map([
|
|
4280
|
-
["capture", "endcapture"],
|
|
4281
|
-
["case", "endcase"],
|
|
4282
|
-
["comment", "endcomment"],
|
|
4283
|
-
["for", "endfor"],
|
|
4284
|
-
["form", "endform"],
|
|
4285
|
-
["if", "endif"],
|
|
4286
|
-
["ifchanged", "endifchanged"],
|
|
4287
|
-
["javascript", "endjavascript"],
|
|
4288
|
-
["paginate", "endpaginate"],
|
|
4289
|
-
["raw", "endraw"],
|
|
4290
|
-
["schema", "endschema"],
|
|
4291
|
-
["style", "endstyle"],
|
|
4292
|
-
["stylesheet", "endstylesheet"],
|
|
4293
|
-
["tablerow", "endtablerow"],
|
|
4294
|
-
["unless", "endunless"]
|
|
4295
|
-
]);
|
|
4296
|
-
const CLOSING_TAGS = new Set(BLOCK_TAGS.values());
|
|
4297
|
-
const OPAQUE_BLOCK_TAGS = new Set([
|
|
4298
|
-
"comment",
|
|
4299
|
-
"javascript",
|
|
4300
|
-
"raw",
|
|
4301
|
-
"schema",
|
|
4302
|
-
"style",
|
|
4303
|
-
"stylesheet"
|
|
4304
|
-
]);
|
|
4305
|
-
/**
|
|
4306
|
-
* Find structurally unbalanced Liquid block tags such as an `{% if %}` with
|
|
4307
|
-
* no `{% endif %}`. This intentionally recognizes only established paired
|
|
4308
|
-
* tags; custom and inline tags are ignored rather than guessed at.
|
|
4309
|
-
*
|
|
4310
|
-
* Content inside raw/comment/schema/style/javascript blocks is opaque to
|
|
4311
|
-
* Liquid and therefore skipped until that block's matching close tag. This
|
|
4312
|
-
* prevents CSS, JSON, and examples containing Liquid-looking text from
|
|
4313
|
-
* producing false errors.
|
|
4314
|
-
*/
|
|
4315
|
-
function findLiquidBlockTagDiagnostics(content) {
|
|
4316
|
-
const stack = [];
|
|
4317
|
-
const diagnostics = [];
|
|
4318
|
-
let line = 1;
|
|
4319
|
-
let previousTagIndex = 0;
|
|
4320
|
-
const processTag = (name, tagLine) => {
|
|
4321
|
-
const open = stack.at(-1);
|
|
4322
|
-
if (open && OPAQUE_BLOCK_TAGS.has(open.name)) {
|
|
4323
|
-
if (name === open.expectedClose) stack.pop();
|
|
4324
|
-
return;
|
|
4325
|
-
}
|
|
4326
|
-
const expectedClose = BLOCK_TAGS.get(name);
|
|
4327
|
-
if (expectedClose) {
|
|
4328
|
-
stack.push({
|
|
4329
|
-
name,
|
|
4330
|
-
expectedClose,
|
|
4331
|
-
line: tagLine
|
|
4332
|
-
});
|
|
4333
|
-
return;
|
|
4334
|
-
}
|
|
4335
|
-
if (!CLOSING_TAGS.has(name)) return;
|
|
4336
|
-
if (!open) {
|
|
4337
|
-
diagnostics.push({
|
|
4338
|
-
severity: "error",
|
|
4339
|
-
message: `Unexpected Liquid tag '{% ${name} %}' on line ${tagLine}; there is no open block to close.`
|
|
4340
|
-
});
|
|
4341
|
-
return;
|
|
4342
|
-
}
|
|
4343
|
-
if (name !== open.expectedClose) {
|
|
4344
|
-
diagnostics.push({
|
|
4345
|
-
severity: "error",
|
|
4346
|
-
message: `Mismatched Liquid tag '{% ${name} %}' on line ${tagLine}; '{% ${open.name} %}' from line ${open.line} must close with '{% ${open.expectedClose} %}'.`
|
|
4347
|
-
});
|
|
4348
|
-
return;
|
|
4349
|
-
}
|
|
4350
|
-
stack.pop();
|
|
4351
|
-
};
|
|
4352
|
-
for (const match of content.matchAll(/\{%-?\s*([a-zA-Z_][\w-]*)\b(?:(?!\{%)[\s\S])*?-?%\}/g)) {
|
|
4353
|
-
const name = match[1]?.toLowerCase();
|
|
4354
|
-
if (!name) continue;
|
|
4355
|
-
const index = match.index ?? 0;
|
|
4356
|
-
for (let cursor = previousTagIndex; cursor < index; cursor++) if (content.charCodeAt(cursor) === 10) line += 1;
|
|
4357
|
-
previousTagIndex = index;
|
|
4358
|
-
const open = stack.at(-1);
|
|
4359
|
-
if (name === "liquid" && !(open && OPAQUE_BLOCK_TAGS.has(open.name))) {
|
|
4360
|
-
const statements = match[0].replace(/^\{%-?\s*liquid\b/i, "").replace(/-?%\}$/, "").split("\n");
|
|
4361
|
-
for (const [offset, statement] of statements.entries()) {
|
|
4362
|
-
const statementName = /^\s*([a-zA-Z_][\w-]*)\b/.exec(statement)?.[1];
|
|
4363
|
-
if (!statementName) continue;
|
|
4364
|
-
processTag(statementName.toLowerCase(), line + offset);
|
|
4365
|
-
}
|
|
4366
|
-
} else processTag(name, line);
|
|
4367
|
-
}
|
|
4368
|
-
for (const open of stack.reverse()) diagnostics.push({
|
|
4369
|
-
severity: "error",
|
|
4370
|
-
message: `Unclosed Liquid tag '{% ${open.name} %}' on line ${open.line}; expected '{% ${open.expectedClose} %}'.`
|
|
4371
|
-
});
|
|
4372
|
-
return diagnostics;
|
|
4373
|
-
}
|
|
4374
4376
|
//#endregion
|
|
4375
4377
|
//#region src/theme/dev-server/port-preflight.ts
|
|
4376
4378
|
/**
|
|
@@ -13286,6 +13288,18 @@ async function compareBranch(api, themeId, slug, entries) {
|
|
|
13286
13288
|
body: { entries }
|
|
13287
13289
|
}))).comparison;
|
|
13288
13290
|
}
|
|
13291
|
+
/** Where a branch stands against its parent theme, and its latest promotion. */
|
|
13292
|
+
function previewPromotion(api, themeId, slug) {
|
|
13293
|
+
return call(api.get(`${base(themeId)}/branches/${slug}/promotion`));
|
|
13294
|
+
}
|
|
13295
|
+
/** Promote the branch onto its parent theme. */
|
|
13296
|
+
async function promoteBranch(api, themeId, slug) {
|
|
13297
|
+
return (await call(api.request(`${base(themeId)}/branches/${slug}/promotion`, { method: "POST" }))).promotion;
|
|
13298
|
+
}
|
|
13299
|
+
/** Undo a promotion, putting the parent theme back as it was before it. */
|
|
13300
|
+
async function undoPromotion(api, themeId, promotionId) {
|
|
13301
|
+
return (await call(api.request(`${base(themeId)}/branch-promotions/${promotionId}/undo`, { method: "POST" }))).promotion;
|
|
13302
|
+
}
|
|
13289
13303
|
/**
|
|
13290
13304
|
* Upload one declared content as raw bytes. The shared client always sends
|
|
13291
13305
|
* JSON, so this goes through fetch with the same base URL and token.
|
|
@@ -13533,6 +13547,23 @@ async function compareWithStaging(api, themeId, root) {
|
|
|
13533
13547
|
};
|
|
13534
13548
|
}
|
|
13535
13549
|
//#endregion
|
|
13550
|
+
//#region src/theme/staging-promote.ts
|
|
13551
|
+
const STAGING = "staging";
|
|
13552
|
+
/** What promoting staging would change, and its latest promotion. */
|
|
13553
|
+
function readStagingPromotion(api, themeId) {
|
|
13554
|
+
return previewPromotion(api, themeId, STAGING);
|
|
13555
|
+
}
|
|
13556
|
+
/** Promote staging onto the theme. */
|
|
13557
|
+
function promoteStaging(api, themeId) {
|
|
13558
|
+
return promoteBranch(api, themeId, STAGING);
|
|
13559
|
+
}
|
|
13560
|
+
/** Undo staging's latest promotion, if it is still in place. */
|
|
13561
|
+
async function undoStagingPromotion(api, themeId) {
|
|
13562
|
+
const { latest_promotion: latest } = await readStagingPromotion(api, themeId);
|
|
13563
|
+
if (!latest || latest.state !== "promoted") throw new Error("Nothing to undo: staging has no promotion in place.");
|
|
13564
|
+
return undoPromotion(api, themeId, latest.id);
|
|
13565
|
+
}
|
|
13566
|
+
//#endregion
|
|
13536
13567
|
//#region src/commands/staging.ts
|
|
13537
13568
|
/**
|
|
13538
13569
|
* The production theme staging belongs to: --theme, else the theme this
|
|
@@ -13593,6 +13624,21 @@ async function run$1(opts, action) {
|
|
|
13593
13624
|
process.exitCode = 1;
|
|
13594
13625
|
}
|
|
13595
13626
|
}
|
|
13627
|
+
/**
|
|
13628
|
+
* Whether to go ahead with a change to the live theme: --yes, or a yes at the
|
|
13629
|
+
* terminal. JSON mode never prompts, so it needs --yes.
|
|
13630
|
+
*/
|
|
13631
|
+
async function approved(opts, question) {
|
|
13632
|
+
if (opts.yes) return true;
|
|
13633
|
+
if (opts.json || !process.stdin.isTTY) throw new Error("This changes the live theme; pass --yes to go ahead without a prompt.");
|
|
13634
|
+
const { confirmed } = await prompts({
|
|
13635
|
+
type: "confirm",
|
|
13636
|
+
name: "confirmed",
|
|
13637
|
+
message: question,
|
|
13638
|
+
initial: false
|
|
13639
|
+
}, { onCancel: () => process.exit(130) });
|
|
13640
|
+
return confirmed === true;
|
|
13641
|
+
}
|
|
13596
13642
|
function report(status, json) {
|
|
13597
13643
|
if (json) {
|
|
13598
13644
|
console.log(JSON.stringify(stagingJson(status)));
|
|
@@ -13651,7 +13697,53 @@ function createStagingCommand() {
|
|
|
13651
13697
|
for (const path of compared.localOnly) console.log(chalk.green(` local only ${path}`));
|
|
13652
13698
|
for (const path of compared.branchOnly) console.log(chalk.red(` staging only ${path}`));
|
|
13653
13699
|
}));
|
|
13654
|
-
|
|
13700
|
+
const promote = withThemeOptions$1(new Command("promote").description("Copy what staging serves onto the live theme, all at once, if the live theme hasn't changed since staging was based on it")).option("-y, --yes", "Promote without asking").action((opts) => run$1(opts, async () => {
|
|
13701
|
+
requireToken();
|
|
13702
|
+
const api = createApiClient();
|
|
13703
|
+
const themeId = resolveThemeId(opts);
|
|
13704
|
+
const { preview } = await readStagingPromotion(api, themeId);
|
|
13705
|
+
if (preview.state === "in_sync") {
|
|
13706
|
+
if (opts.json) console.log(JSON.stringify({
|
|
13707
|
+
promotion: null,
|
|
13708
|
+
preview
|
|
13709
|
+
}));
|
|
13710
|
+
else console.log("The live theme already serves what staging does.");
|
|
13711
|
+
return;
|
|
13712
|
+
}
|
|
13713
|
+
if (preview.state === "parent_changed") throw new Error("The live theme changed since staging was based on it, so promoting would overwrite that change. Push your files with `fluid theme push` instead.");
|
|
13714
|
+
if (!opts.json) {
|
|
13715
|
+
console.log("Promoting staging changes the live theme:");
|
|
13716
|
+
for (const path of preview.writes) console.log(chalk.yellow(` write ${path}`));
|
|
13717
|
+
for (const path of preview.removals) console.log(chalk.red(` remove ${path}`));
|
|
13718
|
+
}
|
|
13719
|
+
if (!await approved(opts, "Promote staging to the live theme?")) {
|
|
13720
|
+
console.log("Not promoted.");
|
|
13721
|
+
return;
|
|
13722
|
+
}
|
|
13723
|
+
const promotion = await promoteStaging(api, themeId);
|
|
13724
|
+
if (opts.json) {
|
|
13725
|
+
console.log(JSON.stringify({
|
|
13726
|
+
promotion,
|
|
13727
|
+
preview
|
|
13728
|
+
}));
|
|
13729
|
+
return;
|
|
13730
|
+
}
|
|
13731
|
+
console.log(`Promoted: ${preview.writes.length} files written and ${preview.removals.length} removed on the live theme. Undo with \`fluid theme staging undo-promote\`.`);
|
|
13732
|
+
}));
|
|
13733
|
+
const undoPromote = withThemeOptions$1(new Command("undo-promote").description("Put the live theme back as it was before staging's latest promotion")).option("-y, --yes", "Undo without asking").action((opts) => run$1(opts, async () => {
|
|
13734
|
+
requireToken();
|
|
13735
|
+
if (!await approved(opts, "Put the live theme back as it was before the latest promotion?")) {
|
|
13736
|
+
console.log("Not undone.");
|
|
13737
|
+
return;
|
|
13738
|
+
}
|
|
13739
|
+
const promotion = await undoStagingPromotion(createApiClient(), resolveThemeId(opts));
|
|
13740
|
+
if (opts.json) {
|
|
13741
|
+
console.log(JSON.stringify({ promotion }));
|
|
13742
|
+
return;
|
|
13743
|
+
}
|
|
13744
|
+
console.log(`Undid the promotion of ${promotion.promoted_at}${promotion.promoted_by.name ? ` by ${promotion.promoted_by.name}` : ""}.`);
|
|
13745
|
+
}));
|
|
13746
|
+
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).addCommand(promote).addCommand(undoPromote).addCommand(compare);
|
|
13655
13747
|
}
|
|
13656
13748
|
//#endregion
|
|
13657
13749
|
//#region src/commands/widget.ts
|