Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions deploy/cloudflareDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,33 @@ class CloudflareDeploy {

this.hooks = {
"deploy:deploy": () =>
BB.bind(this)
.then(this.checkAccountType)
.then(async isMultiScript => {
this.serverless.cli.log('Starting Serverless Cloudflare-Worker deployment.');
if (isMultiScript && await duplicate.checkIfDuplicateRoutes(this.serverless, this.provider)) {
return BB.reject("Duplicate routes pointing to different script");
}
BB.bind(this)
.then(this.checkAccountType)
.then(async isMultiScript => {
this.serverless.cli.log('Starting Serverless Cloudflare-Worker deployment.');
if (isMultiScript && await duplicate.checkIfDuplicateRoutes(this.serverless, this.provider)) {
return BB.reject("Duplicate routes pointing to different script");
}

if (this.getInvalidScriptNames()) {
return BB.reject(
"Worker names can contain lowercase letters, numbers, underscores, and dashes. They cannot start with dashes."
);
}
if (this.getInvalidScriptNames()) {
return BB.reject(
"Worker names can contain lowercase letters, numbers, underscores, and dashes. They cannot start with dashes."
);
}

if (isMultiScript) {
return this.multiScriptDeployAll()
} else {
const functionObject = this.getFunctionObjectForSingleScript();
return this.deploySingleScript(functionObject);
}
})
.then(this.logDeployResponse)
.then(k => this.serverless.cli.log(`Finished deployment in ${(Date.now() - startTime) / 1000} seconds.`))
.then(k => this.serverless.cli.log('Finished Serverless Cloudflare-Worker deployment.'))
if (isMultiScript) {
return this.multiScriptDeployAll()
} else {
const functionObject = this.getFunctionObjectForSingleScript();
return this.deploySingleScript(functionObject);
}
})
.then(this.logDeployResponse)
.catch(error => {
return BB.reject(error.message);
})
.then(k => this.serverless.cli.log(`Finished deployment in ${(Date.now() - startTime) / 1000} seconds.`))
.then(k => this.serverless.cli.log('Finished Serverless Cloudflare-Worker deployment.'))
};
}
}
Expand Down
53 changes: 28 additions & 25 deletions deploy/cloudflareDeployFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,34 @@ class CloudflareDeployFunction {

this.hooks = {
"deploy:function:deploy": () =>
BB.bind(this)
.then(this.validateFunctionName)
.then( (functions) => {
functionNamesForDeploy = functions;
return this.checkAccountType;
})
.then(async isMultiScript => {
if (isMultiScript && await duplicate.checkIfDuplicateRoutes(this.serverless, this.provider)) {
return BB.reject("Duplicate routes pointing to different script");
}

if (this.getInvalidScriptNames()) {
return BB.reject(
"Worker names can contain lowercase letters, numbers, underscores, and dashes. They cannot start with dashes."
);
}

if (isMultiScript) {
return this.multiScriptDeployAll(functionNamesForDeploy);
} else {
const functionObject = this.getFunctionObjectForSingleScript();
return this.deploySingleScript(functionObject);
}
})
.then(this.logDeployResponse)
BB.bind(this)
.then(this.validateFunctionName)
.then( (functions) => {
functionNamesForDeploy = functions;
return this.checkAccountType;
})
.then(async isMultiScript => {
if (isMultiScript && await duplicate.checkIfDuplicateRoutes(this.serverless, this.provider)) {
return BB.reject("Duplicate routes pointing to different script");
}

if (this.getInvalidScriptNames()) {
return BB.reject(
"Worker names can contain lowercase letters, numbers, underscores, and dashes. They cannot start with dashes."
);
}

if (isMultiScript) {
return this.multiScriptDeployAll(functionNamesForDeploy);
} else {
const functionObject = this.getFunctionObjectForSingleScript();
return this.deploySingleScript(functionObject);
}
})
.then(this.logDeployResponse)
.catch(error => {
return BB.reject(error.message);
})
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions deploy/lib/logResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = {
this.aggregateWorkerResponse(this.serverless.cli, workerScriptResponse);
this.aggregateRoutesResponse(this.serverless.cli, routesResponse);
} else {
this.parseWorkerResponse(this.serverless.cli, workerScriptResponse);
this.parseRoutesResponse(this.serverless.cli, routesResponse);
this.aggregateWorkerResponse(this.serverless.cli, [workerScriptResponse]);
this.aggregateRoutesResponse(this.serverless.cli, [routesResponse]);
}
}
};
35 changes: 24 additions & 11 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ module.exports = {
return { workerDeploySuccess, workerResult, workerErrors };
},
aggregateWorkerResponse(serverlessConsole, apiResponse) {
let status = [];
apiResponse.forEach(resp => {
status.push(this.parseWorkerResponse(serverlessConsole, resp));
});
let success = true;
const status = [];
for (let resp of apiResponse) {
const response = this.parseWorkerResponse(serverlessConsole, resp);
success &= response.workerDeploySuccess;
status.push(response);
}
if (!success) {
throw new Error('Worker script failed to deploy.');
}
return status;
},

Expand All @@ -71,7 +77,8 @@ module.exports = {
errors: routeErrors
} = resp;

if (routeSuccess || !this.routeContainsFatalErrors(routeErrors)) {
routeSuccess |= !this.routeContainsFatalErrors(routeErrors);
if (routeSuccess) {
serverlessConsole.log(`✅ Routes Deployed `);
} else {
serverlessConsole.log(`❌ Fatal Error, Routes Not Deployed!`);
Expand All @@ -89,12 +96,18 @@ module.exports = {
},

aggregateRoutesResponse(serverlessConsole, apiResponse) {
let status = [];

apiResponse.forEach(resp => {
status.push(this.parseRoutesResponse(serverlessConsole, resp));
});

let success = true;
const status = [];
for (const resp of apiResponse) {
const routesResults = this.parseRoutesResponse(serverlessConsole, resp);
for (const routeResult of routesResults) {
success &= routeResult.routesSuccess;
}
status.push(routesResults);
}
if (!success) {
throw new Error('Worker routes failed to deploy.');
}
return status;
},

Expand Down