@slicemachine/init 2.4.3 → 2.4.4-dev-next-release.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/SliceMachineInitProcess.cjs +104 -31
  2. package/dist/SliceMachineInitProcess.cjs.map +1 -1
  3. package/dist/SliceMachineInitProcess.d.ts +4 -0
  4. package/dist/SliceMachineInitProcess.js +106 -33
  5. package/dist/SliceMachineInitProcess.js.map +1 -1
  6. package/dist/_node_modules/@babel/code-frame/lib/index.cjs +2 -2
  7. package/dist/_node_modules/@babel/code-frame/lib/index.js +2 -2
  8. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.cjs +1 -1
  9. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.js +1 -1
  10. package/dist/_node_modules/@babel/highlight/lib/index.cjs +3 -3
  11. package/dist/_node_modules/@babel/highlight/lib/index.js +3 -3
  12. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.cjs +1 -1
  13. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.js +1 -1
  14. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.cjs +1 -1
  15. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.js +1 -1
  16. package/dist/_node_modules/@nodelib/fs.scandir/out/settings.cjs +1 -1
  17. package/dist/_node_modules/@nodelib/fs.scandir/out/settings.js +1 -1
  18. package/dist/_node_modules/@nodelib/fs.stat/out/index.cjs +1 -1
  19. package/dist/_node_modules/@nodelib/fs.stat/out/index.js +1 -1
  20. package/dist/_node_modules/@nodelib/fs.walk/out/index.cjs +1 -1
  21. package/dist/_node_modules/@nodelib/fs.walk/out/index.js +1 -1
  22. package/dist/_node_modules/cross-spawn/index.cjs +1 -1
  23. package/dist/_node_modules/cross-spawn/index.js +1 -1
  24. package/dist/_node_modules/dir-glob/index.cjs +2 -2
  25. package/dist/_node_modules/dir-glob/index.js +2 -2
  26. package/dist/_node_modules/fast-glob/out/index.cjs +1 -1
  27. package/dist/_node_modules/fast-glob/out/index.js +1 -1
  28. package/dist/_node_modules/fast-glob/out/managers/tasks.cjs +1 -1
  29. package/dist/_node_modules/fast-glob/out/managers/tasks.js +1 -1
  30. package/dist/_node_modules/fast-glob/out/providers/filters/deep.cjs +1 -1
  31. package/dist/_node_modules/fast-glob/out/providers/filters/deep.js +1 -1
  32. package/dist/_node_modules/fast-glob/out/providers/filters/entry.cjs +1 -1
  33. package/dist/_node_modules/fast-glob/out/providers/filters/entry.js +1 -1
  34. package/dist/_node_modules/fast-glob/out/providers/filters/error.cjs +1 -1
  35. package/dist/_node_modules/fast-glob/out/providers/filters/error.js +1 -1
  36. package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.cjs +1 -1
  37. package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.js +1 -1
  38. package/dist/_node_modules/fast-glob/out/providers/transformers/entry.cjs +1 -1
  39. package/dist/_node_modules/fast-glob/out/providers/transformers/entry.js +1 -1
  40. package/dist/_node_modules/fast-glob/out/readers/async.cjs +1 -1
  41. package/dist/_node_modules/fast-glob/out/readers/async.js +1 -1
  42. package/dist/_node_modules/fast-glob/out/readers/reader.cjs +2 -2
  43. package/dist/_node_modules/fast-glob/out/readers/reader.js +2 -2
  44. package/dist/_node_modules/fast-glob/out/readers/stream.cjs +2 -2
  45. package/dist/_node_modules/fast-glob/out/readers/stream.js +2 -2
  46. package/dist/_node_modules/fast-glob/out/readers/sync.cjs +2 -2
  47. package/dist/_node_modules/fast-glob/out/readers/sync.js +2 -2
  48. package/dist/_node_modules/fast-glob/out/utils/index.cjs +1 -1
  49. package/dist/_node_modules/fast-glob/out/utils/index.js +1 -1
  50. package/dist/_node_modules/get-stream/index.cjs +1 -1
  51. package/dist/_node_modules/get-stream/index.js +1 -1
  52. package/dist/_node_modules/js-tokens/index.cjs +1 -1
  53. package/dist/_node_modules/js-tokens/index.js +1 -1
  54. package/dist/_node_modules/lines-and-columns/build/index.cjs +1 -1
  55. package/dist/_node_modules/lines-and-columns/build/index.js +1 -1
  56. package/dist/_node_modules/map-obj/index.cjs +1 -1
  57. package/dist/_node_modules/map-obj/index.js +1 -1
  58. package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.cjs +1 -1
  59. package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.js +1 -1
  60. package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.cjs +1 -1
  61. package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.js +1 -1
  62. package/dist/_node_modules/parse-json/index.cjs +2 -2
  63. package/dist/_node_modules/parse-json/index.js +2 -2
  64. package/dist/_node_modules/path-key/index.cjs +1 -1
  65. package/dist/_node_modules/path-key/index.js +1 -1
  66. package/dist/_node_modules/path-type/index.cjs +1 -1
  67. package/dist/_node_modules/path-type/index.js +1 -1
  68. package/dist/_node_modules/signal-exit/index.cjs +1 -1
  69. package/dist/_node_modules/signal-exit/index.js +1 -1
  70. package/dist/_virtual/index10.cjs +2 -2
  71. package/dist/_virtual/index10.js +2 -2
  72. package/dist/_virtual/index11.cjs +2 -2
  73. package/dist/_virtual/index11.js +2 -2
  74. package/dist/_virtual/index12.cjs +2 -2
  75. package/dist/_virtual/index12.js +2 -2
  76. package/dist/_virtual/index13.cjs +2 -2
  77. package/dist/_virtual/index13.js +2 -2
  78. package/dist/_virtual/index14.cjs +2 -2
  79. package/dist/_virtual/index14.js +2 -2
  80. package/dist/_virtual/index15.cjs +2 -2
  81. package/dist/_virtual/index15.js +2 -2
  82. package/dist/_virtual/index16.cjs +2 -2
  83. package/dist/_virtual/index16.js +2 -2
  84. package/dist/_virtual/index17.cjs +2 -2
  85. package/dist/_virtual/index17.js +2 -2
  86. package/dist/_virtual/index18.cjs +2 -2
  87. package/dist/_virtual/index18.js +2 -2
  88. package/dist/_virtual/index19.cjs +2 -2
  89. package/dist/_virtual/index19.js +2 -2
  90. package/dist/_virtual/index3.cjs +2 -2
  91. package/dist/_virtual/index3.js +2 -2
  92. package/dist/_virtual/index4.cjs +2 -2
  93. package/dist/_virtual/index4.js +2 -2
  94. package/dist/_virtual/index5.cjs +2 -2
  95. package/dist/_virtual/index5.js +2 -2
  96. package/dist/_virtual/index6.cjs +2 -2
  97. package/dist/_virtual/index6.js +2 -2
  98. package/dist/_virtual/index7.cjs +2 -2
  99. package/dist/_virtual/index7.js +2 -2
  100. package/dist/_virtual/index8.cjs +2 -2
  101. package/dist/_virtual/index8.js +2 -2
  102. package/dist/_virtual/index9.cjs +2 -2
  103. package/dist/_virtual/index9.js +2 -2
  104. package/dist/cli.cjs +17 -7
  105. package/dist/cli.cjs.map +1 -1
  106. package/dist/cli.js +17 -7
  107. package/dist/cli.js.map +1 -1
  108. package/dist/constants.cjs +4 -0
  109. package/dist/constants.cjs.map +1 -1
  110. package/dist/constants.d.ts +2 -0
  111. package/dist/constants.js +4 -0
  112. package/dist/constants.js.map +1 -1
  113. package/dist/packages/init/package.json.cjs +6 -5
  114. package/dist/packages/init/package.json.cjs.map +1 -1
  115. package/dist/packages/init/package.json.js +6 -5
  116. package/dist/packages/init/package.json.js.map +1 -1
  117. package/package.json +6 -5
  118. package/src/SliceMachineInitProcess.ts +164 -46
  119. package/src/cli.ts +17 -7
  120. package/src/constants.ts +2 -0
@@ -8,6 +8,7 @@ import { execaCommand, type ExecaChildProcess } from "execa";
8
8
  import open from "open";
9
9
  import logSymbols from "log-symbols";
10
10
  import { globby } from "globby";
11
+ import { downloadTemplate } from "giget";
11
12
 
12
13
  import {
13
14
  createSliceMachineManager,
@@ -32,11 +33,18 @@ import {
32
33
  import { listr, listrRun } from "./lib/listr";
33
34
  import { prompt } from "./lib/prompt";
34
35
  import { assertExists } from "./lib/assertExists";
35
- import { START_SCRIPT_KEY, START_SCRIPT_VALUE } from "./constants";
36
+ import {
37
+ GIGET_ORGANIZATION,
38
+ GIGET_PROVIDER,
39
+ START_SCRIPT_KEY,
40
+ START_SCRIPT_VALUE,
41
+ } from "./constants";
36
42
  import { detectStarterId } from "./lib/starters";
37
43
 
38
44
  export type SliceMachineInitProcessOptions = {
39
45
  repository?: string;
46
+ starter?: string;
47
+ directoryName?: string;
40
48
  push?: boolean;
41
49
  pushSlices?: boolean;
42
50
  pushCustomTypes?: boolean;
@@ -94,30 +102,40 @@ export class SliceMachineInitProcess {
94
102
  console.log(
95
103
  `\n${chalk.bgGray(` ${chalk.bold.white("Slice Machine")} `)} ${chalk.dim(
96
104
  "→",
97
- )} Init command started\n`,
105
+ )} Initializing\n`,
98
106
  );
99
107
 
100
- if (await this.manager.telemetry.checkIsTelemetryEnabled()) {
101
- // We prefer to manually allow console logs despite the app being a CLI to catch wild/unwanted console logs better
102
- // eslint-disable-next-line no-console
103
- console.log(
104
- `${
105
- logSymbols.info
106
- } We collect telemetry data to improve user experience.\n Learn more: ${chalk.cyan(
107
- "https://prismic.dev/slice-machine/telemetry",
108
- )}\n`,
109
- );
110
- }
111
- await this.manager.telemetry.initTelemetry({
112
- appName: pkg.name,
113
- appVersion: pkg.version,
114
- });
115
- await this.manager.telemetry.track({
116
- event: "command:init:start",
117
- repository: this.options.repository,
118
- });
119
-
120
108
  try {
109
+ if (this.options.starter) {
110
+ await this.copyStarter();
111
+ } else if (this.options.directoryName) {
112
+ // We prefer to manually allow console logs despite the app being a CLI to catch wild/unwanted console logs better
113
+ // eslint-disable-next-line no-console
114
+ console.log(
115
+ `${logSymbols.warning} --directory-name has no effect because --starter is not specified\n`,
116
+ );
117
+ }
118
+
119
+ if (await this.manager.telemetry.checkIsTelemetryEnabled()) {
120
+ // We prefer to manually allow console logs despite the app being a CLI to catch wild/unwanted console logs better
121
+ // eslint-disable-next-line no-console
122
+ console.log(
123
+ `${
124
+ logSymbols.info
125
+ } We collect telemetry data to improve user experience.\n Learn more: ${chalk.cyan(
126
+ "https://prismic.dev/slice-machine/telemetry",
127
+ )}\n`,
128
+ );
129
+ }
130
+ await this.manager.telemetry.initTelemetry({
131
+ appName: pkg.name,
132
+ appVersion: pkg.version,
133
+ });
134
+ await this.manager.telemetry.track({
135
+ event: "command:init:start",
136
+ repository: this.options.repository,
137
+ });
138
+
121
139
  await this.detectEnvironment();
122
140
 
123
141
  assertExists(
@@ -174,7 +192,7 @@ export class SliceMachineInitProcess {
174
192
  console.log(
175
193
  `\n${chalk.bgGreen(` ${chalk.bold.white("Slice Machine")} `)} ${chalk.dim(
176
194
  "→",
177
- )} Init command successful!`,
195
+ )} Initialization successful!`,
178
196
  );
179
197
 
180
198
  try {
@@ -193,15 +211,49 @@ export class SliceMachineInitProcess {
193
211
  script: "dev",
194
212
  });
195
213
 
214
+ const apiEndpoints = this.manager.getAPIEndpoints();
215
+ const wroomHost = new URL(apiEndpoints.PrismicWroom).host;
216
+
217
+ const dashboardURL = new URL(
218
+ `https://${this.context.repository.domain}.${wroomHost}`,
219
+ )
220
+ .toString()
221
+ .replace(/\/$/, "");
222
+ const apiURL = new URL(
223
+ "./api/v2",
224
+ `https://${this.context.repository.domain}.cdn.${wroomHost}`,
225
+ ).toString();
226
+
196
227
  // We prefer to manually allow console logs despite the app being a CLI to catch wild/unwanted console logs better
197
228
  // eslint-disable-next-line no-console
198
229
  console.log(`
199
- GETTING STARTED
200
- Run Slice Machine ${chalk.cyan(runSmCommand)}
201
- Run your project ${chalk.cyan(runProjectCommand)}
230
+ YOUR REPOSITORY
231
+ Dashboard ${chalk.cyan(dashboardURL)}
232
+ API ${chalk.cyan(apiURL)}
233
+
234
+ RESOURCES
235
+ Documentation ${chalk.cyan(
236
+ this.context.framework.prismicDocumentation,
237
+ )}
238
+ Getting help ${chalk.cyan("https://community.prismic.io")}
239
+
240
+ GETTING STARTED
241
+ Run Slice Machine ${chalk.cyan(runSmCommand)}
242
+ Run your project ${chalk.cyan(runProjectCommand)}
202
243
  `);
203
244
 
204
- if (this.options.startSlicemachine) {
245
+ if (this.options.starter && this.options.repository) {
246
+ const { openDashboard } = await prompt<boolean, "openDashboard">({
247
+ type: "confirm",
248
+ name: "openDashboard",
249
+ message: "Would you like to open your repository dashboard?",
250
+ initial: true,
251
+ });
252
+
253
+ if (openDashboard) {
254
+ open(dashboardURL);
255
+ }
256
+ } else if (this.options.startSlicemachine) {
205
257
  const pkgJSONPath = path.join(this.manager.cwd, "package.json");
206
258
  const pkg = JSON.parse(await fs.readFile(pkgJSONPath, "utf-8"));
207
259
  const scripts = pkg.scripts || {};
@@ -214,13 +266,13 @@ GETTING STARTED
214
266
  ) {
215
267
  return {
216
268
  command: runProjectCommand,
217
- message: `Would you like to launch your project + Slicemachine (${runProjectCommand})?`,
269
+ message: `Would you like to run your project and Slice Machine concurrently (${runProjectCommand})?`,
218
270
  };
219
271
  }
220
272
 
221
273
  return {
222
274
  command: runSmCommand,
223
- message: `Would you like to launch Slicemachine (${runSmCommand})?`,
275
+ message: `Would you like to run Slice Machine (${runSmCommand})?`,
224
276
  };
225
277
  })();
226
278
  const { startSlicemachine } = await prompt<
@@ -291,6 +343,72 @@ GETTING STARTED
291
343
  });
292
344
  };
293
345
 
346
+ protected async copyStarter(): Promise<void> {
347
+ const dir = await this.getStarterDirectoryName();
348
+
349
+ return listrRun([
350
+ {
351
+ title: "Copying starter...\n",
352
+ task: async () => {
353
+ const starter = this.options.starter;
354
+
355
+ await downloadTemplate(
356
+ `${GIGET_PROVIDER}:${GIGET_ORGANIZATION}/${starter}#HEAD`,
357
+ {
358
+ dir,
359
+ },
360
+ );
361
+
362
+ process.chdir(dir);
363
+ this.manager.cwd = process.cwd();
364
+ },
365
+ },
366
+ ]);
367
+ }
368
+
369
+ protected async getStarterDirectoryName(): Promise<string> {
370
+ let directoryName: string;
371
+ const folderNames = await fs.readdir(process.cwd());
372
+
373
+ if (
374
+ this.options.directoryName &&
375
+ !folderNames.includes(this.options.directoryName)
376
+ ) {
377
+ // Use provided directory
378
+ directoryName = this.options.directoryName;
379
+ } else if (
380
+ this.options.repository &&
381
+ !folderNames.includes(this.options.repository)
382
+ ) {
383
+ // Use repository name
384
+ directoryName = this.options.repository;
385
+ } else {
386
+ // Use random name
387
+ let suggestedName: string;
388
+ do {
389
+ suggestedName = getRandomRepositoryDomain();
390
+ } while (folderNames.includes(suggestedName));
391
+
392
+ const { selectedDirectory } = await prompt<string, "selectedDirectory">({
393
+ type: "text",
394
+ name: "selectedDirectory",
395
+ message: "Your starter directory name",
396
+ initial: suggestedName,
397
+ validate: async (rawDirectory: string) => {
398
+ if (folderNames.includes(rawDirectory)) {
399
+ return "Directory name already exists";
400
+ }
401
+
402
+ return true;
403
+ },
404
+ });
405
+
406
+ directoryName = selectedDirectory;
407
+ }
408
+
409
+ return directoryName;
410
+ }
411
+
294
412
  protected detectEnvironment(): Promise<void> {
295
413
  return listrRun([
296
414
  {
@@ -654,26 +772,26 @@ GETTING STARTED
654
772
  }
655
773
  };
656
774
 
657
- // 1. Try to suggest name after package name
658
- try {
659
- const pkgJSONPath = path.join(this.manager.cwd, "package.json");
660
- const pkg = JSON.parse(await fs.readFile(pkgJSONPath, "utf-8"));
661
-
662
- const maybeSuggestion = await trySuggestName(pkg.name);
663
- if (maybeSuggestion) {
664
- suggestedName = maybeSuggestion;
665
- }
666
- } catch {
667
- // Noop
775
+ // 1. Try to suggest name after directory name
776
+ const maybeSuggestion = await trySuggestName(
777
+ path.basename(this.manager.cwd),
778
+ );
779
+ if (maybeSuggestion) {
780
+ suggestedName = maybeSuggestion;
668
781
  }
669
782
 
670
- // 2. Try to suggest name after directory name
783
+ // 2. Try to suggest name after package name
671
784
  if (!suggestedName) {
672
- const maybeSuggestion = await trySuggestName(
673
- path.basename(this.manager.cwd),
674
- );
675
- if (maybeSuggestion) {
676
- suggestedName = maybeSuggestion;
785
+ try {
786
+ const pkgJSONPath = path.join(this.manager.cwd, "package.json");
787
+ const pkg = JSON.parse(await fs.readFile(pkgJSONPath, "utf-8"));
788
+
789
+ const maybeSuggestion = await trySuggestName(pkg.name);
790
+ if (maybeSuggestion) {
791
+ suggestedName = maybeSuggestion;
792
+ }
793
+ } catch {
794
+ // Noop
677
795
  }
678
796
  }
679
797
 
package/src/cli.ts CHANGED
@@ -5,7 +5,7 @@ import { createSliceMachineInitProcess } from "./SliceMachineInitProcess";
5
5
 
6
6
  const cli = meow(
7
7
  `
8
- Prismic Slice Machine Init CLI
8
+ Slice Machine init CLI help
9
9
 
10
10
  DOCUMENTATION
11
11
  https://prismic.io/docs
@@ -17,13 +17,15 @@ USAGE
17
17
  $ npx @slicemachine/init
18
18
 
19
19
  OPTIONS
20
- --repository, -r Specify a Prismic repository to use
20
+ --repository, -r Specify a Prismic repository to use
21
+ --starter, -s Specify a starter to use
22
+ --directory-name, -d Name of a new directory for the starter
21
23
 
22
- --no-push For starters, prevent anything from being pushed
23
- --no-push-slices For starters, prevent slices from being pushed
24
- --no-push-custom-types For starters, prevent types from being pushed
25
- --no-push-documents For starters, prevent documents from being pushed
26
- --no-start-slicemachine Prevents init from running SliceMachine
24
+ --no-push Don't push anything to Prismic
25
+ --no-push-slices Don't push slices to Prismic
26
+ --no-push-custom-types Don't push types to Prismic
27
+ --no-push-documents Don't push documents to Prismic
28
+ --no-start-slicemachine Don't run Slice Machine
27
29
 
28
30
  --help, -h Display CLI help
29
31
  --version, -v Display CLI version
@@ -35,6 +37,14 @@ OPTIONS
35
37
  type: "string",
36
38
  alias: "r",
37
39
  },
40
+ starter: {
41
+ type: "string",
42
+ alias: "s",
43
+ },
44
+ directoryName: {
45
+ type: "string",
46
+ alias: "d",
47
+ },
38
48
  push: {
39
49
  type: "boolean",
40
50
  default: true,
package/src/constants.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  // Those contants should be unique to the init script, if they are needed elsewhere then they should be extracted to the manager
2
2
  export const START_SCRIPT_KEY = "slicemachine";
3
3
  export const START_SCRIPT_VALUE = "start-slicemachine";
4
+ export const GIGET_PROVIDER = "github";
5
+ export const GIGET_ORGANIZATION = "prismicio-community";