Skip to content

Commit 15b2688

Browse files
feat: prompt to enable local dev
1 parent 0972650 commit 15b2688

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

messages/prompts.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ Unable to enumerate a list of available devices.
3737
# component.select
3838

3939
Which Lightning Web Component would you like to preview (Use arrow keys)
40+
41+
# component.enable-local-dev
42+
43+
Local dev isn't enabled for this org. Enable it?

src/commands/lightning/dev/component.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ export default class LightningDevComponent extends SfCommand<ComponentPreviewRes
7575
const targetOrg = flags['target-org'];
7676
const apiVersion = flags['api-version'];
7777

78-
// Auto enable local dev
79-
if (process.env.AUTO_ENABLE_LOCAL_DEV === 'true') {
80-
try {
81-
await MetaUtils.ensureLightningPreviewEnabled(targetOrg.getConnection(undefined));
82-
await MetaUtils.ensureFirstPartyCookiesNotRequired(targetOrg.getConnection(undefined));
83-
} catch (error) {
84-
this.log('Error autoenabling local dev', error);
78+
// If local dev is not enabled, prompt the user to enable local dev
79+
const setupConnection = targetOrg.getConnection(undefined);
80+
const isLightningPreviewEnabled = await MetaUtils.isLightningPreviewEnabled(setupConnection);
81+
if (!isLightningPreviewEnabled) {
82+
const enableLocalDev = await PromptUtils.promptUserToEnableLocalDev();
83+
if (enableLocalDev) {
84+
try {
85+
await MetaUtils.ensureLightningPreviewEnabled(setupConnection);
86+
await MetaUtils.ensureFirstPartyCookiesNotRequired(setupConnection);
87+
this.log('Local dev is now enabled for this org.');
88+
} catch (error) {
89+
this.log('Error autoenabling local dev', error);
90+
}
8591
}
8692
}
8793

src/shared/promptUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ export class PromptUtils {
114114
return response;
115115
}
116116

117+
public static async promptUserToEnableLocalDev(): Promise<boolean> {
118+
return confirm({
119+
message: messages.getMessage('component.enable-local-dev'),
120+
default: true,
121+
});
122+
}
123+
117124
// returns the shorthand version of a Version object (eg. 17.0.0 => 17, 17.4.0 => 17.4, 17.4.1 => 17.4.1)
118125
private static getShortVersion(version: Version | string): string {
119126
// TODO: consider making this function part of the Version class in @lwc-dev-mobile-core

0 commit comments

Comments
 (0)