Skip to content

Commit a1bc8ba

Browse files
committed
chore: clean up create-mail, tests
1 parent e8751a6 commit a1bc8ba

File tree

9 files changed

+210
-16
lines changed

9 files changed

+210
-16
lines changed

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Release Projects
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
tags-ignore:
9+
- '*-v*'
10+
11+
permissions:
12+
contents: read
13+
pages: write
14+
id-token: write
15+
16+
jobs:
17+
release:
18+
if: |
19+
!startsWith(github.event.head_commit.message, 'chore(release):') &&
20+
!startsWith(github.event.head_commit.message, 'chore(repo):')
21+
22+
permissions:
23+
contents: write
24+
25+
runs-on: ubuntu-latest
26+
27+
name: release
28+
29+
steps:
30+
- name: Checkout Commit
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 100
34+
fetch-tags: true
35+
ref: main
36+
token: ${{ secrets.GH_TOKEN }}
37+
38+
- name: Fetch Tags
39+
run: git fetch --tags
40+
41+
- name: Set Git Config
42+
run: |
43+
git config pull.rebase false
44+
git config --global user.email "[email protected]"
45+
git config --global user.name "Release Workflow"
46+
git remote set-url origin https://github.com/${{ github.repository }}
47+
48+
- name: Setup
49+
uses: ./.github/actions/setup
50+
51+
- name: Build Projects
52+
run: |
53+
moon jsx-email:build
54+
moon create-mail:build
55+
moon run :build --query "project~plugin-*"
56+
57+
- name: Release
58+
run: moon run :release --affected --concurrency 1 --remote
59+
env:
60+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
61+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

docs/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For those not familiar with the bits above, here are some links to resources tha
2626

2727
## New Projects
2828

29-
If you're starting a new project — whether that's a project solely for email templates, or a project that will eventually host additional code — our [`create-mail`](https://github.com/shellscape/jsx-email/tree/main/packages/create-jsx-email) utility is a perfect choice, and the fastest way to get started. The utility will scaffold a new project and get everything ready for developing new email templates. To begin, make sure you have a terminal (or command line) open and your current working directory is the directory you'd like to create a new project. Run the following command in your terminal (without the `$` symbol):
29+
If you're starting a new project — whether that's a project solely for email templates, or a project that will eventually host additional code — our [`create-mail`](https://github.com/shellscape/jsx-email/tree/main/packages/create-mail) utility is a perfect choice, and the fastest way to get started. The utility will scaffold a new project and get everything ready for developing new email templates. To begin, make sure you have a terminal (or command line) open and your current working directory is the directory you'd like to create a new project. Run the following command in your terminal (without the `$` symbol):
3030

3131
```console
3232
$ npm create jsx-email

packages/create-mail/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Please upgrade Node.js to a supported version: ${engines}\n`);
2525
await checkEngine();
2626
const { run } = await import('./dist/index.js');
2727
return run();
28-
})
28+
})()
2929
.then(() => process.exit(0))
3030
.catch((error) => {
3131
danger(error);

packages/create-mail/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const createEmail = async ({ jsx, name, outputPath }: CreateEmailArgs) =>
7777
return outPath;
7878
};
7979

80-
const run = async () => {
80+
export const run = async () => {
8181
log(intro);
8282

8383
const skip = process.argv.some((arg) => arg === '--yes');
@@ -184,5 +184,3 @@ ${install}
184184

185185
log(footer);
186186
};
187-
188-
run();

packages/jsx-email/src/cli/commands/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const command: CommandFn = async (argv: CreateOptions, input) => {
5555

5656
const [name] = input;
5757
const { jsx, out } = argv;
58-
const template = await readFile(join(__dirname, '../../../templates/email.mustache'), 'utf8');
58+
const template = await readFile(join(__dirname, '../../templates/email.mustache'), 'utf8');
5959
const data = {
6060
asConst: jsx ? '' : asConst,
6161
name,

test/cli/.snapshots/create-jsx-email.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`create-jsx-email > command 1`] = `
3+
exports[`create-mail > command 1`] = `
44
"
5-
create-jsx-email
5+
create-mail
66
77
The fastest way to get started with JSX Email
88
@@ -22,7 +22,7 @@ Check out the docs! http://jsx.email/docs/quick-start
2222
"
2323
`;
2424

25-
exports[`create-jsx-email > command 2`] = `
25+
exports[`create-mail > command 2`] = `
2626
"import {
2727
Body,
2828
Button,
@@ -124,7 +124,7 @@ export const Template = ({ email, name }: TemplateProps) => (
124124
"
125125
`;
126126
127-
exports[`create-jsx-email > command 3`] = `
127+
exports[`create-mail > command 3`] = `
128128
[
129129
".test/new/.gitignore",
130130
".test/new/README.md",
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`create-mail > command 1`] = `
4+
"
5+
create-mail
6+
7+
The fastest way to get started with JSX Email
8+
9+
10+
Creating Project at: .test/new/templates
11+
Creating a new template at: .test/new/templates/email.tsx
12+
13+
✓ jsx-email Project Created
14+
15+
Next, run:
16+
17+
$ cd email-project
18+
$ pnpm install
19+
$ pnpm run dev
20+
21+
Check out the docs! http://jsx.email/docs/quick-start
22+
"
23+
`;
24+
25+
exports[`create-mail > command 2`] = `
26+
"import {
27+
Body,
28+
Button,
29+
Container,
30+
Head,
31+
Hr,
32+
Html,
33+
Link,
34+
Preview,
35+
Section,
36+
Text
37+
} from 'jsx-email';
38+
39+
interface TemplateProps {
40+
email: string;
41+
name: string;
42+
}
43+
44+
const main = {
45+
backgroundColor: '#f6f9fc',
46+
fontFamily:
47+
'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Ubuntu,sans-serif'
48+
};
49+
50+
const container = {
51+
backgroundColor: '#ffffff',
52+
margin: '0 auto',
53+
marginBottom: '64px',
54+
padding: '20px 0 48px'
55+
};
56+
57+
const box = {
58+
padding: '0 48px'
59+
};
60+
61+
const hr = {
62+
borderColor: '#e6ebf1',
63+
margin: '20px 0'
64+
};
65+
66+
const paragraph = {
67+
color: '#777',
68+
fontSize: '16px',
69+
lineHeight: '24px',
70+
textAlign: 'left' as const
71+
};
72+
73+
const anchor = {
74+
color: '#777'
75+
};
76+
77+
const button = {
78+
fontWeight: 'bold',
79+
padding: '10px',
80+
textDecoration: 'none'
81+
};
82+
83+
export const previewProps: TemplateProps = {
84+
85+
name: 'Bruce Wayne'
86+
};
87+
88+
export const templateName = 'email-project';
89+
90+
export const Template = ({ email, name }: TemplateProps) => (
91+
<Html>
92+
<Head />
93+
<Preview>This is our email preview text for {name} &lt;{email}&gt;</Preview>
94+
<Body style={main}>
95+
<Container style={container}>
96+
<Section style={box}>
97+
<Text style={paragraph}>This is our email body text</Text>
98+
<Button
99+
align={'center'}
100+
backgroundColor={'#777'}
101+
borderRadius={5}
102+
fontSize={16}
103+
height={60}
104+
href="https://example.com"
105+
style={button}
106+
textColor={'#fff'}
107+
width={160}
108+
>
109+
Action Button
110+
</Button>
111+
<Hr style={hr} />
112+
<Text style={paragraph}>
113+
This is text content with a{' '}
114+
<Link style={anchor} href="mailto:{email}">
115+
link
116+
</Link>
117+
.
118+
</Text>
119+
</Section>
120+
</Container>
121+
</Body>
122+
</Html>
123+
);
124+
"
125+
`;
126+
127+
exports[`create-mail > command 3`] = `
128+
[
129+
".test/new/.gitignore",
130+
".test/new/README.md",
131+
".test/new/package.json",
132+
".test/new/tsconfig.json",
133+
".test/new/templates/email.tsx",
134+
]
135+
`;

test/cli/.snapshots/create.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface TemplateProps {
2222
const main = {
2323
backgroundColor: '#f6f9fc',
2424
fontFamily:
25-
'-apple-system,BlinkMacSystemFont,\\"Segoe UI\\",Roboto,\\"Helvetica Neue\\",Ubuntu,sans-serif'
25+
'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Ubuntu,sans-serif'
2626
};
2727
2828
const container = {
@@ -79,7 +79,7 @@ export const Template = ({ email, name }: TemplateProps) => (
7979
borderRadius={5}
8080
fontSize={16}
8181
height={60}
82-
href=\\"https://example.com\\"
82+
href="https://example.com"
8383
style={button}
8484
textColor={'#fff'}
8585
width={160}
@@ -89,7 +89,7 @@ export const Template = ({ email, name }: TemplateProps) => (
8989
<Hr style={hr} />
9090
<Text style={paragraph}>
9191
This is text content with a{' '}
92-
<Link style={anchor} href=\\"mailto:{email}\\">
92+
<Link style={anchor} href="mailto:{email}">
9393
link
9494
</Link>
9595
.

test/cli/create-jsx-email.test.ts renamed to test/cli/create-mail.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import strip from 'strip-ansi';
77

88
process.chdir(__dirname);
99

10-
describe('create-jsx-email', async () => {
10+
describe('create-mail', async () => {
1111
test('command', async () => {
1212
const { stdout } = await execa({
1313
cwd: __dirname,
1414
shell: true
1515
// Note: For some reason `pnpm exec` is fucking with our CWD, and resets it to
1616
// packages/jsx-email, which causes the config not to be found. so we use npx instead
17-
})`IS_CLI_TEST=true create-jsx-email .test/new --yes`;
17+
})`IS_CLI_TEST=true create-mail .test/new --yes`;
1818
const plain = strip(stdout)
19-
.replace(/^(.*)create-jsx-email/, 'create-jsx-email')
19+
.replace(/^(.*)create-mail/, 'create-mail')
2020
.replace(/v(\d+\.\d+\.\d+)/, '');
2121

2222
expect(plain).toMatchSnapshot();

0 commit comments

Comments
 (0)