@slicemachine/adapter-next 0.3.10 → 0.3.11-dev-next-release.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/dist/hooks/documentation-read.cjs +7 -6
- package/dist/hooks/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js +7 -6
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs +51 -58
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +51 -57
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +29 -44
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +29 -26
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/lib/checkHasAppRouter.cjs +23 -2
- package/dist/lib/checkHasAppRouter.cjs.map +1 -1
- package/dist/lib/checkHasAppRouter.js +6 -2
- package/dist/lib/checkHasAppRouter.js.map +1 -1
- package/dist/lib/checkHasSrcDirectory.cjs +5 -2
- package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
- package/dist/lib/checkHasSrcDirectory.js +5 -2
- package/dist/lib/checkHasSrcDirectory.js.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.js +2 -3
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +29 -21
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +29 -20
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/plugin.cjs +178 -36
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +178 -36
- package/dist/plugin.js.map +1 -1
- package/package.json +5 -7
- package/src/hooks/documentation-read.ts +9 -7
- package/src/hooks/project-init.ts +58 -69
- package/src/hooks/slice-create.ts +39 -31
- package/src/lib/checkHasAppRouter.ts +6 -6
- package/src/lib/checkHasSrcDirectory.ts +5 -2
- package/src/lib/checkIsTypeScriptProject.ts +5 -4
- package/src/lib/upsertSliceLibraryIndexFile.ts +53 -33
- package/src/plugin.ts +245 -37
- package/dist/hooks/customType-asset-delete.cjs +0 -31
- package/dist/hooks/customType-asset-delete.cjs.map +0 -1
- package/dist/hooks/customType-asset-delete.d.ts +0 -3
- package/dist/hooks/customType-asset-delete.js +0 -14
- package/dist/hooks/customType-asset-delete.js.map +0 -1
- package/dist/hooks/customType-asset-read.cjs +0 -34
- package/dist/hooks/customType-asset-read.cjs.map +0 -1
- package/dist/hooks/customType-asset-read.d.ts +0 -3
- package/dist/hooks/customType-asset-read.js +0 -17
- package/dist/hooks/customType-asset-read.js.map +0 -1
- package/dist/hooks/customType-asset-update.cjs +0 -34
- package/dist/hooks/customType-asset-update.cjs.map +0 -1
- package/dist/hooks/customType-asset-update.d.ts +0 -3
- package/dist/hooks/customType-asset-update.js +0 -16
- package/dist/hooks/customType-asset-update.js.map +0 -1
- package/dist/hooks/customType-create.cjs +0 -43
- package/dist/hooks/customType-create.cjs.map +0 -1
- package/dist/hooks/customType-create.d.ts +0 -3
- package/dist/hooks/customType-create.js +0 -25
- package/dist/hooks/customType-create.js.map +0 -1
- package/dist/hooks/customType-delete.cjs +0 -32
- package/dist/hooks/customType-delete.cjs.map +0 -1
- package/dist/hooks/customType-delete.d.ts +0 -3
- package/dist/hooks/customType-delete.js +0 -15
- package/dist/hooks/customType-delete.js.map +0 -1
- package/dist/hooks/customType-read.cjs +0 -31
- package/dist/hooks/customType-read.cjs.map +0 -1
- package/dist/hooks/customType-read.d.ts +0 -3
- package/dist/hooks/customType-read.js +0 -14
- package/dist/hooks/customType-read.js.map +0 -1
- package/dist/hooks/customType-rename.cjs +0 -6
- package/dist/hooks/customType-rename.cjs.map +0 -1
- package/dist/hooks/customType-rename.d.ts +0 -1
- package/dist/hooks/customType-rename.js +0 -6
- package/dist/hooks/customType-rename.js.map +0 -1
- package/dist/hooks/customType-update.cjs +0 -6
- package/dist/hooks/customType-update.cjs.map +0 -1
- package/dist/hooks/customType-update.d.ts +0 -1
- package/dist/hooks/customType-update.js +0 -6
- package/dist/hooks/customType-update.js.map +0 -1
- package/dist/hooks/customTypeLibrary-read.cjs +0 -55
- package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
- package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
- package/dist/hooks/customTypeLibrary-read.js +0 -37
- package/dist/hooks/customTypeLibrary-read.js.map +0 -1
- package/dist/hooks/slice-asset-delete.cjs +0 -33
- package/dist/hooks/slice-asset-delete.cjs.map +0 -1
- package/dist/hooks/slice-asset-delete.d.ts +0 -3
- package/dist/hooks/slice-asset-delete.js +0 -16
- package/dist/hooks/slice-asset-delete.js.map +0 -1
- package/dist/hooks/slice-asset-read.cjs +0 -36
- package/dist/hooks/slice-asset-read.cjs.map +0 -1
- package/dist/hooks/slice-asset-read.d.ts +0 -3
- package/dist/hooks/slice-asset-read.js +0 -19
- package/dist/hooks/slice-asset-read.js.map +0 -1
- package/dist/hooks/slice-asset-update.cjs +0 -36
- package/dist/hooks/slice-asset-update.cjs.map +0 -1
- package/dist/hooks/slice-asset-update.d.ts +0 -3
- package/dist/hooks/slice-asset-update.js +0 -18
- package/dist/hooks/slice-asset-update.js.map +0 -1
- package/dist/hooks/slice-delete.cjs +0 -41
- package/dist/hooks/slice-delete.cjs.map +0 -1
- package/dist/hooks/slice-delete.d.ts +0 -3
- package/dist/hooks/slice-delete.js +0 -24
- package/dist/hooks/slice-delete.js.map +0 -1
- package/dist/hooks/slice-read.cjs +0 -62
- package/dist/hooks/slice-read.cjs.map +0 -1
- package/dist/hooks/slice-read.d.ts +0 -3
- package/dist/hooks/slice-read.js +0 -44
- package/dist/hooks/slice-read.js.map +0 -1
- package/dist/hooks/slice-rename.cjs +0 -51
- package/dist/hooks/slice-rename.cjs.map +0 -1
- package/dist/hooks/slice-rename.d.ts +0 -3
- package/dist/hooks/slice-rename.js +0 -34
- package/dist/hooks/slice-rename.js.map +0 -1
- package/dist/hooks/slice-update.cjs +0 -14
- package/dist/hooks/slice-update.cjs.map +0 -1
- package/dist/hooks/slice-update.d.ts +0 -3
- package/dist/hooks/slice-update.js +0 -14
- package/dist/hooks/slice-update.js.map +0 -1
- package/dist/hooks/sliceLibrary-read.cjs +0 -52
- package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
- package/dist/hooks/sliceLibrary-read.d.ts +0 -3
- package/dist/hooks/sliceLibrary-read.js +0 -34
- package/dist/hooks/sliceLibrary-read.js.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
- package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
- package/dist/lib/buildCustomTypeAssetPath.js +0 -12
- package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
- package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
- package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
- package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceAssetPath.cjs +0 -34
- package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
- package/dist/lib/buildSliceAssetPath.d.ts +0 -11
- package/dist/lib/buildSliceAssetPath.js +0 -17
- package/dist/lib/buildSliceAssetPath.js.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
- package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
- package/dist/lib/buildSliceDirectoryPath.js +0 -13
- package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
- package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/checkPathExists.cjs +0 -30
- package/dist/lib/checkPathExists.cjs.map +0 -1
- package/dist/lib/checkPathExists.d.ts +0 -2
- package/dist/lib/checkPathExists.js +0 -13
- package/dist/lib/checkPathExists.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -7
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -335
- package/dist/lib/isSharedSliceModel.js +0 -7
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/readJSONFile.cjs +0 -26
- package/dist/lib/readJSONFile.cjs.map +0 -1
- package/dist/lib/readJSONFile.d.ts +0 -1
- package/dist/lib/readJSONFile.js +0 -9
- package/dist/lib/readJSONFile.js.map +0 -1
- package/dist/lib/updateSliceModelFile.cjs +0 -33
- package/dist/lib/updateSliceModelFile.cjs.map +0 -1
- package/dist/lib/updateSliceModelFile.d.ts +0 -9
- package/dist/lib/updateSliceModelFile.js +0 -15
- package/dist/lib/updateSliceModelFile.js.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
- package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
- package/dist/lib/upsertGlobalContentTypes.js +0 -38
- package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
- package/src/hooks/customType-asset-delete.ts +0 -18
- package/src/hooks/customType-asset-read.ts +0 -22
- package/src/hooks/customType-asset-update.ts +0 -20
- package/src/hooks/customType-create.ts +0 -45
- package/src/hooks/customType-delete.ts +0 -21
- package/src/hooks/customType-read.ts +0 -24
- package/src/hooks/customType-rename.ts +0 -3
- package/src/hooks/customType-update.ts +0 -3
- package/src/hooks/customTypeLibrary-read.ts +0 -58
- package/src/hooks/slice-asset-delete.ts +0 -21
- package/src/hooks/slice-asset-read.ts +0 -25
- package/src/hooks/slice-asset-update.ts +0 -23
- package/src/hooks/slice-delete.ts +0 -41
- package/src/hooks/slice-read.ts +0 -69
- package/src/hooks/slice-rename.ts +0 -46
- package/src/hooks/slice-update.ts +0 -19
- package/src/hooks/sliceLibrary-read.ts +0 -48
- package/src/lib/buildCustomTypeAssetPath.ts +0 -24
- package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
- package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
- package/src/lib/buildSliceAssetPath.ts +0 -32
- package/src/lib/buildSliceDirectoryPath.ts +0 -26
- package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
- package/src/lib/checkPathExists.ts +0 -12
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/readJSONFile.ts +0 -7
- package/src/lib/updateSliceModelFile.ts +0 -33
- package/src/lib/upsertGlobalContentTypes.ts +0 -63
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
1
|
import * as path from "node:path";
|
|
3
2
|
import type {
|
|
4
3
|
ProjectInitHook,
|
|
5
4
|
ProjectInitHookData,
|
|
6
5
|
SliceMachineContext,
|
|
7
6
|
} from "@slicemachine/plugin-kit";
|
|
7
|
+
import {
|
|
8
|
+
checkHasProjectFile,
|
|
9
|
+
writeProjectFile,
|
|
10
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
8
11
|
import { source } from "common-tags";
|
|
9
12
|
|
|
10
13
|
import { checkHasAppRouter } from "../lib/checkHasAppRouter";
|
|
11
14
|
import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory";
|
|
12
15
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
13
|
-
import { checkPathExists } from "../lib/checkPathExists";
|
|
14
16
|
import { getJSFileExtension } from "../lib/getJSFileExtension";
|
|
15
17
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
16
18
|
|
|
@@ -46,12 +48,13 @@ const createPrismicIOFile = async ({
|
|
|
46
48
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
47
49
|
|
|
48
50
|
const extension = await getJSFileExtension({ helpers, options });
|
|
49
|
-
const filename =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const filename = path.join(
|
|
52
|
+
...[hasSrcDirectory ? "src" : undefined, `prismicio.${extension}`].filter(
|
|
53
|
+
(segment): segment is NonNullable<typeof segment> => Boolean(segment),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
53
56
|
|
|
54
|
-
if (await
|
|
57
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -229,11 +232,12 @@ const createPrismicIOFile = async ({
|
|
|
229
232
|
`;
|
|
230
233
|
}
|
|
231
234
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
await writeProjectFile({
|
|
236
|
+
filename,
|
|
237
|
+
contents,
|
|
238
|
+
format: options.format,
|
|
239
|
+
helpers,
|
|
240
|
+
});
|
|
237
241
|
};
|
|
238
242
|
|
|
239
243
|
type CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;
|
|
@@ -246,7 +250,7 @@ const createSliceSimulatorPage = async ({
|
|
|
246
250
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
247
251
|
|
|
248
252
|
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
249
|
-
const
|
|
253
|
+
const filename = path.join(
|
|
250
254
|
...[
|
|
251
255
|
hasSrcDirectory ? "src" : undefined,
|
|
252
256
|
hasAppRouter
|
|
@@ -257,13 +261,11 @@ const createSliceSimulatorPage = async ({
|
|
|
257
261
|
),
|
|
258
262
|
);
|
|
259
263
|
|
|
260
|
-
if (await
|
|
264
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
261
265
|
return;
|
|
262
266
|
}
|
|
263
267
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
let contents = source`
|
|
268
|
+
const contents = source`
|
|
267
269
|
"use client"
|
|
268
270
|
|
|
269
271
|
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
@@ -280,11 +282,12 @@ const createSliceSimulatorPage = async ({
|
|
|
280
282
|
}
|
|
281
283
|
`;
|
|
282
284
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
await writeProjectFile({
|
|
286
|
+
filename,
|
|
287
|
+
contents,
|
|
288
|
+
format: options.format,
|
|
289
|
+
helpers,
|
|
290
|
+
});
|
|
288
291
|
};
|
|
289
292
|
|
|
290
293
|
const createPreviewRoute = async ({
|
|
@@ -299,7 +302,7 @@ const createPreviewRoute = async ({
|
|
|
299
302
|
});
|
|
300
303
|
|
|
301
304
|
const extension = await getJSFileExtension({ helpers, options });
|
|
302
|
-
const
|
|
305
|
+
const filename = path.join(
|
|
303
306
|
...[
|
|
304
307
|
hasSrcDirectory ? "src" : undefined,
|
|
305
308
|
hasAppRouter
|
|
@@ -310,7 +313,7 @@ const createPreviewRoute = async ({
|
|
|
310
313
|
),
|
|
311
314
|
);
|
|
312
315
|
|
|
313
|
-
if (await
|
|
316
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
314
317
|
return;
|
|
315
318
|
}
|
|
316
319
|
|
|
@@ -320,7 +323,6 @@ const createPreviewRoute = async ({
|
|
|
320
323
|
if (isTypeScriptProject) {
|
|
321
324
|
contents = source`
|
|
322
325
|
import { NextRequest } from "next/server";
|
|
323
|
-
import { draftMode } from "next/headers";
|
|
324
326
|
import { redirectToPreviewURL } from "@prismicio/next";
|
|
325
327
|
|
|
326
328
|
import { createClient } from "../../../prismicio";
|
|
@@ -328,14 +330,11 @@ const createPreviewRoute = async ({
|
|
|
328
330
|
export async function GET(request: NextRequest) {
|
|
329
331
|
const client = createClient();
|
|
330
332
|
|
|
331
|
-
draftMode().enable();
|
|
332
|
-
|
|
333
333
|
await redirectToPreviewURL({ client, request });
|
|
334
334
|
}
|
|
335
335
|
`;
|
|
336
336
|
} else {
|
|
337
337
|
contents = source`
|
|
338
|
-
import { draftMode } from "next/headers";
|
|
339
338
|
import { redirectToPreviewURL } from "@prismicio/next";
|
|
340
339
|
|
|
341
340
|
import { createClient } from "../../../prismicio";
|
|
@@ -343,8 +342,6 @@ const createPreviewRoute = async ({
|
|
|
343
342
|
export async function GET(request) {
|
|
344
343
|
const client = createClient();
|
|
345
344
|
|
|
346
|
-
draftMode().enable();
|
|
347
|
-
|
|
348
345
|
await redirectToPreviewURL({ client, request });
|
|
349
346
|
}
|
|
350
347
|
`;
|
|
@@ -382,12 +379,12 @@ const createPreviewRoute = async ({
|
|
|
382
379
|
}
|
|
383
380
|
}
|
|
384
381
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
382
|
+
await writeProjectFile({
|
|
383
|
+
filename,
|
|
384
|
+
contents,
|
|
385
|
+
format: options.format,
|
|
386
|
+
helpers,
|
|
387
|
+
});
|
|
391
388
|
};
|
|
392
389
|
|
|
393
390
|
const createExitPreviewRoute = async ({
|
|
@@ -402,7 +399,7 @@ const createExitPreviewRoute = async ({
|
|
|
402
399
|
});
|
|
403
400
|
|
|
404
401
|
const extension = await getJSFileExtension({ helpers, options });
|
|
405
|
-
const
|
|
402
|
+
const filename = path.join(
|
|
406
403
|
...[
|
|
407
404
|
hasSrcDirectory ? "src" : undefined,
|
|
408
405
|
hasAppRouter
|
|
@@ -413,14 +410,14 @@ const createExitPreviewRoute = async ({
|
|
|
413
410
|
),
|
|
414
411
|
);
|
|
415
412
|
|
|
416
|
-
if (await
|
|
413
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
417
414
|
return;
|
|
418
415
|
}
|
|
419
416
|
|
|
420
417
|
let contents: string;
|
|
421
418
|
|
|
422
419
|
if (hasAppRouter) {
|
|
423
|
-
contents = `
|
|
420
|
+
contents = source`
|
|
424
421
|
import { exitPreview } from "@prismicio/next";
|
|
425
422
|
|
|
426
423
|
export async function GET() {
|
|
@@ -448,17 +445,18 @@ const createExitPreviewRoute = async ({
|
|
|
448
445
|
}
|
|
449
446
|
}
|
|
450
447
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
448
|
+
await writeProjectFile({
|
|
449
|
+
filename,
|
|
450
|
+
contents,
|
|
451
|
+
format: options.format,
|
|
452
|
+
helpers,
|
|
453
|
+
});
|
|
457
454
|
};
|
|
458
455
|
|
|
459
456
|
const modifySliceMachineConfig = async ({
|
|
460
457
|
helpers,
|
|
461
458
|
options,
|
|
459
|
+
actions,
|
|
462
460
|
}: SliceMachineContext<PluginOptions>) => {
|
|
463
461
|
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
464
462
|
const project = await helpers.getProject();
|
|
@@ -471,24 +469,15 @@ const modifySliceMachineConfig = async ({
|
|
|
471
469
|
// is empty.
|
|
472
470
|
if (
|
|
473
471
|
hasSrcDirectory &&
|
|
472
|
+
project.config.libraries &&
|
|
474
473
|
JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])
|
|
475
474
|
) {
|
|
476
|
-
|
|
477
|
-
|
|
475
|
+
const sliceLibrary = await actions.readSliceLibrary({
|
|
476
|
+
libraryID: project.config.libraries[0],
|
|
477
|
+
});
|
|
478
478
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
} catch (error) {
|
|
483
|
-
if (
|
|
484
|
-
error instanceof Error &&
|
|
485
|
-
"code" in error &&
|
|
486
|
-
error.code === "ENOENT"
|
|
487
|
-
) {
|
|
488
|
-
// The directory does not exist, which means we
|
|
489
|
-
// can safely nest the library.
|
|
490
|
-
project.config.libraries = ["./src/slices"];
|
|
491
|
-
}
|
|
479
|
+
if (sliceLibrary.sliceIDs.length < 1) {
|
|
480
|
+
project.config.libraries = ["./src/slices"];
|
|
492
481
|
}
|
|
493
482
|
}
|
|
494
483
|
|
|
@@ -510,7 +499,7 @@ const createRevalidateRoute = async ({
|
|
|
510
499
|
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
511
500
|
|
|
512
501
|
const extension = await getJSFileExtension({ helpers, options });
|
|
513
|
-
const
|
|
502
|
+
const filename = path.join(
|
|
514
503
|
...[
|
|
515
504
|
hasSrcDirectory ? "src" : undefined,
|
|
516
505
|
`app/api/revalidate/route.${extension}`,
|
|
@@ -519,11 +508,11 @@ const createRevalidateRoute = async ({
|
|
|
519
508
|
),
|
|
520
509
|
);
|
|
521
510
|
|
|
522
|
-
if (await
|
|
511
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
523
512
|
return;
|
|
524
513
|
}
|
|
525
514
|
|
|
526
|
-
|
|
515
|
+
const contents = source`
|
|
527
516
|
import { NextResponse } from "next/server";
|
|
528
517
|
import { revalidateTag } from "next/cache";
|
|
529
518
|
|
|
@@ -534,12 +523,12 @@ const createRevalidateRoute = async ({
|
|
|
534
523
|
}
|
|
535
524
|
`;
|
|
536
525
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
526
|
+
await writeProjectFile({
|
|
527
|
+
filename,
|
|
528
|
+
contents,
|
|
529
|
+
format: options.format,
|
|
530
|
+
helpers,
|
|
531
|
+
});
|
|
543
532
|
};
|
|
544
533
|
|
|
545
534
|
export const projectInit: ProjectInitHook<PluginOptions> = async (
|
|
@@ -3,31 +3,34 @@ import type {
|
|
|
3
3
|
SliceCreateHookData,
|
|
4
4
|
SliceMachineContext,
|
|
5
5
|
} from "@slicemachine/plugin-kit";
|
|
6
|
+
import {
|
|
7
|
+
upsertGlobalTypeScriptTypes,
|
|
8
|
+
writeSliceFile,
|
|
9
|
+
writeSliceModel,
|
|
10
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
6
11
|
import { stripIndent } from "common-tags";
|
|
7
|
-
import * as fs from "node:fs/promises";
|
|
8
|
-
import * as path from "node:path";
|
|
9
12
|
|
|
10
|
-
import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
|
|
11
13
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
12
14
|
import { getJSFileExtension } from "../lib/getJSFileExtension";
|
|
13
15
|
import { pascalCase } from "../lib/pascalCase";
|
|
14
16
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
15
|
-
import { updateSliceModelFile } from "../lib/updateSliceModelFile";
|
|
16
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
17
17
|
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
18
18
|
|
|
19
19
|
import type { PluginOptions } from "../types";
|
|
20
20
|
|
|
21
21
|
type Args = {
|
|
22
|
-
dir: string;
|
|
23
22
|
data: SliceCreateHookData;
|
|
24
23
|
} & SliceMachineContext<PluginOptions>;
|
|
25
24
|
|
|
26
|
-
const createComponentFile = async ({
|
|
25
|
+
const createComponentFile = async ({
|
|
26
|
+
data,
|
|
27
|
+
helpers,
|
|
28
|
+
actions,
|
|
29
|
+
options,
|
|
30
|
+
}: Args) => {
|
|
27
31
|
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const pascalName = pascalCase(model.name);
|
|
32
|
+
const filename = `index.${extension}`;
|
|
33
|
+
const pascalName = pascalCase(data.model.name);
|
|
31
34
|
|
|
32
35
|
let contents: string;
|
|
33
36
|
|
|
@@ -47,7 +50,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
47
50
|
export type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
|
-
* Component for "${model.name}" Slices.
|
|
53
|
+
* Component for "${data.model.name}" Slices.
|
|
51
54
|
*/
|
|
52
55
|
const ${pascalName} = ({ slice }: ${pascalName}Props): JSX.Element => {
|
|
53
56
|
return (
|
|
@@ -55,7 +58,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
55
58
|
data-slice-type={slice.slice_type}
|
|
56
59
|
data-slice-variation={slice.variation}
|
|
57
60
|
>
|
|
58
|
-
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
61
|
+
Placeholder component for ${data.model.id} (variation: {slice.variation}) Slices
|
|
59
62
|
</section>
|
|
60
63
|
);
|
|
61
64
|
};
|
|
@@ -75,7 +78,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
75
78
|
data-slice-type={slice.slice_type}
|
|
76
79
|
data-slice-variation={slice.variation}
|
|
77
80
|
>
|
|
78
|
-
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
81
|
+
Placeholder component for ${data.model.id} (variation: {slice.variation}) Slices
|
|
79
82
|
</section>
|
|
80
83
|
);
|
|
81
84
|
};
|
|
@@ -84,40 +87,45 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
84
87
|
`;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
await writeSliceFile({
|
|
91
|
+
libraryID: data.libraryID,
|
|
92
|
+
model: data.model,
|
|
93
|
+
filename,
|
|
94
|
+
contents,
|
|
95
|
+
format: options.format,
|
|
96
|
+
actions,
|
|
97
|
+
helpers,
|
|
98
|
+
});
|
|
92
99
|
};
|
|
93
100
|
|
|
94
101
|
export const sliceCreate: SliceCreateHook<PluginOptions> = async (
|
|
95
102
|
data,
|
|
96
103
|
context,
|
|
97
104
|
) => {
|
|
98
|
-
const dir = buildSliceDirectoryPath({
|
|
99
|
-
libraryID: data.libraryID,
|
|
100
|
-
model: data.model,
|
|
101
|
-
helpers: context.helpers,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await fs.mkdir(dir, { recursive: true });
|
|
105
|
-
|
|
106
105
|
rejectIfNecessary(
|
|
107
106
|
await Promise.allSettled([
|
|
108
|
-
|
|
107
|
+
writeSliceModel({
|
|
109
108
|
libraryID: data.libraryID,
|
|
110
109
|
model: data.model,
|
|
111
|
-
|
|
110
|
+
format: context.options.format,
|
|
111
|
+
helpers: context.helpers,
|
|
112
112
|
}),
|
|
113
|
-
createComponentFile({
|
|
113
|
+
createComponentFile({ data, ...context }),
|
|
114
114
|
]),
|
|
115
115
|
);
|
|
116
116
|
|
|
117
117
|
rejectIfNecessary(
|
|
118
118
|
await Promise.allSettled([
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
upsertSliceLibraryIndexFile({
|
|
120
|
+
libraryID: data.libraryID,
|
|
121
|
+
...context,
|
|
122
|
+
}),
|
|
123
|
+
upsertGlobalTypeScriptTypes({
|
|
124
|
+
filename: context.options.generatedTypesFilePath,
|
|
125
|
+
format: context.options.format,
|
|
126
|
+
helpers: context.helpers,
|
|
127
|
+
actions: context.actions,
|
|
128
|
+
}),
|
|
121
129
|
]),
|
|
122
130
|
);
|
|
123
131
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
+
import * as path from "node:path";
|
|
2
4
|
|
|
3
5
|
import { PluginOptions } from "../types";
|
|
4
6
|
import { checkHasSrcDirectory } from "./checkHasSrcDirectory";
|
|
5
|
-
import { checkPathExists } from "./checkPathExists";
|
|
6
7
|
|
|
7
8
|
type CheckHasAppRouterArgs = Pick<
|
|
8
9
|
SliceMachineContext<PluginOptions>,
|
|
@@ -14,9 +15,8 @@ export async function checkHasAppRouter(
|
|
|
14
15
|
): Promise<boolean> {
|
|
15
16
|
const hasSrcDirectory = await checkHasSrcDirectory({ helpers: args.helpers });
|
|
16
17
|
|
|
17
|
-
return await
|
|
18
|
-
hasSrcDirectory
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
18
|
+
return await checkHasProjectFile({
|
|
19
|
+
filename: hasSrcDirectory ? path.join("src", "app") : "app",
|
|
20
|
+
helpers: args.helpers,
|
|
21
|
+
});
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
2
3
|
|
|
3
4
|
import { PluginOptions } from "../types";
|
|
4
|
-
import { checkPathExists } from "./checkPathExists";
|
|
5
5
|
|
|
6
6
|
type CheckHasSrcDirectoryArgs = Pick<
|
|
7
7
|
SliceMachineContext<PluginOptions>,
|
|
@@ -11,5 +11,8 @@ type CheckHasSrcDirectoryArgs = Pick<
|
|
|
11
11
|
export async function checkHasSrcDirectory(
|
|
12
12
|
args: CheckHasSrcDirectoryArgs,
|
|
13
13
|
): Promise<boolean> {
|
|
14
|
-
return await
|
|
14
|
+
return await checkHasProjectFile({
|
|
15
|
+
filename: "src",
|
|
16
|
+
helpers: args.helpers,
|
|
17
|
+
});
|
|
15
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkIsTypeScriptProject as baseCheckIsTypeScriptProject } from "@slicemachine/plugin-kit/fs";
|
|
2
3
|
|
|
3
4
|
import { PluginOptions } from "../types";
|
|
4
|
-
import { checkPathExists } from "./checkPathExists";
|
|
5
5
|
|
|
6
6
|
type CheckIsTypeScriptProjectArgs = {
|
|
7
7
|
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
@@ -11,7 +11,8 @@ type CheckIsTypeScriptProjectArgs = {
|
|
|
11
11
|
export const checkIsTypeScriptProject = async (
|
|
12
12
|
args: CheckIsTypeScriptProjectArgs,
|
|
13
13
|
): Promise<boolean> => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return (
|
|
15
|
+
args.options.typescript ??
|
|
16
|
+
baseCheckIsTypeScriptProject({ helpers: args.helpers })
|
|
17
|
+
);
|
|
17
18
|
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import {
|
|
3
|
+
buildSliceDirectoryPath,
|
|
4
|
+
buildSliceLibraryDirectoryPath,
|
|
5
|
+
writeProjectFile,
|
|
6
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
2
7
|
import { stripIndent } from "common-tags";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
8
|
import * as path from "node:path";
|
|
5
9
|
import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
6
10
|
|
|
7
11
|
import { PluginOptions } from "../types";
|
|
8
12
|
|
|
9
13
|
import { pascalCase } from "./pascalCase";
|
|
10
|
-
import { buildSliceLibraryDirectoryPath } from "./buildSliceLibraryDirectoryPath";
|
|
11
14
|
import { getJSFileExtension } from "./getJSFileExtension";
|
|
12
15
|
|
|
13
16
|
type UpsertSliceLibraryIndexFileArgs = {
|
|
@@ -17,18 +20,6 @@ type UpsertSliceLibraryIndexFileArgs = {
|
|
|
17
20
|
export const upsertSliceLibraryIndexFile = async (
|
|
18
21
|
args: UpsertSliceLibraryIndexFileArgs,
|
|
19
22
|
): Promise<void> => {
|
|
20
|
-
const extension = await getJSFileExtension({
|
|
21
|
-
helpers: args.helpers,
|
|
22
|
-
options: args.options,
|
|
23
|
-
});
|
|
24
|
-
const filePath = path.join(
|
|
25
|
-
buildSliceLibraryDirectoryPath({
|
|
26
|
-
libraryID: args.libraryID,
|
|
27
|
-
helpers: args.helpers,
|
|
28
|
-
}),
|
|
29
|
-
`index.${extension}`,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
23
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
33
24
|
libraryID: args.libraryID,
|
|
34
25
|
});
|
|
@@ -42,28 +33,44 @@ export const upsertSliceLibraryIndexFile = async (
|
|
|
42
33
|
import dynamic from 'next/dynamic'
|
|
43
34
|
|
|
44
35
|
export const components = {
|
|
45
|
-
${
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
${(
|
|
37
|
+
await Promise.all(
|
|
38
|
+
slices.map(async (slice) => {
|
|
39
|
+
const id = slice.model.id;
|
|
40
|
+
const dirName = path.basename(
|
|
41
|
+
await buildSliceDirectoryPath({
|
|
42
|
+
model: slice.model,
|
|
43
|
+
helpers: args.helpers,
|
|
44
|
+
libraryID: args.libraryID,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
).join(",\n")}
|
|
53
52
|
}
|
|
54
53
|
`;
|
|
55
54
|
} else {
|
|
56
55
|
contents = stripIndent`
|
|
57
56
|
${NON_EDITABLE_FILE_BANNER}
|
|
58
57
|
|
|
59
|
-
${
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
${(
|
|
59
|
+
await Promise.all(
|
|
60
|
+
slices.map(async (slice) => {
|
|
61
|
+
const dirName = path.basename(
|
|
62
|
+
await buildSliceDirectoryPath({
|
|
63
|
+
model: slice.model,
|
|
64
|
+
helpers: args.helpers,
|
|
65
|
+
libraryID: args.libraryID,
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
const componentName = pascalCase(slice.model.name);
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
return `import ${componentName} from "./${dirName}";`;
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
).join("\n")}
|
|
67
74
|
|
|
68
75
|
export const components = {
|
|
69
76
|
${slices
|
|
@@ -78,9 +85,22 @@ export const upsertSliceLibraryIndexFile = async (
|
|
|
78
85
|
`;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
const extension = await getJSFileExtension({
|
|
89
|
+
helpers: args.helpers,
|
|
90
|
+
options: args.options,
|
|
91
|
+
});
|
|
92
|
+
const filePath = path.join(
|
|
93
|
+
buildSliceLibraryDirectoryPath({
|
|
94
|
+
libraryID: args.libraryID,
|
|
95
|
+
helpers: args.helpers,
|
|
96
|
+
}),
|
|
97
|
+
`index.${extension}`,
|
|
98
|
+
);
|
|
84
99
|
|
|
85
|
-
await
|
|
100
|
+
await writeProjectFile({
|
|
101
|
+
filename: filePath,
|
|
102
|
+
contents,
|
|
103
|
+
format: args.options.format,
|
|
104
|
+
helpers: args.helpers,
|
|
105
|
+
});
|
|
86
106
|
};
|