diff --git a/packages/@ionic/cli/src/commands/start.ts b/packages/@ionic/cli/src/commands/start.ts index 9c8db7fad0..79328f13a5 100644 --- a/packages/@ionic/cli/src/commands/start.ts +++ b/packages/@ionic/cli/src/commands/start.ts @@ -12,6 +12,7 @@ import { Command } from '../lib/command'; import { FatalException } from '../lib/errors'; import { runCommand } from '../lib/executor'; import { createProjectFromDetails, createProjectFromDirectory, isValidProjectId } from '../lib/project'; +import { promptToSignup } from '../lib/session'; import { prependNodeModulesBinToPath } from '../lib/shell'; import { AppSchema, STARTER_BASE_URL, STARTER_TEMPLATES, SUPPORTED_FRAMEWORKS, getAdvertisement, getStarterList, getStarterProjectTypes, readStarterManifest, verifyOptions } from '../lib/start'; import { emoji } from '../lib/utils/emoji'; @@ -480,6 +481,11 @@ Use the ${input('--type')} option to start projects using older versions of Ioni } } + // Prompt to create account + if (!this.env.session.isLoggedIn()) { + await promptToSignup(this.env); + } + if (options['link']) { const cmdArgs = ['link']; diff --git a/packages/@ionic/cli/src/lib/session.ts b/packages/@ionic/cli/src/lib/session.ts index 1458f88c40..b6f3db3ffd 100644 --- a/packages/@ionic/cli/src/lib/session.ts +++ b/packages/@ionic/cli/src/lib/session.ts @@ -6,6 +6,7 @@ import { isLoginResponse, isSuperAgentError } from '../guards'; import { input } from './color'; import { FatalException, SessionException } from './errors'; import { formatResponseError } from './http'; +import { openUrl } from './open'; export interface SessionDeps { readonly config: IConfig; @@ -137,8 +138,9 @@ export class ProSession extends BaseSession implements ISession { export async function promptToLogin(env: IonicEnvironment): Promise { const { validators } = await import('@ionic/cli-framework'); + env.log.nl(); env.log.msg( - `Log in to your Ionic account\n` + + `Log in to your Ionic account!\n` + `If you don't have one yet, create yours by running: ${input(`ionic signup`)}\n` ); @@ -160,6 +162,27 @@ export async function promptToLogin(env: IonicEnvironment): Promise { await env.session.login(email, password); } +export async function promptToSignup(env: IonicEnvironment): Promise { + env.log.nl(); + env.log.msg( + `Join the Ionic Community! 💙\n` + + `Connect with millions of developers on the Ionic Forum and get access to live events, news updates, and more.\n\n` + ); + + const create = await env.prompt({ + type: 'confirm', + name: 'create', + message: 'Create free Ionic account?', + default: false, + }); + + if (create) { + const dashUrl = env.config.getDashUrl(); + + await openUrl(`${dashUrl}/signup?source=cli`); + } +} + function hasTokenAttribute(r: any): r is { token: string; } { return r && typeof r === 'object' && typeof r.token === 'string'; }