Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add signup prompt on first init #4440

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}