grunt-mobify-cloud
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -10,2 +10,4 @@ /* | ||
var path = require('path'); | ||
var settingsPath = 'test/fixtures/creds'; | ||
@@ -32,9 +34,17 @@ | ||
hostname: 'localhost', | ||
server: 'test/mockServer.js' | ||
server: 'test/mock-server.js' | ||
} | ||
} | ||
}, | ||
mobifyUpload: { | ||
'mobify-verify_adaptive_dependencies': { | ||
options: { | ||
projectSlug: 'test-project', | ||
basePath: path.join(process.cwd(), 'test/fixtures'), | ||
origin: 'https://localhost:3000', | ||
settingsFile: settingsPath | ||
} | ||
}, | ||
'mobify-upload': { | ||
options: { | ||
origin: 'https://localhost:3000', | ||
projectSlug: 'test-project', | ||
@@ -46,3 +56,3 @@ settingsFile: settingsPath, | ||
}, | ||
saveCredentials: { | ||
'mobify-save_credentials': { | ||
options: { | ||
@@ -53,3 +63,3 @@ settingsPath: './.mobify' | ||
nodeunit: { | ||
tests: ['test/*Test.js'] | ||
tests: ['test/test-*.js'] | ||
}, | ||
@@ -75,6 +85,4 @@ release: { | ||
grunt.registerTask('test', ['express', 'mobifyUpload', 'nodeunit']); | ||
grunt.registerTask('test', ['express', 'mobify-verify_adaptive_dependencies', 'mobify-upload', 'nodeunit']); | ||
grunt.registerTask('default', ['jshint', 'test']); | ||
}; |
155
lib/utils.js
var grunt = require('grunt'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var archiver = require('archiver'); | ||
var Request = require('request'); | ||
var packageJSON = require('../package.json'); | ||
var gruntMobifyVersion = require('../package.json')['version']; | ||
exports.createArchive = function(paths, projectSlug, destination, cb) { | ||
exports.createBundle = function(filePaths, projectSlug, destination, cb) { | ||
var output = fs.createWriteStream(destination); | ||
@@ -18,17 +18,20 @@ var archive = archiver('tar'); | ||
// Filter out directories | ||
var files = paths.filter(function(f) { | ||
return grunt.file.isFile(f); | ||
}); | ||
filePaths.forEach(function(srcPath) { | ||
// Ignore directories. | ||
if (!grunt.file.isFile(srcPath)) { | ||
return; | ||
} | ||
files.forEach(function(srcFile) { | ||
var filepath = srcFile.replace(/[^\/]+\//, ''); | ||
// Cloud expects files in a bundle to live under `/project-slug/bld/'. | ||
// Cloud expects the folder structure /projectslug/bld/all_your_files | ||
archive.file(srcFile, {name: projectSlug + '/bld/' + filepath}); | ||
// Strip leading directory, e.g. 'build/'. | ||
destPath = srcPath.replace(/[^\/]+\//, ''); | ||
// And replace it with 'project-slug/bld/'. | ||
destPath = path.join(projectSlug, 'bld', destPath); | ||
archive.file(srcPath, { name: destPath }); | ||
}); | ||
archive.finalize(); | ||
// Wait for archive to finish getting written. | ||
output.on('finish', cb); | ||
@@ -49,47 +52,2 @@ }; | ||
exports.buildRequest = function(options, cb) { | ||
// Avoids DEPTH_ZERO_SELF_SIGNED_CERT error for self-signed certs | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
var opts = { | ||
uri: options.origin + '/api/projects/' + options.projectSlug + '/builds/', | ||
method: 'POST', | ||
auth: options.auth, | ||
headers: { | ||
'Content-Length': options.dataLength, | ||
'User-Agent': 'grunt-mobify#' + packageJSON.version | ||
} | ||
}; | ||
var request = new Request(opts, function(err, response, body) { | ||
if (err){ | ||
if (response) { | ||
throw new Error('Failed uploading build ' + '" (status code: ' + response.statusCode + ') - ' + opts.method + ' @ ' + opts.uri); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
var status = response.statusCode; | ||
var msg; | ||
if (status >= 400) { | ||
if (status === 401){ | ||
msg = "Request unauthorized. Check your credentials."; | ||
} | ||
else if (status === 404){ | ||
msg = "Project not found. Check your project name"; | ||
} | ||
else{ | ||
msg = "Got a bad response: " + body; | ||
} | ||
throw(new Error(msg)); | ||
} | ||
else { | ||
console.log('Build uploaded!'); | ||
} | ||
cb(); | ||
}); | ||
return request; | ||
}; | ||
exports.buildObject = function(filepath, message){ | ||
@@ -117,1 +75,82 @@ // encoding: null ensures that a Buffer is returned | ||
}; | ||
/** | ||
* Request helpers | ||
*/ | ||
exports.getProjectApiPath = function(origin, slug, path) { | ||
// Strip trailing slash. | ||
origin = origin.replace(/\/$/, ''); | ||
// Strip leading slash. | ||
path = path.replace(/^\//, ''); | ||
return origin + "/api/projects/" + slug + "/" + path; | ||
}; | ||
exports.getRequestHeaders = function(additionalHeaders) { | ||
var headers = { | ||
'User-Agent': 'grunt-mobify#' + gruntMobifyVersion | ||
}; | ||
// Merge `additionalHeaders` into `headers`. | ||
if (additionalHeaders) { | ||
for (header in additionalHeaders) { | ||
headers[header] = additionalHeaders[header]; | ||
} | ||
} | ||
return headers; | ||
}; | ||
var throwForStatus = exports.throwForStatus = function(response) { | ||
var msg = null; | ||
var status = response.statusCode; | ||
if (status >= 400) { | ||
if (status == 401) { | ||
msg = "Request unauthorized. Check your credentials."; | ||
} | ||
else if (status == 404) { | ||
msg = "Project not found. Check your project's slug."; | ||
} | ||
else { | ||
msg = "Got a bad response: " + response.body; | ||
} | ||
throw new Error(msg); | ||
} | ||
}; | ||
exports.buildRequest = function(options, cb) { | ||
// Avoids DEPTH_ZERO_SELF_SIGNED_CERT error for self-signed certs | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
var headers = this.getRequestHeaders(); | ||
var uri = this.getProjectApiPath( | ||
options.origin, options.projectSlug, 'builds/' | ||
); | ||
var headers = this.getRequestHeaders( | ||
{'Content-Length': options.dataLength} | ||
); | ||
var opts = { | ||
uri: uri, | ||
method: 'POST', | ||
auth: options.auth, | ||
headers: headers | ||
}; | ||
var request = new Request(opts, function(err, response, body) { | ||
if (err){ | ||
throw new Error("Failed to upload build: " + err); | ||
} | ||
throwForStatus(response); | ||
console.log('Build uploaded!'); | ||
cb(); | ||
}); | ||
return request; | ||
}; |
{ | ||
"name": "grunt-mobify-cloud", | ||
"description": "A plugin for working with Mobify projects", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"homepage": "http://cloud.mobify.com", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
# mobifyUpload | ||
# mobify-upload | ||
@@ -8,3 +8,3 @@ > Push builds to the Mobify Cloud | ||
``` | ||
mobifyUpload: { | ||
'mobify-upload': { | ||
options: { | ||
@@ -22,11 +22,11 @@ projectSlug: 'mobify-test', | ||
### host | ||
### origin | ||
> type: string | ||
You can optionally specify the host of the endpoint where you want to upload your build. It defaults to cloud.mobify.com | ||
You can optionally specify the origin of the endpoint where you want to upload your build. It defaults to cloud.mobify.com | ||
``` | ||
options: { | ||
host: 'cloud-test.mobify.com' | ||
origin: 'https://cloud-test.mobify.com' | ||
} | ||
@@ -42,6 +42,6 @@ ``` | ||
``` | ||
grunt mobifyUpload --message="An informative and witty build message." | ||
grunt mobify-upload --message="An informative and witty build message." | ||
``` | ||
# saveCredentials | ||
# mobify-save_credentials | ||
@@ -53,3 +53,3 @@ > save your email and mobify api_key for future use | ||
``` | ||
saveCredentials: { | ||
'mobify-save_credentials': { | ||
src: '/Users/myself/.mobify' | ||
@@ -62,5 +62,13 @@ } | ||
``` | ||
grunt saveCredentials --user="user@mobify.com" --key="5up3rR4Nd0mK3y" | ||
grunt mobify-save_credentials --user="user@mobify.com" --key="5up3rR4Nd0mK3y" | ||
``` | ||
# mobify-verify_adaptive_dependencies | ||
> Verifies your `package.json` and `bower.json` files against the Mobify Cloud. | ||
``` | ||
grunt mobify-verify_adaptive_dependencies | ||
``` | ||
# Deploy | ||
@@ -67,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
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
41241
15
307
76
2