Skip to content

Commit

Permalink
Merge pull request #892 from frontity/disable-newsletter
Browse files Browse the repository at this point in the history
Disable newsletter from the CLI
  • Loading branch information
luisherranz committed Feb 19, 2022
2 parents 741e4f5 + d347626 commit 71e41a3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-zoos-turn.md
@@ -0,0 +1,5 @@
---
"frontity": patch
---

Disable newsletter from the CLI.
Expand Up @@ -95,21 +95,5 @@ Array [
},
],
],
Array [
Array [
Object {
"default": false,
"message": "Do you want to receive framework updates by email?",
"name": "subscribe",
"type": "confirm",
},
Object {
"message": "Please, enter your email:",
"name": "email",
"type": "input",
"when": [Function],
},
],
],
]
`;
10 changes: 5 additions & 5 deletions packages/frontity/src/cli/__tests__/create.cli.test.ts
Expand Up @@ -50,18 +50,18 @@ describe("CLI create", () => {

await create(options);

expect(mockedInquirer.prompt).toHaveBeenCalledTimes(3);
expect(mockedInquirer.prompt).toHaveBeenCalledTimes(2);
expect(mockedInquirer.prompt.mock.calls[0][0]).toMatchObject([
{ message: "Enter a name for the project:" },
]);
expect(mockedInquirer.prompt.mock.calls[1][0]).toMatchObject([
{ message: "Pick a starter theme to clone:" },
]);

expect(mockedInquirer.prompt.mock.calls[2][0]).toMatchObject([
{ message: "Do you want to receive framework updates by email?" },
{ message: "Please, enter your email:" },
]);
// expect(mockedInquirer.prompt.mock.calls[2][0]).toMatchObject([
// { message: "Do you want to receive framework updates by email?" },
// { message: "Please, enter your email:" },
// ]);
expect(mockedInquirer.prompt.mock.calls).toMatchSnapshot();
});

Expand Down
36 changes: 0 additions & 36 deletions packages/frontity/src/cli/create.ts
Expand Up @@ -3,7 +3,6 @@ import ora from "ora";
import chalk from "chalk";
import { prompt, Question, ListQuestion } from "inquirer";
import createCommand from "../commands/create";
import { subscribe } from "../steps";
import { errorLogger, log } from "../utils";
import { CreateCommandOptions } from "../steps/types";

Expand Down Expand Up @@ -171,41 +170,6 @@ const create = async ({

log(chalk.bold("\nFrontity project created.\n"));

if (promptUser) {
const subscribeQuestions: Question[] = [
{
name: "subscribe",
type: "confirm",
message: "Do you want to receive framework updates by email?",
default: false,
},
{
name: "email",
type: "input",
message: "Please, enter your email:",
when: (answers) => answers.subscribe,
},
];
const answers = await prompt(subscribeQuestions);

if (answers.subscribe) {
emitter.on("subscribe", (message, action) => {
if (action) ora.promise(action, message);
else log(message);
});

await subscribe(answers.email);

log("\nThanks for subscribing! 😃");
} else {
log(
`\nOk, that's fine! 😉\nYou can subscribe at any point with ${chalk.bold.green(
"npx frontity subscribe <email>"
)}.`
);
}
}

log(
`\nRun ${chalk.bold.green(
`cd ${options.name} && npx frontity dev`
Expand Down
10 changes: 8 additions & 2 deletions packages/frontity/src/commands/subscribe.ts
@@ -1,15 +1,21 @@
import { EventPromised } from "../utils/eventPromised";
import { subscribe } from "../steps";

// TODO: make param an object
/**
* Subscribe to Frontity newsletter.
*
* @param email - The email to be subscribed.
* @param emit - The eventEmitter to send messages.
* @param reject - The promise reject method in case something goes wrong.
*/
const subscribeCommand = async (
email: string,
emit: (event: string, ...value: any[]) => void,
reject: (reason: any) => void
) => {
try {
emit("message", "Subscribing to frontity");
await subscribe(email);
await subscribe();
} catch (error) {
reject(error);
}
Expand Down
21 changes: 4 additions & 17 deletions packages/frontity/src/steps/index.ts
Expand Up @@ -410,8 +410,8 @@ export const revertProgress = async (dirExisted: boolean, path: string) => {
*
* @returns True or false depending if the email is valid.
*/
const isEmailValid = (email: string): boolean =>
/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,63}$/i.test(email);
// const isEmailValid = (email: string): boolean =>
// /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,63}$/i.test(email);

/**
* Subscribe an email to the newsletter service.
Expand All @@ -420,19 +420,6 @@ const isEmailValid = (email: string): boolean =>
*
* @returns The response of the subscription.
*/
export const subscribe = async (email: string) => {
if (!isEmailValid(email))
throw new Error("Email not valid. Please enter a valid email.");

return fetch(
"https://n8n.frontity.org/webhook/62923334-59a4-484c-a9c2-632814b94225",
{
method: "POST",
body: JSON.stringify({
event: "frontity-subscribe",
email: email.toLowerCase(),
}),
headers: { "Content-Type": "application/json" },
}
);
export const subscribe = async () => {
throw new Error("Frontity newsletter is currently disabled");
};

0 comments on commit 71e41a3

Please sign in to comment.