forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace netlify's zip-it-and-ship-it for serverless deploy (redwoodjs…
- Loading branch information
Showing
4 changed files
with
128 additions
and
57 deletions.
There are no files selected for viewing
39 changes: 19 additions & 20 deletions
39
packages/cli/src/commands/deploy/aws-providers/serverless.js
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,34 +1,33 @@ | ||
export const preRequisites = [ | ||
import ntfPack from '../packing/nft' | ||
|
||
export const preRequisites = () => [ | ||
{ | ||
title: 'Checking if Serverless framework is installed...', | ||
command: ['serverless', ['--version']], | ||
errorMessage: [ | ||
'Looks like Serverless is not installed.', | ||
'Please follow the steps at https://www.serverless.com/framework/docs/providers/aws/guide/installation/ to install Serverless.', | ||
], | ||
}, | ||
{ | ||
title: 'Checking if @netlify/zip-it-and-ship-it is installed...', | ||
command: ['yarn', ['zip-it-and-ship-it', '--version']], | ||
errorMessage: [ | ||
'Looks like @netlify/zip-it-and-ship-it is not installed.', | ||
'Either run `yarn rw setup aws-serverless` or add it separately as a dev dependency in the api workspace.', | ||
'Please follow the steps at https://www.serverless.com/framework/docs/getting-started to install Serverless.', | ||
], | ||
}, | ||
] | ||
|
||
export const buildCommands = [ | ||
{ title: 'Building API...', command: ['yarn', ['rw', 'build', 'api']] }, | ||
export const buildCommands = () => [ | ||
{ | ||
title: 'Packaging API...', | ||
command: [ | ||
'yarn', | ||
['zip-it-and-ship-it', 'api/dist/functions/', 'api/dist/zipball'], | ||
], | ||
title: 'Building API...', | ||
command: ['yarn', ['rw', 'build', 'api']], | ||
}, | ||
{ | ||
title: 'Packing Functions...', | ||
task: ntfPack, | ||
}, | ||
] | ||
|
||
export const deployCommand = { | ||
title: 'Deploying...', | ||
command: ['serverless', ['deploy']], | ||
export const deployCommands = (yargs) => { | ||
const stage = yargs.stage ? ['--stage', yargs.stage] : [] | ||
return [ | ||
{ | ||
title: 'Deploying...', | ||
command: ['serverless', ['deploy', ...stage]], | ||
}, | ||
] | ||
} |
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,60 @@ | ||
import path from 'path' | ||
|
||
import { nodeFileTrace } from '@vercel/nft' | ||
import archiver from 'archiver' | ||
import fse from 'fs-extra' | ||
|
||
const ZIPBALL_DIR = './api/dist/zipball' | ||
|
||
function zipDirectory(source, out) { | ||
const archive = archiver('zip', { zlib: { level: 5 } }) | ||
const stream = fse.createWriteStream(out) | ||
|
||
return new Promise((resolve, reject) => { | ||
archive | ||
.directory(source, false) | ||
.on('error', (err) => reject(err)) | ||
.pipe(stream) | ||
|
||
stream.on('close', () => resolve()) | ||
archive.finalize() | ||
}) | ||
} | ||
|
||
async function packageSingleFunction(functionFile) { | ||
const { name: functionName } = path.parse(functionFile) | ||
const { fileList: functionDependencyFileList } = await nodeFileTrace([ | ||
functionFile, | ||
]) | ||
const copyPromises = [] | ||
for (const singleDependencyPath of functionDependencyFileList) { | ||
copyPromises.push( | ||
fse.copy( | ||
'./' + singleDependencyPath, | ||
`${ZIPBALL_DIR}/${functionName}/${singleDependencyPath}` | ||
) | ||
) | ||
} | ||
const functionEntryPromise = fse.outputFile( | ||
`${ZIPBALL_DIR}/${functionName}/${functionName}.js`, | ||
`module.exports = require('${functionFile}')` | ||
) | ||
copyPromises.push(functionEntryPromise) | ||
|
||
await Promise.all(copyPromises) | ||
await zipDirectory( | ||
`${ZIPBALL_DIR}/${functionName}`, | ||
`${ZIPBALL_DIR}/${functionName}.zip` | ||
) | ||
await fse.remove(`${ZIPBALL_DIR}/${functionName}`) | ||
return | ||
} | ||
|
||
async function ntfPack() { | ||
const filesToBePacked = (await fse.readdir('./api/dist/functions')) | ||
.filter((path) => path.endsWith('.js')) | ||
.map((path) => `./api/dist/functions/${path}`) | ||
return Promise.all(filesToBePacked.map(packageSingleFunction)) | ||
} | ||
|
||
export default ntfPack |
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