Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
inputs.bucketName = inputs.bucketName || 'backend-' + this.context.resourceId()
inputs.region = inputs.region || 'us-east-1'
// Default to current working directory
inputs.code = inputs.code || {}
inputs.code.root = inputs.code.root ? path.resolve(inputs.code.root) : process.cwd()
if (inputs.code.src) {
inputs.code.src = path.join(inputs.code.root, inputs.code.src)
}
let exists
if (inputs.code.src) {
exists = await utils.fileExists(path.join(inputs.code.src, 'index.js'))
} else {
exists = await utils.fileExists(path.join(inputs.code.root, 'index.js'))
}
if (!exists) {
throw Error(
`No index.js file found in the directory "${inputs.code.src || inputs.code.root}"`
)
}
// If a hook is provided, build the assets
if (inputs.code.hook) {
this.context.status('Building assets')
this.context.debug(`Running ${inputs.code.hook} in ${inputs.code.root}.`)
const options = { cwd: inputs.code.root }
try {
await exec(inputs.code.hook, options)
if (path.sep === '\\') {
key = key.replace(/\\/g, '/')
}
const itemParams = {
Bucket: bucket,
Region: region,
Key: key,
Body: fs.createReadStream(item.path)
}
handler = util.promisify(clients.putObject.bind(clients))
uploadItems.push(handler(itemParams))
})
await Promise.all(uploadItems)
} else if (inputs.file && (await utils.fileExists(inputs.file))) {
// upload a single file using multipart uploads
this.context.debug(`Uploading file ${inputs.file} to bucket ${bucket}`)
const itemParams = {
Bucket: bucket,
Region: region,
Key: inputs.key || path.basename(inputs.file),
Body: fs.createReadStream(inputs.file)
}
const handler = util.promisify(clients.putObject.bind(clients))
try {
await handler(itemParams)
} catch (e) {
throw e
}
const getTemplate = async inputs => {
const template = inputs.template || {};
if (typeof template === "string") {
if (
(!utils.isJsonPath(template) && !utils.isYamlPath(template)) ||
!(await utils.fileExists(template))
) {
throw Error("the referenced template path does not exist");
}
return utils.readFile(template);
} else if (typeof template !== "object") {
throw Error(
"the template input could either be an object, or a string path to a template file"
);
}
return template;
};
path.join(shimsDir, 'index.js'),
path.join(shimsDir, 'media-typer.js'),
path.join(shimsDir, 'middleware.js'),
path.join(shimsDir, 'mime-db.json'),
path.join(shimsDir, 'mime-types.js'),
path.join(shimsDir, 'type-is.js')
]
inputs.exclude = ['.git/**', '.gitignore', '.serverless', '.DS_Store']
inputs.handler = 'index.handler'
inputs.runtime = 'Nodejs8.9'
inputs.name = inputs.functionName || 'ExpressComponent_' + result
inputs.codeUri = inputs.code || process.cwd()
const appFile = path.join(path.resolve(inputs.codeUri), 'app.js')
if (!(await utils.fileExists(appFile))) {
throw new Error(`app.js not found in ${inputs.codeUri}`)
}
const tencentCloudFunction = await this.load('@serverless/tencent-scf')
const tencentApiGateway = await this.load('@serverless/tencent-apigateway')
if (inputs.functionConf) {
inputs.timeout = inputs.functionConf.timeout ? inputs.functionConf.timeout : 3
inputs.memorySize = inputs.functionConf.memorySize ? inputs.functionConf.memorySize : 128
if (inputs.functionConf.environment) {
inputs.environment = inputs.functionConf.environment
}
if (inputs.functionConf.vpcConfig) {
inputs.vpcConfig = inputs.functionConf.vpcConfig
}
}