Skip to content

Commit

Permalink
feat: 🎸 finish first deno implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
klaascuvelier committed Feb 11, 2022
1 parent 06982d9 commit c6d02e4
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 114 deletions.
43 changes: 39 additions & 4 deletions packages/nx-deno-deploy/README.md
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>
```
10 changes: 10 additions & 0 deletions packages/nx-deno-deploy/executors.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"$schema": "http://json-schema.org/schema",
"executors": {
"serve": {
"implementation": "./src/executors/serve/executor",
"schema": "./src/executors/serve/schema.json",
"description": "Run Deno project locally"
},
"test": {
"implementation": "./src/executors/test/executor",
"schema": "./src/executors/test/schema.json",
"description": "Test Deno project"
},
"deploy": {
"implementation": "./src/executors/deploy/executor",
"schema": "./src/executors/deploy/schema.json",
Expand Down
16 changes: 8 additions & 8 deletions packages/nx-deno-deploy/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"name": "nx-netlify-deploy",
"version": "0.0.1",
"generators": {
"add-deploy-target": {
"factory": "./src/generators/add-deploy-target/generator",
"schema": "./src/generators/add-deploy-target/schema.json",
"description": "Adds the Deno deploy target"
"add-targets": {
"factory": "./src/generators/add-targets/generator",
"schema": "./src/generators/add-targets/schema.json",
"description": "Adds the Deno deploy, serve and test target"
},
"project": {
"factory": "./src/generators/create-deno-project/index",
"schema": "./src/generators/create-deno-project/schema.json",
"description": "Creates a deno project"
"create-project": {
"factory": "./src/generators/create-project/index",
"schema": "./src/generators/create-project/schema.json",
"description": "Creates a Deno project"
}
}
}
28 changes: 22 additions & 6 deletions packages/nx-deno-deploy/src/executors/deploy/executor.ts
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 ?? ''
);
}
6 changes: 2 additions & 4 deletions packages/nx-deno-deploy/src/executors/deploy/schema.d.ts
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;
}
15 changes: 4 additions & 11 deletions packages/nx-deno-deploy/src/executors/deploy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,16 @@
"description": "Deploys a project to Deno",
"type": "object",
"properties": {
"projectName": {
"type": "string",
"description": "Deno project name"
},
"entryPath": {
"token": {
"type": "string",
"description": "Entry path in the project artifacts"
"description": "Optional token to use for deploy authentication",
"default": ""
},
"isProd": {
"type": "boolean",
"description": "Is production deploy",
"default": false
},
"token": {
"type": "string",
"description": "Deploy token",
}
},
"required": ["projectName", "entryPath"]
"required": []
}
19 changes: 19 additions & 0 deletions packages/nx-deno-deploy/src/executors/serve/executor.ts
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);
}
8 changes: 8 additions & 0 deletions packages/nx-deno-deploy/src/executors/serve/schema.json
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": {}
}
16 changes: 16 additions & 0 deletions packages/nx-deno-deploy/src/executors/test/executor.ts
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);
}
10 changes: 10 additions & 0 deletions packages/nx-deno-deploy/src/executors/test/schema.json
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": []
}

This file was deleted.

This file was deleted.

42 changes: 42 additions & 0 deletions packages/nx-deno-deploy/src/generators/add-targets/generator.ts
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface AddDeployTargetGeneratorSchema {
appName: string;
mainFile: string;
denoProject?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
"index": 0
}
},
"projectName": {
"denoProject": {
"type": "string",
"description": "Name of the Deno project",
"description": "Name of the Deno project (if this differs from the appName)",
"default": ""
},
"token": {
"mainFile": {
"type": "string",
"description": "Optional authentication token"
},
"entryPath": {
"type": "string",
"description": "Entry path to deploy"
"default": "main.ts"
}
},
"required": [
"projectName"
"appName", "mainFile"
]
}

This file was deleted.

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`
Loading

0 comments on commit c6d02e4

Please sign in to comment.