-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add serve and deploy args from wrangler (#27)
* feat: add all wrangler dev options to serve executor schema * refactor: rename publish executor to deploy to match wrangler deprecation * feat: add all wrangler deploy arguments to deploy executor * docs: add new arguments documentation * feat: add publish as an alias to deploy * chore: upgrade nx ci to latest version * Revert "chore: upgrade nx ci to latest version" This reverts commit 037572e. * feat: rename generator to set executor deploy instead of publish * fix: adjust tests
- Loading branch information
1 parent
35e5c10
commit beb2483
Showing
16 changed files
with
438 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
5 changes: 5 additions & 0 deletions
5
packages/plugins/nx-cloudflare/src/executors/deploy/compat.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 @@ | ||
import { convertNxExecutor } from '@nx/devkit'; | ||
|
||
import deployExecutor from './deploy.impl'; | ||
|
||
export default convertNxExecutor(deployExecutor); |
47 changes: 47 additions & 0 deletions
47
packages/plugins/nx-cloudflare/src/executors/deploy/deploy.impl.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,47 @@ | ||
import { ExecutorContext } from '@nx/devkit'; | ||
import { DeploySchema } from './schema'; | ||
import { fork } from 'child_process'; | ||
import { createCliOptions } from '../../utils/create-cli-options'; | ||
|
||
export default async function deployExecutor( | ||
options: DeploySchema, | ||
context: ExecutorContext | ||
): Promise<{ success: boolean }> { | ||
const projectRoot = | ||
context.projectGraph?.nodes?.[context?.projectName]?.data?.root; | ||
|
||
if (!projectRoot) { | ||
throw new Error( | ||
`Unable to find the Project Root for ${context.projectName}. Is it set in the project.json?` | ||
); | ||
} | ||
|
||
const args = createCliOptions({ ...options }); | ||
const p = runWrangler(args, projectRoot); | ||
p.stdout.on('data', (message) => { | ||
process.stdout.write(message); | ||
}); | ||
p.stderr.on('data', (message) => { | ||
process.stderr.write(message); | ||
}); | ||
|
||
return new Promise<{ success: boolean }>((resolve) => { | ||
p.on('close', (code) => { | ||
resolve({ success: code === 0 }); | ||
}); | ||
}); | ||
} | ||
|
||
function runWrangler(args: string[], cwd: string) { | ||
try { | ||
const wranglerBin = require.resolve('wrangler/bin/wrangler'); | ||
|
||
return fork(wranglerBin, ['deploy', ...args], { | ||
stdio: ['pipe', 'pipe', 'pipe', 'ipc'], | ||
cwd, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
throw new Error('Unable to run Wrangler. Is Wrangler installed?'); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/plugins/nx-cloudflare/src/executors/deploy/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,22 @@ | ||
export interface DeploySchema { | ||
name: string; | ||
noBundle: boolean; | ||
env: string; | ||
outdir: string; | ||
compatibilityDate: string; | ||
compatibilityFlags: string[]; | ||
latest: boolean; | ||
assets: string; | ||
site: string; | ||
siteInclude: string[]; | ||
siteExclude: string[]; | ||
var: string[]; | ||
define: string[]; | ||
triggers: string[]; | ||
routes: string[]; | ||
tsconfig: string; | ||
minify: boolean; | ||
nodeCompat: boolean; | ||
dryRun: boolean; | ||
keepVars: boolean; | ||
} |
110 changes: 110 additions & 0 deletions
110
packages/plugins/nx-cloudflare/src/executors/deploy/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,110 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"version": 2, | ||
"title": "Deploy executor", | ||
"description": "", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Name of the Worker." | ||
}, | ||
"noBundle": { | ||
"type": "boolean", | ||
"default": false, | ||
"description": "Skip Wrangler’s build steps and directly deploy script without modification. Particularly useful when using custom builds." | ||
}, | ||
"env": { | ||
"type": "string", | ||
"description": "Perform on a specific environment." | ||
}, | ||
"outdir": { | ||
"type": "string", | ||
"description": "Path to directory where Wrangler will write the bundled Worker files." | ||
}, | ||
"compatibilityDate": { | ||
"type": "string", | ||
"description": "A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used." | ||
}, | ||
"compatibilityFlags": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Flags to use for compatibility checks." | ||
}, | ||
"latest": { | ||
"type": "boolean", | ||
"default": true, | ||
"description": "Use the latest version of the Workers runtime." | ||
}, | ||
"assets": { | ||
"type": "string", | ||
"description": "Root folder of static assets to be served. Unlike --site, --assets does not require a Worker script to serve your assets." | ||
}, | ||
"site": { | ||
"type": "string", | ||
"description": "Root folder of static assets for Workers Sites." | ||
}, | ||
"siteInclude": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded." | ||
}, | ||
"siteExclude": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded." | ||
}, | ||
"var": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Array of key:value pairs to inject as variables into your code. The value will always be passed as a string to your Worker." | ||
}, | ||
"define": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Array of key:value pairs to replace global identifiers in your code." | ||
}, | ||
"triggers": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Cron schedules to attach to the deployed Worker. Refer to Cron Trigger Examples." | ||
}, | ||
"routes": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "Routes where this Worker will be deployed." | ||
}, | ||
"tsconfig": { | ||
"type": "string", | ||
"description": "Path to a custom tsconfig.json file." | ||
}, | ||
"minify": { | ||
"type": "boolean", | ||
"description": "Minify the bundled script before deploying." | ||
}, | ||
"nodeCompat": { | ||
"type": "boolean", | ||
"description": "Enable node.js compatibility." | ||
}, | ||
"keepVars": { | ||
"type": "boolean", | ||
"default": false, | ||
"description": "It is recommended best practice to treat your Wrangler developer environment as a source of truth for your Worker configuration, and avoid making changes via the Cloudflare dashboard. If you change your environment variables or bindings in the Cloudflare dashboard, Wrangler will override them the next time you deploy. If you want to disable this behavior set keepVars to true." | ||
} | ||
}, | ||
"required": [] | ||
} |
5 changes: 0 additions & 5 deletions
5
packages/plugins/nx-cloudflare/src/executors/publish/compat.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/plugins/nx-cloudflare/src/executors/publish/publish.impl.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/plugins/nx-cloudflare/src/executors/publish/schema.d.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/plugins/nx-cloudflare/src/executors/publish/schema.json
This file was deleted.
Oops, something went wrong.
28 changes: 27 additions & 1 deletion
28
packages/plugins/nx-cloudflare/src/executors/serve/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 |
---|---|---|
@@ -1,3 +1,29 @@ | ||
export interface Schema { | ||
export interface ServeSchema { | ||
name?: string; | ||
noBundle?: boolean; | ||
env?: string; | ||
compatibilityDate?: string; | ||
compatibilityFlags?: string[]; | ||
latest?: boolean; | ||
ip?: string; | ||
port?: number; | ||
inspectorPort?: number; | ||
routes?: string[]; | ||
host?: string; | ||
localProtocol?: 'http' | 'https'; | ||
localUpstream?: string; | ||
assets?: string; | ||
site?: string; | ||
siteInclude?: string[]; | ||
siteExclude?: string[]; | ||
upstreamProtocol?: 'http' | 'https'; | ||
var?: string[]; | ||
define?: string[]; | ||
tsconfig?: string; | ||
minify?: boolean; | ||
nodeCompat?: boolean; | ||
persistTo?: string; | ||
remote?: boolean; | ||
testScheduled?: boolean; | ||
logLevel?: 'debug' | 'info' | 'log' | 'warn' | 'error' | 'none'; | ||
} |
Oops, something went wrong.