Skip to content

Commit

Permalink
feat(cli): Add signup prompt on first init (#4440)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 14, 2021
1 parent 816dea2 commit b3faa97
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/src/sysconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export interface SystemConfig {
* If undefined, a choice has not yet been made.
*/
readonly telemetry?: boolean;

/**
* Wheter the user choose to signup or not.
*
* If undefined, the prompt has not been shown.
*/
readonly signup?: boolean;
}

export async function readConfig(): Promise<SystemConfig> {
Expand Down
28 changes: 28 additions & 0 deletions cli/src/tasks/init.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import open from 'open';
import { basename, dirname, resolve } from 'path';

import c from '../colors';
Expand All @@ -11,6 +12,7 @@ import { getCordovaPreferences } from '../cordova';
import type { Config, ExternalConfig } from '../definitions';
import { fatal, isFatal } from '../errors';
import { output, logSuccess, logPrompt } from '../log';
import { readConfig, writeConfig as sysWriteConfig } from '../sysconfig';
import { resolveNode } from '../util/node';
import { checkInteractive, isInteractive } from '../util/term';

Expand Down Expand Up @@ -150,6 +152,14 @@ async function runMergeConfig(
);

printNextSteps(basename(newConfigPath));
if (isInteractive()) {
let sysconfig = await readConfig();
if (typeof sysconfig.signup === 'undefined') {
const signup = await promptToSignup();
sysconfig = { ...sysconfig, signup };
await sysWriteConfig(sysconfig);
}
}
}

async function mergeConfig(
Expand All @@ -171,3 +181,21 @@ function printNextSteps(newConfigName: string) {
)}\n`,
);
}

async function promptToSignup(): Promise<boolean> {
const answers = await logPrompt(
`Join the Ionic Community! 💙\n` +
`Connect with millions of developers on the Ionic Forum and get access to live events, news updates, and more.`,
{
type: 'confirm',
name: 'create',
message: `Create free Ionic account?`,
initial: true,
},
);

if (answers.create) {
open(`http://ionicframework.com/signup?source=capacitor`);
}
return answers.create;
}

0 comments on commit b3faa97

Please sign in to comment.