generated from sst/monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 496b3dd
Showing
18 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# sst | ||
.sst | ||
|
||
# tmp files | ||
.#* | ||
|
||
# env | ||
.env*.local | ||
.env | ||
|
||
# opennext | ||
.open-next | ||
|
||
# misc | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 SST | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Monorepo Template | ||
|
||
A template to create a monorepo SST v3 project. [Learn more](https://sst.dev/docs/set-up-a-monorepo). | ||
|
||
## Get started | ||
|
||
1. Use this template to [create your own repo](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template). | ||
|
||
2. Clone the new repo. | ||
|
||
```bash | ||
git clone <REPO_URL> MY_APP | ||
cd MY_APP | ||
``` | ||
|
||
3. Rename the files in the project to the name of your app. | ||
|
||
```bash | ||
npx replace-in-file '/monorepo-template/g' 'MY_APP' '**/*.*' --verbose | ||
``` | ||
|
||
4. Deploy! | ||
|
||
```bash | ||
npm install | ||
npx sst deploy | ||
``` | ||
|
||
5. Optionally, enable [_git push to deploy_](https://sst.dev/docs/console/#autodeploy). | ||
|
||
## Usage | ||
|
||
This template uses [npm Workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces). It has 3 packages to start with and you can add more it. | ||
|
||
1. `core/` | ||
|
||
This is for any shared code. It's defined as modules. For example, there's the `Example` module. | ||
|
||
```ts | ||
export module Example { | ||
export function hello() { | ||
return "Hello, world!"; | ||
} | ||
} | ||
``` | ||
|
||
That you can use across other packages using. | ||
|
||
```ts | ||
import { Example } from "@aws-monorepo/core/example"; | ||
|
||
Example.hello(); | ||
``` | ||
|
||
We also have [Vitest](https://vitest.dev/) configured for testing this package with the `sst shell` CLI. | ||
|
||
```bash | ||
npm test | ||
``` | ||
|
||
2. `functions/` | ||
|
||
This is for your Lambda functions and it uses the `core` package as a local dependency. | ||
|
||
3. `scripts/` | ||
|
||
This is for any scripts that you can run on your SST app using the `sst shell` CLI and [`tsx`](https://www.npmjs.com/package/tsx). For example, you can run the example script using: | ||
|
||
```bash | ||
npm run shell src/example.ts | ||
``` | ||
|
||
### Infrastructure | ||
|
||
The `infra/` directory allows you to logically split the infrastructure of your app into separate files. This can be helpful as your app grows. | ||
|
||
In the template, we have an `api.ts`, and `storage.ts`. These export the created resources. And are imported in the `sst.config.ts`. | ||
|
||
--- | ||
|
||
**Join our community** [Discord](https://sst.dev/discord) | [YouTube](https://www.youtube.com/c/sst-dev) | [X.com](https://x.com/SST_dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { bucket } from "./storage"; | ||
|
||
export const myApi = new sst.aws.Function("MyApi", { | ||
url: true, | ||
link: [bucket], | ||
handler: "packages/functions/src/api.handler" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const bucket = new sst.aws.Bucket("MyBucket"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "monorepo-template", | ||
"version": "0.0.0", | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"scripts": {}, | ||
"devDependencies": { | ||
"@tsconfig/node22": "^22", | ||
"typescript": "^5" | ||
}, | ||
"dependencies": { | ||
"sst": "^3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@monorepo-template/core", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"scripts": { | ||
"test": "sst shell vitest" | ||
}, | ||
"exports": { | ||
"./*": [ | ||
"./src/*/index.ts", | ||
"./src/*.ts" | ||
] | ||
}, | ||
"dependencies": { | ||
"sst": "*" | ||
}, | ||
"devDependencies": { | ||
"vitest": "^2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export module Example { | ||
export function hello() { | ||
return "Hello, world!"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect, test } from "vitest"; | ||
import { Example } from "../"; | ||
|
||
test("Hello test", () => { | ||
const expected = "Hello, world!"; | ||
|
||
expect(Example.hello()).toEqual(expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@monorepo-template/functions", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"dependencies": { | ||
"@monorepo-template/core": "*", | ||
"sst": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Resource } from "sst"; | ||
import { Handler } from "aws-lambda"; | ||
import { Example } from "@monorepo-template/core/example"; | ||
|
||
export const handler: Handler = async (_event) => { | ||
return { | ||
statusCode: 200, | ||
body: `${Example.hello()} Linked to ${Resource.MyBucket.name}.`, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@monorepo-template/scripts", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"dependencies": { | ||
"@monorepo-template/core": "*", | ||
"sst": "*" | ||
}, | ||
"scripts": { | ||
"shell": "sst shell tsx" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22", | ||
"tsx": "^4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Resource } from "sst"; | ||
import { Example } from "@monorepo-template/core/example"; | ||
|
||
console.log(`${Example.hello()} Linked to ${Resource.MyBucket.name}.`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@tsconfig/node22/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"moduleResolution": "Bundler", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// <reference path="./.sst/platform/config.d.ts" /> | ||
|
||
export default $config({ | ||
app(input) { | ||
return { | ||
name: "monorepo-template", | ||
removal: input?.stage === "production" ? "retain" : "remove", | ||
protect: ["production"].includes(input?.stage), | ||
home: "aws", | ||
}; | ||
}, | ||
async run() { | ||
const storage = await import("./infra/storage"); | ||
await import("./infra/api"); | ||
|
||
return { | ||
MyBucket: storage.bucket.name, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |