@anyday/sanity-workspace-manager 0.4.0 → 0.5.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/README.md +20 -3
- package/dist/cli.mjs +20 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,22 @@ suggestion you can accept with Enter:
|
|
|
57
57
|
The id is permanent: jobs store it and it prefixes each site's Vercel project. Registering a
|
|
58
58
|
different id later creates a second project type instead of updating this one.
|
|
59
59
|
|
|
60
|
+
### Which command to run
|
|
61
|
+
|
|
62
|
+
| Command | Questions | Starter pages | Use it when |
|
|
63
|
+
| ---------------------------------- | ------------------------ | ---------------------------------------------- | --------------------------------------------- |
|
|
64
|
+
| `init --live` | Yes, then a list to pick | The pages you pick (none: one empty home page) | Usually: real theme, colours and pages |
|
|
65
|
+
| `init --live --starter home,about` | Yes, no list | Those pages | You already know which pages |
|
|
66
|
+
| `init --live --yes` | None, suggestions taken | One empty home page | Scripts, or no starter content wanted |
|
|
67
|
+
| `init` | Yes | One empty home page | The project has no content yet, or no sign-in |
|
|
68
|
+
|
|
69
|
+
Without `--live`, `init` reads only the repo's files, so the manifest has the structure but no
|
|
70
|
+
values: colour defaults are `#000000`, theme defaults and `studioOrigins` are empty. Fill them in
|
|
71
|
+
by hand, or run again with `--live --force` once the project has content.
|
|
72
|
+
|
|
73
|
+
Starter pages are only what **Start fresh** writes. **Copy from a workspace** is picked in the
|
|
74
|
+
Workspaces app for each new workspace, and reads its source live; it needs no `init` option.
|
|
75
|
+
|
|
60
76
|
### What it reads
|
|
61
77
|
|
|
62
78
|
| Source | Used for |
|
|
@@ -73,7 +89,7 @@ and each folder in `apps`.
|
|
|
73
89
|
|
|
74
90
|
| Option | Does |
|
|
75
91
|
| -------------------- | ----------------------------------------------------------------------------------------------- |
|
|
76
|
-
| `--yes` |
|
|
92
|
+
| `--yes` | Asks nothing: takes every suggestion and skips the starter list |
|
|
77
93
|
| `--project <id>` | The Sanity project new workspaces copy their schema from |
|
|
78
94
|
| `--org <id>` | The Sanity organisation new workspaces are created in (found with `--live`) |
|
|
79
95
|
| `--vercel-team <id>` | The client's own Vercel team for the sites; leave out for Anyday's team |
|
|
@@ -81,7 +97,7 @@ and each folder in `apps`.
|
|
|
81
97
|
| `--live` | Reads the current theme, settings and starter pages from that project |
|
|
82
98
|
| `--dataset <name>` | The dataset `--live` reads (default `production`) |
|
|
83
99
|
| `--starter <pages>` | Starter pages without the list: `home`, slugs or document ids, comma-separated (needs `--live`) |
|
|
84
|
-
| `--force` | Replaces an existing `workspace-manager.json
|
|
100
|
+
| `--force` | Replaces an existing `workspace-manager.json`, keeping its file-backed theme defaults (fonts) |
|
|
85
101
|
| `--print` | Prints the draft instead of writing it |
|
|
86
102
|
|
|
87
103
|
### Starter pages
|
|
@@ -104,7 +120,8 @@ slug, the home page's language wins. With `--yes` and no `--starter`, the starte
|
|
|
104
120
|
home page.
|
|
105
121
|
|
|
106
122
|
Starter pages get `{{siteName}}` and `{{language}}` where the source site's name and language
|
|
107
|
-
were.
|
|
123
|
+
were. Fonts are left out of theme defaults, since uploaded fonts are often licensed per brand: add
|
|
124
|
+
them by hand when they may be reused, and a later `--force` keeps them.
|
|
108
125
|
|
|
109
126
|
### Review before registering
|
|
110
127
|
|
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { existsSync as existsSync3, writeFileSync } from "node:fs";
|
|
4
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4, writeFileSync } from "node:fs";
|
|
5
5
|
import { resolve } from "node:path";
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
@@ -772,6 +772,17 @@ function placeholders(value, siteName, language, key, parent) {
|
|
|
772
772
|
}
|
|
773
773
|
return value;
|
|
774
774
|
}
|
|
775
|
+
function keepFileDefaults(draft, existing) {
|
|
776
|
+
const defaults = draft.manifest.brand.theme.defaults;
|
|
777
|
+
const previous = existing?.brand?.theme?.defaults ?? {};
|
|
778
|
+
const kept = Object.keys(previous).filter(
|
|
779
|
+
(field) => !(field in defaults) && hasReference(previous[field])
|
|
780
|
+
);
|
|
781
|
+
for (const field of kept) defaults[field] = previous[field];
|
|
782
|
+
if (kept.length)
|
|
783
|
+
draft.notes.push(`Kept from the existing manifest's theme defaults: ${kept.join(", ")}`);
|
|
784
|
+
return kept;
|
|
785
|
+
}
|
|
775
786
|
var hasReference = (value) => JSON.stringify(value ?? null).includes('"_ref":');
|
|
776
787
|
function references(value) {
|
|
777
788
|
if (Array.isArray(value)) return value.flatMap(references);
|
|
@@ -1069,6 +1080,7 @@ async function init(argv) {
|
|
|
1069
1080
|
});
|
|
1070
1081
|
draft = draftManifest(repo, base, live);
|
|
1071
1082
|
}
|
|
1083
|
+
if (existsSync3(out)) keepFileDefaults(draft, readJson(out));
|
|
1072
1084
|
configFrom(parseManifest(draft.manifest));
|
|
1073
1085
|
const json = `${JSON.stringify(draft.manifest, null, 2)}
|
|
1074
1086
|
`;
|
|
@@ -1079,6 +1091,13 @@ async function init(argv) {
|
|
|
1079
1091
|
Check before registering:`);
|
|
1080
1092
|
for (const note of draft.notes) console.error(` - ${note}`);
|
|
1081
1093
|
}
|
|
1094
|
+
function readJson(path) {
|
|
1095
|
+
try {
|
|
1096
|
+
return JSON.parse(readFileSync4(path, "utf8"));
|
|
1097
|
+
} catch {
|
|
1098
|
+
return null;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1082
1101
|
async function ask(suggested, orgFor) {
|
|
1083
1102
|
const prompt = createInterface({ input: process.stdin, output: process.stderr });
|
|
1084
1103
|
const question = async (label, fallback) => (await prompt.question(`${label}${fallback ? ` (${fallback})` : ""}: `)).trim() || fallback;
|