diff --git a/cli/src/sysconfig.ts b/cli/src/sysconfig.ts index 4b3f7f3ed4..e3ca293242 100644 --- a/cli/src/sysconfig.ts +++ b/cli/src/sysconfig.ts @@ -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 { diff --git a/cli/src/tasks/init.ts b/cli/src/tasks/init.ts index b46c759be8..67d8e7052d 100644 --- a/cli/src/tasks/init.ts +++ b/cli/src/tasks/init.ts @@ -1,3 +1,4 @@ +import open from 'open'; import { basename, dirname, resolve } from 'path'; import c from '../colors'; @@ -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'; @@ -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( @@ -171,3 +181,21 @@ function printNextSteps(newConfigName: string) { )}\n`, ); } + +async function promptToSignup(): Promise { + 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; +}