@prismicio/cli 0.0.1
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/bin/prismic.js +47 -0
- package/dist/_node_modules/meow/build/dependencies.js +9040 -0
- package/dist/_node_modules/meow/build/dependencies.js.map +1 -0
- package/dist/_node_modules/meow/build/index.js +80 -0
- package/dist/_node_modules/meow/build/index.js.map +1 -0
- package/dist/_node_modules/meow/build/options.js +86 -0
- package/dist/_node_modules/meow/build/options.js.map +1 -0
- package/dist/_node_modules/meow/build/parser.js +61 -0
- package/dist/_node_modules/meow/build/parser.js.map +1 -0
- package/dist/_node_modules/meow/build/utils.js +8 -0
- package/dist/_node_modules/meow/build/utils.js.map +1 -0
- package/dist/_node_modules/meow/build/validate.js +102 -0
- package/dist/_node_modules/meow/build/validate.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +147 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +34 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/sync.d.ts +6 -0
- package/dist/commands/sync.js +32 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/core/auth.d.ts +2 -0
- package/dist/core/auth.js +72 -0
- package/dist/core/auth.js.map +1 -0
- package/dist/core/customType.d.ts +6 -0
- package/dist/core/customType.js +43 -0
- package/dist/core/customType.js.map +1 -0
- package/dist/core/framework.d.ts +41 -0
- package/dist/core/framework.js +128 -0
- package/dist/core/framework.js.map +1 -0
- package/dist/core/project.d.ts +19 -0
- package/dist/core/project.js +92 -0
- package/dist/core/project.js.map +1 -0
- package/dist/core/repository.d.ts +6 -0
- package/dist/core/repository.js +33 -0
- package/dist/core/repository.js.map +1 -0
- package/dist/core/slices.d.ts +6 -0
- package/dist/core/slices.js +47 -0
- package/dist/core/slices.js.map +1 -0
- package/dist/core/version.d.ts +15 -0
- package/dist/core/version.js +27 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/packages/cli/package.json.js +63 -0
- package/dist/packages/cli/package.json.js.map +1 -0
- package/dist/utils/error.d.ts +8 -0
- package/dist/utils/error.js +18 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/listr.d.ts +5 -0
- package/dist/utils/listr.js +12 -0
- package/dist/utils/listr.js.map +1 -0
- package/dist/utils/output.d.ts +3 -0
- package/dist/utils/output.js +34 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/package.d.ts +10 -0
- package/dist/utils/package.js +20 -0
- package/dist/utils/package.js.map +1 -0
- package/dist/utils/sentry.d.ts +10 -0
- package/dist/utils/sentry.js +62 -0
- package/dist/utils/sentry.js.map +1 -0
- package/dist/utils/telemetry.d.ts +14 -0
- package/dist/utils/telemetry.js +42 -0
- package/dist/utils/telemetry.js.map +1 -0
- package/package.json +84 -0
- package/src/cli.ts +186 -0
- package/src/commands/init.ts +68 -0
- package/src/commands/sync.ts +58 -0
- package/src/core/auth.ts +98 -0
- package/src/core/customType.ts +64 -0
- package/src/core/framework.ts +180 -0
- package/src/core/project.ts +148 -0
- package/src/core/repository.ts +51 -0
- package/src/core/slices.ts +67 -0
- package/src/core/version.ts +50 -0
- package/src/index.ts +1 -0
- package/src/utils/error.ts +40 -0
- package/src/utils/listr.ts +13 -0
- package/src/utils/output.ts +45 -0
- package/src/utils/package.ts +29 -0
- package/src/utils/sentry.ts +104 -0
- package/src/utils/telemetry.ts +70 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { version } from "../packages/cli/package.json.js";
|
|
2
|
+
import { login } from "../core/auth.js";
|
|
3
|
+
import { saveCustomTypes } from "../core/customType.js";
|
|
4
|
+
import { detectProjectState, detectProjectContext } from "../core/project.js";
|
|
5
|
+
import { validateRepository } from "../core/repository.js";
|
|
6
|
+
import { saveSlices } from "../core/slices.js";
|
|
7
|
+
import { checkCLIVersion } from "../core/version.js";
|
|
8
|
+
import { displaySuccess } from "../utils/output.js";
|
|
9
|
+
async function sync(args) {
|
|
10
|
+
const { manager } = args;
|
|
11
|
+
await login(manager);
|
|
12
|
+
await detectProjectState({ manager, commandType: "sync" });
|
|
13
|
+
const repositoryName = await manager.project.getRepositoryName();
|
|
14
|
+
await validateRepository({ manager, repository: repositoryName });
|
|
15
|
+
await detectProjectContext(manager);
|
|
16
|
+
await checkCLIVersion({ manager, currentVersion: version });
|
|
17
|
+
await manager.plugins.initPlugins();
|
|
18
|
+
await saveSlices({ manager });
|
|
19
|
+
await saveCustomTypes({ manager });
|
|
20
|
+
await manager.telemetry.track({
|
|
21
|
+
event: "prismic-cli:end",
|
|
22
|
+
commandType: "sync",
|
|
23
|
+
repository: repositoryName,
|
|
24
|
+
fullCommand: process.argv.join(" "),
|
|
25
|
+
success: true
|
|
26
|
+
});
|
|
27
|
+
displaySuccess("Sync completed successfully!", "Your local types are up to date.");
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
sync
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sources":["../../../src/commands/sync.ts"],"sourcesContent":["import type { PrismicManager } from \"@prismicio/manager\";\n\nimport { version as pkgVersion } from \"../../package.json\";\nimport { login } from \"../core/auth\";\nimport { saveCustomTypes } from \"../core/customType\";\nimport { detectProjectContext, detectProjectState } from \"../core/project\";\nimport { validateRepository } from \"../core/repository\";\nimport { saveSlices } from \"../core/slices\";\nimport { checkCLIVersion } from \"../core/version\";\nimport { displaySuccess } from \"../utils/output\";\n\ntype SyncArgs = {\n\tmanager: PrismicManager;\n};\n\nexport async function sync(args: SyncArgs): Promise<void> {\n\tconst { manager } = args;\n\n\t// Authentication - Also updates Sentry context\n\tawait login(manager);\n\n\t// Ensure the project is already initialized\n\tawait detectProjectState({ manager, commandType: \"sync\" });\n\n\t// Get repository from Prismic config file\n\tconst repositoryName = await manager.project.getRepositoryName();\n\n\t// Ensure the repository exists and the user has write access\n\tawait validateRepository({ manager, repository: repositoryName });\n\n\t// Ensure validity of the framework and package manager - Also updates Sentry context\n\tawait detectProjectContext(manager);\n\n\t// Check CLI version - Voluntarily late so Sentry context is updated\n\tawait checkCLIVersion({ manager, currentVersion: pkgVersion });\n\n\t// Initialize the plugin system\n\tawait manager.plugins.initPlugins();\n\n\t// Save Prismic slices locally\n\tawait saveSlices({ manager });\n\n\t// Save Prismic custom types locally\n\tawait saveCustomTypes({ manager });\n\n\tawait manager.telemetry.track({\n\t\tevent: \"prismic-cli:end\",\n\t\tcommandType: \"sync\",\n\t\trepository: repositoryName,\n\t\tfullCommand: process.argv.join(\" \"),\n\t\tsuccess: true,\n\t});\n\n\tdisplaySuccess(\n\t\t\"Sync completed successfully!\",\n\t\t\"Your local types are up to date.\",\n\t);\n}\n"],"names":["pkgVersion"],"mappings":";;;;;;;;AAeA,eAAsB,KAAK,MAAc;AACxC,QAAM,EAAE,YAAY;AAGpB,QAAM,MAAM,OAAO;AAGnB,QAAM,mBAAmB,EAAE,SAAS,aAAa,QAAQ;AAGzD,QAAM,iBAAiB,MAAM,QAAQ,QAAQ,kBAAA;AAG7C,QAAM,mBAAmB,EAAE,SAAS,YAAY,gBAAgB;AAGhE,QAAM,qBAAqB,OAAO;AAGlC,QAAM,gBAAgB,EAAE,SAAS,gBAAgBA,SAAY;AAG7D,QAAM,QAAQ,QAAQ,YAAA;AAGtB,QAAM,WAAW,EAAE,SAAS;AAG5B,QAAM,gBAAgB,EAAE,SAAS;AAEjC,QAAM,QAAQ,UAAU,MAAM;AAAA,IAC7B,OAAO;AAAA,IACP,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,aAAa,QAAQ,KAAK,KAAK,GAAG;AAAA,IAClC,SAAS;AAAA,EAAA,CACT;AAED,iBACC,gCACA,kCAAkC;AAEpC;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import open from "open";
|
|
3
|
+
import { listrRun, listr } from "../utils/listr.js";
|
|
4
|
+
import { updateSentryContext } from "../utils/sentry.js";
|
|
5
|
+
async function login(manager) {
|
|
6
|
+
return listrRun([
|
|
7
|
+
{
|
|
8
|
+
title: "Logging in to Prismic...",
|
|
9
|
+
task: async (_, parentTask) => {
|
|
10
|
+
const isLoggedIn = await manager.user.checkIsLoggedIn();
|
|
11
|
+
if (!isLoggedIn) {
|
|
12
|
+
parentTask.title = getLoggingInTitle(chalk.cyan("Press any key to open the browser to login..."));
|
|
13
|
+
await pressKeyToLogin();
|
|
14
|
+
await waitingForLogin(manager, ({ url }) => {
|
|
15
|
+
parentTask.title = getLoggingInTitle(chalk.cyan("Opening browser, waiting for you to login..."), chalk.yellow("If your browser did not open automatically, please use the url below:"), url);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
parentTask.title = `Logged in`;
|
|
19
|
+
return listr([
|
|
20
|
+
{
|
|
21
|
+
title: "Fetching user profile...",
|
|
22
|
+
task: async (_2, task) => {
|
|
23
|
+
const userProfile = await manager.user.getProfile();
|
|
24
|
+
await manager.telemetry.identify(userProfile);
|
|
25
|
+
updateSentryContext({ userProfile });
|
|
26
|
+
parentTask.title = `Logged in as ${chalk.cyan(userProfile?.email)}`;
|
|
27
|
+
task.title = "Fetched user profile";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
], { concurrent: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
function getLoggingInTitle(subtitle, ...extra) {
|
|
36
|
+
return `Logging in to Prismic...
|
|
37
|
+
|
|
38
|
+
███████████████████████████████████████████████████████████████████████████
|
|
39
|
+
|
|
40
|
+
${subtitle ? `* * ${subtitle}` : ""}
|
|
41
|
+
${extra.length ? `
|
|
42
|
+
${extra.map((line) => ` ${line}`).join("\n")}
|
|
43
|
+
` : ""}
|
|
44
|
+
███████████████████████████████████████████████████████████████████████████
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
async function pressKeyToLogin() {
|
|
48
|
+
await new Promise((resolve) => {
|
|
49
|
+
const initialRawMode = !!process.stdin.isRaw;
|
|
50
|
+
process.stdin.setRawMode?.(true);
|
|
51
|
+
process.stdin.resume();
|
|
52
|
+
process.stdin.once("data", (data) => {
|
|
53
|
+
process.stdin.setRawMode?.(initialRawMode);
|
|
54
|
+
process.stdin.pause();
|
|
55
|
+
resolve(data.toString("utf-8"));
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function waitingForLogin(manager, onListenCallback) {
|
|
60
|
+
const sessionInfo = await manager.user.getLoginSessionInfo();
|
|
61
|
+
await manager.user.nodeLoginSession({
|
|
62
|
+
port: sessionInfo.port,
|
|
63
|
+
onListenCallback() {
|
|
64
|
+
open(sessionInfo.url);
|
|
65
|
+
onListenCallback?.(sessionInfo);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
login
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sources":["../../../src/core/auth.ts"],"sourcesContent":["import type { PrismicManager } from \"@prismicio/manager\";\nimport chalk from \"chalk\";\nimport open from \"open\";\n\nimport { listr, listrRun } from \"../utils/listr\";\nimport { updateSentryContext } from \"../utils/sentry\";\n\nexport async function login(manager: PrismicManager): Promise<void> {\n\treturn listrRun([\n\t\t{\n\t\t\ttitle: \"Logging in to Prismic...\",\n\t\t\ttask: async (_, parentTask) => {\n\t\t\t\tconst isLoggedIn = await manager.user.checkIsLoggedIn();\n\n\t\t\t\tif (!isLoggedIn) {\n\t\t\t\t\tparentTask.title = getLoggingInTitle(\n\t\t\t\t\t\tchalk.cyan(\"Press any key to open the browser to login...\"),\n\t\t\t\t\t);\n\t\t\t\t\tawait pressKeyToLogin();\n\t\t\t\t\tawait waitingForLogin(manager, ({ url }) => {\n\t\t\t\t\t\tparentTask.title = getLoggingInTitle(\n\t\t\t\t\t\t\tchalk.cyan(\"Opening browser, waiting for you to login...\"),\n\t\t\t\t\t\t\tchalk.yellow(\n\t\t\t\t\t\t\t\t\"If your browser did not open automatically, please use the url below:\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tparentTask.title = `Logged in`;\n\n\t\t\t\treturn listr(\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttitle: \"Fetching user profile...\",\n\t\t\t\t\t\t\ttask: async (_, task) => {\n\t\t\t\t\t\t\t\tconst userProfile = await manager.user.getProfile();\n\n\t\t\t\t\t\t\t\t// Identify the user for Amplitude\n\t\t\t\t\t\t\t\tawait manager.telemetry.identify(userProfile);\n\n\t\t\t\t\t\t\t\t// Update Sentry context for the current user\n\t\t\t\t\t\t\t\tupdateSentryContext({ userProfile });\n\n\t\t\t\t\t\t\t\tparentTask.title = `Logged in as ${chalk.cyan(\n\t\t\t\t\t\t\t\t\tuserProfile?.email,\n\t\t\t\t\t\t\t\t)}`;\n\t\t\t\t\t\t\t\ttask.title = \"Fetched user profile\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t{ concurrent: true },\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t]);\n}\n\nfunction getLoggingInTitle(subtitle?: string, ...extra: string[]): string {\n\treturn `Logging in to Prismic...\n \n███████████████████████████████████████████████████████████████████████████\n\n${subtitle ? `* * ${subtitle}` : \"\"}\n${extra.length ? `\\n${extra.map((line) => ` ${line}`).join(\"\\n\")}\\n` : \"\"}\n███████████████████████████████████████████████████████████████████████████\n`;\n}\n\nasync function pressKeyToLogin(): Promise<void> {\n\tawait new Promise((resolve) => {\n\t\tconst initialRawMode = !!process.stdin.isRaw;\n\t\tprocess.stdin.setRawMode?.(true);\n\t\tprocess.stdin.resume();\n\t\tprocess.stdin.once(\"data\", (data: Buffer) => {\n\t\t\tprocess.stdin.setRawMode?.(initialRawMode);\n\t\t\tprocess.stdin.pause();\n\t\t\tresolve(data.toString(\"utf-8\"));\n\t\t});\n\t});\n}\n\nasync function waitingForLogin(\n\tmanager: PrismicManager,\n\tonListenCallback?: (\n\t\tsessionInfo: Awaited<ReturnType<typeof manager.user.getLoginSessionInfo>>,\n\t) => void,\n): Promise<void> {\n\tconst sessionInfo = await manager.user.getLoginSessionInfo();\n\tawait manager.user.nodeLoginSession({\n\t\tport: sessionInfo.port,\n\t\tonListenCallback() {\n\t\t\topen(sessionInfo.url);\n\t\t\tonListenCallback?.(sessionInfo);\n\t\t},\n\t});\n}\n"],"names":["_"],"mappings":";;;;AAOA,eAAsB,MAAM,SAAuB;AAClD,SAAO,SAAS;AAAA,IACf;AAAA,MACC,OAAO;AAAA,MACP,MAAM,OAAO,GAAG,eAAc;AAC7B,cAAM,aAAa,MAAM,QAAQ,KAAK,gBAAA;AAEtC,YAAI,CAAC,YAAY;AAChB,qBAAW,QAAQ,kBAClB,MAAM,KAAK,+CAA+C,CAAC;AAE5D,gBAAM,gBAAA;AACN,gBAAM,gBAAgB,SAAS,CAAC,EAAE,UAAS;AAC1C,uBAAW,QAAQ,kBAClB,MAAM,KAAK,8CAA8C,GACzD,MAAM,OACL,uEAAuE,GAExE,GAAG;AAAA,UAEL,CAAC;AAAA,QACF;AAEA,mBAAW,QAAQ;AAEnB,eAAO,MACN;AAAA,UACC;AAAA,YACC,OAAO;AAAA,YACP,MAAM,OAAOA,IAAG,SAAQ;AACvB,oBAAM,cAAc,MAAM,QAAQ,KAAK,WAAA;AAGvC,oBAAM,QAAQ,UAAU,SAAS,WAAW;AAG5C,kCAAoB,EAAE,aAAa;AAEnC,yBAAW,QAAQ,gBAAgB,MAAM,KACxC,aAAa,KAAK,CAClB;AACD,mBAAK,QAAQ;AAAA,YACd;AAAA,UAAA;AAAA,QACA,GAEF,EAAE,YAAY,MAAM;AAAA,MAEtB;AAAA,IAAA;AAAA,EACA,CACD;AACF;AAEA,SAAS,kBAAkB,aAAsB,OAAe;AAC/D,SAAO;AAAA;AAAA;AAAA;AAAA,EAIN,WAAW,OAAO,QAAQ,KAAK,EAAE;AAAA,EACjC,MAAM,SAAS;AAAA,EAAK,MAAM,IAAI,CAAC,SAAS,MAAM,IAAI,EAAE,EAAE,KAAK,IAAI,CAAC;AAAA,IAAO,EAAE;AAAA;AAAA;AAG3E;AAEA,eAAe,kBAAe;AAC7B,QAAM,IAAI,QAAQ,CAAC,YAAW;AAC7B,UAAM,iBAAiB,CAAC,CAAC,QAAQ,MAAM;AACvC,YAAQ,MAAM,aAAa,IAAI;AAC/B,YAAQ,MAAM,OAAA;AACd,YAAQ,MAAM,KAAK,QAAQ,CAAC,SAAgB;AAC3C,cAAQ,MAAM,aAAa,cAAc;AACzC,cAAQ,MAAM,MAAA;AACd,cAAQ,KAAK,SAAS,OAAO,CAAC;AAAA,IAC/B,CAAC;AAAA,EACF,CAAC;AACF;AAEA,eAAe,gBACd,SACA,kBAES;AAET,QAAM,cAAc,MAAM,QAAQ,KAAK,oBAAA;AACvC,QAAM,QAAQ,KAAK,iBAAiB;AAAA,IACnC,MAAM,YAAY;AAAA,IAClB,mBAAgB;AACf,WAAK,YAAY,GAAG;AACpB,yBAAmB,WAAW;AAAA,IAC/B;AAAA,EAAA,CACA;AACF;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { listrRun } from "../utils/listr.js";
|
|
2
|
+
async function saveCustomTypes(args) {
|
|
3
|
+
const { manager } = args;
|
|
4
|
+
await listrRun([
|
|
5
|
+
{
|
|
6
|
+
title: "Fetching Prismic custom types...",
|
|
7
|
+
task: async (_, parentTask) => {
|
|
8
|
+
const customTypes = await manager.customTypes.fetchRemoteCustomTypes();
|
|
9
|
+
parentTask.title = "Saving Prismic custom types changes...";
|
|
10
|
+
const localCustomTypes = await manager.customTypes.readAllCustomTypes();
|
|
11
|
+
for (const remoteCustomType of customTypes) {
|
|
12
|
+
const existsLocally = localCustomTypes.models.some((local) => local.model.id === remoteCustomType.id);
|
|
13
|
+
if (existsLocally) {
|
|
14
|
+
await manager.customTypes.updateCustomType({
|
|
15
|
+
model: remoteCustomType
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const localCustomType of localCustomTypes.models) {
|
|
20
|
+
const existsRemotely = customTypes.some((remote) => remote.id === localCustomType.model.id);
|
|
21
|
+
if (!existsRemotely) {
|
|
22
|
+
await manager.customTypes.deleteCustomType({
|
|
23
|
+
id: localCustomType.model.id
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const remoteCustomType of customTypes) {
|
|
28
|
+
const existsLocally = localCustomTypes.models.some((local) => local.model.id === remoteCustomType.id);
|
|
29
|
+
if (!existsLocally) {
|
|
30
|
+
await manager.customTypes.createCustomType({
|
|
31
|
+
model: remoteCustomType
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
parentTask.title = "Prismic custom types changes saved";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
saveCustomTypes
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=customType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customType.js","sources":["../../../src/core/customType.ts"],"sourcesContent":["import type { PrismicManager } from \"@prismicio/manager\";\n\nimport { listrRun } from \"../utils/listr\";\n\ntype SaveCustomTypesArgs = {\n\tmanager: PrismicManager;\n};\n\nexport async function saveCustomTypes(\n\targs: SaveCustomTypesArgs,\n): Promise<void> {\n\tconst { manager } = args;\n\n\tawait listrRun([\n\t\t{\n\t\t\ttitle: \"Fetching Prismic custom types...\",\n\t\t\ttask: async (_, parentTask) => {\n\t\t\t\tconst customTypes = await manager.customTypes.fetchRemoteCustomTypes();\n\n\t\t\t\tparentTask.title = \"Saving Prismic custom types changes...\";\n\n\t\t\t\tconst localCustomTypes = await manager.customTypes.readAllCustomTypes();\n\n\t\t\t\t// Handle custom types update\n\t\t\t\tfor (const remoteCustomType of customTypes) {\n\t\t\t\t\tconst existsLocally = localCustomTypes.models.some(\n\t\t\t\t\t\t(local) => local.model.id === remoteCustomType.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (existsLocally) {\n\t\t\t\t\t\tawait manager.customTypes.updateCustomType({\n\t\t\t\t\t\t\tmodel: remoteCustomType,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle custom types deletion\n\t\t\t\tfor (const localCustomType of localCustomTypes.models) {\n\t\t\t\t\tconst existsRemotely = customTypes.some(\n\t\t\t\t\t\t(remote) => remote.id === localCustomType.model.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (!existsRemotely) {\n\t\t\t\t\t\tawait manager.customTypes.deleteCustomType({\n\t\t\t\t\t\t\tid: localCustomType.model.id,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle custom types creation\n\t\t\t\tfor (const remoteCustomType of customTypes) {\n\t\t\t\t\tconst existsLocally = localCustomTypes.models.some(\n\t\t\t\t\t\t(local) => local.model.id === remoteCustomType.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (!existsLocally) {\n\t\t\t\t\t\tawait manager.customTypes.createCustomType({\n\t\t\t\t\t\t\tmodel: remoteCustomType,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentTask.title = \"Prismic custom types changes saved\";\n\t\t\t},\n\t\t},\n\t]);\n}\n"],"names":[],"mappings":";AAQA,eAAsB,gBACrB,MAAyB;AAEzB,QAAM,EAAE,YAAY;AAEpB,QAAM,SAAS;AAAA,IACd;AAAA,MACC,OAAO;AAAA,MACP,MAAM,OAAO,GAAG,eAAc;AAC7B,cAAM,cAAc,MAAM,QAAQ,YAAY,uBAAA;AAE9C,mBAAW,QAAQ;AAEnB,cAAM,mBAAmB,MAAM,QAAQ,YAAY,mBAAA;AAGnD,mBAAW,oBAAoB,aAAa;AAC3C,gBAAM,gBAAgB,iBAAiB,OAAO,KAC7C,CAAC,UAAU,MAAM,MAAM,OAAO,iBAAiB,EAAE;AAElD,cAAI,eAAe;AAClB,kBAAM,QAAQ,YAAY,iBAAiB;AAAA,cAC1C,OAAO;AAAA,YAAA,CACP;AAAA,UACF;AAAA,QACD;AAGA,mBAAW,mBAAmB,iBAAiB,QAAQ;AACtD,gBAAM,iBAAiB,YAAY,KAClC,CAAC,WAAW,OAAO,OAAO,gBAAgB,MAAM,EAAE;AAEnD,cAAI,CAAC,gBAAgB;AACpB,kBAAM,QAAQ,YAAY,iBAAiB;AAAA,cAC1C,IAAI,gBAAgB,MAAM;AAAA,YAAA,CAC1B;AAAA,UACF;AAAA,QACD;AAGA,mBAAW,oBAAoB,aAAa;AAC3C,gBAAM,gBAAgB,iBAAiB,OAAO,KAC7C,CAAC,UAAU,MAAM,MAAM,OAAO,iBAAiB,EAAE;AAElD,cAAI,CAAC,eAAe;AACnB,kBAAM,QAAQ,YAAY,iBAAiB;AAAA,cAC1C,OAAO;AAAA,YAAA,CACP;AAAA,UACF;AAAA,QACD;AAEA,mBAAW,QAAQ;AAAA,MACpB;AAAA,IAAA;AAAA,EACA,CACD;AACF;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type PrismicManager } from "@prismicio/manager";
|
|
2
|
+
import { type ProjectContext } from "./project.js";
|
|
3
|
+
export type Framework = {
|
|
4
|
+
/**
|
|
5
|
+
* Framework's human readable name.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Framework 's id sent to Segment from Slice Machine
|
|
10
|
+
*/
|
|
11
|
+
telemetryID: "next" | "nuxt-2" | "nuxt" | "sveltekit-1" | "sveltekit-2";
|
|
12
|
+
/**
|
|
13
|
+
* Package name of the adapter responsible for this framework
|
|
14
|
+
*/
|
|
15
|
+
adapterName: string;
|
|
16
|
+
/**
|
|
17
|
+
* A package name/semver range map defining framework compatibility
|
|
18
|
+
* requirements.
|
|
19
|
+
*
|
|
20
|
+
* Project should match all entries to be considered compatible.
|
|
21
|
+
*/
|
|
22
|
+
compatibility: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Frameworks we support, orders shouldn't matter much but is respected (the
|
|
26
|
+
* higher it is the more priority it has in case multiple matches)
|
|
27
|
+
*/
|
|
28
|
+
export declare const FRAMEWORKS: Record<string, Framework>;
|
|
29
|
+
export declare const detectFramework: (cwd: string) => Promise<Framework>;
|
|
30
|
+
type InitFrameworkArgs = {
|
|
31
|
+
manager: PrismicManager;
|
|
32
|
+
projectContext: ProjectContext;
|
|
33
|
+
};
|
|
34
|
+
export declare function initFramework(args: InitFrameworkArgs): Promise<void>;
|
|
35
|
+
export declare const FRAMEWORK_PLUGINS: {
|
|
36
|
+
"@prismicio/adapter-next": import("@prismicio/plugin-kit").Plugin<import("@prismicio/adapter-next").PluginOptions>;
|
|
37
|
+
"@prismicio/adapter-nuxt": import("@prismicio/plugin-kit").Plugin<import("@prismicio/adapter-nuxt").PluginOptions>;
|
|
38
|
+
"@prismicio/adapter-nuxt2": import("@prismicio/plugin-kit").Plugin<import("@prismicio/adapter-nuxt2").PluginOptions>;
|
|
39
|
+
"@prismicio/adapter-sveltekit": import("@prismicio/plugin-kit").Plugin<import("@prismicio/adapter-sveltekit").PluginOptions>;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readdir, rm, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import adapterNextPlugin from "@prismicio/adapter-next";
|
|
4
|
+
import adapterNuxtPlugin from "@prismicio/adapter-nuxt";
|
|
5
|
+
import adapterNuxt2Plugin from "@prismicio/adapter-nuxt2";
|
|
6
|
+
import adapterSveltekitPlugin from "@prismicio/adapter-sveltekit";
|
|
7
|
+
import semver from "semver";
|
|
8
|
+
import { listrRun } from "../utils/listr.js";
|
|
9
|
+
const FRAMEWORKS = {
|
|
10
|
+
"nuxt-2": {
|
|
11
|
+
name: "Nuxt 2",
|
|
12
|
+
telemetryID: "nuxt-2",
|
|
13
|
+
adapterName: "@prismicio/adapter-nuxt2",
|
|
14
|
+
compatibility: {
|
|
15
|
+
nuxt: "^2.0.0"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
nuxt: {
|
|
19
|
+
name: "Nuxt",
|
|
20
|
+
telemetryID: "nuxt",
|
|
21
|
+
adapterName: "@prismicio/adapter-nuxt",
|
|
22
|
+
compatibility: {
|
|
23
|
+
nuxt: "^3.0.0 || ^4.0.0"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
next: {
|
|
27
|
+
name: "Next.js",
|
|
28
|
+
telemetryID: "next",
|
|
29
|
+
adapterName: "@prismicio/adapter-next",
|
|
30
|
+
compatibility: {
|
|
31
|
+
next: "^11 || ^12 || ^13 || ^14 || ^15 || ^16.0.0-beta.0"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"sveltekit-1": {
|
|
35
|
+
name: "SvelteKit",
|
|
36
|
+
telemetryID: "sveltekit-1",
|
|
37
|
+
adapterName: "@prismicio/adapter-sveltekit",
|
|
38
|
+
compatibility: {
|
|
39
|
+
"@sveltejs/kit": "^1.0.0"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"sveltekit-2": {
|
|
43
|
+
name: "SvelteKit",
|
|
44
|
+
telemetryID: "sveltekit-2",
|
|
45
|
+
adapterName: "@prismicio/adapter-sveltekit",
|
|
46
|
+
compatibility: {
|
|
47
|
+
"@sveltejs/kit": "^2.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const detectFramework = async (cwd) => {
|
|
52
|
+
const path = join(cwd, "package.json");
|
|
53
|
+
let allDependencies;
|
|
54
|
+
try {
|
|
55
|
+
const pkg = JSON.parse(await readFile(path, "utf-8"));
|
|
56
|
+
allDependencies = {
|
|
57
|
+
...pkg.dependencies,
|
|
58
|
+
...pkg.devDependencies
|
|
59
|
+
};
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw new Error(`Failed to read project's \`package.json\` at \`${path}\``, { cause: error });
|
|
62
|
+
}
|
|
63
|
+
const framework = Object.values(FRAMEWORKS).find((framework2) => {
|
|
64
|
+
return Object.entries(framework2.compatibility).every(([pkg, range]) => {
|
|
65
|
+
if (pkg in allDependencies) {
|
|
66
|
+
try {
|
|
67
|
+
const minimumVersion = semver.minVersion(allDependencies[pkg]);
|
|
68
|
+
return semver.satisfies(minimumVersion, range);
|
|
69
|
+
} catch {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
if (!framework) {
|
|
77
|
+
throw new Error("No framework compatible with Prismic was found.");
|
|
78
|
+
}
|
|
79
|
+
return framework;
|
|
80
|
+
};
|
|
81
|
+
async function initFramework(args) {
|
|
82
|
+
const { manager, projectContext } = args;
|
|
83
|
+
const { framework } = projectContext;
|
|
84
|
+
await listrRun([
|
|
85
|
+
{
|
|
86
|
+
title: `Initializing project for ${framework.name}...`,
|
|
87
|
+
task: async (_, parentTask) => {
|
|
88
|
+
const updateOutput = (data) => {
|
|
89
|
+
if (data instanceof Buffer) {
|
|
90
|
+
parentTask.output = data.toString();
|
|
91
|
+
} else if (typeof data === "string") {
|
|
92
|
+
parentTask.output = data;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
await manager.project.initProject({
|
|
96
|
+
log: updateOutput
|
|
97
|
+
});
|
|
98
|
+
const projectRoot = await manager.project.getRoot();
|
|
99
|
+
const entries = await readdir(projectRoot, {
|
|
100
|
+
recursive: true,
|
|
101
|
+
withFileTypes: true
|
|
102
|
+
});
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
if (entry.isDirectory() && entry.name === "slice-simulator") {
|
|
105
|
+
await rm(join(entry.path, entry.name), {
|
|
106
|
+
recursive: true,
|
|
107
|
+
force: true
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
parentTask.title = `Updated project for ${framework.name}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
const FRAMEWORK_PLUGINS = {
|
|
117
|
+
"@prismicio/adapter-next": adapterNextPlugin,
|
|
118
|
+
"@prismicio/adapter-nuxt": adapterNuxtPlugin,
|
|
119
|
+
"@prismicio/adapter-nuxt2": adapterNuxt2Plugin,
|
|
120
|
+
"@prismicio/adapter-sveltekit": adapterSveltekitPlugin
|
|
121
|
+
};
|
|
122
|
+
export {
|
|
123
|
+
FRAMEWORKS,
|
|
124
|
+
FRAMEWORK_PLUGINS,
|
|
125
|
+
detectFramework,
|
|
126
|
+
initFramework
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=framework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework.js","sources":["../../../src/core/framework.ts"],"sourcesContent":["import { readFile, readdir, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport adapterNextPlugin from \"@prismicio/adapter-next\";\nimport adapterNuxtPlugin from \"@prismicio/adapter-nuxt\";\nimport adapterNuxt2Plugin from \"@prismicio/adapter-nuxt2\";\nimport adapterSveltekitPlugin from \"@prismicio/adapter-sveltekit\";\nimport { type PrismicManager } from \"@prismicio/manager\";\nimport semver from \"semver\";\n\nimport { listrRun } from \"../utils/listr\";\n\nimport { type ProjectContext } from \"./project\";\n\nexport type Framework = {\n\t/**\n\t * Framework's human readable name.\n\t */\n\tname: string;\n\n\t/**\n\t * Framework 's id sent to Segment from Slice Machine\n\t */\n\ttelemetryID: \"next\" | \"nuxt-2\" | \"nuxt\" | \"sveltekit-1\" | \"sveltekit-2\";\n\n\t/**\n\t * Package name of the adapter responsible for this framework\n\t */\n\tadapterName: string;\n\n\t/**\n\t * A package name/semver range map defining framework compatibility\n\t * requirements.\n\t *\n\t * Project should match all entries to be considered compatible.\n\t */\n\tcompatibility: Record<string, string>;\n};\n\n/**\n * Frameworks we support, orders shouldn't matter much but is respected (the\n * higher it is the more priority it has in case multiple matches)\n */\nexport const FRAMEWORKS: Record<string, Framework> = {\n\t\"nuxt-2\": {\n\t\tname: \"Nuxt 2\",\n\t\ttelemetryID: \"nuxt-2\",\n\t\tadapterName: \"@prismicio/adapter-nuxt2\",\n\t\tcompatibility: {\n\t\t\tnuxt: \"^2.0.0\",\n\t\t},\n\t},\n\tnuxt: {\n\t\tname: \"Nuxt\",\n\t\ttelemetryID: \"nuxt\",\n\t\tadapterName: \"@prismicio/adapter-nuxt\",\n\t\tcompatibility: {\n\t\t\tnuxt: \"^3.0.0 || ^4.0.0\",\n\t\t},\n\t},\n\tnext: {\n\t\tname: \"Next.js\",\n\t\ttelemetryID: \"next\",\n\t\tadapterName: \"@prismicio/adapter-next\",\n\t\tcompatibility: {\n\t\t\tnext: \"^11 || ^12 || ^13 || ^14 || ^15 || ^16.0.0-beta.0\",\n\t\t},\n\t},\n\t\"sveltekit-1\": {\n\t\tname: \"SvelteKit\",\n\t\ttelemetryID: \"sveltekit-1\",\n\t\tadapterName: \"@prismicio/adapter-sveltekit\",\n\t\tcompatibility: {\n\t\t\t\"@sveltejs/kit\": \"^1.0.0\",\n\t\t},\n\t},\n\t\"sveltekit-2\": {\n\t\tname: \"SvelteKit\",\n\t\ttelemetryID: \"sveltekit-2\",\n\t\tadapterName: \"@prismicio/adapter-sveltekit\",\n\t\tcompatibility: {\n\t\t\t\"@sveltejs/kit\": \"^2.0.0\",\n\t\t},\n\t},\n} as const;\n\nexport const detectFramework = async (cwd: string): Promise<Framework> => {\n\tconst path = join(cwd, \"package.json\");\n\n\tlet allDependencies: Record<string, string>;\n\ttry {\n\t\tconst pkg = JSON.parse(await readFile(path, \"utf-8\"));\n\n\t\tallDependencies = {\n\t\t\t...pkg.dependencies,\n\t\t\t...pkg.devDependencies,\n\t\t};\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to read project's \\`package.json\\` at \\`${path}\\``,\n\t\t\t{ cause: error },\n\t\t);\n\t}\n\n\tconst framework = Object.values(FRAMEWORKS).find((framework) => {\n\t\treturn Object.entries(framework.compatibility).every(([pkg, range]) => {\n\t\t\tif (pkg in allDependencies) {\n\t\t\t\ttry {\n\t\t\t\t\t// Determine lowest version possibly in use\n\t\t\t\t\tconst minimumVersion = semver.minVersion(allDependencies[pkg]);\n\n\t\t\t\t\treturn semver.satisfies(minimumVersion!, range);\n\t\t\t\t} catch {\n\t\t\t\t\t// We assume unconventional tags, `latest`, `beta`, `dev` matches the framework\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn false;\n\t\t});\n\t});\n\n\tif (!framework) {\n\t\tthrow new Error(\"No framework compatible with Prismic was found.\");\n\t}\n\n\treturn framework;\n};\n\ntype InitFrameworkArgs = {\n\tmanager: PrismicManager;\n\tprojectContext: ProjectContext;\n};\n\nexport async function initFramework(args: InitFrameworkArgs): Promise<void> {\n\tconst { manager, projectContext } = args;\n\tconst { framework } = projectContext;\n\n\tawait listrRun([\n\t\t{\n\t\t\ttitle: `Initializing project for ${framework.name}...`,\n\t\t\ttask: async (_, parentTask) => {\n\t\t\t\tconst updateOutput = (data: Buffer | string | null) => {\n\t\t\t\t\tif (data instanceof Buffer) {\n\t\t\t\t\t\tparentTask.output = data.toString();\n\t\t\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\t\t\tparentTask.output = data;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tawait manager.project.initProject({\n\t\t\t\t\tlog: updateOutput,\n\t\t\t\t});\n\n\t\t\t\t// TODO: Export simulator management out of adapter and remove this code\n\t\t\t\tconst projectRoot = await manager.project.getRoot();\n\t\t\t\tconst entries = await readdir(projectRoot, {\n\t\t\t\t\trecursive: true,\n\t\t\t\t\twithFileTypes: true,\n\t\t\t\t});\n\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\tif (entry.isDirectory() && entry.name === \"slice-simulator\") {\n\t\t\t\t\t\tawait rm(join(entry.path, entry.name), {\n\t\t\t\t\t\t\trecursive: true,\n\t\t\t\t\t\t\tforce: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentTask.title = `Updated project for ${framework.name}`;\n\t\t\t},\n\t\t},\n\t]);\n}\n\nexport const FRAMEWORK_PLUGINS = {\n\t\"@prismicio/adapter-next\": adapterNextPlugin,\n\t\"@prismicio/adapter-nuxt\": adapterNuxtPlugin,\n\t\"@prismicio/adapter-nuxt2\": adapterNuxt2Plugin,\n\t\"@prismicio/adapter-sveltekit\": adapterSveltekitPlugin,\n};\n"],"names":["framework"],"mappings":";;;;;;;;AA2CO,MAAM,aAAwC;AAAA,EACpD,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,eAAe;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACN;AAAA,EAEF,MAAM;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,eAAe;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACN;AAAA,EAEF,MAAM;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,eAAe;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACN;AAAA,EAEF,eAAe;AAAA,IACd,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,eAAe;AAAA,MACd,iBAAiB;AAAA,IAAA;AAAA,EACjB;AAAA,EAEF,eAAe;AAAA,IACd,MAAM;AAAA,IACN,aAAa;AAAA,IACb,aAAa;AAAA,IACb,eAAe;AAAA,MACd,iBAAiB;AAAA,IAAA;AAAA,EACjB;;AAII,MAAM,kBAAkB,OAAO,QAAmC;AACxE,QAAM,OAAO,KAAK,KAAK,cAAc;AAErC,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,KAAK,MAAM,MAAM,SAAS,MAAM,OAAO,CAAC;AAEpD,sBAAkB;AAAA,MACjB,GAAG,IAAI;AAAA,MACP,GAAG,IAAI;AAAA,IAAA;AAAA,EAET,SAAS,OAAO;AACf,UAAM,IAAI,MACT,kDAAkD,IAAI,MACtD,EAAE,OAAO,OAAO;AAAA,EAElB;AAEA,QAAM,YAAY,OAAO,OAAO,UAAU,EAAE,KAAK,CAACA,eAAa;AAC9D,WAAO,OAAO,QAAQA,WAAU,aAAa,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,MAAK;AACrE,UAAI,OAAO,iBAAiB;AAC3B,YAAI;AAEH,gBAAM,iBAAiB,OAAO,WAAW,gBAAgB,GAAG,CAAC;AAE7D,iBAAO,OAAO,UAAU,gBAAiB,KAAK;AAAA,QAC/C,QAAQ;AAEP,iBAAO;AAAA,QACR;AAAA,MACD;AAEA,aAAO;AAAA,IACR,CAAC;AAAA,EACF,CAAC;AAED,MAAI,CAAC,WAAW;AACf,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AAEA,SAAO;AACR;AAOA,eAAsB,cAAc,MAAuB;AAC1D,QAAM,EAAE,SAAS,eAAA,IAAmB;AACpC,QAAM,EAAE,cAAc;AAEtB,QAAM,SAAS;AAAA,IACd;AAAA,MACC,OAAO,4BAA4B,UAAU,IAAI;AAAA,MACjD,MAAM,OAAO,GAAG,eAAc;AAC7B,cAAM,eAAe,CAAC,SAAgC;AACrD,cAAI,gBAAgB,QAAQ;AAC3B,uBAAW,SAAS,KAAK,SAAA;AAAA,UAC1B,WAAW,OAAO,SAAS,UAAU;AACpC,uBAAW,SAAS;AAAA,UACrB;AAAA,QACD;AACA,cAAM,QAAQ,QAAQ,YAAY;AAAA,UACjC,KAAK;AAAA,QAAA,CACL;AAGD,cAAM,cAAc,MAAM,QAAQ,QAAQ,QAAA;AAC1C,cAAM,UAAU,MAAM,QAAQ,aAAa;AAAA,UAC1C,WAAW;AAAA,UACX,eAAe;AAAA,QAAA,CACf;AACD,mBAAW,SAAS,SAAS;AAC5B,cAAI,MAAM,YAAA,KAAiB,MAAM,SAAS,mBAAmB;AAC5D,kBAAM,GAAG,KAAK,MAAM,MAAM,MAAM,IAAI,GAAG;AAAA,cACtC,WAAW;AAAA,cACX,OAAO;AAAA,YAAA,CACP;AAAA,UACF;AAAA,QACD;AAEA,mBAAW,QAAQ,uBAAuB,UAAU,IAAI;AAAA,MACzD;AAAA,IAAA;AAAA,EACA,CACD;AACF;AAEO,MAAM,oBAAoB;AAAA,EAChC,2BAA2B;AAAA,EAC3B,2BAA2B;AAAA,EAC3B,4BAA4B;AAAA,EAC5B,gCAAgC;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PackageManager, PrismicManager } from "@prismicio/manager";
|
|
2
|
+
import { type Framework } from "../core/framework.js";
|
|
3
|
+
type DetectProjectStateArgs = {
|
|
4
|
+
manager: PrismicManager;
|
|
5
|
+
commandType: "init" | "sync";
|
|
6
|
+
};
|
|
7
|
+
export declare function detectProjectState(args: DetectProjectStateArgs): Promise<void>;
|
|
8
|
+
export type ProjectContext = {
|
|
9
|
+
framework: Framework;
|
|
10
|
+
packageManager: PackageManager;
|
|
11
|
+
};
|
|
12
|
+
export declare function detectProjectContext(manager: PrismicManager): Promise<ProjectContext>;
|
|
13
|
+
type CreatePrismicConfigArgs = {
|
|
14
|
+
manager: PrismicManager;
|
|
15
|
+
projectContext: ProjectContext;
|
|
16
|
+
repositoryName: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function createPrismicConfig(args: CreatePrismicConfigArgs): Promise<void>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { detectFramework } from "./framework.js";
|
|
3
|
+
import { listrRun, listr } from "../utils/listr.js";
|
|
4
|
+
import { updateSentryContext } from "../utils/sentry.js";
|
|
5
|
+
async function detectProjectState(args) {
|
|
6
|
+
const { manager, commandType } = args;
|
|
7
|
+
let prismicConfig;
|
|
8
|
+
try {
|
|
9
|
+
prismicConfig = await manager.project.getPrismicConfig();
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
const legacyConfigExists = await manager.project.checkLegacyConfigExists();
|
|
13
|
+
if (commandType === "init" && (prismicConfig || legacyConfigExists)) {
|
|
14
|
+
throw new Error("Project has already been initialized.");
|
|
15
|
+
} else if (commandType === "sync" && !prismicConfig) {
|
|
16
|
+
if (legacyConfigExists) {
|
|
17
|
+
await manager.project.migrateLegacyConfig();
|
|
18
|
+
} else {
|
|
19
|
+
throw new Error("Project requires initialization before syncing.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function detectProjectContext(manager) {
|
|
24
|
+
let framework;
|
|
25
|
+
let packageManager;
|
|
26
|
+
await listrRun([
|
|
27
|
+
{
|
|
28
|
+
title: "Detecting environment...",
|
|
29
|
+
task: (_, parentTask) => listr([
|
|
30
|
+
{
|
|
31
|
+
title: "Detecting framework...",
|
|
32
|
+
task: async (_2, task) => {
|
|
33
|
+
framework = await detectFramework(manager.cwd);
|
|
34
|
+
updateSentryContext({ framework: framework.telemetryID });
|
|
35
|
+
task.title = `Detected framework ${chalk.cyan(framework.name)}`;
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
title: "Detecting package manager...",
|
|
40
|
+
task: async (_2, task) => {
|
|
41
|
+
packageManager = await manager.project.detectPackageManager({
|
|
42
|
+
root: manager.cwd
|
|
43
|
+
});
|
|
44
|
+
task.title = `Detected package manager ${chalk.cyan(packageManager)}`;
|
|
45
|
+
if (!framework) {
|
|
46
|
+
throw new Error("Project framework must be available through context to proceed");
|
|
47
|
+
}
|
|
48
|
+
parentTask.title = `Detected framework ${chalk.cyan(framework.name)} and package manager ${chalk.cyan(packageManager)}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
])
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
if (!framework) {
|
|
55
|
+
throw new Error("Project framework must be available through context to proceed");
|
|
56
|
+
}
|
|
57
|
+
if (!packageManager) {
|
|
58
|
+
throw new Error("Project package manager must be available through context to proceed");
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
framework,
|
|
62
|
+
packageManager
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async function createPrismicConfig(args) {
|
|
66
|
+
const { manager, projectContext, repositoryName } = args;
|
|
67
|
+
const { framework } = projectContext;
|
|
68
|
+
return listrRun([
|
|
69
|
+
{
|
|
70
|
+
title: "Creating Prismic configuration...",
|
|
71
|
+
task: async (_, parentTask) => {
|
|
72
|
+
parentTask.title = "Creating Prismic configuration...";
|
|
73
|
+
const prismicConfigPath = await manager.project.suggestPrismicConfigPath();
|
|
74
|
+
await manager.project.writePrismicConfig({
|
|
75
|
+
config: {
|
|
76
|
+
repositoryName,
|
|
77
|
+
adapter: framework.adapterName,
|
|
78
|
+
libraries: ["./slices"]
|
|
79
|
+
},
|
|
80
|
+
path: prismicConfigPath
|
|
81
|
+
});
|
|
82
|
+
parentTask.title = "Created Prismic configuration";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
createPrismicConfig,
|
|
89
|
+
detectProjectContext,
|
|
90
|
+
detectProjectState
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sources":["../../../src/core/project.ts"],"sourcesContent":["import type {\n\tPackageManager,\n\tPrismicConfig,\n\tPrismicManager,\n} from \"@prismicio/manager\";\nimport chalk from \"chalk\";\n\nimport { type Framework, detectFramework } from \"../core/framework\";\nimport { listr, listrRun } from \"../utils/listr\";\nimport { updateSentryContext } from \"../utils/sentry\";\n\ntype DetectProjectStateArgs = {\n\tmanager: PrismicManager;\n\tcommandType: \"init\" | \"sync\";\n};\n\nexport async function detectProjectState(\n\targs: DetectProjectStateArgs,\n): Promise<void> {\n\tconst { manager, commandType } = args;\n\n\tlet prismicConfig: PrismicConfig | undefined;\n\n\ttry {\n\t\tprismicConfig = await manager.project.getPrismicConfig();\n\t} catch {\n\t\t// We want to manage the error depending on the need to be initialized or not\n\t}\n\n\tconst legacyConfigExists = await manager.project.checkLegacyConfigExists();\n\n\tif (commandType === \"init\" && (prismicConfig || legacyConfigExists)) {\n\t\tthrow new Error(\"Project has already been initialized.\");\n\t} else if (commandType === \"sync\" && !prismicConfig) {\n\t\tif (legacyConfigExists) {\n\t\t\tawait manager.project.migrateLegacyConfig();\n\t\t} else {\n\t\t\tthrow new Error(\"Project requires initialization before syncing.\");\n\t\t}\n\t}\n}\n\nexport type ProjectContext = {\n\tframework: Framework;\n\tpackageManager: PackageManager;\n};\n\nexport async function detectProjectContext(\n\tmanager: PrismicManager,\n): Promise<ProjectContext> {\n\tlet framework: Framework | undefined;\n\tlet packageManager: PackageManager | undefined;\n\n\tawait listrRun([\n\t\t{\n\t\t\ttitle: \"Detecting environment...\",\n\t\t\ttask: (_, parentTask) =>\n\t\t\t\tlistr([\n\t\t\t\t\t{\n\t\t\t\t\t\ttitle: \"Detecting framework...\",\n\t\t\t\t\t\ttask: async (_, task) => {\n\t\t\t\t\t\t\tframework = await detectFramework(manager.cwd);\n\n\t\t\t\t\t\t\t// Update Sentry context for the framework\n\t\t\t\t\t\t\tupdateSentryContext({ framework: framework.telemetryID });\n\n\t\t\t\t\t\t\ttask.title = `Detected framework ${chalk.cyan(framework.name)}`;\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttitle: \"Detecting package manager...\",\n\t\t\t\t\t\ttask: async (_, task) => {\n\t\t\t\t\t\t\tpackageManager = await manager.project.detectPackageManager({\n\t\t\t\t\t\t\t\troot: manager.cwd,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\ttask.title = `Detected package manager ${chalk.cyan(\n\t\t\t\t\t\t\t\tpackageManager,\n\t\t\t\t\t\t\t)}`;\n\n\t\t\t\t\t\t\tif (!framework) {\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\"Project framework must be available through context to proceed\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tparentTask.title = `Detected framework ${chalk.cyan(\n\t\t\t\t\t\t\t\tframework.name,\n\t\t\t\t\t\t\t)} and package manager ${chalk.cyan(packageManager)}`;\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]),\n\t\t},\n\t]);\n\n\tif (!framework) {\n\t\tthrow new Error(\n\t\t\t\"Project framework must be available through context to proceed\",\n\t\t);\n\t}\n\n\tif (!packageManager) {\n\t\tthrow new Error(\n\t\t\t\"Project package manager must be available through context to proceed\",\n\t\t);\n\t}\n\n\treturn {\n\t\tframework,\n\t\tpackageManager,\n\t};\n}\n\ntype CreatePrismicConfigArgs = {\n\tmanager: PrismicManager;\n\tprojectContext: ProjectContext;\n\trepositoryName: string;\n};\n\nexport async function createPrismicConfig(\n\targs: CreatePrismicConfigArgs,\n): Promise<void> {\n\tconst { manager, projectContext, repositoryName } = args;\n\tconst { framework } = projectContext;\n\n\treturn listrRun([\n\t\t{\n\t\t\ttitle: \"Creating Prismic configuration...\",\n\t\t\ttask: async (_, parentTask) => {\n\t\t\t\tparentTask.title = \"Creating Prismic configuration...\";\n\n\t\t\t\tconst prismicConfigPath =\n\t\t\t\t\tawait manager.project.suggestPrismicConfigPath();\n\n\t\t\t\tawait manager.project.writePrismicConfig({\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\trepositoryName,\n\t\t\t\t\t\tadapter: framework.adapterName,\n\t\t\t\t\t\tlibraries: [\"./slices\"],\n\t\t\t\t\t},\n\t\t\t\t\tpath: prismicConfigPath,\n\t\t\t\t});\n\n\t\t\t\tparentTask.title = \"Created Prismic configuration\";\n\t\t\t},\n\t\t},\n\t]);\n}\n"],"names":["_"],"mappings":";;;;AAgBA,eAAsB,mBACrB,MAA4B;AAE5B,QAAM,EAAE,SAAS,YAAA,IAAgB;AAEjC,MAAI;AAEJ,MAAI;AACH,oBAAgB,MAAM,QAAQ,QAAQ,iBAAA;AAAA,EACvC,QAAQ;AAAA,EAER;AAEA,QAAM,qBAAqB,MAAM,QAAQ,QAAQ,wBAAA;AAEjD,MAAI,gBAAgB,WAAW,iBAAiB,qBAAqB;AACpE,UAAM,IAAI,MAAM,uCAAuC;AAAA,EACxD,WAAW,gBAAgB,UAAU,CAAC,eAAe;AACpD,QAAI,oBAAoB;AACvB,YAAM,QAAQ,QAAQ,oBAAA;AAAA,IACvB,OAAO;AACN,YAAM,IAAI,MAAM,iDAAiD;AAAA,IAClE;AAAA,EACD;AACD;AAOA,eAAsB,qBACrB,SAAuB;AAEvB,MAAI;AACJ,MAAI;AAEJ,QAAM,SAAS;AAAA,IACd;AAAA,MACC,OAAO;AAAA,MACP,MAAM,CAAC,GAAG,eACT,MAAM;AAAA,QACL;AAAA,UACC,OAAO;AAAA,UACP,MAAM,OAAOA,IAAG,SAAQ;AACvB,wBAAY,MAAM,gBAAgB,QAAQ,GAAG;AAG7C,gCAAoB,EAAE,WAAW,UAAU,YAAA,CAAa;AAExD,iBAAK,QAAQ,sBAAsB,MAAM,KAAK,UAAU,IAAI,CAAC;AAAA,UAC9D;AAAA,QAAA;AAAA,QAED;AAAA,UACC,OAAO;AAAA,UACP,MAAM,OAAOA,IAAG,SAAQ;AACvB,6BAAiB,MAAM,QAAQ,QAAQ,qBAAqB;AAAA,cAC3D,MAAM,QAAQ;AAAA,YAAA,CACd;AAED,iBAAK,QAAQ,4BAA4B,MAAM,KAC9C,cAAc,CACd;AAED,gBAAI,CAAC,WAAW;AACf,oBAAM,IAAI,MACT,gEAAgE;AAAA,YAElE;AAEA,uBAAW,QAAQ,sBAAsB,MAAM,KAC9C,UAAU,IAAI,CACd,wBAAwB,MAAM,KAAK,cAAc,CAAC;AAAA,UACpD;AAAA,QAAA;AAAA,MACA,CACD;AAAA,IAAA;AAAA,EACF,CACD;AAED,MAAI,CAAC,WAAW;AACf,UAAM,IAAI,MACT,gEAAgE;AAAA,EAElE;AAEA,MAAI,CAAC,gBAAgB;AACpB,UAAM,IAAI,MACT,sEAAsE;AAAA,EAExE;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;AAQA,eAAsB,oBACrB,MAA6B;AAE7B,QAAM,EAAE,SAAS,gBAAgB,eAAA,IAAmB;AACpD,QAAM,EAAE,cAAc;AAEtB,SAAO,SAAS;AAAA,IACf;AAAA,MACC,OAAO;AAAA,MACP,MAAM,OAAO,GAAG,eAAc;AAC7B,mBAAW,QAAQ;AAEnB,cAAM,oBACL,MAAM,QAAQ,QAAQ,yBAAA;AAEvB,cAAM,QAAQ,QAAQ,mBAAmB;AAAA,UACxC,QAAQ;AAAA,YACP;AAAA,YACA,SAAS,UAAU;AAAA,YACnB,WAAW,CAAC,UAAU;AAAA,UAAA;AAAA,UAEvB,MAAM;AAAA,QAAA,CACN;AAED,mBAAW,QAAQ;AAAA,MACpB;AAAA,IAAA;AAAA,EACA,CACD;AACF;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { listrRun } from "../utils/listr.js";
|
|
2
|
+
import { updateSentryContext } from "../utils/sentry.js";
|
|
3
|
+
async function validateRepository(args) {
|
|
4
|
+
const { manager, repository } = args;
|
|
5
|
+
return listrRun([
|
|
6
|
+
{
|
|
7
|
+
title: `Validating repository...`,
|
|
8
|
+
task: async (_, task) => {
|
|
9
|
+
updateSentryContext({ repositoryName: repository });
|
|
10
|
+
const repositoryExists = await manager.prismicRepository.checkExists({
|
|
11
|
+
domain: repository
|
|
12
|
+
});
|
|
13
|
+
if (!repositoryExists) {
|
|
14
|
+
throw new Error(`Repository ${repository} does not exist.`);
|
|
15
|
+
}
|
|
16
|
+
const userRepositories = await manager.prismicRepository.readAll();
|
|
17
|
+
const userSelectedRepository = userRepositories.find((repo) => repo.domain === repository);
|
|
18
|
+
if (!userSelectedRepository) {
|
|
19
|
+
throw new Error(`You're not part of the repository ${repository}.`);
|
|
20
|
+
}
|
|
21
|
+
const hasWriteAccess = await manager.prismicRepository.hasWriteAccess(userSelectedRepository);
|
|
22
|
+
if (!hasWriteAccess) {
|
|
23
|
+
throw new Error(`You do not have administrator access to repository ${repository}.`);
|
|
24
|
+
}
|
|
25
|
+
task.title = `Validated repository (${repository})`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
validateRepository
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sources":["../../../src/core/repository.ts"],"sourcesContent":["import type { PrismicManager } from \"@prismicio/manager\";\n\nimport { listrRun } from \"../utils/listr\";\nimport { updateSentryContext } from \"../utils/sentry\";\n\nexport type ValidateRepositoryArgs = {\n\tmanager: PrismicManager;\n\trepository: string;\n};\n\nexport async function validateRepository(\n\targs: ValidateRepositoryArgs,\n): Promise<void> {\n\tconst { manager, repository } = args;\n\n\treturn listrRun([\n\t\t{\n\t\t\ttitle: `Validating repository...`,\n\t\t\ttask: async (_, task) => {\n\t\t\t\t// Update Sentry context for the repository name\n\t\t\t\tupdateSentryContext({ repositoryName: repository });\n\n\t\t\t\tconst repositoryExists = await manager.prismicRepository.checkExists({\n\t\t\t\t\tdomain: repository,\n\t\t\t\t});\n\t\t\t\tif (!repositoryExists) {\n\t\t\t\t\tthrow new Error(`Repository ${repository} does not exist.`);\n\t\t\t\t}\n\n\t\t\t\tconst userRepositories = await manager.prismicRepository.readAll();\n\t\t\t\tconst userSelectedRepository = userRepositories.find(\n\t\t\t\t\t(repo) => repo.domain === repository,\n\t\t\t\t);\n\t\t\t\tif (!userSelectedRepository) {\n\t\t\t\t\tthrow new Error(`You're not part of the repository ${repository}.`);\n\t\t\t\t}\n\n\t\t\t\tconst hasWriteAccess = await manager.prismicRepository.hasWriteAccess(\n\t\t\t\t\tuserSelectedRepository,\n\t\t\t\t);\n\t\t\t\tif (!hasWriteAccess) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`You do not have administrator access to repository ${repository}.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\ttask.title = `Validated repository (${repository})`;\n\t\t\t},\n\t\t},\n\t]);\n}\n"],"names":[],"mappings":";;AAUA,eAAsB,mBACrB,MAA4B;AAE5B,QAAM,EAAE,SAAS,WAAA,IAAe;AAEhC,SAAO,SAAS;AAAA,IACf;AAAA,MACC,OAAO;AAAA,MACP,MAAM,OAAO,GAAG,SAAQ;AAEvB,4BAAoB,EAAE,gBAAgB,YAAY;AAElD,cAAM,mBAAmB,MAAM,QAAQ,kBAAkB,YAAY;AAAA,UACpE,QAAQ;AAAA,QAAA,CACR;AACD,YAAI,CAAC,kBAAkB;AACtB,gBAAM,IAAI,MAAM,cAAc,UAAU,kBAAkB;AAAA,QAC3D;AAEA,cAAM,mBAAmB,MAAM,QAAQ,kBAAkB,QAAA;AACzD,cAAM,yBAAyB,iBAAiB,KAC/C,CAAC,SAAS,KAAK,WAAW,UAAU;AAErC,YAAI,CAAC,wBAAwB;AAC5B,gBAAM,IAAI,MAAM,qCAAqC,UAAU,GAAG;AAAA,QACnE;AAEA,cAAM,iBAAiB,MAAM,QAAQ,kBAAkB,eACtD,sBAAsB;AAEvB,YAAI,CAAC,gBAAgB;AACpB,gBAAM,IAAI,MACT,sDAAsD,UAAU,GAAG;AAAA,QAErE;AAEA,aAAK,QAAQ,yBAAyB,UAAU;AAAA,MACjD;AAAA,IAAA;AAAA,EACA,CACD;AACF;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { listrRun } from "../utils/listr.js";
|
|
2
|
+
async function saveSlices(args) {
|
|
3
|
+
const { manager } = args;
|
|
4
|
+
await listrRun([
|
|
5
|
+
{
|
|
6
|
+
title: "Fetching Prismic slices...",
|
|
7
|
+
task: async (_, parentTask) => {
|
|
8
|
+
const slices = await manager.slices.fetchRemoteSlices();
|
|
9
|
+
parentTask.title = "Saving Prismic slices changes...";
|
|
10
|
+
const localSlices = await manager.slices.readAllSlices();
|
|
11
|
+
for (const remoteSlice of slices) {
|
|
12
|
+
const localSlice = localSlices.models.find((local) => local.model.id === remoteSlice.id);
|
|
13
|
+
if (localSlice) {
|
|
14
|
+
await manager.slices.updateSlice({
|
|
15
|
+
libraryID: localSlice.libraryID,
|
|
16
|
+
model: remoteSlice
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const localSlice of localSlices.models) {
|
|
21
|
+
const existsRemotely = slices.some((slice) => slice.id === localSlice.model.id);
|
|
22
|
+
if (!existsRemotely) {
|
|
23
|
+
await manager.slices.deleteSlice({
|
|
24
|
+
libraryID: localSlice.libraryID,
|
|
25
|
+
sliceID: localSlice.model.id
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const defaultLibraryID = await manager.slices.getDefaultLibraryID();
|
|
30
|
+
for (const remoteSlice of slices) {
|
|
31
|
+
const existsLocally = localSlices.models.some((localSlice) => localSlice.model.id === remoteSlice.id);
|
|
32
|
+
if (!existsLocally) {
|
|
33
|
+
await manager.slices.createSlice({
|
|
34
|
+
libraryID: defaultLibraryID,
|
|
35
|
+
model: remoteSlice
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
parentTask.title = "Prismic slices changes saved";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
saveSlices
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=slices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slices.js","sources":["../../../src/core/slices.ts"],"sourcesContent":["import type { PrismicManager } from \"@prismicio/manager\";\n\nimport { listrRun } from \"../utils/listr\";\n\ntype SaveSlicesArgs = {\n\tmanager: PrismicManager;\n};\n\nexport async function saveSlices(args: SaveSlicesArgs): Promise<void> {\n\tconst { manager } = args;\n\n\t// Save slices to local directory\n\tawait listrRun([\n\t\t{\n\t\t\ttitle: \"Fetching Prismic slices...\",\n\t\t\ttask: async (_, parentTask) => {\n\t\t\t\tconst slices = await manager.slices.fetchRemoteSlices();\n\n\t\t\t\tparentTask.title = \"Saving Prismic slices changes...\";\n\n\t\t\t\tconst localSlices = await manager.slices.readAllSlices();\n\n\t\t\t\t// Handle slices update\n\t\t\t\tfor (const remoteSlice of slices) {\n\t\t\t\t\tconst localSlice = localSlices.models.find(\n\t\t\t\t\t\t(local) => local.model.id === remoteSlice.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (localSlice) {\n\t\t\t\t\t\tawait manager.slices.updateSlice({\n\t\t\t\t\t\t\tlibraryID: localSlice.libraryID,\n\t\t\t\t\t\t\tmodel: remoteSlice,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle slices deletion\n\t\t\t\tfor (const localSlice of localSlices.models) {\n\t\t\t\t\tconst existsRemotely = slices.some(\n\t\t\t\t\t\t(slice) => slice.id === localSlice.model.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (!existsRemotely) {\n\t\t\t\t\t\tawait manager.slices.deleteSlice({\n\t\t\t\t\t\t\tlibraryID: localSlice.libraryID,\n\t\t\t\t\t\t\tsliceID: localSlice.model.id,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Handle slices creation\n\t\t\t\tconst defaultLibraryID = await manager.slices.getDefaultLibraryID();\n\t\t\t\tfor (const remoteSlice of slices) {\n\t\t\t\t\tconst existsLocally = localSlices.models.some(\n\t\t\t\t\t\t(localSlice) => localSlice.model.id === remoteSlice.id,\n\t\t\t\t\t);\n\t\t\t\t\tif (!existsLocally) {\n\t\t\t\t\t\tawait manager.slices.createSlice({\n\t\t\t\t\t\t\tlibraryID: defaultLibraryID,\n\t\t\t\t\t\t\tmodel: remoteSlice,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tparentTask.title = \"Prismic slices changes saved\";\n\t\t\t},\n\t\t},\n\t]);\n}\n"],"names":[],"mappings":";AAQA,eAAsB,WAAW,MAAoB;AACpD,QAAM,EAAE,YAAY;AAGpB,QAAM,SAAS;AAAA,IACd;AAAA,MACC,OAAO;AAAA,MACP,MAAM,OAAO,GAAG,eAAc;AAC7B,cAAM,SAAS,MAAM,QAAQ,OAAO,kBAAA;AAEpC,mBAAW,QAAQ;AAEnB,cAAM,cAAc,MAAM,QAAQ,OAAO,cAAA;AAGzC,mBAAW,eAAe,QAAQ;AACjC,gBAAM,aAAa,YAAY,OAAO,KACrC,CAAC,UAAU,MAAM,MAAM,OAAO,YAAY,EAAE;AAE7C,cAAI,YAAY;AACf,kBAAM,QAAQ,OAAO,YAAY;AAAA,cAChC,WAAW,WAAW;AAAA,cACtB,OAAO;AAAA,YAAA,CACP;AAAA,UACF;AAAA,QACD;AAGA,mBAAW,cAAc,YAAY,QAAQ;AAC5C,gBAAM,iBAAiB,OAAO,KAC7B,CAAC,UAAU,MAAM,OAAO,WAAW,MAAM,EAAE;AAE5C,cAAI,CAAC,gBAAgB;AACpB,kBAAM,QAAQ,OAAO,YAAY;AAAA,cAChC,WAAW,WAAW;AAAA,cACtB,SAAS,WAAW,MAAM;AAAA,YAAA,CAC1B;AAAA,UACF;AAAA,QACD;AAGA,cAAM,mBAAmB,MAAM,QAAQ,OAAO,oBAAA;AAC9C,mBAAW,eAAe,QAAQ;AACjC,gBAAM,gBAAgB,YAAY,OAAO,KACxC,CAAC,eAAe,WAAW,MAAM,OAAO,YAAY,EAAE;AAEvD,cAAI,CAAC,eAAe;AACnB,kBAAM,QAAQ,OAAO,YAAY;AAAA,cAChC,WAAW;AAAA,cACX,OAAO;AAAA,YAAA,CACP;AAAA,UACF;AAAA,QACD;AAEA,mBAAW,QAAQ;AAAA,MACpB;AAAA,IAAA;AAAA,EACA,CACD;AACF;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PrismicManager } from "@prismicio/manager";
|
|
2
|
+
type CheckCLIVersionArgs = {
|
|
3
|
+
manager: PrismicManager;
|
|
4
|
+
currentVersion: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the current CLI version is the latest available version. Throws an
|
|
8
|
+
* Error if the version is outdated.
|
|
9
|
+
*
|
|
10
|
+
* @param args - Arguments object containing the manager and current version.
|
|
11
|
+
*
|
|
12
|
+
* @throws Error If the current version is not the latest.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkCLIVersion(args: CheckCLIVersionArgs): Promise<void>;
|
|
15
|
+
export {};
|