-
Notifications
You must be signed in to change notification settings - Fork 49
/
set-up-content.ts
60 lines (52 loc) · 1.72 KB
/
set-up-content.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
createClient,
createWriteClient,
createMigration,
} from "@prismicio/client";
import { createPrismicAuthManager } from "@slicemachine/manager";
import sm from "./slicemachine.config.json";
import pkg from "./package.json";
main();
async function main() {
const authManager = createPrismicAuthManager();
const isLoggedIn = await authManager.checkIsLoggedIn();
if (!isLoggedIn) {
const sessionInfo = await authManager.getLoginSessionInfo();
await authManager.nodeLoginSession({
port: sessionInfo.port,
onListenCallback() {
console.log(
`Open this URL in your browser and log in: ${sessionInfo.url}`,
);
},
});
console.log("Logged in!");
}
const sourceClient = createClient(pkg.name);
console.log(
`Fetching source documents from "${sourceClient.repositoryName}"...`,
);
const allDocuments = await sourceClient.dangerouslyGetAll();
const client = createWriteClient(sm.repositoryName, {
writeToken: await authManager.getAuthenticationToken(),
});
const migration = createMigration();
for (const document of allDocuments) {
if (["homepage", "settings"].includes(document.type))
// @ts-expect-error - These documents shouldn't have UIDs.
delete document.uid;
migration.createDocumentFromPrismic(
document,
(document.uid || document.type)
.replace(/-/g, " ")
.split(" ")
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join(" "),
);
}
console.log(`Copying documents to "${client.repositoryName}"...`);
await client.migrate(migration);
console.log(
`Done! Next, visit https://${sm.repositoryName}.prismic.io/builder/migration to publish your release.`,
);
}