Skip to content

Commit ed94b94

Browse files
authored
Refactor repo to become a monorepo (#34)
This PR turns the repo into a monorepo using [turborepo](https://turborepo.com/). This facilitates adding more projects to this repo, such as an email server. The current repo is already kinda a monorepo, with a CLI component and an emails component. This PR establishes clear boundaries between projects.
1 parent f6c4f27 commit ed94b94

30 files changed

+3260
-998
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
run: npm ci
2525
- name: Build
2626
run: npm run build
27-
- name: Create Package
27+
- name: Create CLI Package
2828
run: |
29+
cd apps/cli
30+
2931
if npm version --no-git-tag-version from-git > /dev/null 2>&1; then
3032
echo "Using auto version based on git tag"
3133
else
@@ -38,10 +40,10 @@ jobs:
3840
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
3941
with:
4042
name: package
41-
path: out/
43+
path: apps/cli/out/
4244
- name: Attach build artifact to release
4345
if: github.event_name == 'release'
4446
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # 2.0.8
4547
with:
46-
files: out/*.tgz
48+
files: apps/cli/out/*.tgz
4749

.gitignore

Lines changed: 3 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,3 @@
1-
# Created by https://www.toptal.com/developers/gitignore/api/node
2-
# Edit at https://www.toptal.com/developers/gitignore?templates=node
3-
4-
### Node ###
5-
# Logs
6-
logs
7-
*.log
8-
npm-debug.log*
9-
yarn-debug.log*
10-
yarn-error.log*
11-
lerna-debug.log*
12-
.pnpm-debug.log*
13-
14-
# Diagnostic reports (https://nodejs.org/api/report.html)
15-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16-
17-
# Runtime data
18-
pids
19-
*.pid
20-
*.seed
21-
*.pid.lock
22-
23-
# Directory for instrumented libs generated by jscoverage/JSCover
24-
lib-cov
25-
26-
# Coverage directory used by tools like istanbul
27-
coverage
28-
*.lcov
29-
30-
# nyc test coverage
31-
.nyc_output
32-
33-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34-
.grunt
35-
36-
# Bower dependency directory (https://bower.io/)
37-
bower_components
38-
39-
# node-waf configuration
40-
.lock-wscript
41-
42-
# Compiled binary addons (https://nodejs.org/api/addons.html)
43-
build/Release
44-
45-
# Dependency directories
46-
node_modules/
47-
jspm_packages/
48-
49-
# Snowpack dependency directory (https://snowpack.dev/)
50-
web_modules/
51-
52-
# TypeScript cache
53-
*.tsbuildinfo
54-
55-
# Optional npm cache directory
56-
.npm
57-
58-
# Optional eslint cache
59-
.eslintcache
60-
61-
# Optional stylelint cache
62-
.stylelintcache
63-
64-
# Microbundle cache
65-
.rpt2_cache/
66-
.rts2_cache_cjs/
67-
.rts2_cache_es/
68-
.rts2_cache_umd/
69-
70-
# Optional REPL history
71-
.node_repl_history
72-
73-
# Output of 'npm pack'
74-
*.tgz
75-
76-
# Yarn Integrity file
77-
.yarn-integrity
78-
79-
# dotenv environment variable files
80-
.env
81-
.env.development.local
82-
.env.test.local
83-
.env.production.local
84-
.env.local
85-
86-
# parcel-bundler cache (https://parceljs.org/)
87-
.cache
88-
.parcel-cache
89-
90-
# Next.js build output
91-
.next
92-
out
93-
94-
# Nuxt.js build / generate output
95-
.nuxt
96-
dist
97-
98-
# Gatsby files
99-
.cache/
100-
# Comment in the public line in if your project uses Gatsby and not Next.js
101-
# https://nextjs.org/blog/next-9-1#public-directory-support
102-
# public
103-
104-
# vuepress build output
105-
.vuepress/dist
106-
107-
# vuepress v2.x temp and cache directory
108-
.temp
109-
110-
# Docusaurus cache and generated files
111-
.docusaurus
112-
113-
# Serverless directories
114-
.serverless/
115-
116-
# FuseBox cache
117-
.fusebox/
118-
119-
# DynamoDB Local files
120-
.dynamodb/
121-
122-
# TernJS port file
123-
.tern-port
124-
125-
# Stores VSCode versions used for testing VSCode extensions
126-
.vscode-test
127-
128-
# yarn v2
129-
.yarn/cache
130-
.yarn/unplugged
131-
.yarn/build-state.yml
132-
.yarn/install-state.gz
133-
.pnp.*
134-
135-
### Node Patch ###
136-
# Serverless Webpack directories
137-
.webpack/
138-
139-
# Optional stylelint cache
140-
141-
# SvelteKit build / generate output
142-
.svelte-kit
143-
144-
# End of https://www.toptal.com/developers/gitignore/api/node
145-
146-
/.react-email
147-
# For storing development cache
148-
/emails/static/cache
1+
.turbo
2+
node_modules
3+
dist

apps/cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/out

apps/cli/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@watonomous/watcloud-email-cli",
3+
"bin": {
4+
"watcloud-emails": "dist/index.js"
5+
},
6+
"files": [
7+
"dist"
8+
],
9+
"scripts": {
10+
"dev": "tsup --watch",
11+
"build": "tsup",
12+
"check-types": "tsc --noEmit",
13+
"clean": "rm -rf dist"
14+
},
15+
"devDependencies": {
16+
"@react-email/components": "^0.1.1",
17+
"commander": "^12.1.0",
18+
"@repo/ts-config": "*",
19+
"@repo/utils": "*",
20+
"@watonomous/watcloud-email-templates": "*",
21+
"tsup": "^8.5.0",
22+
"typescript": "^5.6.3"
23+
}
24+
}

cli/index.ts renamed to apps/cli/src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import { render } from '@react-email/components';
44
import { Command } from 'commander';
55
import fs from 'fs';
6-
import { waitForAssets } from '../utils/watcloud-uri';
6+
import { waitForAssets } from '@repo/utils/watcloud-uri';
7+
import { Emails } from '@watonomous/watcloud-email-templates';
78

89
const program = new Command();
910

1011
// Returns the email template with the given name and performs any necessary initialization.
1112
async function getTemplate(template_name: string, props_array: any[] = []) {
12-
const mod = require(`../emails/${template_name}`);
13+
const mod = Emails[template_name];
14+
if (!mod) {
15+
throw new Error(`Template ${template_name} not found`);
16+
}
1317
if (mod.init) {
1418
await Promise.all(props_array.map(mod.init));
1519
}
@@ -89,12 +93,7 @@ program
8993
.command('list')
9094
.description('List all available templates')
9195
.action(() => {
92-
const files = fs.readdirSync(__dirname + '/../emails');
93-
const templates = files.map((file) => file.replace(/\.jsx?$|\.tsx?$/, ''));
94-
console.log('Available templates:');
95-
for (const template of templates) {
96-
console.log(template);
97-
}
96+
console.log('Available templates: ' + Object.keys(Emails).join(','));
9897
});
9998

10099
program.parse();

apps/cli/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "@repo/ts-config/tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "dist"
6+
},
7+
"include": [
8+
"src"
9+
]
10+
}

apps/cli/tsup.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig((options) => ({
4+
entry: ['src/index.ts'],
5+
format: ['cjs'],
6+
// Don't need QoL features when building the final bundle
7+
dts: Boolean(options.watch),
8+
sourcemap: Boolean(options.watch),
9+
minify: !options.watch,
10+
// Include all dependencies in the final bundle
11+
noExternal: options.watch ? [] : [ /.*/ ],
12+
// Clean the output directory before building when building the final bundle
13+
clean: !options.watch,
14+
}));

0 commit comments

Comments
 (0)