Skip to content

Commit df063e3

Browse files
authored
feat: enrich Segment events with starter context from config (#1772)
1 parent 72bb68c commit df063e3

6 files changed

Lines changed: 17 additions & 3 deletions

File tree

packages/init/src/SliceMachineInitProcess.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
10841084
...config,
10851085
repositoryName: this.context.repository.domain,
10861086
adapter: this.context.framework.adapterName,
1087+
...(this.options.starter
1088+
? { starter: this.options.starter }
1089+
: {}),
10871090
},
10881091
});
10891092
parentTask.title = "Updated Slice Machine configuration";
@@ -1098,6 +1101,9 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
10981101
repositoryName: this.context.repository.domain,
10991102
adapter: this.context.framework.adapterName,
11001103
libraries: ["./slices"],
1104+
...(this.options.starter
1105+
? { starter: this.options.starter }
1106+
: {}),
11011107
},
11021108
path: sliceMachineConfigPath,
11031109
});

packages/manager/src/lib/decodeSliceMachineConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const SliceMachineConfigCodec = t.intersection([
2727
localSliceSimulatorURL: t.string,
2828
plugins: t.array(SliceMachineConfigPluginRegistrationCodec),
2929
labs: t.partial({ legacySliceUpgrader: t.boolean }),
30+
starter: t.string,
3031
}),
3132
]);
3233

packages/manager/src/managers/telemetry/TelemetryManager.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ export class TelemetryManager extends BaseManager {
102102
async track(args: TelemetryManagerTrackArgs): Promise<void> {
103103
const { event, repository, _includeEnvironmentKind, ...properties } = args;
104104
let repositoryName = repository;
105+
let starter: string | undefined;
105106

106107
if (repositoryName === undefined) {
107108
try {
108-
repositoryName = await this.project.getRepositoryName();
109-
} catch (error) {
110-
// noop, happen only when the user is not in a project
109+
const config = await this.project.getSliceMachineConfig();
110+
repositoryName = config.repositoryName;
111+
starter = config.starter;
112+
} catch {
113+
// noop, happens only when the user is not in a project
111114
}
112115
}
113116

@@ -150,6 +153,7 @@ export class TelemetryManager extends BaseManager {
150153
properties: {
151154
nodeVersion: process.versions.node,
152155
environmentKind,
156+
starter,
153157
...properties,
154158
},
155159
context: { ...this._context },

packages/manager/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type SliceMachineConfig = {
3232
adapter: SliceMachineConfigPluginRegistration;
3333
plugins?: SliceMachineConfigPluginRegistration[];
3434
labs?: { legacySliceUpgrader?: boolean };
35+
starter?: string;
3536
};
3637

3738
export type OnlyHookErrors<

packages/plugin-kit/src/lib/decodeSliceMachineConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const SliceMachineConfigCodec = t.intersection([
2727
localSliceSimulatorURL: t.string,
2828
plugins: t.array(SliceMachineConfigPluginRegistrationCodec),
2929
labs: t.partial({ legacySliceUpgrader: t.boolean }),
30+
starter: t.string,
3031
}),
3132
]);
3233

packages/plugin-kit/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type SliceMachineConfig = {
7070
adapter: SliceMachineConfigPluginRegistration;
7171
plugins?: SliceMachineConfigPluginRegistration[];
7272
labs?: { legacySliceUpgrader?: boolean };
73+
starter?: string;
7374
};
7475

7576
/**

0 commit comments

Comments
 (0)