serverless-alpha
Advanced tools
Comparing version 0.0.12 to 0.0.13
28
index.js
@@ -28,2 +28,3 @@ 'use strict' // eslint-disable-line strict | ||
const addFunctionToYmlContent = require('./utils/addFunctionToYmlContent') | ||
const functionZipName = require('./utils/functionZipName') | ||
// const signupQuestions = require('./utils/signupQuestions') | ||
@@ -231,3 +232,3 @@ const log = require('./utils/log') | ||
const functionDirectoryPath = path.join(homeDirectory, '.serverless', 'functions', name, version) | ||
const functionZipPath = path.join(functionDirectoryPath, 'function.zip') | ||
const functionZipPath = path.join(functionDirectoryPath, functionZipName(name, version)) | ||
const functionAttributesPath = path.join(functionDirectoryPath, 'attributes.json') | ||
@@ -241,3 +242,3 @@ const funcWithArtifact = R.compose( | ||
} | ||
return downloadAndSaveFunction(versionData.links.zip, versionData.attributes, functionDirectoryPath) | ||
return downloadAndSaveFunction(versionData.links.zip, versionData.attributes, functionDirectoryPath, name, version) | ||
.then(() => funcWithArtifact) | ||
@@ -267,3 +268,3 @@ .catch(() => reject('Failed to download the function from the Serverless Registry.')) | ||
const serverlessFunctionName = sanitizeFunctionName(this.serverless.variables.options.save || functionName) | ||
log(`Installing Function '${functionName}'...`) | ||
log(`Installing Function ${functionName}...`) | ||
@@ -299,3 +300,3 @@ // TODO also accept `serverless.yaml` | ||
const functionDirectoryPath = path.join(homeDirectory, '.serverless', 'functions', functionName, version) | ||
const functionZipPath = path.join(functionDirectoryPath, 'function.zip') | ||
const functionZipPath = path.join(functionDirectoryPath, functionZipName(functionName, version)) | ||
const functionAttributesPath = path.join(functionDirectoryPath, 'attributes.json') | ||
@@ -310,8 +311,15 @@ if (fs.existsSync(functionZipPath) && fs.existsSync(functionAttributesPath)) { | ||
} else { | ||
downloadAndSaveFunction(response.data.links.zip, response.data.attributes, functionDirectoryPath) | ||
trackAndExit('installFunction', { | ||
usedCachedFunction: false, | ||
functionName: functionName, | ||
version: version, | ||
}) | ||
log(`Downloading the function '${functionName}'...`) | ||
downloadAndSaveFunction(response.data.links.zip, response.data.attributes, functionDirectoryPath, functionName, version) | ||
.then(() => { | ||
trackAndExit('installFunction', { | ||
usedCachedFunction: false, | ||
functionName: functionName, | ||
version: version, | ||
}) | ||
}) | ||
.catch((err) => { | ||
log(err) | ||
log('Failed to download the function. Please remove the function definition from serverless.yml and try again.') | ||
}) | ||
} | ||
@@ -318,0 +326,0 @@ }) |
{ | ||
"name": "serverless-alpha", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"author": "serverless.com", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -6,3 +6,3 @@ const validateFunction = require('../validateFunction') | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -29,3 +29,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'my-test-function', | ||
name: 'myTestFunction', | ||
version: '1.2.3', | ||
@@ -43,3 +43,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
runtime: 'node4.3', | ||
@@ -56,3 +56,3 @@ handler: 'handler.run', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: 'v2', | ||
@@ -70,3 +70,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -83,3 +83,3 @@ handler: 'handler.run', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -96,3 +96,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -111,3 +111,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -126,3 +126,3 @@ runtime: 'node4.3', | ||
const functionConfig = { | ||
name: 'myTestFunction', | ||
name: 'my-test-function', | ||
version: '1.2.3', | ||
@@ -129,0 +129,0 @@ runtime: 'node4.3', |
const fs = require('fs') | ||
const path = require('path') | ||
const https = require('https') | ||
const fsExtra = require('fs-extra') | ||
const fetch = require('node-fetch') | ||
const BbPromise = require('bluebird') | ||
const log = require('./log') | ||
const functionZipName = require('./functionZipName') | ||
module.exports = (zipLink, functionAttributes, functionDirectoryPath) => ( | ||
fetch(zipLink) | ||
.then(zipResponse => { | ||
fsExtra.ensureDir(functionDirectoryPath, (err) => { | ||
if (err) { | ||
throw new Error('Couldn\'t create the directory') | ||
} | ||
const functionZipPath = path.join(functionDirectoryPath, 'function.zip') | ||
const functionAttributesPath = path.join(functionDirectoryPath, 'attributes.json') | ||
const destination = fs.createWriteStream(functionZipPath) | ||
zipResponse.body.pipe(destination) | ||
const attributesContent = JSON.stringify(functionAttributes) | ||
fs.writeFileSync(functionAttributesPath, attributesContent) | ||
log('Successfully downloaded the function from the Serverless Registry.') | ||
// Node fetch failed to download larger files e.g. 6mb+ | ||
const download = (url, dest) => ( | ||
new BbPromise((resolve, reject) => { | ||
const file = fs.createWriteStream(dest) | ||
https.get(url, (response) => { | ||
response.pipe(file) | ||
file.on('finish', () => { | ||
file.close(resolve) | ||
}) | ||
}).on('error', (err) => { | ||
fs.unlink(dest) // Delete the file async. (But we don't check the result) | ||
// TODO track error here | ||
reject(err) | ||
}) | ||
}) | ||
) | ||
module.exports = (zipLink, functionAttributes, functionDirectoryPath, name, version) => ( | ||
new BbPromise((resolve, reject) => { | ||
fsExtra.ensureDir(functionDirectoryPath, (err) => { | ||
if (err) { | ||
reject('Couldn\'t create the function directory.') | ||
} | ||
const functionZipPath = path.join(functionDirectoryPath, functionZipName(name, version)) | ||
const functionAttributesPath = path.join(functionDirectoryPath, 'attributes.json') | ||
const attributesContent = JSON.stringify(functionAttributes) | ||
return download(zipLink, functionZipPath) | ||
.then(() => { | ||
fs.writeFileSync(functionAttributesPath, attributesContent) | ||
log(`Successfully downloaded the function '${name}' from the Serverless Registry.`) | ||
resolve() | ||
}) | ||
.catch(() => { reject('Download failed.') }) | ||
}) | ||
}) | ||
) |
@@ -48,2 +48,7 @@ const Analytics = require('analytics-node') | ||
new BbPromise((resolve, reject) => { | ||
// prevent that this blocks furhter actions UX is more important than tracking | ||
setTimeout(() => { | ||
resolve() | ||
}, 3000) | ||
try { | ||
@@ -50,0 +55,0 @@ if (!statsActive()) { |
@@ -1,2 +0,2 @@ | ||
const functionNamePattern = /^[a-zA-Z0-9_]+$/i | ||
const functionNamePattern = /^[a-z0-9-_]+$/ | ||
const versionPattern = /^(\d+\.)?(\d+\.)?(\*|\d+)$/i | ||
@@ -7,3 +7,3 @@ | ||
if (!functionConfig.name || !functionNamePattern.test(functionConfig.name)) { | ||
throw new Error(`Invalid functions.yml: Function name "${functionConfig.name}" is missing or invalid. Function names should match /^[a-zA-Z0-9_]+$/`) | ||
throw new Error(`Invalid functions.yml: Function name "${functionConfig.name}" is missing or invalid. Function names should match /^[a-z0-9-_]+$/`) | ||
} | ||
@@ -10,0 +10,0 @@ if (!versionPattern.test(functionConfig.version)) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53429
46
1071