Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 62b5811

Browse files
committed
add code import - remark
1 parent 495da1c commit 62b5811

File tree

6 files changed

+184
-3
lines changed

6 files changed

+184
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"react-icons": "^5.3.0",
6868
"rehype-autolink-headings": "^7.1.0",
6969
"remark": "^15.0.1",
70+
"remark-code-import": "^1.2.0",
7071
"remark-gfm": "^4.0.0",
7172
"remark-mdx": "^3.0.0",
7273
"simple-functional-loader": "^1.2.1",

src/assets/cli-usage.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Nitric - The fastest way to build serverless apps
2+
3+
To start with nitric, run the 'nitric new' command:
4+
5+
$ nitric new
6+
7+
This will guide you through project creation, including selecting from available templates.
8+
9+
For further details visit our docs https://nitric.io/docs
10+
11+
Usage:
12+
nitric [command]
13+
14+
Available Commands:
15+
build Build a Nitric project
16+
completion Generate the autocompletion script for the specified shell
17+
down Undeploy a previously deployed stack, deleting resources
18+
help Help about any command
19+
new Create a new project
20+
run Run your project locally for development and testing
21+
stack Manage stacks (the deployed app containing multiple resources e.g. services, buckets and topics)
22+
start Run nitric services locally for development and testing
23+
up Create or update a deployed stack
24+
version Print the version number of this CLI
25+
26+
Flags:
27+
--ci CI mode, disable output styling and auto-confirm all operations
28+
-h, --help help for nitric
29+
30+
Use "nitric [command] --help" for more information about a command.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { api, sql } from '@nitric/sdk'
2+
import { drizzle } from 'drizzle-orm/postgres-js'
3+
import * as schema from '../schema'
4+
import postgres from 'postgres'
5+
import { eq } from 'drizzle-orm'
6+
7+
const mainApi = api('main')
8+
const db = sql('my-data')
9+
10+
let drizzleClient
11+
const getClient = async () => {
12+
// ensure we only create the client once
13+
if (!drizzleClient) {
14+
const connectionString = await db.connectionString()
15+
16+
const queryClient = postgres(connectionString)
17+
drizzleClient = drizzle(queryClient, { schema })
18+
}
19+
return drizzleClient
20+
}
21+
22+
// api demonstrating connecting with drizzle and then doing an insert and select
23+
mainApi.post('/users/:name', async (ctx) => {
24+
const { name } = ctx.req.params
25+
26+
const client = await getClient()
27+
28+
await client.insert(schema.users).values({
29+
name,
30+
email: `${name}@example.com`,
31+
})
32+
33+
const createdUser = await client
34+
.select()
35+
.from(schema.users)
36+
.where(eq(schema.users.name, name))
37+
38+
ctx.res.body = `Created ${name} with ID ${createdUser[0].id}`
39+
40+
return ctx
41+
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { api, sql } from '@nitric/sdk'
2+
import { PrismaClient } from '@prisma/client'
3+
4+
const mainApi = api('main')
5+
const db = sql('my-data')
6+
7+
let prisma
8+
const getClient = async () => {
9+
// ensure we only create the client once
10+
if (!prisma) {
11+
const connectionString = await db.connectionString()
12+
13+
prisma = new PrismaClient({
14+
datasourceUrl: connectionString,
15+
})
16+
}
17+
return prisma
18+
}
19+
20+
// api demonstrating connecting to prisma and then doing an insert and select
21+
mainApi.post('/users/:name', async (ctx) => {
22+
const { name } = ctx.req.params
23+
24+
const client = await getClient()
25+
26+
await client.user.create({
27+
data: {
28+
name,
29+
email: `${name}@example.com`,
30+
},
31+
})
32+
33+
const createdUser = await client.user.findFirstOrThrow({
34+
where: {
35+
name,
36+
},
37+
})
38+
39+
ctx.res.body = `Created ${name} with ID ${createdUser.id}`
40+
41+
return ctx
42+
})

src/mdx/remark.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mdxAnnotations } from 'mdx-annotations'
22
import remarkGfm from 'remark-gfm'
3+
import codeImport from 'remark-code-import'
34

4-
export const remarkPlugins = [mdxAnnotations.remark, remarkGfm]
5+
export const remarkPlugins = [mdxAnnotations.remark, remarkGfm, codeImport]

yarn.lock

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,7 @@
18401840
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.3.tgz#acaab0f919ce69cce629c2d4ed2eb4adc1b6c20c"
18411841
integrity sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==
18421842

1843-
"@types/unist@^2.0.0":
1843+
"@types/unist@^2.0.0", "@types/unist@^2.0.2":
18441844
version "2.0.11"
18451845
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.11.tgz#11af57b127e32487774841f7a4e54eab166d03c4"
18461846
integrity sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==
@@ -4284,6 +4284,11 @@ is-boolean-object@^1.1.0:
42844284
call-bind "^1.0.2"
42854285
has-tostringtag "^1.0.0"
42864286

4287+
is-buffer@^2.0.0:
4288+
version "2.0.5"
4289+
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
4290+
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==
4291+
42874292
is-bun-module@^1.0.2:
42884293
version "1.1.0"
42894294
resolved "https://registry.yarnpkg.com/is-bun-module/-/is-bun-module-1.1.0.tgz#a66b9830869437f6cdad440ba49ab6e4dc837269"
@@ -5533,6 +5538,11 @@ mimic-function@^5.0.0:
55335538
resolved "https://registry.yarnpkg.com/mimic-function/-/mimic-function-5.0.1.tgz#acbe2b3349f99b9deaca7fb70e48b83e94e67076"
55345539
integrity sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==
55355540

5541+
min-indent@^1.0.1:
5542+
version "1.0.1"
5543+
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869"
5544+
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
5545+
55365546
55375547
version "9.0.3"
55385548
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825"
@@ -6246,6 +6256,15 @@ rehype-stringify@^10.0.0:
62466256
hast-util-to-html "^9.0.0"
62476257
unified "^11.0.0"
62486258

6259+
remark-code-import@^1.2.0:
6260+
version "1.2.0"
6261+
resolved "https://registry.yarnpkg.com/remark-code-import/-/remark-code-import-1.2.0.tgz#2f879c05909eb5f7cf5a1236bab415010eec69dd"
6262+
integrity sha512-fgwLruqlZbVOIhCJFjY+JDwPZhA4/eK3InJzN8Ox8UDdtudpG212JwtRj6la+lAzJU7JmSEyewZSukVZdknt3Q==
6263+
dependencies:
6264+
strip-indent "^4.0.0"
6265+
to-gatsby-remark-plugin "^0.1.0"
6266+
unist-util-visit "^4.1.0"
6267+
62496268
remark-frontmatter@^5.0.0:
62506269
version "5.0.0"
62516270
resolved "https://registry.yarnpkg.com/remark-frontmatter/-/remark-frontmatter-5.0.0.tgz#b68d61552a421ec412c76f4f66c344627dc187a2"
@@ -6843,6 +6862,13 @@ strip-final-newline@^3.0.0:
68436862
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-3.0.0.tgz#52894c313fbff318835280aed60ff71ebf12b8fd"
68446863
integrity sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==
68456864

6865+
strip-indent@^4.0.0:
6866+
version "4.0.0"
6867+
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-4.0.0.tgz#b41379433dd06f5eae805e21d631e07ee670d853"
6868+
integrity sha512-mnVSV2l+Zv6BLpSD/8V87CW/y9EmmbYzGCIavsnsI6/nwn26DwffM/yztm30Z/I2DY9wdS3vXVCMnHDgZaVNoA==
6869+
dependencies:
6870+
min-indent "^1.0.1"
6871+
68466872
strip-json-comments@^3.1.1:
68476873
version "3.1.1"
68486874
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
@@ -6993,13 +7019,28 @@ tmp@~0.2.3:
69937019
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae"
69947020
integrity sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==
69957021

7022+
to-gatsby-remark-plugin@^0.1.0:
7023+
version "0.1.0"
7024+
resolved "https://registry.yarnpkg.com/to-gatsby-remark-plugin/-/to-gatsby-remark-plugin-0.1.0.tgz#34167b2c3cf3209745cf97e5a488042586f9990d"
7025+
integrity sha512-blmhJ/gIrytWnWLgPSRCkhCPeki6UBK2daa3k9mGahN7GjwHu8KrS7F70MvwlsG7IE794JLgwAdCbi4hU4faFQ==
7026+
dependencies:
7027+
to-vfile "^6.1.0"
7028+
69967029
to-regex-range@^5.0.1:
69977030
version "5.0.1"
69987031
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
69997032
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
70007033
dependencies:
70017034
is-number "^7.0.0"
70027035

7036+
to-vfile@^6.1.0:
7037+
version "6.1.0"
7038+
resolved "https://registry.yarnpkg.com/to-vfile/-/to-vfile-6.1.0.tgz#5f7a3f65813c2c4e34ee1f7643a5646344627699"
7039+
integrity sha512-BxX8EkCxOAZe+D/ToHdDsJcVI4HqQfmw0tCkp31zf3dNP/XWIAjU4CmeuSwsSoOzOTqHPOL0KUzyZqJplkD0Qw==
7040+
dependencies:
7041+
is-buffer "^2.0.0"
7042+
vfile "^4.0.0"
7043+
70037044
toml@^3.0.0:
70047045
version "3.0.0"
70057046
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
@@ -7221,6 +7262,13 @@ unist-util-remove-position@^5.0.0:
72217262
"@types/unist" "^3.0.0"
72227263
unist-util-visit "^5.0.0"
72237264

7265+
unist-util-stringify-position@^2.0.0:
7266+
version "2.0.3"
7267+
resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz#cce3bfa1cdf85ba7375d1d5b17bdc4cada9bd9da"
7268+
integrity sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==
7269+
dependencies:
7270+
"@types/unist" "^2.0.2"
7271+
72247272
unist-util-stringify-position@^4.0.0:
72257273
version "4.0.0"
72267274
resolved "https://registry.yarnpkg.com/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz#449c6e21a880e0855bf5aabadeb3a740314abac2"
@@ -7244,7 +7292,7 @@ unist-util-visit-parents@^6.0.0:
72447292
"@types/unist" "^3.0.0"
72457293
unist-util-is "^6.0.0"
72467294

7247-
unist-util-visit@^4.1.1:
7295+
unist-util-visit@^4.1.0, unist-util-visit@^4.1.1:
72487296
version "4.1.2"
72497297
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-4.1.2.tgz#125a42d1eb876283715a3cb5cceaa531828c72e2"
72507298
integrity sha512-MSd8OUGISqHdVvfY9TPhyK2VdUrPgxkUtWSuMHF6XAAFuL4LokseigBnZtPnJMu+FbynTkFNnFlyjxpVKujMRg==
@@ -7352,6 +7400,14 @@ vfile-location@^5.0.0:
73527400
"@types/unist" "^3.0.0"
73537401
vfile "^6.0.0"
73547402

7403+
vfile-message@^2.0.0:
7404+
version "2.0.4"
7405+
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-2.0.4.tgz#5b43b88171d409eae58477d13f23dd41d52c371a"
7406+
integrity sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==
7407+
dependencies:
7408+
"@types/unist" "^2.0.0"
7409+
unist-util-stringify-position "^2.0.0"
7410+
73557411
vfile-message@^4.0.0:
73567412
version "4.0.2"
73577413
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-4.0.2.tgz#c883c9f677c72c166362fd635f21fc165a7d1181"
@@ -7360,6 +7416,16 @@ vfile-message@^4.0.0:
73607416
"@types/unist" "^3.0.0"
73617417
unist-util-stringify-position "^4.0.0"
73627418

7419+
vfile@^4.0.0:
7420+
version "4.2.1"
7421+
resolved "https://registry.yarnpkg.com/vfile/-/vfile-4.2.1.tgz#03f1dce28fc625c625bc6514350fbdb00fa9e624"
7422+
integrity sha512-O6AE4OskCG5S1emQ/4gl8zK586RqA3srz3nfK/Viy0UPToBc5Trp9BVFb1u0CjsKrAWwnpr4ifM/KBXPWwJbCA==
7423+
dependencies:
7424+
"@types/unist" "^2.0.0"
7425+
is-buffer "^2.0.0"
7426+
unist-util-stringify-position "^2.0.0"
7427+
vfile-message "^2.0.0"
7428+
73637429
vfile@^6.0.0, vfile@^6.0.1:
73647430
version "6.0.3"
73657431
resolved "https://registry.yarnpkg.com/vfile/-/vfile-6.0.3.tgz#3652ab1c496531852bf55a6bac57af981ebc38ab"

0 commit comments

Comments
 (0)