@k11r/nx-cloudflare-wrangler
Advanced tools
Comparing version 1.5.0 to 1.5.1
{ | ||
"name": "@k11r/nx-cloudflare-wrangler", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"generators": "./generators.json", | ||
@@ -5,0 +5,0 @@ "executors": "./executors.json", |
# nx-cloudflare-wrangler | ||
This library was generated with [Nx](https://nx.dev). | ||
An executor and generator for Cloudflare Wrangler (workers and pages) | ||
## Running unit tests | ||
## Workers | ||
Run `nx test nx-cloudflare-wrangler` to execute the unit tests via [Jest](https://jestjs.io). | ||
### Generate a new worker project | ||
## Running lint | ||
`npx nx g @k11r/nx-cloudflare-wrangler:worker <app-name>` | ||
Run `nx lint nx-cloudflare-wrangler` to execute the lint via [ESLint](https://eslint.org/). | ||
Creates a new NX project (based on the node template) with a new worker. | ||
`build` and `deploy` targets are added automatically. | ||
## Pages | ||
### Add `deploy` target to an existing project | ||
`npx nx g @k11r/nx-cloudflare-wrangler:pages <app-name>` | ||
This will only add a `deploy` target, the `build` property in `wrangler.toml` will point to the `build` target of the project. |
import { ExecutorContext } from '@nrwl/devkit'; | ||
import { DeployExecutorSchema } from './schema'; | ||
export default function deployExecutor(options: DeployExecutorSchema, context: ExecutorContext): Promise<unknown>; | ||
import { PagesDeployExecutorSchema } from './schema'; | ||
export default function deployExecutor(options: PagesDeployExecutorSchema, context: ExecutorContext): Promise<unknown>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const devkit_1 = require("@nrwl/devkit"); | ||
const wrangler_1 = require("../../wrangler"); | ||
const child_process_1 = require("child_process"); | ||
function deployExecutor(options, context) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return wrangler_1.runWranglerCommandForProject(options, context, 'pages publish'); | ||
const dist = devkit_1.joinPathFragments(process.cwd(), context.workspace.projects[context.projectName].targets.build.options | ||
.outputPath); | ||
const branch = child_process_1.execSync('git rev-parse --abbrev-ref HEAD') | ||
.toString() | ||
.trim(); | ||
const commitHash = child_process_1.execSync('git rev-parse HEAD').toString().trim(); | ||
const commitMessage = `deploy ${branch} ${new Date().toISOString()}`; | ||
const deployOptions = Object.assign({ dist, | ||
branch, | ||
commitHash, | ||
commitMessage, commitDirty: false }, options); | ||
return wrangler_1.runWranglerCommandForProject(deployOptions, context, 'pages publish'); | ||
}); | ||
@@ -9,0 +22,0 @@ } |
import { ExecutorContext } from '@nrwl/devkit'; | ||
import { DeployExecutorSchema } from './schema'; | ||
export default function deployExecutor(options: DeployExecutorSchema, context: ExecutorContext): Promise<unknown>; | ||
import { WorkerDeployExecutorSchema } from './schema'; | ||
export default function deployExecutor(options: WorkerDeployExecutorSchema, context: ExecutorContext): Promise<unknown>; |
import { ExecutorContext } from '@nrwl/devkit'; | ||
import { ServeExecutorSchema } from './schema'; | ||
export default function serveExecutor(options: ServeExecutorSchema, context: ExecutorContext): Promise<unknown>; | ||
import { WorkerServeExecutorSchema } from './schema'; | ||
export default function serveExecutor(options: WorkerServeExecutorSchema, context: ExecutorContext): Promise<unknown>; |
import { ExecutorContext } from '@nrwl/devkit'; | ||
import { ServeExecutorSchema } from './workers/serve/schema'; | ||
import { DeployExecutorSchema } from './workers/deploy/schema'; | ||
export declare function runWranglerCommandForProject(options: ServeExecutorSchema | DeployExecutorSchema, context: ExecutorContext, command: 'dev' | 'publish' | 'pages dev' | 'pages publish'): Promise<unknown>; | ||
import { WorkerServeExecutorSchema } from './workers/serve/schema'; | ||
import { WorkerDeployExecutorSchema } from './workers/deploy/schema'; | ||
import { PagesDeployExecutorSchema } from './pages/deploy/schema'; | ||
export declare function runWranglerCommandForProject(options: WorkerServeExecutorSchema | WorkerDeployExecutorSchema | PagesDeployExecutorSchema, context: ExecutorContext, command: 'dev' | 'publish' | 'pages publish'): Promise<unknown>; |
@@ -8,3 +8,3 @@ "use strict"; | ||
function runWranglerCommandForProject(options, context, command) { | ||
var _a; | ||
var _a, _b; | ||
const { projectName, target } = context; | ||
@@ -14,7 +14,24 @@ const executorOptions = (_a = target.options) !== null && _a !== void 0 ? _a : {}; | ||
const projectConfiguration = devkit_1.readProjectConfiguration(tree, projectName); | ||
const wranglerOptions = Object.keys(executorOptions).reduce((acc, option) => { | ||
return acc; | ||
}, []); | ||
const wranglerOptions = []; | ||
if (command === 'pages publish') { | ||
wranglerOptions.push(options.dist); | ||
wranglerOptions.push('--project-name="' + | ||
((_b = options.projectName) !== null && _b !== void 0 ? _b : projectName) + | ||
'"'); | ||
wranglerOptions.push('--branch="' + options.branch + '"'); | ||
wranglerOptions.push('--commit-hash=' + options.commitHash); | ||
wranglerOptions.push('--commit-message="' + | ||
options.commitMessage + | ||
'"'); | ||
wranglerOptions.push('--commit-dirty=' + | ||
(options.commitDirty | ||
? 'true' | ||
: 'false')); | ||
} | ||
else if (command === 'publish') { | ||
wranglerOptions.push(devkit_1.joinPathFragments(devkit_1.workspaceRoot, projectConfiguration.targets.build.options.outputPath, 'index.js')); | ||
} | ||
return new Promise((resolve) => { | ||
try { | ||
console.log(`wrangler ${command} ${wranglerOptions.join(' ')}`); | ||
child_process_1.execSync(`wrangler ${command} ${wranglerOptions.join(' ')}`, { | ||
@@ -21,0 +38,0 @@ cwd: projectConfiguration.root, |
@@ -5,26 +5,8 @@ "use strict"; | ||
const devkit_1 = require("@nrwl/devkit"); | ||
const node_1 = require("@nrwl/node"); | ||
function projectGenerator(tree, schema) { | ||
var _a, _b, _c, _d; | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
yield node_1.applicationGenerator(tree, schema); | ||
const appName = (schema.directory ? `${schema.directory}-` : '') + schema.name; | ||
const projectConfiguration = devkit_1.readProjectConfiguration(tree, appName); | ||
const projectRoot = projectConfiguration.root; | ||
const templatePath = devkit_1.joinPathFragments(__dirname, './files'); | ||
const substitutions = Object.assign({ tmpl: '', zone_id: (_a = schema.zone_id) !== null && _a !== void 0 ? _a : '', account_id: (_b = schema.account_id) !== null && _b !== void 0 ? _b : '', route: (_c = schema.route) !== null && _c !== void 0 ? _c : '', workers_dev: (_d = schema.route) !== null && _d !== void 0 ? _d : true }, devkit_1.names(schema.name)); | ||
// remove all files that were created except for the config files | ||
tree.listChanges() | ||
.filter((fileChange) => fileChange.type === 'CREATE' && | ||
!fileChange.path.endsWith('/project.json') && | ||
!fileChange.path.endsWith('.eslintrc.json') && | ||
fileChange.path !== 'workspace.json') | ||
.forEach((fileChange) => { | ||
tree.delete(fileChange.path); | ||
}); | ||
devkit_1.generateFiles(tree, templatePath, projectRoot, substitutions); | ||
yield devkit_1.formatFiles(tree); | ||
updateGitIgnore(tree); | ||
addTargets(tree, schema.name, {}); | ||
console.log(tree.read('.gitignore').toString()); | ||
addTargets(tree, schema.name, schema.projectName && schema.projectName.length > 0 | ||
? { projectName: schema.projectName } | ||
: {}); | ||
return () => { | ||
@@ -43,3 +25,3 @@ devkit_1.installPackagesTask(tree); | ||
: null; | ||
projectConfiguration.targets = Object.assign(Object.assign({}, ((_a = projectConfiguration.targets) !== null && _a !== void 0 ? _a : {})), { serve: Object.assign({ executor: '@k11r/nx-cloudflare-wrangler:serve' }, options), deploy: Object.assign({ executor: '@k11r/nx-cloudflare-wrangler:deploy' }, options) }); | ||
projectConfiguration.targets = Object.assign(Object.assign({}, ((_a = projectConfiguration.targets) !== null && _a !== void 0 ? _a : {})), { deploy: Object.assign({ executor: '@k11r/nx-cloudflare-wrangler:deploy-page' }, options) }); | ||
devkit_1.updateProjectConfiguration(tree, appName, projectConfiguration); | ||
@@ -51,16 +33,2 @@ } | ||
} | ||
function updateGitIgnore(tree) { | ||
const requiredIgnores = ['.dist']; | ||
try { | ||
const content = tree.exists('.gitignore') | ||
? tree.read('.gitignore').toString() | ||
: ``; | ||
const ignores = content.split(`\n`); | ||
const ignoresToAdd = requiredIgnores.filter((newIgnore) => !ignores.find((i) => i.trim() === newIgnore.trim())); | ||
tree.write('.gitignore', content + `\n` + ignoresToAdd.join(`\n`)); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -14,3 +14,3 @@ "use strict"; | ||
const templatePath = devkit_1.joinPathFragments(__dirname, './files'); | ||
const substitutions = Object.assign({ tmpl: '', zone_id: (_a = schema.zone_id) !== null && _a !== void 0 ? _a : '', account_id: (_b = schema.account_id) !== null && _b !== void 0 ? _b : '', route: (_c = schema.route) !== null && _c !== void 0 ? _c : '', workers_dev: (_d = schema.route) !== null && _d !== void 0 ? _d : true }, devkit_1.names(schema.name)); | ||
const substitutions = Object.assign({ tmpl: '', zone_id: (_a = schema.zone_id) !== null && _a !== void 0 ? _a : '', account_id: (_b = schema.account_id) !== null && _b !== void 0 ? _b : '', route: (_c = schema.route) !== null && _c !== void 0 ? _c : '', workers_dev: (_d = schema.route) !== null && _d !== void 0 ? _d : true, compatibility_date: new Date().toISOString().split('T')[0] }, devkit_1.names(schema.name)); | ||
// remove all files that were created except for the config files | ||
@@ -28,4 +28,3 @@ tree.listChanges() | ||
updateGitIgnore(tree); | ||
addTargets(tree, schema.name, {}); | ||
console.log(tree.read('.gitignore').toString()); | ||
addTargets(tree, schema.name); | ||
return () => { | ||
@@ -37,10 +36,21 @@ devkit_1.installPackagesTask(tree); | ||
exports.default = projectGenerator; | ||
function addTargets(tree, appName, cloudflareOptions) { | ||
function addTargets(tree, appName) { | ||
var _a; | ||
try { | ||
const projectConfiguration = devkit_1.readProjectConfiguration(tree, appName); | ||
const options = Object.keys(cloudflareOptions).length > 0 | ||
? { options: cloudflareOptions } | ||
: null; | ||
projectConfiguration.targets = Object.assign(Object.assign({}, ((_a = projectConfiguration.targets) !== null && _a !== void 0 ? _a : {})), { serve: Object.assign({ executor: '@k11r/nx-cloudflare-wrangler:serve' }, options), deploy: Object.assign({ executor: '@k11r/nx-cloudflare-wrangler:deploy' }, options) }); | ||
const packageRoot = projectConfiguration.root; | ||
const packageSourceRoot = projectConfiguration.sourceRoot; | ||
projectConfiguration.targets = Object.assign(Object.assign({}, ((_a = projectConfiguration.targets) !== null && _a !== void 0 ? _a : {})), { serve: { | ||
executor: '@k11r/nx-cloudflare-wrangler:serve-worker', | ||
}, deploy: { | ||
executor: '@k11r/nx-cloudflare-wrangler:deploy-worker', | ||
}, build: { | ||
executor: '@k11r/nx-cloudflare-wrangler:build-worker', | ||
options: { | ||
outputPath: `dist/packages/${appName}`, | ||
tsConfig: `${packageRoot}/tsconfig.json`, | ||
packageJson: `${packageRoot}/package.json`, | ||
main: `${packageSourceRoot}/index.ts`, | ||
}, | ||
} }); | ||
devkit_1.updateProjectConfiguration(tree, appName, projectConfiguration); | ||
@@ -47,0 +57,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27315
47
446
21
4