-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 finish first deno implementation
- Loading branch information
1 parent
06982d9
commit c6d02e4
Showing
23 changed files
with
356 additions
and
114 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 |
---|---|---|
@@ -1,8 +1,43 @@ | ||
# nx-deno-deploy | ||
|
||
Deployer and generator for Deno projects | ||
Requires [Deno](https://deno.com/deploy) and [deno-ctl](https://github.com/denoland/deployctl) | ||
|
||
Requires [deno-ctl](https://github.com/denoland/deployctl). | ||
## Executors | ||
|
||
## Add deno deploy to existing project | ||
`npx nx g @k11r/nx-deno-deploy:add-deploy-target <app-name> --projectName=<some-name>` | ||
### Serve | ||
|
||
Serves the project using `deno run`. | ||
|
||
All flags can be provided in the project configuration.s | ||
|
||
### Test | ||
|
||
Test the project using `deno test` | ||
|
||
### Deploy | ||
|
||
Deploy the project to Deno Deploy using `deployctl deploy`. | ||
|
||
Optionally `--isProd=true` can be specified to indicate this is a production deploy. An authentication token can be provided suing `--token=` | ||
|
||
## Generators | ||
|
||
## add-targets | ||
|
||
Adds the `serve`, `test` and `deploy` targets to an existing project. | ||
|
||
Requires the `appName` and a `mainFile` path (relative to the source root). Optionally the `denoProject` param can be used to specify the name of your project on Deno (if it would not match the NX project name). | ||
|
||
``` | ||
npx nx g @k11r/nx-deno-deploy:add-targets <app-name> --mainFile=main.ts | ||
``` | ||
|
||
## create-project | ||
|
||
Creates a new project (in the app folder) with the Deno specifics `serve`, `test` and `deploy` targets. | ||
|
||
Only `appName` is required. Optionally the `denoProject` param can be used to specify the name of your project on Deno (if it would not match the NX project name). | ||
|
||
``` | ||
npx nx g @k11r/nx-deno-deploy:create-project <app-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
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
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
import {ExecutorContext} from "@nrwl/tao/src/shared/workspace"; | ||
import {DeployExecutorSchema} from "./schema"; | ||
import {deployProject} from "../../lib/deploy-ctl"; | ||
import { ExecutorContext } from '@nrwl/tao/src/shared/workspace'; | ||
import { DeployExecutorSchema } from './schema'; | ||
import { deployProject } from '../../lib/deploy-ctl'; | ||
import { FsTree } from '@nrwl/tao/src/shared/tree'; | ||
import { readProjectConfiguration } from '@nrwl/devkit'; | ||
|
||
export default async function deployExecutor(options: DeployExecutorSchema, context: ExecutorContext) { | ||
const {projectName, isProd, token, entryPath} = options; | ||
export default async function deployExecutor( | ||
options: DeployExecutorSchema, | ||
context: ExecutorContext | ||
) { | ||
const { projectName, target } = context; | ||
const { isProd, token } = options; | ||
|
||
const tree = new FsTree(process.cwd(), false); | ||
const projectConfiguration = readProjectConfiguration(tree, projectName); | ||
const sourceRoot = projectConfiguration.sourceRoot; | ||
const { mainFile, denoProject } = target.options; | ||
|
||
return deployProject(entryPath, projectName, token, isProd); | ||
return deployProject( | ||
mainFile, | ||
sourceRoot, | ||
denoProject?.length > 0 ? denoProject : projectName, | ||
isProd ?? false, | ||
token ?? '' | ||
); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export interface DeployExecutorSchema { | ||
projectName: string; | ||
entryPath: string; | ||
token: string; | ||
isProd?: boolean | ||
isProd?: boolean; | ||
token?: string; | ||
} |
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
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,19 @@ | ||
import { ExecutorContext } from '@nrwl/tao/src/shared/workspace'; | ||
import { FsTree } from '@nrwl/tao/src/shared/tree'; | ||
import { readProjectConfiguration } from '@nrwl/devkit'; | ||
import { runProject } from '../../lib/deploy-ctl'; | ||
|
||
export default async function serveExecutor( | ||
options: any, | ||
context: ExecutorContext | ||
) { | ||
const { projectName, target } = context; | ||
const tree = new FsTree(process.cwd(), false); | ||
const projectConfiguration = readProjectConfiguration(tree, projectName); | ||
|
||
const sourceRoot = projectConfiguration.sourceRoot; | ||
const mainFile = target.options.mainFile; | ||
const flags = target.options.flags ?? []; | ||
|
||
return runProject(mainFile, sourceRoot, flags); | ||
} |
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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "Serve executor", | ||
"description": "Runs a Deno project", | ||
"type": "object", | ||
"properties": {} | ||
} |
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 @@ | ||
import { ExecutorContext } from '@nrwl/tao/src/shared/workspace'; | ||
import { FsTree } from '@nrwl/tao/src/shared/tree'; | ||
import { readProjectConfiguration } from '@nrwl/devkit'; | ||
import { testProject } from '../../lib/deploy-ctl'; | ||
|
||
export default async function testExecutor( | ||
options: any, | ||
context: ExecutorContext | ||
) { | ||
const { projectName } = context; | ||
const tree = new FsTree(process.cwd(), false); | ||
const projectConfiguration = readProjectConfiguration(tree, projectName); | ||
const sourceRoot = projectConfiguration.sourceRoot; | ||
|
||
return testProject(sourceRoot); | ||
} |
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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "Test executor", | ||
"description": "Test a Deno project", | ||
"type": "object", | ||
"properties": { | ||
}, | ||
"required": [] | ||
} |
27 changes: 0 additions & 27 deletions
27
packages/nx-deno-deploy/src/generators/add-deploy-target/generator.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/nx-deno-deploy/src/generators/add-deploy-target/schema.d.ts
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
packages/nx-deno-deploy/src/generators/add-targets/generator.ts
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,42 @@ | ||
import { | ||
readProjectConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { AddDeployTargetGeneratorSchema } from './schema'; | ||
|
||
export default async function ( | ||
tree: Tree, | ||
options: AddDeployTargetGeneratorSchema | ||
) { | ||
try { | ||
const { appName, mainFile, denoProject } = options; | ||
|
||
console.log('Adding serve, test and deploy target to ' + appName); | ||
const projectConfiguration = readProjectConfiguration(tree, appName); | ||
|
||
projectConfiguration.targets = { | ||
...projectConfiguration.targets, | ||
serve: { | ||
executor: '@k11r/nx-deno-deploy:serve', | ||
options: { | ||
mainFile, | ||
flags: [], | ||
}, | ||
}, | ||
test: { | ||
executor: '@k11r/nx-deno-deploy:test', | ||
}, | ||
deploy: { | ||
executor: '@k11r/nx-deno-deploy:deploy', | ||
options: { | ||
mainFile, | ||
...(denoProject?.length > 0 ? { denoProject } : null), | ||
}, | ||
}, | ||
}; | ||
updateProjectConfiguration(tree, options.appName, projectConfiguration); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/nx-deno-deploy/src/generators/add-targets/schema.d.ts
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 interface AddDeployTargetGeneratorSchema { | ||
appName: string; | ||
mainFile: string; | ||
denoProject?: string; | ||
} |
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
3 changes: 0 additions & 3 deletions
3
packages/nx-deno-deploy/src/generators/create-deno-project/schema.d.ts
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
packages/nx-deno-deploy/src/generators/create-project/files/README.md
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,62 @@ | ||
# <%= name %> | ||
|
||
This Deno project was created with `@k11r/nx-deno-deploy` | ||
|
||
|
||
|
||
## Commands | ||
|
||
### Serve | ||
|
||
Run any Deno project locally. | ||
|
||
#### Prerequisites | ||
|
||
- Make sure Deno is installed | ||
|
||
#### Permissions | ||
|
||
The permissions to be passed to the Deno CLI can be specified in the NX project configuration. | ||
More information on permissions is available in [the manual](https://deno.land/manual@main/runtime/permission_apis). | ||
|
||
|
||
|
||
|
||
#### Examples | ||
|
||
`nx run <my-project>:serve` | ||
|
||
### Test | ||
|
||
Test application using `deno test`. | ||
More information is available in [the manual](https://deno.land/manual/testing). | ||
|
||
|
||
#### Prerequisites | ||
|
||
- Make sure Deno is installed | ||
|
||
#### Examples | ||
|
||
`nx run <my-project>:test` | ||
|
||
### Deploy | ||
|
||
Deploy the configured project to Deno Deploy. | ||
|
||
Projects will not be build before deploying, by pointing to the entrypath `deployctl` will deploy necessary files directly from the source folder. | ||
|
||
#### Prerequisites | ||
- Make sure you have [deployctl](https://github.com/denoland/deployctl) installed | ||
- Make sure you provide a token in the configuration or have `DENO_DEPLOY_TOKEN` set in your environment | ||
- Make sure you created the project you are about to deploy | ||
|
||
#### Examples | ||
|
||
**Deploy** project using NX-config | ||
|
||
`nx run <my-project>:deploy` | ||
|
||
**Deploy project as prod** | ||
|
||
`nx run <my-project>:deploy --isProd` |
File renamed without changes.
Oops, something went wrong.