-
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.
- Loading branch information
1 parent
eb3aabc
commit 06982d9
Showing
28 changed files
with
414 additions
and
12 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,3 +1,4 @@ | ||
{ | ||
"singleQuote": true | ||
"singleQuote": true, | ||
"tabWidth": 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] | ||
} |
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 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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 @@ | ||
# nx-deno-deploy | ||
|
||
Deployer and generator for Deno projects | ||
|
||
Requires [deno-ctl](https://github.com/denoland/deployctl). | ||
|
||
## Add deno deploy to existing project | ||
`npx nx g @k11r/nx-deno-deploy:add-deploy-target <app-name> --projectName=<some-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,10 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"executors": { | ||
"deploy": { | ||
"implementation": "./src/executors/deploy/executor", | ||
"schema": "./src/executors/deploy/schema.json", | ||
"description": "Deno deploy executor" | ||
} | ||
} | ||
} |
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,17 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"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" | ||
}, | ||
"project": { | ||
"factory": "./src/generators/create-deno-project/index", | ||
"schema": "./src/generators/create-deno-project/schema.json", | ||
"description": "Creates a deno project" | ||
} | ||
} | ||
} |
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 @@ | ||
module.exports = { | ||
displayName: 'nx-deno-deploy', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/nx-deno-deploy', | ||
}; |
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,9 @@ | ||
{ | ||
"name": "@k11r/nx-deno-deploy", | ||
"version": "0.0.1", | ||
"generators": "./generators.json", | ||
"executors": "./executors.json", | ||
"peerDependencies": { | ||
"@nrwl/node": "^13.8.0" | ||
} | ||
} |
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 {ExecutorContext} from "@nrwl/tao/src/shared/workspace"; | ||
import {DeployExecutorSchema} from "./schema"; | ||
import {deployProject} from "../../lib/deploy-ctl"; | ||
|
||
export default async function deployExecutor(options: DeployExecutorSchema, context: ExecutorContext) { | ||
const {projectName, isProd, token, entryPath} = options; | ||
|
||
|
||
return deployProject(entryPath, projectName, token, isProd); | ||
} |
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,6 @@ | ||
export interface DeployExecutorSchema { | ||
projectName: string; | ||
entryPath: string; | ||
token: string; | ||
isProd?: boolean | ||
} |
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,27 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "Deploy executor", | ||
"description": "Deploys a project to Deno", | ||
"type": "object", | ||
"properties": { | ||
"projectName": { | ||
"type": "string", | ||
"description": "Deno project name" | ||
}, | ||
"entryPath": { | ||
"type": "string", | ||
"description": "Entry path in the project artifacts" | ||
}, | ||
"isProd": { | ||
"type": "boolean", | ||
"description": "Is production deploy", | ||
"default": false | ||
}, | ||
"token": { | ||
"type": "string", | ||
"description": "Deploy token", | ||
} | ||
}, | ||
"required": ["projectName", "entryPath"] | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/nx-deno-deploy/src/generators/add-deploy-target/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,27 @@ | ||
import { readProjectConfiguration, Tree, updateProjectConfiguration } from '@nrwl/devkit'; | ||
import { AddDeployTargetGeneratorSchema } from './schema'; | ||
|
||
export default async function (tree: Tree, options: AddDeployTargetGeneratorSchema) { | ||
try { | ||
console.log("Adding 'deploy' target to " + options.appName); | ||
const projectConfiguration = readProjectConfiguration(tree, options.appName); | ||
const entryPath = options.entryPath ?? projectConfiguration.targets['build']['options']['outputPath'] + 'index.ts'; | ||
const projectName = options.projectName ?? options.appName; | ||
const token = options.token ?? null; | ||
|
||
projectConfiguration.targets = { | ||
...projectConfiguration.targets, | ||
deploy: { | ||
executor: '@k11r/nx-deno-deploy:deploy', | ||
options: { | ||
projectName, | ||
entryPath, | ||
...(token ? {token} : null) | ||
}, | ||
}, | ||
}; | ||
updateProjectConfiguration(tree, options.appName, projectConfiguration); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/nx-deno-deploy/src/generators/add-deploy-target/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,6 @@ | ||
export interface AddDeployTargetGeneratorSchema { | ||
appName: string; | ||
projectName?: string; | ||
entryPath?: string; | ||
token?: string; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/nx-deno-deploy/src/generators/add-deploy-target/schema.json
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,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"$id": "AddDeployTarget", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"appName": { | ||
"type": "string", | ||
"description": "Name of the project to add deno deploy to", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
} | ||
}, | ||
"projectName": { | ||
"type": "string", | ||
"description": "Name of the Deno project", | ||
}, | ||
"token": { | ||
"type": "string", | ||
"description": "Optional authentication token" | ||
}, | ||
"entryPath": { | ||
"type": "string", | ||
"description": "Entry path to deploy" | ||
} | ||
}, | ||
"required": [ | ||
"projectName" | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/nx-deno-deploy/src/generators/create-deno-project/files/main.ts__tmpl__
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 { serve } from "https://deno.land/std@0.120.0/http/server.ts"; | ||
|
||
function handler(req: Request): Response { | ||
return new Response("Hello from <%= name %>"); | ||
} | ||
|
||
console.log("Listening on http://localhost:8000"); | ||
await serve(handler); |
41 changes: 41 additions & 0 deletions
41
packages/nx-deno-deploy/src/generators/create-deno-project/index.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,41 @@ | ||
import { | ||
Tree, | ||
formatFiles, | ||
installPackagesTask, | ||
generateFiles, | ||
joinPathFragments, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { applicationGenerator } from '@nrwl/node'; | ||
import denoDeployGenerator from '../add-deploy-target/generator'; | ||
import { CreateDenoProjectSchema } from './schema'; | ||
|
||
export default async function (tree: Tree, schema: CreateDenoProjectSchema) { | ||
await applicationGenerator(tree, schema); | ||
|
||
const appName = schema.name; | ||
const projectConfiguration = readProjectConfiguration(tree, schema.name); | ||
const projectRoot = projectConfiguration.root; | ||
const buildTarget = projectConfiguration.targets['build']; | ||
const outputPath = buildTarget.options.outputPath; | ||
const entryPath = joinPathFragments(outputPath, 'main.ts'); | ||
|
||
// remove all files that were created | ||
tree.listChanges() | ||
.filter((fileChange) => fileChange.type === 'CREATE') | ||
.forEach((fileChange) => { | ||
tree.delete(fileChange.path); | ||
}); | ||
|
||
generateFiles(tree, joinPathFragments(__dirname, './files'), projectRoot, { | ||
...schema, | ||
tmpl: '', | ||
}); | ||
|
||
await formatFiles(tree); | ||
await denoDeployGenerator(tree, { entryPath, appName }); | ||
|
||
return () => { | ||
installPackagesTask(tree); | ||
}; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/nx-deno-deploy/src/generators/create-deno-project/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,3 @@ | ||
import {Schema} from '@nrwl/node/src/generators/application/schema'; | ||
|
||
export type CreateDenoProjectSchema = Schema; |
18 changes: 18 additions & 0 deletions
18
packages/nx-deno-deploy/src/generators/create-deno-project/schema.json
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 @@ | ||
{ | ||
"$schema": "../../../../../node_modules/@nrwl/node/src/generators/application/schema.json", | ||
"cli": "nx", | ||
"$id": "DenoProject", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Identifier for the Deno deploy project", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What is the name of the app?" | ||
} | ||
}, | ||
"required": ["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,4 @@ | ||
export * from './lib/deploy-ctl'; | ||
export * from './executors/deploy/executor'; | ||
export * from './generators/add-deploy-target/generator'; | ||
export * from './generators/create-deno-project/index'; |
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,34 @@ | ||
import {execSync} from "child_process"; | ||
|
||
const deployCommand = 'deployctl'; | ||
|
||
export function isDeployCtlAvailable(): boolean { | ||
try { | ||
execSync(`which ${deployCommand}`).toString('utf-8'); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
export function deployProject(entryPoint: string, projectName: string, token: string | null = null, isProd = false) { | ||
if (!isDeployCtlAvailable()) { | ||
throw new Error(`Deno deployctl is not installed.`); | ||
} | ||
|
||
const options = [ | ||
`--project=${projectName}`, | ||
isProd ? '--prod' : null, | ||
token?.length > 0 ? `--token=${token}` : null | ||
].filter(part => part !== null).join(' ') | ||
|
||
const command = `${deployCommand} deploy ${options} ${entryPoint}` | ||
|
||
try { | ||
execSync(command); | ||
return {success: true}; | ||
} catch (e) { | ||
return {success: false, error: e.toString()}; | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
Oops, something went wrong.