Skip to content

Commit

Permalink
Stop linking emails (#395)
Browse files Browse the repository at this point in the history
* stop linking emails

* remove more files

* re-add emails

* stop eslinting for now

* fix

* cleanup

* get greens

* generate js instead

* fix link, exclude root emails directory

* Update packages/cli/src/util/generators.ts

Co-authored-by: Peter Sugihara <[email protected]>

* Apply suggestions from code review

Co-authored-by: Peter Sugihara <[email protected]>

Co-authored-by: Peter Sugihara <[email protected]>
  • Loading branch information
elliothursh and psugihara authored Dec 5, 2022
1 parent a24ebe5 commit 1b1a2b0
Show file tree
Hide file tree
Showing 50 changed files with 51 additions and 54 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Mailing
dev-app
tmp-testMailQueue.json
dist
Expand All @@ -6,6 +7,7 @@ mailing.config.json
previews_html
out
.mailing
/emails

# Logs
logs
Expand Down Expand Up @@ -110,12 +112,6 @@ typings/
# TernJS port file
.tern-port

# This gets generated by the CLI when we test locally
emails
!packages/cli/src/generator_templates/ts/emails/
!packages/cli/src/generator_templates/js/emails/
!packages/web/emails

# E2E tests
e2e/runs
e2e/cache
Expand Down
2 changes: 0 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

yarn lint:unlink
yarn lint-staged
yarn lint:link
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"*.{js,jsx,ts,tsx}": "eslint --fix",
"*.rb": "rubocop --autocorrect",
"packages/cli/src/generator_templates/ts/**/*.{ts,tsx}": "scripts/build-js-templates"
"packages/cli/src/emails/**/*.{ts,tsx}": "scripts/build-js-templates"
}
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const nodeConfig = (): Config => {
watchPathIgnorePatterns: [
"<rootDir>/emails/",
"<rootDir>/packages/cli/src/emails/",
"<rootDir>/packages/cli/src/generator_templates/ts/emails/",
"<rootDir>/.mailing/",
"tmp-testMailQueue.json",
],
Expand Down
1 change: 0 additions & 1 deletion jest.integration.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const config: Config = {
watchPathIgnorePatterns: [
"<rootDir>/emails/",
"<rootDir>/packages/cli/src/emails/",
"<rootDir>/packages/cli/src/generator_templates/ts/emails/",
"<rootDir>/.mailing/",
"tmp-testMailQueue.json",
],
Expand Down
16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@
"packages/*"
],
"scripts": {
"lint": "yarn lint:unlink; eslint .; yarn lint:link",
"lint:unlink": "rm packages/cli/src/emails",
"lint:link": "ln -s 'generator_templates/ts/emails/' packages/cli/src/emails",
"lint": "eslint .",
"dev": "cd packages/cli && yarn dev",
"dev:web": "cd packages/web && yarn dev",
"dev:js": "yarn link:emails:js && yarn dev",
"dev:init": "cd packages/cli && rm -rf previews_html; rm -rf .mailing emails mailing.config.json; src/dev.js",
"dev:export-previews": "yarn link:emails; cd packages/cli && rm -rf .mailing && src/dev.js export-previews",
"dev:server:build": "cd packages/cli && rm -rf .mailing && src/dev.js server build",
"link:emails": "rm -rf emails; ln -s packages/cli/src/generator_templates/ts/emails emails;",
"link:emails:js": "rm -rf emails; ln -s packages/cli/src/generator_templates/js/emails emails;",
"link:emails": "echo 'noop'",
"build": "preconstruct build",
"test": "yarn link:emails; yarn jest",
"test:integration": "yarn integration:servers:start \"yarn link:emails; yarn jest -c jest.integration.config.ts $TEST_FLAGS\"",
"test:integration:watch": "yarn integration:servers:start \"yarn link:emails; yarn jest -c jest.integration.config.ts --watch\"",
"test": "yarn jest",
"test:integration": "yarn integration:servers:start \"yarn jest -c jest.integration.config.ts $TEST_FLAGS\"",
"test:integration:watch": "yarn integration:servers:start \"yarn jest -c jest.integration.config.ts --watch\"",
"ci:test": "yarn test:servers:start test",
"ci:test:integration": "yarn integration:servers:start \"yarn link:emails; yarn jest -c jest.integration.config.ts\"",
"ci:test:integration": "yarn integration:servers:start \"yarn jest -c jest.integration.config.ts\"",
"test:integration:cypress": "yarn integration:servers:start \"cd packages/cli && yarn cypress run -C cypressIntegration.config.ts\"",
"test:integration:cypress:open": "yarn integration:servers:start \"cd packages/cli && yarn cypress open -C cypressIntegration.config.ts\"",
"ci:cli": "cd packages/cli && yarn ci:server",
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/commands/__test__/exportPreviews.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe("exportPreviews command", () => {
}));
});

afterEach(() => {
fsExtra.removeSync("./out");
fsExtra.removeSync("./packages/cli/previews_html");
});

it("outputs html files to outDir", async () => {
await handler({
outDir: "./out",
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/__test__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fsExtra, { removeSync } from "fs-extra";
import { handler, InitArguments } from "../init";
import { log } from "../../util/serverLogger";

jest.useFakeTimers();
jest.mock("../../util/serverLogger");
jest.mock("../preview/preview", () => ({ handler: jest.fn() }));

Expand All @@ -15,6 +14,9 @@ describe("init command", () => {
.mockImplementation((path) =>
/package\.json/.test(path.toString()) ? "{}" : ""
);
});

afterEach(() => {
removeSync("/tmp/src/emails");
});

Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const handler = buildHandler(
if (undefined === argv.emailsDir)
throw new Error("emailsDir option not set");

if (!existsSync(resolve(argv.emailsDir, "previews"))) {
if (existsSync(resolve(argv.emailsDir, "previews"))) {
log("Using emails directory", argv.emailsDir);
} else {
const options = {
isTypescript: argv.typescript,
emailsDir: argv.emailsDir,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/emails

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 10 additions & 11 deletions packages/cli/src/util/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import tree from "tree-node-cli";
import { log } from "./serverLogger";

export async function generateEmailsDirectory({
isTypescript,
emailsDir,
isTypescript,
}: {
isTypescript: boolean;
emailsDir: string;
isTypescript: boolean;
}) {
// copy the emails dir template in!
const path = `generator_templates/${isTypescript ? "ts" : "js"}/emails`;
const srcDir =
process.env.MM_DEV || process.env.NODE_ENV === "test"
? __dirname + "/.."
: __dirname + "/../src";
await copy(resolve(srcDir, path), emailsDir, {
overwrite: false,

// copy the emails dir template in!
const srcEmails = isTypescript ? "emails" : "emails-js";
await copy(resolve(srcDir, srcEmails), emailsDir, { overwrite: false });

const fileTree = tree(emailsDir, {
exclude: [/node_modules|\.mailing|yarn\.lock|yalc\.lock/],
});
log(
`generated your emails dir at ${emailsDir}:\n${tree(emailsDir, {
exclude: [/node_modules|\.mailing|yarn\.lock|yalc\.lock/],
})}`
);
log(`generated your emails dir at ${emailsDir}:\n${fileTree}`);
}
2 changes: 1 addition & 1 deletion packages/web/pages/docs/templates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Lancey [Demo](https://lancey-mailing.vercel.app/) / [Source](https://github.com/sofn-xyz/mailing-templates/tree/main/lancey)
- Fynn [Demo](https://fynn-mailing.vercel.app/) / [Source](https://github.com/sofn-xyz/mailing-templates/tree/main/fynn)
- Mailing [Demo](https://emails.mailing.run/) / [Source](https://github.com/sofn-xyz/mailing/tree/main/packages/web/emails)
- BookBook [Demo](https://demo.mailing.run/) / [Source](https://github.com/sofn-xyz/mailing/tree/main/packages/cli/src/generator_templates/ts/emails)
- BookBook [Demo](https://book-book-mailing.vercel.app/) / [Source](https://github.com/sofn-xyz/mailing-templates/tree/main/book-book)

Built some cool templates you want to share? Submit a PR adding it to [the list](https://github.com/sofn-xyz/mailing/blob/main/packages/web/pages/docs/templates.mdx).

Expand Down
18 changes: 0 additions & 18 deletions scripts/build-js-templates

This file was deleted.

20 changes: 20 additions & 0 deletions scripts/generate-emails-js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Generate JS templates from TS Templates
npx tsc \
--allowSyntheticDefaultImports true \
--moduleResolution node \
--jsx preserve \
--target es2020 \
--outDir packages/cli/src/emails-js \
--noEmit false \
packages/cli/src/emails/**/*.tsx \
packages/cli/src/emails/*.tsx \
packages/cli/src/emails/*.ts

# Format the generated JS templates
npx prettier --write packages/cli/src/emails-js/*
yarn eslint --fix --ext .jsx,.js packages/cli/src/emails-js/*

# Add the generated JS templates to git
git add packages/cli/src/emails-js/*

3 comments on commit 1b1a2b0

@vercel
Copy link

@vercel vercel bot commented on 1b1a2b0 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 1b1a2b0 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./packages/web

web-git-main-sofn.vercel.app
web-rho-puce.vercel.app
web-sofn.vercel.app
mailing.run
www.mailing.run

@vercel
Copy link

@vercel vercel bot commented on 1b1a2b0 Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web-emails – ./packages/web

web-emails-git-main-sofn.vercel.app
mailing-web.vercel.app
web-emails-sofn.vercel.app
emails.mailing.run

Please sign in to comment.