@slicemachine/init 0.1.1-dev-plugins.3 → 0.1.1-dev-plugins.5
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/SliceMachineInitProcess.cjs +111 -43
- package/dist/SliceMachineInitProcess.cjs.map +1 -1
- package/dist/SliceMachineInitProcess.d.ts +4 -0
- package/dist/SliceMachineInitProcess.js +112 -44
- package/dist/SliceMachineInitProcess.js.map +1 -1
- package/dist/__node_modules/@babel/code-frame/lib/index.cjs +1 -1
- package/dist/__node_modules/@babel/code-frame/lib/index.js +1 -1
- package/dist/__node_modules/@babel/helper-validator-identifier/lib/index.cjs +1 -1
- package/dist/__node_modules/@babel/helper-validator-identifier/lib/index.js +1 -1
- package/dist/__node_modules/@babel/highlight/lib/index.cjs +3 -3
- package/dist/__node_modules/@babel/highlight/lib/index.js +3 -3
- package/dist/__node_modules/@nodelib/fs.scandir/out/providers/async.cjs +1 -1
- package/dist/__node_modules/@nodelib/fs.scandir/out/providers/async.js +1 -1
- package/dist/__node_modules/@nodelib/fs.scandir/out/providers/sync.cjs +1 -1
- package/dist/__node_modules/@nodelib/fs.scandir/out/providers/sync.js +1 -1
- package/dist/__node_modules/@nodelib/fs.scandir/out/settings.cjs +1 -1
- package/dist/__node_modules/@nodelib/fs.scandir/out/settings.js +1 -1
- package/dist/__node_modules/@nodelib/fs.stat/out/index.cjs +1 -1
- package/dist/__node_modules/@nodelib/fs.stat/out/index.js +1 -1
- package/dist/__node_modules/@nodelib/fs.walk/out/index.cjs +1 -1
- package/dist/__node_modules/@nodelib/fs.walk/out/index.js +1 -1
- package/dist/__node_modules/camelcase-keys/index.cjs +1 -1
- package/dist/__node_modules/camelcase-keys/index.js +1 -1
- package/dist/__node_modules/cross-spawn/index.cjs +1 -1
- package/dist/__node_modules/cross-spawn/index.js +1 -1
- package/dist/__node_modules/cross-spawn/lib/util/resolveCommand.cjs +1 -1
- package/dist/__node_modules/cross-spawn/lib/util/resolveCommand.js +1 -1
- package/dist/__node_modules/dir-glob/index.cjs +2 -2
- package/dist/__node_modules/dir-glob/index.js +2 -2
- package/dist/__node_modules/fast-glob/out/index.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/index.js +1 -1
- package/dist/__node_modules/fast-glob/out/managers/tasks.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/managers/tasks.js +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/deep.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/deep.js +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/entry.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/entry.js +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/error.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/providers/filters/error.js +1 -1
- package/dist/__node_modules/fast-glob/out/providers/matchers/matcher.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/providers/matchers/matcher.js +1 -1
- package/dist/__node_modules/fast-glob/out/providers/transformers/entry.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/providers/transformers/entry.js +1 -1
- package/dist/__node_modules/fast-glob/out/readers/async.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/readers/async.js +1 -1
- package/dist/__node_modules/fast-glob/out/readers/reader.cjs +2 -2
- package/dist/__node_modules/fast-glob/out/readers/reader.js +2 -2
- package/dist/__node_modules/fast-glob/out/readers/stream.cjs +2 -2
- package/dist/__node_modules/fast-glob/out/readers/stream.js +2 -2
- package/dist/__node_modules/fast-glob/out/readers/sync.cjs +2 -2
- package/dist/__node_modules/fast-glob/out/readers/sync.js +2 -2
- package/dist/__node_modules/fast-glob/out/utils/index.cjs +1 -1
- package/dist/__node_modules/fast-glob/out/utils/index.js +1 -1
- package/dist/__node_modules/globby/index.cjs +1 -1
- package/dist/__node_modules/globby/index.js +1 -1
- package/dist/__node_modules/js-tokens/index.cjs +1 -1
- package/dist/__node_modules/js-tokens/index.js +1 -1
- package/dist/__node_modules/map-obj/index.cjs +1 -1
- package/dist/__node_modules/map-obj/index.js +1 -1
- package/dist/__node_modules/meow/__node_modules/hosted-git-info/lib/index.cjs +1 -1
- package/dist/__node_modules/meow/__node_modules/hosted-git-info/lib/index.js +1 -1
- package/dist/__node_modules/meow/__node_modules/normalize-package-data/lib/fixer.cjs +1 -1
- package/dist/__node_modules/meow/__node_modules/normalize-package-data/lib/fixer.js +1 -1
- package/dist/__node_modules/meow/__node_modules/read-pkg/__node_modules/hosted-git-info/index.cjs +1 -1
- package/dist/__node_modules/meow/__node_modules/read-pkg/__node_modules/hosted-git-info/index.js +1 -1
- package/dist/__node_modules/meow/__node_modules/read-pkg/__node_modules/normalize-package-data/lib/fixer.cjs +1 -1
- package/dist/__node_modules/meow/__node_modules/read-pkg/__node_modules/normalize-package-data/lib/fixer.js +1 -1
- package/dist/__node_modules/micromatch/index.cjs +1 -1
- package/dist/__node_modules/micromatch/index.js +1 -1
- package/dist/__node_modules/path-key/index.cjs +1 -1
- package/dist/__node_modules/path-key/index.js +1 -1
- package/dist/__node_modules/path-type/index.cjs +1 -1
- package/dist/__node_modules/path-type/index.js +1 -1
- package/dist/__node_modules/picomatch/index.cjs +1 -1
- package/dist/__node_modules/picomatch/index.js +1 -1
- package/dist/_virtual/index13.cjs +2 -2
- package/dist/_virtual/index13.js +2 -2
- package/dist/_virtual/index14.cjs +10 -2
- package/dist/_virtual/index14.cjs.map +1 -1
- package/dist/_virtual/index14.js +11 -2
- package/dist/_virtual/index14.js.map +1 -1
- package/dist/_virtual/index15.cjs +2 -2
- package/dist/_virtual/index15.js +2 -2
- package/dist/_virtual/index16.cjs +2 -10
- package/dist/_virtual/index16.cjs.map +1 -1
- package/dist/_virtual/index16.js +2 -11
- package/dist/_virtual/index16.js.map +1 -1
- package/dist/_virtual/index17.cjs +2 -2
- package/dist/_virtual/index17.js +6 -6
- package/dist/_virtual/index18.cjs +2 -10
- package/dist/_virtual/index18.cjs.map +1 -1
- package/dist/_virtual/index18.js +2 -11
- package/dist/_virtual/index18.js.map +1 -1
- package/dist/_virtual/index19.cjs +2 -2
- package/dist/_virtual/index19.js +2 -2
- package/dist/_virtual/index20.cjs +10 -2
- package/dist/_virtual/index20.cjs.map +1 -1
- package/dist/_virtual/index20.js +11 -2
- package/dist/_virtual/index20.js.map +1 -1
- package/dist/_virtual/index3.cjs +2 -2
- package/dist/_virtual/index3.js +6 -6
- package/dist/_virtual/index4.cjs +2 -2
- package/dist/_virtual/index4.js +6 -6
- package/dist/_virtual/index5.cjs +10 -2
- package/dist/_virtual/index5.cjs.map +1 -1
- package/dist/_virtual/index5.js +11 -2
- package/dist/_virtual/index5.js.map +1 -1
- package/dist/_virtual/index6.cjs +10 -2
- package/dist/_virtual/index6.cjs.map +1 -1
- package/dist/_virtual/index6.js +11 -2
- package/dist/_virtual/index6.js.map +1 -1
- package/dist/_virtual/index7.cjs +2 -10
- package/dist/_virtual/index7.cjs.map +1 -1
- package/dist/_virtual/index7.js +2 -11
- package/dist/_virtual/index7.js.map +1 -1
- package/dist/_virtual/index8.cjs +2 -10
- package/dist/_virtual/index8.cjs.map +1 -1
- package/dist/_virtual/index8.js +2 -11
- package/dist/_virtual/index8.js.map +1 -1
- package/dist/constants.cjs +7 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/lib/framework.cjs +7 -3
- package/dist/lib/framework.cjs.map +1 -1
- package/dist/lib/framework.d.ts +8 -0
- package/dist/lib/framework.js +7 -3
- package/dist/lib/framework.js.map +1 -1
- package/dist/lib/packageManager.cjs +11 -3
- package/dist/lib/packageManager.cjs.map +1 -1
- package/dist/lib/packageManager.d.ts +9 -1
- package/dist/lib/packageManager.js +12 -4
- package/dist/lib/packageManager.js.map +1 -1
- package/dist/lib/prompt.cjs +3 -2
- package/dist/lib/prompt.cjs.map +1 -1
- package/dist/lib/prompt.js +3 -2
- package/dist/lib/prompt.js.map +1 -1
- package/dist/packages/init/__node_modules/execa/index.cjs +1 -1
- package/dist/packages/init/__node_modules/execa/index.js +1 -1
- package/dist/packages/init/package.json.cjs +1 -1
- package/dist/packages/init/package.json.js +1 -1
- package/package.json +8 -3
- package/src/SliceMachineInitProcess.ts +176 -61
- package/src/constants.ts +3 -0
- package/src/lib/framework.ts +20 -7
- package/src/lib/packageManager.ts +20 -4
- package/src/lib/prompt.ts +2 -2
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
installDependencies,
|
|
20
20
|
detectPackageManager,
|
|
21
21
|
PackageManagerAgent,
|
|
22
|
+
getRunScriptCommand,
|
|
23
|
+
getExecuteCommand,
|
|
22
24
|
} from "./lib/packageManager";
|
|
23
25
|
import {
|
|
24
26
|
getRandomRepositoryDomain,
|
|
@@ -30,6 +32,7 @@ import {
|
|
|
30
32
|
import { listr, listrRun } from "./lib/listr";
|
|
31
33
|
import { prompt } from "./lib/prompt";
|
|
32
34
|
import { assertExists } from "./lib/assertExists";
|
|
35
|
+
import { START_SCRIPT_KEY, START_SCRIPT_VALUE } from "./constants";
|
|
33
36
|
|
|
34
37
|
export type SliceMachineInitProcessOptions = {
|
|
35
38
|
repository?: string;
|
|
@@ -63,6 +66,9 @@ type SliceMachineInitProcessContext = {
|
|
|
63
66
|
domain: string;
|
|
64
67
|
exists: boolean;
|
|
65
68
|
};
|
|
69
|
+
projectInitialization?: {
|
|
70
|
+
patchedScript?: boolean;
|
|
71
|
+
};
|
|
66
72
|
};
|
|
67
73
|
|
|
68
74
|
export class SliceMachineInitProcess {
|
|
@@ -122,6 +128,7 @@ export class SliceMachineInitProcess {
|
|
|
122
128
|
await this.finishCoreDependenciesInstallation();
|
|
123
129
|
await this.upsertSliceMachineConfigurationAndStartPluginRunner();
|
|
124
130
|
await this.pushDataToPrismic();
|
|
131
|
+
await this.initializeProject();
|
|
125
132
|
await this.initializePlugins();
|
|
126
133
|
} catch (error) {
|
|
127
134
|
await this.trackError(error);
|
|
@@ -143,6 +150,40 @@ export class SliceMachineInitProcess {
|
|
|
143
150
|
"→",
|
|
144
151
|
)} Init command successful!`,
|
|
145
152
|
);
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
// We prefer to manually allow console logs despite the app being a CLI to catch wild/unwanted console logs better
|
|
156
|
+
// eslint-disable-next-line no-console
|
|
157
|
+
console.log(`
|
|
158
|
+
YOUR REPOSITORY
|
|
159
|
+
Dashboard ${chalk.cyan(
|
|
160
|
+
`https://${this.context.repository.domain}.prismic.io`,
|
|
161
|
+
)}
|
|
162
|
+
API ${chalk.cyan(
|
|
163
|
+
`https://${this.context.repository.domain}.cdn.prismic.io/api/v2`,
|
|
164
|
+
)}
|
|
165
|
+
|
|
166
|
+
RESOURCES
|
|
167
|
+
Documentation ${chalk.cyan(
|
|
168
|
+
this.context.framework.prismicDocumentation,
|
|
169
|
+
)}
|
|
170
|
+
Getting help ${chalk.cyan("https://community.prismic.io")}
|
|
171
|
+
|
|
172
|
+
GETTING STARTED
|
|
173
|
+
Start Slice Machine ${chalk.cyan(
|
|
174
|
+
this.context.projectInitialization?.patchedScript
|
|
175
|
+
? await getRunScriptCommand({
|
|
176
|
+
agent: this.context.packageManager || "npm",
|
|
177
|
+
script: "slicemachine",
|
|
178
|
+
})
|
|
179
|
+
: await getExecuteCommand({
|
|
180
|
+
agent: this.context.packageManager || "npm",
|
|
181
|
+
script: "start-slicemachine",
|
|
182
|
+
}),
|
|
183
|
+
)}`);
|
|
184
|
+
} catch {
|
|
185
|
+
// Noop, it's only the final convenience messsage
|
|
186
|
+
}
|
|
146
187
|
}
|
|
147
188
|
|
|
148
189
|
protected trackError = (error: unknown): Promise<void> => {
|
|
@@ -181,7 +222,22 @@ export class SliceMachineInitProcess {
|
|
|
181
222
|
{
|
|
182
223
|
title: "Detecting package manager...",
|
|
183
224
|
task: async (_, task) => {
|
|
184
|
-
|
|
225
|
+
try {
|
|
226
|
+
this.context.packageManager = await detectPackageManager(
|
|
227
|
+
this.options.cwd,
|
|
228
|
+
);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
// Default to NPM
|
|
231
|
+
if (
|
|
232
|
+
error instanceof Error &&
|
|
233
|
+
(error.message.match(/failed to detect/i) ||
|
|
234
|
+
error.message.match(/command failed/i))
|
|
235
|
+
) {
|
|
236
|
+
this.context.packageManager = "npm";
|
|
237
|
+
} else {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
185
241
|
|
|
186
242
|
task.title = `Detected package manager ${chalk.cyan(
|
|
187
243
|
this.context.packageManager,
|
|
@@ -267,10 +323,10 @@ export class SliceMachineInitProcess {
|
|
|
267
323
|
if (!isLoggedIn) {
|
|
268
324
|
parentTask.output = "Press any key to open the browser to login...";
|
|
269
325
|
await new Promise((resolve) => {
|
|
270
|
-
const initialRawMode = process.stdin.isRaw;
|
|
271
|
-
process.stdin.setRawMode(true);
|
|
326
|
+
const initialRawMode = !!process.stdin.isRaw;
|
|
327
|
+
process.stdin.setRawMode?.(true);
|
|
272
328
|
process.stdin.once("data", (data: Buffer) => {
|
|
273
|
-
process.stdin.setRawMode(initialRawMode);
|
|
329
|
+
process.stdin.setRawMode?.(initialRawMode);
|
|
274
330
|
process.stdin.pause();
|
|
275
331
|
resolve(data.toString("utf-8"));
|
|
276
332
|
});
|
|
@@ -281,9 +337,7 @@ export class SliceMachineInitProcess {
|
|
|
281
337
|
await this.manager.user.nodeLoginSession({
|
|
282
338
|
port,
|
|
283
339
|
onListenCallback() {
|
|
284
|
-
open(url)
|
|
285
|
-
throw error;
|
|
286
|
-
});
|
|
340
|
+
open(url);
|
|
287
341
|
},
|
|
288
342
|
});
|
|
289
343
|
}
|
|
@@ -345,8 +399,10 @@ export class SliceMachineInitProcess {
|
|
|
345
399
|
"Flag `repository` must be set to run `useRepositoryFlag`",
|
|
346
400
|
);
|
|
347
401
|
|
|
402
|
+
const domain = formatRepositoryDomain(this.options.repository);
|
|
403
|
+
|
|
348
404
|
const maybeRepository = this.context.userRepositories.find(
|
|
349
|
-
(repository) => repository.domain ===
|
|
405
|
+
(repository) => repository.domain === domain,
|
|
350
406
|
);
|
|
351
407
|
|
|
352
408
|
if (maybeRepository) {
|
|
@@ -360,7 +416,6 @@ export class SliceMachineInitProcess {
|
|
|
360
416
|
);
|
|
361
417
|
}
|
|
362
418
|
} else {
|
|
363
|
-
const domain = formatRepositoryDomain(this.options.repository);
|
|
364
419
|
const validation = await validateRepositoryDomainAndAvailability({
|
|
365
420
|
domain,
|
|
366
421
|
existsFn: (domain) =>
|
|
@@ -377,11 +432,11 @@ export class SliceMachineInitProcess {
|
|
|
377
432
|
}
|
|
378
433
|
|
|
379
434
|
task.title = `Selected repository ${chalk.cyan(
|
|
380
|
-
|
|
435
|
+
domain,
|
|
381
436
|
)} (flag ${chalk.cyan("repository")} used)`;
|
|
382
437
|
|
|
383
438
|
this.context.repository = {
|
|
384
|
-
domain
|
|
439
|
+
domain,
|
|
385
440
|
exists: !!maybeRepository,
|
|
386
441
|
};
|
|
387
442
|
},
|
|
@@ -503,15 +558,13 @@ export class SliceMachineInitProcess {
|
|
|
503
558
|
|
|
504
559
|
// 3. Use random name
|
|
505
560
|
if (!suggestedName) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
while (
|
|
561
|
+
do {
|
|
562
|
+
suggestedName = getRandomRepositoryDomain();
|
|
563
|
+
} while (
|
|
509
564
|
await this.manager.prismicRepository.checkExists({
|
|
510
565
|
domain: suggestedName,
|
|
511
566
|
})
|
|
512
|
-
)
|
|
513
|
-
suggestedName = getRandomRepositoryDomain();
|
|
514
|
-
}
|
|
567
|
+
);
|
|
515
568
|
}
|
|
516
569
|
|
|
517
570
|
const { domain } = await prompt<string, "domain">({
|
|
@@ -525,38 +578,36 @@ export class SliceMachineInitProcess {
|
|
|
525
578
|
const domain = formatRepositoryDomain(rawDomain);
|
|
526
579
|
const validation = validateRepositoryDomain({ domain });
|
|
527
580
|
|
|
581
|
+
const minRule = validation.LessThan4
|
|
582
|
+
? chalk.red(
|
|
583
|
+
`1. Name must be ${chalk.bold("4 characters long or more")}`,
|
|
584
|
+
)
|
|
585
|
+
: `1. Name must be ${chalk.cyan("4 characters long or more")}`;
|
|
586
|
+
|
|
587
|
+
const maxRule = validation.MoreThan30
|
|
588
|
+
? chalk.red(
|
|
589
|
+
`1. Name must be ${chalk.bold("30 characters long or less")}`,
|
|
590
|
+
)
|
|
591
|
+
: `1. Name must be ${chalk.cyan("30 characters long or less")}`;
|
|
592
|
+
|
|
528
593
|
this.msg = chalk.reset(
|
|
529
594
|
`
|
|
530
595
|
Choose a name for your Prismic repository
|
|
531
596
|
|
|
532
597
|
NAMING RULES
|
|
533
|
-
${
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
)}`,
|
|
537
|
-
)}
|
|
538
|
-
${chalk[validation.MoreThan30 ? "red" : "gray"](
|
|
539
|
-
` 2. Name must be ${chalk[validation.MoreThan30 ? "bold" : "cyan"](
|
|
540
|
-
"30 characters long or less",
|
|
541
|
-
)}`,
|
|
542
|
-
)}
|
|
543
|
-
${chalk.gray(` 3. Name will be ${chalk.cyan("kebab-cased")} automatically`)}
|
|
598
|
+
${minRule}
|
|
599
|
+
${maxRule}
|
|
600
|
+
3. Name will be ${chalk.cyan("kebab-cased")} automatically
|
|
544
601
|
|
|
545
602
|
CONSIDERATIONS
|
|
546
|
-
${chalk.
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
` 2. A ${chalk.cyan(
|
|
551
|
-
"display name",
|
|
552
|
-
)} for the repository can be configured later on`,
|
|
553
|
-
)}
|
|
603
|
+
1. Once picked, your repository name ${chalk.cyan("cannot be changed")}
|
|
604
|
+
2. A ${chalk.cyan(
|
|
605
|
+
"display name",
|
|
606
|
+
)} for the repository can be configured later on
|
|
554
607
|
|
|
555
608
|
PREVIEW
|
|
556
|
-
|
|
557
|
-
${chalk.
|
|
558
|
-
` API ${chalk.cyan(`https://${domain}.cdn.prismic.io/api/v2`)}`,
|
|
559
|
-
)}
|
|
609
|
+
Dashboard ${chalk.cyan(`https://${domain}.prismic.io`)}
|
|
610
|
+
API ${chalk.cyan(`https://${domain}.cdn.prismic.io/api/v2`)}
|
|
560
611
|
|
|
561
612
|
${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
562
613
|
);
|
|
@@ -581,8 +632,8 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
581
632
|
});
|
|
582
633
|
|
|
583
634
|
// Clear extra lines
|
|
584
|
-
process.stdout.moveCursor(0, -16);
|
|
585
|
-
process.stdout.clearScreenDown();
|
|
635
|
+
process.stdout.moveCursor?.(0, -16);
|
|
636
|
+
process.stdout.clearScreenDown?.();
|
|
586
637
|
|
|
587
638
|
this.context.repository = {
|
|
588
639
|
domain,
|
|
@@ -642,8 +693,11 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
642
693
|
task.output = data.toString();
|
|
643
694
|
}
|
|
644
695
|
};
|
|
645
|
-
|
|
646
|
-
|
|
696
|
+
|
|
697
|
+
// Don't clutter console with logs when process is non TTY (CI, etc.)
|
|
698
|
+
if (process.stdout.isTTY || process.env.NODE_ENV === "test") {
|
|
699
|
+
this.context.installProcess.stdout?.on("data", updateOutput);
|
|
700
|
+
}
|
|
647
701
|
this.context.installProcess.stderr?.on("data", updateOutput);
|
|
648
702
|
|
|
649
703
|
try {
|
|
@@ -654,17 +708,14 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
654
708
|
* that all install errors, earlier and presents, can be catched.
|
|
655
709
|
*
|
|
656
710
|
* Here, we force the task to wait so that it is neither marked as
|
|
657
|
-
* done or has the opportunity to handle the error itself
|
|
711
|
+
* done or has the opportunity to handle the error itself.
|
|
658
712
|
*/
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
throw error;
|
|
663
|
-
}, 5000);
|
|
664
|
-
});
|
|
713
|
+
// If for whatever reason the process is not exited by now, we still throw the error
|
|
714
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
715
|
+
throw error;
|
|
665
716
|
}
|
|
666
717
|
|
|
667
|
-
task.title = `
|
|
718
|
+
task.title = `Installed core dependencies with ${chalk.cyan(
|
|
668
719
|
this.context.packageManager,
|
|
669
720
|
)}`;
|
|
670
721
|
},
|
|
@@ -702,6 +753,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
702
753
|
config: {
|
|
703
754
|
...config,
|
|
704
755
|
repositoryName: this.context.repository.domain,
|
|
756
|
+
adapter: this.context.framework.adapterName,
|
|
705
757
|
},
|
|
706
758
|
});
|
|
707
759
|
parentTask.title = "Updated Slice Machine configuration";
|
|
@@ -877,7 +929,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
877
929
|
});
|
|
878
930
|
if (documentsGlob.length === 0) {
|
|
879
931
|
parentTask.title = "Pushed data to Prismic";
|
|
880
|
-
task.skip("No
|
|
932
|
+
task.skip("No document to push");
|
|
881
933
|
|
|
882
934
|
return;
|
|
883
935
|
}
|
|
@@ -927,7 +979,70 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
927
979
|
]);
|
|
928
980
|
}
|
|
929
981
|
|
|
930
|
-
|
|
982
|
+
protected initializeProject(): Promise<void> {
|
|
983
|
+
return listrRun([
|
|
984
|
+
{
|
|
985
|
+
title: "Initializing project...",
|
|
986
|
+
task: async (_, parentTask) =>
|
|
987
|
+
// We return another Listr instance in the event we have additional task to perform to initialize the project
|
|
988
|
+
listr([
|
|
989
|
+
{
|
|
990
|
+
title: `Patching ${chalk.cyan("package.json")} scripts...`,
|
|
991
|
+
task: async (_, task) => {
|
|
992
|
+
const pkgPath = path.join(this.manager.cwd, "package.json");
|
|
993
|
+
|
|
994
|
+
try {
|
|
995
|
+
const pkgRaw = await fs.readFile(pkgPath, "utf-8");
|
|
996
|
+
const pkg = JSON.parse(pkgRaw);
|
|
997
|
+
|
|
998
|
+
pkg.scripts ||= {};
|
|
999
|
+
|
|
1000
|
+
if (!pkg.scripts[START_SCRIPT_KEY]) {
|
|
1001
|
+
pkg.scripts[START_SCRIPT_KEY] = START_SCRIPT_VALUE;
|
|
1002
|
+
|
|
1003
|
+
// Cheap indent detection based on https://github.com/sindresorhus/detect-indent (simplified because we're only dealing with JSON here)
|
|
1004
|
+
const firstIndent = pkgRaw
|
|
1005
|
+
.split("\n")
|
|
1006
|
+
.find((line) => line.match(/^(?:( )+|\t+)/));
|
|
1007
|
+
const indent = firstIndent?.match(/^(?:( )+|\t+)/)?.[0];
|
|
1008
|
+
|
|
1009
|
+
await fs.writeFile(
|
|
1010
|
+
pkgPath,
|
|
1011
|
+
JSON.stringify(
|
|
1012
|
+
pkg,
|
|
1013
|
+
null,
|
|
1014
|
+
indent && indent !== " " ? indent : " ",
|
|
1015
|
+
),
|
|
1016
|
+
);
|
|
1017
|
+
} else if (
|
|
1018
|
+
!pkg.scripts["slicemachine"].startsWith(START_SCRIPT_VALUE)
|
|
1019
|
+
) {
|
|
1020
|
+
throw new Error("Script already exists");
|
|
1021
|
+
}
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
task.title = `Could not patch ${chalk.cyan(
|
|
1024
|
+
"package.json",
|
|
1025
|
+
)} scripts (warning)`;
|
|
1026
|
+
parentTask.title = `Initialized project (could not patch ${chalk.cyan(
|
|
1027
|
+
"package.json",
|
|
1028
|
+
)} scripts)`;
|
|
1029
|
+
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
this.context.projectInitialization ||= {};
|
|
1034
|
+
this.context.projectInitialization.patchedScript = true;
|
|
1035
|
+
|
|
1036
|
+
task.title = `Patched ${chalk.cyan("package.json")} scripts`;
|
|
1037
|
+
parentTask.title = `Initialized project (patched ${chalk.cyan(
|
|
1038
|
+
"package.json",
|
|
1039
|
+
)} scripts)`;
|
|
1040
|
+
},
|
|
1041
|
+
},
|
|
1042
|
+
]),
|
|
1043
|
+
},
|
|
1044
|
+
]);
|
|
1045
|
+
}
|
|
931
1046
|
|
|
932
1047
|
protected initializePlugins(): Promise<void> {
|
|
933
1048
|
return listrRun([
|
|
@@ -959,7 +1074,10 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
959
1074
|
agent: this.context.packageManager,
|
|
960
1075
|
});
|
|
961
1076
|
|
|
962
|
-
|
|
1077
|
+
// Don't clutter console with logs when process is non TTY (CI, etc.)
|
|
1078
|
+
if (process.stdout.isTTY || process.env.NODE_ENV === "test") {
|
|
1079
|
+
execaProcess.stdout?.on("data", updateOutput);
|
|
1080
|
+
}
|
|
963
1081
|
execaProcess.stderr?.on("data", updateOutput);
|
|
964
1082
|
|
|
965
1083
|
await execaProcess;
|
|
@@ -969,16 +1087,13 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
|
|
|
969
1087
|
"shortMessage" in error &&
|
|
970
1088
|
"stderr" in error
|
|
971
1089
|
) {
|
|
972
|
-
|
|
973
|
-
console.error(
|
|
1090
|
+
throw new Error(
|
|
974
1091
|
`\n\n${error.shortMessage}\n${error.stderr}\n\n${logSymbols.error} Plugins dependency installation failed`,
|
|
1092
|
+
{ cause: error },
|
|
975
1093
|
);
|
|
976
|
-
} else {
|
|
977
|
-
await this.trackError(error);
|
|
978
|
-
console.error(error);
|
|
979
1094
|
}
|
|
980
1095
|
|
|
981
|
-
|
|
1096
|
+
throw error;
|
|
982
1097
|
}
|
|
983
1098
|
},
|
|
984
1099
|
},
|
package/src/constants.ts
ADDED
package/src/lib/framework.ts
CHANGED
|
@@ -14,6 +14,11 @@ export type Framework = {
|
|
|
14
14
|
*/
|
|
15
15
|
prismicName: string;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A link to the Prismic documentation for the framework
|
|
19
|
+
*/
|
|
20
|
+
prismicDocumentation: string;
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
23
|
* Package name of the adapter responsible for this framework
|
|
19
24
|
*/
|
|
@@ -43,10 +48,15 @@ const DEFAULT_DEV_DEPENDENCIES: Record<string, string> = {
|
|
|
43
48
|
"slice-machine-ui": "<1.0.0",
|
|
44
49
|
};
|
|
45
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Frameworks we support, orders shouldn't matter much but is respected (the
|
|
53
|
+
* higher it is the more priority it has in case multiple matches)
|
|
54
|
+
*/
|
|
46
55
|
export const FRAMEWORKS: Record<string, Framework> = {
|
|
47
56
|
"nuxt-2": {
|
|
48
57
|
name: "Nuxt 2",
|
|
49
58
|
prismicName: "nuxt-2",
|
|
59
|
+
prismicDocumentation: "https://prismic.dev/init/nuxt-2",
|
|
50
60
|
adapterName: "@slicemachine/adapter-nuxt",
|
|
51
61
|
compatibility: {
|
|
52
62
|
nuxt: "^2.0.0",
|
|
@@ -59,6 +69,7 @@ export const FRAMEWORKS: Record<string, Framework> = {
|
|
|
59
69
|
"next-11-13": {
|
|
60
70
|
name: "Next.js 11-13",
|
|
61
71
|
prismicName: "next-11-13",
|
|
72
|
+
prismicDocumentation: "https://prismic.dev/init/next-11-13",
|
|
62
73
|
adapterName: "@slicemachine/adapter-next",
|
|
63
74
|
compatibility: {
|
|
64
75
|
next: "^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
@@ -76,6 +87,7 @@ export const FRAMEWORKS: Record<string, Framework> = {
|
|
|
76
87
|
export const UNIVERSAL: Framework = {
|
|
77
88
|
name: "universal (no framework)",
|
|
78
89
|
prismicName: "universal",
|
|
90
|
+
prismicDocumentation: "https://prismic.dev/init/universal",
|
|
79
91
|
adapterName: "@slicemachine/adapter-universal",
|
|
80
92
|
compatibility: {},
|
|
81
93
|
devDependencies: {
|
|
@@ -106,15 +118,16 @@ export const detectFramework = async (cwd: string): Promise<Framework> => {
|
|
|
106
118
|
Object.values(FRAMEWORKS).find((framework) => {
|
|
107
119
|
return Object.entries(framework.compatibility).every(([pkg, range]) => {
|
|
108
120
|
if (pkg in allDependencies) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
try {
|
|
122
|
+
// Determine lowest version possibly in use
|
|
123
|
+
const minimumVersion = semver.minVersion(allDependencies[pkg]);
|
|
124
|
+
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
126
|
+
return semver.satisfies(minimumVersion!, range);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
// We assume unconventional tags, `latest`, `beta`, `dev` matches the framework
|
|
114
129
|
return true;
|
|
115
130
|
}
|
|
116
|
-
|
|
117
|
-
return semver.satisfies(minimumVersion, range);
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseNi, detect as niDetect } from "@antfu/ni";
|
|
1
|
+
import { parseNi, parseNr, detect as niDetect, parseNx } from "@antfu/ni";
|
|
2
2
|
import {
|
|
3
3
|
ExecaChildProcess,
|
|
4
4
|
execaCommand,
|
|
@@ -55,12 +55,28 @@ export const installDependencies = async (
|
|
|
55
55
|
return { execaProcess };
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export const
|
|
58
|
+
export const getRunScriptCommand = async (args: {
|
|
59
|
+
agent: PackageManagerAgent;
|
|
60
|
+
script: string;
|
|
61
|
+
}): Promise<string> => {
|
|
62
|
+
return (await parseNr(args.agent, [args.script])) || `npm run ${args.script}`;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const getExecuteCommand = async (args: {
|
|
66
|
+
agent: PackageManagerAgent;
|
|
67
|
+
script: string;
|
|
68
|
+
}): Promise<string> => {
|
|
69
|
+
return (await parseNx(args.agent, [args.script])) || `npx ${args.script}`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const detectPackageManager = async (
|
|
73
|
+
cwd?: string,
|
|
74
|
+
): Promise<PackageManagerAgent> => {
|
|
59
75
|
// We auto install agent for now otherwise ni could cause some issues with prompt
|
|
60
|
-
const agent = await niDetect({ autoInstall: true });
|
|
76
|
+
const agent = await niDetect({ autoInstall: true, cwd });
|
|
61
77
|
|
|
62
78
|
if (!agent) {
|
|
63
|
-
throw new Error("Failed to detect project's
|
|
79
|
+
throw new Error("Failed to detect project's package manager");
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
return agent;
|
package/src/lib/prompt.ts
CHANGED
|
@@ -20,8 +20,8 @@ export const prompt = async <TReturn, TProperty extends string = string>(
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// Clear prompt line, clean recap are done manually
|
|
23
|
-
process.stdout.moveCursor(0, -1);
|
|
24
|
-
process.stdout.clearLine(1);
|
|
23
|
+
process.stdout.moveCursor?.(0, -1);
|
|
24
|
+
process.stdout.clearLine?.(1);
|
|
25
25
|
|
|
26
26
|
return answers;
|
|
27
27
|
};
|