bearminion 1.17.0 → 1.19.0
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/CHANGELOG.md +20 -0
- package/dist/astro.d.ts +3 -3
- package/dist/cli.js +366 -0
- package/dist/content.d.ts +1 -1
- package/dist/{editor-context-CuD7HgT7.d.ts → editor-context-DzRwKENi.d.ts} +1 -1
- package/dist/{github-store-C4oCDBnl.d.ts → github-store-DsLCe5MR.d.ts} +1 -1
- package/dist/hosted-overlay.js +1 -1
- package/dist/hosted.d.ts +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +19 -3
- package/dist/{page-DNbZW-J7.d.ts → page-BGSTL63-.d.ts} +14 -7
- package/dist/ui/mount.js +5 -3
- package/package.json +1 -1
- package/registry/default/files/src/components/seo/Seo.astro +73 -0
- package/registry/default/files/src/env.d.ts +13 -0
- package/registry/default/files/src/pages/404.astro +18 -0
- package/registry/default/files/src/pages/[...slug].astro +40 -0
- package/registry/default/registry.json +111 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# bearminion
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3713ac3: The starter footer shows a "Powered by BearMinion" link to bearminion.com, and the Footer tab can switch it off.
|
|
8
|
+
|
|
9
|
+
- New `poweredBy` option in `defineSite({ footer })` (default false). When a theme enables it, the Footer tab gets a **Powered by BearMinion** switch and `site.json` accepts `footer.poweredBy`. The link is shown unless the value is `false`.
|
|
10
|
+
- The starter adds `atoms/PoweredBy.astro` and renders it in the bottom row of every footer variant. Existing sites are not changed: copy `Footer.astro` and `PoweredBy.astro` (`npx bearminion status` lists them as outdated) and add `poweredBy: true` to `site-definition.ts` to get it.
|
|
11
|
+
|
|
12
|
+
## 1.18.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- aa89b17: `npx bearminion add hosted` sets a site up for the hosted editor.
|
|
17
|
+
|
|
18
|
+
- Writes the starter files the editor depends on (`src/lib/editing.ts`, `image-url.ts`, `env.d.ts`, the image components, `Seo.astro`, the page routes, and the Media and Logo strip sections when the site has them), `src/editor.ts`, and `astro.editor.config.ts`, the build of the editor deployment. It adds a `build:editor` script to `package.json` without reformatting it, notes everything in `bearminion.lock.json`, and prints the GitHub App and Vercel checklist. `--dry-run`, `--yes`, `--overwrite`, `--install`, `--diff` and `--json` work as for sections.
|
|
19
|
+
- Never edits `astro.config.ts`. The editor build merges the site's config with the adapter and `bearminionHostedEditor`, so the public build cannot load editor code. Vercel only for now.
|
|
20
|
+
- `status` and `add` now recognise the files of every release back to 1.0, not only 1.9 and later. A site made before 1.9 and without a lock file used to see its untouched files reported as `differs`; they are now `outdated` and `add` replaces them. `Seo.astro`, `env.d.ts` and the page routes are tracked as well, so `add hosted` can tell an old copy from one you changed.
|
|
21
|
+
- Sites that already run the hosted editor with an environment-variable gate in `astro.config.ts` keep working and are left as they are.
|
|
22
|
+
|
|
3
23
|
## 1.17.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as CollectionOptions, b as StoreOperation, n as ImageConvertOptions, t as EditorContext, x as UploadStore, y as ContentStore } from "./editor-context-
|
|
2
|
-
import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-
|
|
3
|
-
import { _ as SectionRegistry, d as SectionOf, g as ContentModel, gt as SiteOf, ht as SiteDefinition, n as PageRules, t as Page, w as ContentMigrator } from "./page-
|
|
1
|
+
import { _ as CollectionOptions, b as StoreOperation, n as ImageConvertOptions, t as EditorContext, x as UploadStore, y as ContentStore } from "./editor-context-DzRwKENi.js";
|
|
2
|
+
import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-DsLCe5MR.js";
|
|
3
|
+
import { _ as SectionRegistry, d as SectionOf, g as ContentModel, gt as SiteOf, ht as SiteDefinition, n as PageRules, t as Page, w as ContentMigrator } from "./page-BGSTL63-.js";
|
|
4
4
|
import { AstroIntegration } from "astro";
|
|
5
5
|
//#region src/store.d.ts
|
|
6
6
|
interface FileStoreOptions {
|
package/dist/cli.js
CHANGED
|
@@ -565,6 +565,231 @@ function checkForm(root, requestedHost) {
|
|
|
565
565
|
};
|
|
566
566
|
}
|
|
567
567
|
//#endregion
|
|
568
|
+
//#region src/add/hosted.ts
|
|
569
|
+
const EDITOR_PATH = "src/editor.ts";
|
|
570
|
+
const BUILD_SCRIPT = "build:editor";
|
|
571
|
+
const SECTIONS_PREFIX = "src/components/sections/";
|
|
572
|
+
const BASE_CONFIGS = [
|
|
573
|
+
"astro.config.ts",
|
|
574
|
+
"astro.config.mts",
|
|
575
|
+
"astro.config.mjs",
|
|
576
|
+
"astro.config.js"
|
|
577
|
+
];
|
|
578
|
+
const HOSTS = [{
|
|
579
|
+
name: "vercel",
|
|
580
|
+
description: "Vercel: a second project on the same repository",
|
|
581
|
+
adapterPackage: "@astrojs/vercel",
|
|
582
|
+
adapterImport: "vercel",
|
|
583
|
+
adapterCall: "vercel()"
|
|
584
|
+
}];
|
|
585
|
+
const EDITOR_SOURCE = `import { createHostedEditor } from 'bearminion/hosted'
|
|
586
|
+
import { overlaySource } from 'bearminion/hosted-overlay'
|
|
587
|
+
import { contentModel } from './lib/content-model'
|
|
588
|
+
|
|
589
|
+
const secret = (name: string): string => {
|
|
590
|
+
const value = process.env[name]
|
|
591
|
+
if (!value) throw new Error(\`Missing \${name}.\`)
|
|
592
|
+
return value
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// A function, so a host that hands over its secrets per request works the same way.
|
|
596
|
+
export default () =>
|
|
597
|
+
createHostedEditor({
|
|
598
|
+
...contentModel,
|
|
599
|
+
repo: secret('BEARMINION_REPO'), // 'owner/name'
|
|
600
|
+
auth: {
|
|
601
|
+
clientId: secret('GITHUB_CLIENT_ID'),
|
|
602
|
+
clientSecret: secret('GITHUB_CLIENT_SECRET'),
|
|
603
|
+
secret: secret('SESSION_SECRET'), // 32+ characters: openssl rand -base64 32
|
|
604
|
+
// Only these GitHub logins may sign in, and they still need push access. Leave it out to allow everyone with push access.
|
|
605
|
+
// allowedLogins: ['your-github-login'],
|
|
606
|
+
},
|
|
607
|
+
overlay: overlaySource,
|
|
608
|
+
})
|
|
609
|
+
`;
|
|
610
|
+
/** The site's Astro config and the name the editor build's config gets beside it. Undefined when the site has none. */
|
|
611
|
+
function findBaseConfig(root) {
|
|
612
|
+
for (const file of BASE_CONFIGS) {
|
|
613
|
+
const target = path.join(root, file);
|
|
614
|
+
if (!fs.existsSync(target)) continue;
|
|
615
|
+
const typed = file.endsWith("ts");
|
|
616
|
+
const extension = file.endsWith(".mts") ? "mts" : typed ? "ts" : "mjs";
|
|
617
|
+
return {
|
|
618
|
+
file,
|
|
619
|
+
importPath: typed ? `./${file.replace(/\.m?ts$/, "")}` : `./${file}`,
|
|
620
|
+
editorConfig: `astro.editor.config.${extension}`,
|
|
621
|
+
addsEditor: fs.readFileSync(target, "utf8").includes("bearminionHostedEditor")
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function configSource(host, base) {
|
|
626
|
+
return `import ${host.adapterImport} from '${host.adapterPackage}'
|
|
627
|
+
import { mergeConfig } from 'astro/config'
|
|
628
|
+
import { bearminionHostedEditor } from 'bearminion/astro'
|
|
629
|
+
import site from '${base.importPath}'
|
|
630
|
+
|
|
631
|
+
// The build of the editor deployment: the site's own config plus a server adapter and the hosted editor.
|
|
632
|
+
// \`${BUILD_SCRIPT}\` in package.json runs it. The public site keeps building from ${base.file} and never loads any of this.
|
|
633
|
+
export default mergeConfig(site, {
|
|
634
|
+
adapter: ${host.adapterCall},
|
|
635
|
+
integrations: [bearminionHostedEditor({ module: './${EDITOR_PATH}' })],
|
|
636
|
+
})
|
|
637
|
+
`;
|
|
638
|
+
}
|
|
639
|
+
const buildCommand = (base) => `astro build --config ${base.editorConfig}`;
|
|
640
|
+
/** Adds one script to the text of a `package.json` without reformatting the rest. Undefined when it cannot be done safely. */
|
|
641
|
+
function addScript(text, name, command) {
|
|
642
|
+
const match = /"scripts"\s*:\s*\{/.exec(text);
|
|
643
|
+
if (!match) return void 0;
|
|
644
|
+
const after = match.index + match[0].length;
|
|
645
|
+
const rest = text.slice(after);
|
|
646
|
+
const first = /^(\s*)(\S)/.exec(rest);
|
|
647
|
+
if (!first) return void 0;
|
|
648
|
+
const entry = `${JSON.stringify(name)}: ${JSON.stringify(command)}`;
|
|
649
|
+
let result;
|
|
650
|
+
if (first[2] === "}") {
|
|
651
|
+
const lineStart = text.lastIndexOf("\n", match.index) + 1;
|
|
652
|
+
const indent = /^\s*/.exec(text.slice(lineStart))?.[0] ?? "";
|
|
653
|
+
result = `${text.slice(0, after)}\n${indent} ${entry}\n${indent}${rest.slice(rest.indexOf("}"))}`;
|
|
654
|
+
} else result = `${text.slice(0, after)}${first[1]}${entry},${rest}`;
|
|
655
|
+
try {
|
|
656
|
+
return JSON.parse(result).scripts?.[name] === command ? result : void 0;
|
|
657
|
+
} catch {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
/** The section a file of the site belongs to, when it is a section's own file. */
|
|
662
|
+
const sectionOf = (file) => file.startsWith(SECTIONS_PREFIX) ? file.slice(24).split("/")[0] : void 0;
|
|
663
|
+
function planHosted(root, registry, host, lock, overwrite) {
|
|
664
|
+
const group = registry.groups?.hosted;
|
|
665
|
+
if (group === void 0) throw new Error("This copy of bearminion has no hosted files. Reinstall the package.");
|
|
666
|
+
const base = findBaseConfig(root);
|
|
667
|
+
if (base === void 0) throw new Error("No Astro config found (astro.config.ts, .mts, .mjs or .js). Run this in the site's folder, or pass --cwd.");
|
|
668
|
+
const notes = [];
|
|
669
|
+
const files = [];
|
|
670
|
+
for (const file of group.files) {
|
|
671
|
+
const section = sectionOf(file);
|
|
672
|
+
if (section !== void 0 && !fs.existsSync(path.join(root, SECTIONS_PREFIX, section, "definition.ts"))) continue;
|
|
673
|
+
const entry = registry.files[file];
|
|
674
|
+
if (entry === void 0) throw new Error(`The registry lists ${file} for the hosted editor but holds no copy of it.`);
|
|
675
|
+
const target = path.join(root, file);
|
|
676
|
+
let action;
|
|
677
|
+
if (!fs.existsSync(target)) action = "create";
|
|
678
|
+
else {
|
|
679
|
+
const hash = hashContent(file, fs.readFileSync(target));
|
|
680
|
+
if (hash === entry.hash) action = "same";
|
|
681
|
+
else if (entry.history.includes(hash) || lock.files[file]?.hash === hash) action = "update";
|
|
682
|
+
else action = overwrite ? "overwrite" : "conflict";
|
|
683
|
+
}
|
|
684
|
+
files.push({
|
|
685
|
+
path: file,
|
|
686
|
+
action
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
const recipe = (file, source) => {
|
|
690
|
+
const target = path.join(root, file);
|
|
691
|
+
let action = "create";
|
|
692
|
+
if (fs.existsSync(target)) action = hashContent(file, fs.readFileSync(target)) === hashContent(file, source) ? "same" : overwrite ? "overwrite" : "keep";
|
|
693
|
+
files.push({
|
|
694
|
+
path: file,
|
|
695
|
+
action,
|
|
696
|
+
source
|
|
697
|
+
});
|
|
698
|
+
if (action === "keep") notes.push(`${file} already exists and differs from the recipe, so it was left alone.`);
|
|
699
|
+
};
|
|
700
|
+
recipe(EDITOR_PATH, EDITOR_SOURCE);
|
|
701
|
+
let script = "skipped";
|
|
702
|
+
const scriptCommand = buildCommand(base);
|
|
703
|
+
if (base.addsEditor) notes.push(`${base.file} already adds the hosted editor itself, so no ${base.editorConfig} was written and no ${BUILD_SCRIPT} script was added. Use one way or the other: with an environment-variable gate in ${base.file}, build the editor deployment with that variable set.`);
|
|
704
|
+
else {
|
|
705
|
+
recipe(base.editorConfig, configSource(host, base));
|
|
706
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
707
|
+
const current = manifest.scripts?.[BUILD_SCRIPT];
|
|
708
|
+
if (current === scriptCommand) script = "same";
|
|
709
|
+
else if (current !== void 0) {
|
|
710
|
+
script = "different";
|
|
711
|
+
notes.push(`package.json already has a "${BUILD_SCRIPT}" script that differs from \`${scriptCommand}\`, so it was left alone.`);
|
|
712
|
+
} else if (manifest.scripts === void 0) {
|
|
713
|
+
script = "unavailable";
|
|
714
|
+
notes.push(`package.json has no "scripts" object. Build the editor deployment with: ${scriptCommand}`);
|
|
715
|
+
} else script = "add";
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
files,
|
|
719
|
+
script,
|
|
720
|
+
scriptCommand,
|
|
721
|
+
npm: missingPackages(root, { [host.adapterPackage]: "latest" }),
|
|
722
|
+
dirty: [],
|
|
723
|
+
notes,
|
|
724
|
+
base,
|
|
725
|
+
packageManager: detectPackageManager(root)
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const writesHosted = (action) => action === "create" || action === "update" || action === "overwrite";
|
|
729
|
+
/** Writes what the plan says and notes the files in the lock. Returns the paths written. A plan with conflicts is never applied. */
|
|
730
|
+
function applyHosted(root, registryDir, registry, plan, lock) {
|
|
731
|
+
if (plan.files.some((file) => file.action === "conflict")) throw new Error("The plan has conflicts. Nothing was written.");
|
|
732
|
+
const written = [];
|
|
733
|
+
const recipes = {};
|
|
734
|
+
for (const file of plan.files) {
|
|
735
|
+
if (writesHosted(file.action)) {
|
|
736
|
+
const target = path.join(root, file.path);
|
|
737
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
738
|
+
if (file.source === void 0) fs.copyFileSync(path.join(registryDir, "files", file.path), target);
|
|
739
|
+
else fs.writeFileSync(target, file.source);
|
|
740
|
+
written.push(file.path);
|
|
741
|
+
}
|
|
742
|
+
if (file.source !== void 0 && (writesHosted(file.action) || file.action === "same")) recipes[file.path] = {
|
|
743
|
+
version: registry.version,
|
|
744
|
+
hash: hashContent(file.path, file.source)
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
if (plan.script === "add") {
|
|
748
|
+
const manifest = path.join(root, "package.json");
|
|
749
|
+
const patched = addScript(fs.readFileSync(manifest, "utf8"), BUILD_SCRIPT, plan.scriptCommand);
|
|
750
|
+
if (patched === void 0) {
|
|
751
|
+
plan.script = "unavailable";
|
|
752
|
+
plan.notes.push(`Could not add the script to package.json safely. Add it by hand: "${BUILD_SCRIPT}": "${plan.scriptCommand}"`);
|
|
753
|
+
} else {
|
|
754
|
+
fs.writeFileSync(manifest, patched);
|
|
755
|
+
written.push("package.json");
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
const registryFiles = plan.files.filter((file) => file.source === void 0).map((file) => file.path);
|
|
759
|
+
const recorded = recordFiles(lock, registry, registryFiles);
|
|
760
|
+
const files = Object.fromEntries(Object.entries({
|
|
761
|
+
...recorded.files,
|
|
762
|
+
...recipes
|
|
763
|
+
}).sort(([a], [b]) => a < b ? -1 : 1));
|
|
764
|
+
return {
|
|
765
|
+
written,
|
|
766
|
+
lock: {
|
|
767
|
+
...recorded,
|
|
768
|
+
files
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
/** What is left to do outside the repository. */
|
|
773
|
+
function checklist(manager, base) {
|
|
774
|
+
return [
|
|
775
|
+
"Next, outside this repository:",
|
|
776
|
+
"",
|
|
777
|
+
"1. A GitHub App (Settings > Developer settings > GitHub Apps > New GitHub App)",
|
|
778
|
+
" - Redirect URI: https://<address of the editor deployment>/__bearminion/auth/callback (add it once you have the address)",
|
|
779
|
+
" - Repository permissions: Contents and Pull requests read and write, Metadata read",
|
|
780
|
+
" - Expire user authorization tokens: on",
|
|
781
|
+
" - Install it on this repository only",
|
|
782
|
+
" - Visibility: a private App lets only its owner sign in. If anyone else edits, make it public and set allowedLogins in src/editor.ts.",
|
|
783
|
+
"",
|
|
784
|
+
"2. A second Vercel project from this same repository (the first stays the public site)",
|
|
785
|
+
` - Build Command: ${manager} run ${BUILD_SCRIPT}`,
|
|
786
|
+
" - Deployment Protection: off for this project (the editor has its own sign-in)",
|
|
787
|
+
" - Environment variables: BEARMINION_REPO (owner/name), GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, SESSION_SECRET (openssl rand -base64 32)",
|
|
788
|
+
"",
|
|
789
|
+
`3. Open the new project's address and sign in. The public site's build, from ${base.file}, is unchanged.`
|
|
790
|
+
];
|
|
791
|
+
}
|
|
792
|
+
//#endregion
|
|
568
793
|
//#region src/add/status.ts
|
|
569
794
|
/** Decides the state of one file from its hash in the site, in the release, and in the lock. */
|
|
570
795
|
function classify(siteHash, release, lockHash) {
|
|
@@ -628,12 +853,14 @@ Usage
|
|
|
628
853
|
npx bearminion add <section...> [options]
|
|
629
854
|
npx bearminion add --list
|
|
630
855
|
npx bearminion add form [<service>] [--host <host>]
|
|
856
|
+
npx bearminion add hosted [--host vercel]
|
|
631
857
|
npx bearminion status [--json]
|
|
632
858
|
npx bearminion check form [--host <host>] [--json]
|
|
633
859
|
npx bearminion sync [options]
|
|
634
860
|
|
|
635
861
|
Commands
|
|
636
862
|
add Copy sections into this site, with the files they need
|
|
863
|
+
add hosted Set the site up for the hosted editor: the starter files it needs, the editor module, and a build for the editor deployment
|
|
637
864
|
status Show which sections are in this site and whether their files match this release
|
|
638
865
|
check form Look for what keeps the Contact form from working: missing files, wrong names, unset variables
|
|
639
866
|
sync Rewrite sections/definitions.gen.ts and components.gen.ts from the section directories
|
|
@@ -651,6 +878,10 @@ Options for add form
|
|
|
651
878
|
--host <host> Where the site runs (found from the project when omitted). See --list
|
|
652
879
|
--list List the services and hosts
|
|
653
880
|
|
|
881
|
+
Options for add hosted
|
|
882
|
+
--host <host> Where the editor deployment runs. Only vercel so far (the default)
|
|
883
|
+
--dry-run, -y, --overwrite, --install, --json, --diff work as for sections
|
|
884
|
+
|
|
654
885
|
Options for check form
|
|
655
886
|
--host <host> Where the site runs (found from the project when omitted)
|
|
656
887
|
--json Print one JSON document instead of text
|
|
@@ -802,6 +1033,7 @@ function diffAgainstRelease(root, registryDir, file) {
|
|
|
802
1033
|
}
|
|
803
1034
|
async function runAdd(root, names, values, io) {
|
|
804
1035
|
if (names[0] === "form") return runAddForm(root, names.slice(1), values, io);
|
|
1036
|
+
if (names[0] === "hosted") return runAddHosted(root, names.slice(1), values, io);
|
|
805
1037
|
const { log } = io;
|
|
806
1038
|
const json = values.json === true;
|
|
807
1039
|
const fail = (message, code = 1, extra = {}) => {
|
|
@@ -939,6 +1171,140 @@ async function runAdd(root, names, values, io) {
|
|
|
939
1171
|
}
|
|
940
1172
|
return installed === "failed" ? 1 : 0;
|
|
941
1173
|
}
|
|
1174
|
+
async function runAddHosted(root, names, values, io) {
|
|
1175
|
+
const { log } = io;
|
|
1176
|
+
const json = values.json === true;
|
|
1177
|
+
const fail = (message, code = 1, extra = {}) => {
|
|
1178
|
+
log(json ? JSON.stringify({
|
|
1179
|
+
ok: false,
|
|
1180
|
+
error: message,
|
|
1181
|
+
...extra
|
|
1182
|
+
}, null, 2) : message);
|
|
1183
|
+
return code;
|
|
1184
|
+
};
|
|
1185
|
+
if (names.length > 0) return fail("`add hosted` takes no names. For example: npx bearminion add hosted --host vercel", 2);
|
|
1186
|
+
const hostName = values.host ?? "vercel";
|
|
1187
|
+
if (hostName === "cloudflare") return fail("This command does not set up Cloudflare yet. The recipe for it is in the integration guide: https://docs.bearminion.com/integration/#the-editor-deployment-on-astro");
|
|
1188
|
+
const host = HOSTS.find((candidate) => candidate.name === hostName);
|
|
1189
|
+
if (host === void 0) return fail(`There is no host called "${hostName}". The hosts are: ${HOSTS.map((candidate) => candidate.name).join(", ")}.`);
|
|
1190
|
+
let loaded;
|
|
1191
|
+
try {
|
|
1192
|
+
loaded = loadRegistry(io.registryDir);
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
1195
|
+
}
|
|
1196
|
+
const { registry, dir: registryDir } = loaded;
|
|
1197
|
+
let plan;
|
|
1198
|
+
let lock;
|
|
1199
|
+
try {
|
|
1200
|
+
lock = readLock(root, registry.template);
|
|
1201
|
+
plan = planHosted(root, registry, host, lock, values.overwrite === true);
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
1204
|
+
}
|
|
1205
|
+
plan.dirty = dirtyFiles(root, plan.files.filter((file) => file.action === "update" || file.action === "overwrite").map((file) => file.path));
|
|
1206
|
+
const conflicts = plan.files.filter((file) => file.action === "conflict");
|
|
1207
|
+
const changes = plan.files.filter((file) => file.action !== "same");
|
|
1208
|
+
const installPlan = Object.keys(plan.npm).length > 0 ? installCommand(plan.packageManager, plan.npm) : void 0;
|
|
1209
|
+
const writes = plan.files.filter((file) => writesHosted(file.action)).length + (plan.script === "add" ? 1 : 0);
|
|
1210
|
+
const report = (extra) => JSON.stringify({
|
|
1211
|
+
ok: conflicts.length === 0,
|
|
1212
|
+
version: registry.version,
|
|
1213
|
+
host: host.name,
|
|
1214
|
+
files: plan.files.map(({ path: file, action }) => ({
|
|
1215
|
+
path: file,
|
|
1216
|
+
action
|
|
1217
|
+
})),
|
|
1218
|
+
script: plan.script,
|
|
1219
|
+
npm: plan.npm,
|
|
1220
|
+
notes: plan.notes,
|
|
1221
|
+
dirty: plan.dirty,
|
|
1222
|
+
...extra
|
|
1223
|
+
}, null, 2);
|
|
1224
|
+
const label = (action) => LABELS[action] ?? action;
|
|
1225
|
+
if (!json) {
|
|
1226
|
+
log(`${values["dry-run"] ? "Would set up" : "Setting up"} the hosted editor for ${host.name} (bearminion ${registry.version})`);
|
|
1227
|
+
log("");
|
|
1228
|
+
for (const file of changes) {
|
|
1229
|
+
const note = file.action === "keep" ? "yours, left alone" : NOTES[file.action];
|
|
1230
|
+
log(` ${label(file.action).padEnd(9)} ${file.path}${note ? ` (${note})` : ""}`);
|
|
1231
|
+
}
|
|
1232
|
+
if (plan.script === "add") log(` ${"add".padEnd(9)} package.json (script "${BUILD_SCRIPT}": ${plan.scriptCommand})`);
|
|
1233
|
+
const same = plan.files.length - changes.length;
|
|
1234
|
+
if (same > 0) log(` ${same} file${same === 1 ? "" : "s"} already match.`);
|
|
1235
|
+
log("");
|
|
1236
|
+
}
|
|
1237
|
+
if (conflicts.length > 0) {
|
|
1238
|
+
if (values.diff && !json) for (const file of conflicts) {
|
|
1239
|
+
log(diffAgainstRelease(root, registryDir, file.path));
|
|
1240
|
+
log("");
|
|
1241
|
+
}
|
|
1242
|
+
if (json) log(report({
|
|
1243
|
+
error: "Some files differ from this release and were changed by you.",
|
|
1244
|
+
written: []
|
|
1245
|
+
}));
|
|
1246
|
+
else {
|
|
1247
|
+
log(`${conflicts.length} file${conflicts.length === 1 ? "" : "s"} differ${conflicts.length === 1 ? "s" : ""} from this release because you changed ${conflicts.length === 1 ? "it" : "them"}. Nothing was written.`);
|
|
1248
|
+
log("Use --diff to see how, then merge the lines the editor needs by hand, or use --overwrite to replace them. Commit first: git keeps your version.");
|
|
1249
|
+
}
|
|
1250
|
+
return 1;
|
|
1251
|
+
}
|
|
1252
|
+
if (writes === 0) {
|
|
1253
|
+
if (json) log(report({ written: [] }));
|
|
1254
|
+
else {
|
|
1255
|
+
for (const note of plan.notes) log(note);
|
|
1256
|
+
log("Nothing to write: every file is already in place.");
|
|
1257
|
+
}
|
|
1258
|
+
return 0;
|
|
1259
|
+
}
|
|
1260
|
+
if (!json && plan.files.some((file) => file.action === "update")) log("Files that you did not change are replaced by this release. Other parts of the site use them: read the diff and run your build.");
|
|
1261
|
+
if (!json && plan.dirty.length > 0) log(`Uncommitted changes in ${plan.dirty.join(", ")} will be overwritten.`);
|
|
1262
|
+
if (values["dry-run"]) {
|
|
1263
|
+
if (json) log(report({
|
|
1264
|
+
dryRun: true,
|
|
1265
|
+
written: []
|
|
1266
|
+
}));
|
|
1267
|
+
else {
|
|
1268
|
+
for (const note of plan.notes) log(note);
|
|
1269
|
+
log("Dry run: nothing was written.");
|
|
1270
|
+
}
|
|
1271
|
+
return 0;
|
|
1272
|
+
}
|
|
1273
|
+
if (!values.yes) {
|
|
1274
|
+
if (json || io.confirm === void 0) return fail("Not asking in here: pass --yes to write, or --dry-run to look first.", 1, { files: plan.files.map(({ path: file, action }) => ({
|
|
1275
|
+
path: file,
|
|
1276
|
+
action
|
|
1277
|
+
})) });
|
|
1278
|
+
if (!await io.confirm(`Write ${writes} file${writes === 1 ? "" : "s"}?`)) {
|
|
1279
|
+
log("Nothing was written.");
|
|
1280
|
+
return 1;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
let written;
|
|
1284
|
+
try {
|
|
1285
|
+
const applied = applyHosted(root, registryDir, registry, plan, lock);
|
|
1286
|
+
writeLock(root, applied.lock);
|
|
1287
|
+
written = applied.written;
|
|
1288
|
+
} catch (error) {
|
|
1289
|
+
return fail(error instanceof Error ? error.message : String(error));
|
|
1290
|
+
}
|
|
1291
|
+
let installed;
|
|
1292
|
+
if (installPlan && values.install) installed = io.exec(installPlan.command, installPlan.args, root) === 0 ? "done" : "failed";
|
|
1293
|
+
if (json) {
|
|
1294
|
+
log(report({
|
|
1295
|
+
written,
|
|
1296
|
+
installed: installed ?? null
|
|
1297
|
+
}));
|
|
1298
|
+
return installed === "failed" ? 1 : 0;
|
|
1299
|
+
}
|
|
1300
|
+
log(`Wrote ${written.length} file${written.length === 1 ? "" : "s"} and noted them in bearminion.lock.json.`);
|
|
1301
|
+
for (const note of plan.notes) log(note);
|
|
1302
|
+
if (installPlan && installed === void 0) log(`The editor build needs ${host.adapterPackage}. Install it: ${formatCommand(installPlan)}`);
|
|
1303
|
+
if (installed === "failed") log(`Installing failed. Run it yourself: ${formatCommand(installPlan)}`);
|
|
1304
|
+
log("");
|
|
1305
|
+
for (const line of checklist(plan.packageManager, plan.base)) log(line);
|
|
1306
|
+
return installed === "failed" ? 1 : 0;
|
|
1307
|
+
}
|
|
942
1308
|
const LEVEL_TEXT = {
|
|
943
1309
|
ok: "ok",
|
|
944
1310
|
problem: "problem",
|
package/dist/content.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as SectionRegistry, ht as SiteDefinition, n as PageRules, w as ContentMigrator, y as ThemeDefinition } from "./page-
|
|
1
|
+
import { _ as SectionRegistry, ht as SiteDefinition, n as PageRules, w as ContentMigrator, y as ThemeDefinition } from "./page-BGSTL63-.js";
|
|
2
2
|
import { ZodType, z } from "zod";
|
|
3
3
|
//#region src/upload-names.d.ts
|
|
4
4
|
type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { y as ContentStore } from "./editor-context-
|
|
1
|
+
import { y as ContentStore } from "./editor-context-DzRwKENi.js";
|
|
2
2
|
//#region src/store-error.d.ts
|
|
3
3
|
/** A key that is empty, has an empty or dot segment, or leaves its base directory. */
|
|
4
4
|
declare class StoreKeyError extends Error {
|