@slicemachine/init 2.4.3 → 2.4.4-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/SliceMachineInitProcess.cjs +104 -31
- package/dist/SliceMachineInitProcess.cjs.map +1 -1
- package/dist/SliceMachineInitProcess.d.ts +4 -0
- package/dist/SliceMachineInitProcess.js +106 -33
- package/dist/SliceMachineInitProcess.js.map +1 -1
- package/dist/_node_modules/@babel/code-frame/lib/index.cjs +2 -2
- package/dist/_node_modules/@babel/code-frame/lib/index.js +2 -2
- 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/cross-spawn/index.cjs +1 -1
- package/dist/_node_modules/cross-spawn/index.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/get-stream/index.cjs +1 -1
- package/dist/_node_modules/get-stream/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/lines-and-columns/build/index.cjs +1 -1
- package/dist/_node_modules/lines-and-columns/build/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/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/parse-json/index.cjs +2 -2
- package/dist/_node_modules/parse-json/index.js +2 -2
- package/dist/_node_modules/path-type/index.cjs +1 -1
- package/dist/_node_modules/path-type/index.js +1 -1
- package/dist/_node_modules/signal-exit/index.cjs +1 -1
- package/dist/_node_modules/signal-exit/index.js +1 -1
- package/dist/_virtual/index10.cjs +2 -2
- package/dist/_virtual/index10.js +2 -2
- package/dist/_virtual/index11.cjs +2 -2
- package/dist/_virtual/index11.js +2 -2
- package/dist/_virtual/index12.cjs +2 -2
- package/dist/_virtual/index12.js +2 -2
- package/dist/_virtual/index13.cjs +2 -2
- package/dist/_virtual/index13.js +2 -2
- package/dist/_virtual/index14.cjs +2 -2
- package/dist/_virtual/index14.js +2 -2
- package/dist/_virtual/index15.cjs +2 -2
- package/dist/_virtual/index15.js +2 -2
- package/dist/_virtual/index16.cjs +2 -2
- package/dist/_virtual/index16.js +2 -2
- package/dist/_virtual/index17.cjs +2 -2
- package/dist/_virtual/index17.js +2 -2
- package/dist/_virtual/index18.cjs +2 -2
- package/dist/_virtual/index18.js +2 -2
- package/dist/_virtual/index4.cjs +2 -2
- package/dist/_virtual/index4.js +2 -2
- package/dist/_virtual/index5.cjs +2 -2
- package/dist/_virtual/index5.js +2 -2
- package/dist/_virtual/index6.cjs +2 -2
- package/dist/_virtual/index6.js +2 -2
- package/dist/_virtual/index7.cjs +2 -2
- package/dist/_virtual/index7.js +2 -2
- package/dist/_virtual/index8.cjs +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/cli.cjs +17 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +17 -7
- package/dist/cli.js.map +1 -1
- package/dist/constants.cjs +4 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/packages/init/package.json.cjs +6 -5
- package/dist/packages/init/package.json.cjs.map +1 -1
- package/dist/packages/init/package.json.js +6 -5
- package/dist/packages/init/package.json.js.map +1 -1
- package/package.json +6 -5
- package/src/SliceMachineInitProcess.ts +163 -46
- package/src/cli.ts +17 -7
- 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 {
|
|
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
|
-
)}
|
|
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
|
-
)}
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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.
|
|
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
|
|
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
|
|
275
|
+
message: `Would you like to run Slice Machine (${runSmCommand})?`,
|
|
224
276
|
};
|
|
225
277
|
})();
|
|
226
278
|
const { startSlicemachine } = await prompt<
|
|
@@ -291,6 +343,71 @@ GETTING STARTED
|
|
|
291
343
|
});
|
|
292
344
|
};
|
|
293
345
|
|
|
346
|
+
protected async copyStarter(): Promise<void> {
|
|
347
|
+
return listrRun([
|
|
348
|
+
{
|
|
349
|
+
title: "Copying starter...\n",
|
|
350
|
+
task: async () => {
|
|
351
|
+
const starter = this.options.starter;
|
|
352
|
+
const dir = await this.getStarterDirectoryName();
|
|
353
|
+
|
|
354
|
+
await downloadTemplate(
|
|
355
|
+
`${GIGET_PROVIDER}:${GIGET_ORGANIZATION}/${starter}#HEAD`,
|
|
356
|
+
{
|
|
357
|
+
dir,
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
process.chdir(dir);
|
|
362
|
+
this.manager.cwd = process.cwd();
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
]);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
protected async getStarterDirectoryName(): Promise<string> {
|
|
369
|
+
let directoryName: string;
|
|
370
|
+
const folderNames = await fs.readdir(process.cwd());
|
|
371
|
+
|
|
372
|
+
if (
|
|
373
|
+
this.options.directoryName &&
|
|
374
|
+
!folderNames.includes(this.options.directoryName)
|
|
375
|
+
) {
|
|
376
|
+
// Use provided directory
|
|
377
|
+
directoryName = this.options.directoryName;
|
|
378
|
+
} else if (
|
|
379
|
+
this.options.repository &&
|
|
380
|
+
!folderNames.includes(this.options.repository)
|
|
381
|
+
) {
|
|
382
|
+
// Use repository name
|
|
383
|
+
directoryName = this.options.repository;
|
|
384
|
+
} else {
|
|
385
|
+
// Use random name
|
|
386
|
+
let suggestedName: string;
|
|
387
|
+
do {
|
|
388
|
+
suggestedName = getRandomRepositoryDomain();
|
|
389
|
+
} while (folderNames.includes(suggestedName));
|
|
390
|
+
|
|
391
|
+
const { selectedDirectory } = await prompt<string, "selectedDirectory">({
|
|
392
|
+
type: "text",
|
|
393
|
+
name: "selectedDirectory",
|
|
394
|
+
message: "Your starter directory name",
|
|
395
|
+
initial: suggestedName,
|
|
396
|
+
validate: async (rawDirectory: string) => {
|
|
397
|
+
if (folderNames.includes(rawDirectory)) {
|
|
398
|
+
return "Directory name already exists";
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return true;
|
|
402
|
+
},
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
directoryName = selectedDirectory;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return directoryName;
|
|
409
|
+
}
|
|
410
|
+
|
|
294
411
|
protected detectEnvironment(): Promise<void> {
|
|
295
412
|
return listrRun([
|
|
296
413
|
{
|
|
@@ -654,26 +771,26 @@ GETTING STARTED
|
|
|
654
771
|
}
|
|
655
772
|
};
|
|
656
773
|
|
|
657
|
-
// 1. Try to suggest name after
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (maybeSuggestion) {
|
|
664
|
-
suggestedName = maybeSuggestion;
|
|
665
|
-
}
|
|
666
|
-
} catch {
|
|
667
|
-
// Noop
|
|
774
|
+
// 1. Try to suggest name after directory name
|
|
775
|
+
const maybeSuggestion = await trySuggestName(
|
|
776
|
+
path.basename(this.manager.cwd),
|
|
777
|
+
);
|
|
778
|
+
if (maybeSuggestion) {
|
|
779
|
+
suggestedName = maybeSuggestion;
|
|
668
780
|
}
|
|
669
781
|
|
|
670
|
-
// 2. Try to suggest name after
|
|
782
|
+
// 2. Try to suggest name after package name
|
|
671
783
|
if (!suggestedName) {
|
|
672
|
-
|
|
673
|
-
path.
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
784
|
+
try {
|
|
785
|
+
const pkgJSONPath = path.join(this.manager.cwd, "package.json");
|
|
786
|
+
const pkg = JSON.parse(await fs.readFile(pkgJSONPath, "utf-8"));
|
|
787
|
+
|
|
788
|
+
const maybeSuggestion = await trySuggestName(pkg.name);
|
|
789
|
+
if (maybeSuggestion) {
|
|
790
|
+
suggestedName = maybeSuggestion;
|
|
791
|
+
}
|
|
792
|
+
} catch {
|
|
793
|
+
// Noop
|
|
677
794
|
}
|
|
678
795
|
}
|
|
679
796
|
|
package/src/cli.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { createSliceMachineInitProcess } from "./SliceMachineInitProcess";
|
|
|
5
5
|
|
|
6
6
|
const cli = meow(
|
|
7
7
|
`
|
|
8
|
-
|
|
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
|
|
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
|
|
23
|
-
--no-push-slices
|
|
24
|
-
--no-push-custom-types
|
|
25
|
-
--no-push-documents
|
|
26
|
-
--no-start-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";
|