|
1 |
| -import prompts from "prompts"; |
2 |
| -import fetch from "node-fetch"; |
3 | 1 | import { existsSync } from "fs-extra";
|
4 | 2 | import { ArgumentsCamelCase } from "yargs";
|
5 |
| -import { error, log } from "../util/serverLogger"; |
6 |
| -import { getMailingAPIBaseURL } from "../util/paths"; |
| 3 | +import { log } from "../util/serverLogger"; |
7 | 4 | import { generateEmailsDirectory } from "../util/generators";
|
8 | 5 | import { handler as previewHandler, PreviewArgs } from "./preview/preview";
|
9 | 6 | import { defaults } from "../util/config";
|
@@ -52,68 +49,33 @@ export const builder = {
|
52 | 49 | },
|
53 | 50 | };
|
54 | 51 |
|
55 |
| -export const handler = buildHandler( |
56 |
| - async (argv: InitArguments) => { |
57 |
| - if (typeof argv.port !== "number") |
58 |
| - throw new Error("port option is not set"); |
59 |
| - if (typeof argv.typescript !== "boolean") |
60 |
| - throw new Error("typescript option not set"); |
61 |
| - if (undefined === argv.emailsDir) |
62 |
| - throw new Error("emailsDir option not set"); |
| 52 | +export const handler = buildHandler(async (argv: InitArguments) => { |
| 53 | + if (typeof argv.port !== "number") throw new Error("port option is not set"); |
| 54 | + if (typeof argv.typescript !== "boolean") |
| 55 | + throw new Error("typescript option not set"); |
| 56 | + if (undefined === argv.emailsDir) throw new Error("emailsDir option not set"); |
63 | 57 |
|
64 |
| - if (existsSync(resolve(argv.emailsDir, "previews"))) { |
65 |
| - log("Using emails directory", argv.emailsDir); |
66 |
| - } else { |
67 |
| - const options = { |
68 |
| - isTypescript: argv.typescript, |
69 |
| - emailsDir: argv.emailsDir, |
70 |
| - }; |
71 |
| - await generateEmailsDirectory(options); |
72 |
| - |
73 |
| - if (argv.scaffoldOnly) { |
74 |
| - return; |
75 |
| - } |
76 |
| - |
77 |
| - if (!argv.quiet) { |
78 |
| - const emailResponse = await prompts({ |
79 |
| - type: "text", |
80 |
| - name: "email", |
81 |
| - message: |
82 |
| - "enter your email for occasional updates about mailing (optional)", |
83 |
| - }); |
84 |
| - const { email } = emailResponse; |
85 |
| - if (email?.length > 0) { |
86 |
| - log("great, talk soon"); |
87 |
| - try { |
88 |
| - const url = `${getMailingAPIBaseURL()}/api/newsletterSubscribers`; |
89 |
| - |
90 |
| - void fetch(url, { |
91 |
| - method: "POST", |
92 |
| - headers: { "Content-Type": "application/json" }, |
93 |
| - body: JSON.stringify({ email }), |
94 |
| - }); |
95 |
| - } catch (e) { |
96 |
| - error(e); |
97 |
| - } |
98 |
| - } else { |
99 |
| - log("ok, no problem"); |
100 |
| - } |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 |
| - const previewHandlerArgv: PreviewArgs = { |
105 |
| - port: argv.port, |
106 |
| - quiet: argv.quiet, |
| 58 | + if (existsSync(resolve(argv.emailsDir, "previews"))) { |
| 59 | + log("Using emails directory", argv.emailsDir); |
| 60 | + } else { |
| 61 | + const options = { |
| 62 | + isTypescript: argv.typescript, |
107 | 63 | emailsDir: argv.emailsDir,
|
108 |
| - $0: argv.$0, |
109 |
| - _: argv._, |
110 | 64 | };
|
| 65 | + await generateEmailsDirectory(options); |
111 | 66 |
|
112 |
| - await previewHandler(previewHandlerArgv); |
113 |
| - }, |
114 |
| - { |
115 |
| - captureOptions: () => { |
116 |
| - return { event: "init invoked" }; |
117 |
| - }, |
| 67 | + if (argv.scaffoldOnly) { |
| 68 | + return; |
| 69 | + } |
118 | 70 | }
|
119 |
| -); |
| 71 | + |
| 72 | + const previewHandlerArgv: PreviewArgs = { |
| 73 | + port: argv.port, |
| 74 | + quiet: argv.quiet, |
| 75 | + emailsDir: argv.emailsDir, |
| 76 | + $0: argv.$0, |
| 77 | + _: argv._, |
| 78 | + }; |
| 79 | + |
| 80 | + await previewHandler(previewHandlerArgv); |
| 81 | +}); |
0 commit comments