Socket
Socket
Sign inDemoInstall

lfcdn

Package Overview
Dependencies
271
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.2.7

142

cli.js

@@ -18,3 +18,3 @@ #!/usr/bin/env node

function usage() {
console.log('Usage: lfcdn -e {dev|qa|staging|prod} -c /path/to/config.json --scope {major|minor|patch}');
console.log('Usage: lfcdn -e {dev|qa|staging|prod} -c [/path/to/config.json]');
}

@@ -28,6 +28,4 @@

var versionScope = null;
if (argv.scope) {
versionScope = argv.scope;
}
var maxage = '315360000';
var build = false;

@@ -45,2 +43,7 @@ if ( ! (s3key && s3secret)) {

if (argv.maxage || config.maxage) {
maxage = argv.maxage || config.maxage;
}
var packageJsonPath = path.join(process.cwd(), 'package.json');

@@ -51,2 +54,14 @@ var packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));

if (argv.build || config.build) {
build = (argv.build || config.build) + '';
if (build.indexOf('+') !== 0) {
build = '+' + build;
}
version += build;
}
if (argv.name || config.name) {
name = argv.name || config.name;
}
if ( ! (name && version)) {

@@ -69,91 +84,54 @@ console.log("Couldn't parse name and version from package.json");

if ( ! semver.valid(version)) {
console.log("Invalid semver version");
process.exit(1);
}
console.log(s3bucket+": deploying "+name);
var packageSemver = semver(version);
var versionString = packageSemver.raw;
if (versionString.indexOf('v') !== 0) versionString = 'v' + versionString;
var publisher = awspublish.create({
key: s3key,
secret: s3secret,
bucket: s3bucket
});
if ( ! config.dir) {
(function () {
// S3 doesn't like `+` in it's keys, so we'll convert
// semvers with build fragments to /{version}/builds/{build}
var s3path = ['/libs', name, packageSemver.version].join('/');
if (packageSemver.build.length) {
s3path += '/builds/' + packageSemver.build.join('.');
versionString = versionString.slice(0, versionString.indexOf('+'));
}
config.dir = s3path;
})();
}
var headers = {
'Cache-Control': 'max-age={{maxage}}, no-transform, public'.replace('{{maxage}}', maxage)
};
var pathKeys = ['major', 'minor', 'patch'];
var pathFan = {};
for (var i = 0; i < pathKeys.length; i++) {
pathFan[pathKeys[i]] = '';
}
console.log('config:', config);
console.log('headers:', headers);
/**
* Ensure that the dist is deployed as a major, minor, and patch version.
* e.g., v1/stuff, v1.0/stuff, and v1.0.0/stuff
* @param {string} configPath
*/
function ensureFullFan(configPath) {
console.log("path:", configPath);
pathKeys.forEach(function(val, i) {
addVersionPath(val, i, configPath.split('/'));
});
if ( ! config.dir) {
// S3 doesn't like `+` in it's keys, so we'll convert
// semvers with build fragments to /{version}/builds/{build}
var packageSemver = semver(version);
var s3path = ['/libs', name, 'v' + packageSemver.version].join('/');
if (packageSemver.build.length) {
s3path += '/builds/' + packageSemver.build.join('.');
}
config.dir = s3path;
}
/**
* Add each verion scope to the paths that will be deployed.
* If the --scope option has been provided, only the specified scope will be provided
* @param {string} version The scope e.g. 'major'
* @param {number} keyIndex The index of the scope e.g. 'major' === 0
* @param {Array} basePath The base s3 path that the version scope will be added to. e.g. /project/<version>/stuff
*/
function addVersionPath(version, keyIndex, basePath) {
var s3path = basePath.slice(0);
if (versionScope && version !== versionScope) return;
s3path[basePath.indexOf(name) + 1] = versionString.split('.').slice(0, keyIndex + 1).join('.');
pathFan[version] = s3path;
function logError(e) {
console.log(e.message);
}
var headers = {
'Cache-Control': 'max-age=315360000, no-transform, public'
};
gulp.src('./dist/**/*')
.on('error', logError)
var publisher = awspublish.create({
key: s3key,
secret: s3secret,
bucket: s3bucket
});
.pipe(rename(function (path) {
path.dirname = config.dir + '/' + path.dirname;
}))
.on('error', logError)
// Push the dist to s3
function deployPaths(pathFan) {
console.log(s3bucket+": deploying "+name);
Object.keys(pathFan).forEach(function(val, i) {
var s3path = pathFan[val];
if (!s3path) return;
gulp.src('./dist/*')
.pipe(rename(function (path) {
path.dirname += s3path.join('/');
}))
// gzip, Set Content-Encoding headers
.pipe(awspublish.gzip())
.on('error', logError)
// gzip, Set Content-Encoding headers
.pipe(awspublish.gzip())
// publisher will add Content-Length, Content-Type and headers specified above
// If not specified it will set x-amz-acl to public-read by default
.pipe(publisher.publish(headers))
.on('error', logError)
// publisher will add Content-Length, Content-Type and headers specified above
// If not specified it will set x-amz-acl to public-read by default
.pipe(publisher.publish(headers))
// print upload updates to console
.pipe(awspublish.reporter())
.on('error', logError);
// print upload updates to console
// TODO: full public url
.pipe(awspublish.reporter());
});
}
ensureFullFan(config.dir);
deployPaths(pathFan);
// JJ: I am really sorry about this, but there is a rogue TCP error and I don't care where it is
process.on('uncaughtException', logError);
{
"name": "lfcdn",
"version": "0.0.1",
"version": "0.2.7",
"description": "",

@@ -15,3 +15,3 @@ "main": "index.js",

"dependencies": {
"gulp-awspublish": "0.0.13",
"gulp-awspublish": "0.0.16",
"gulp": "^3.6.1",

@@ -18,0 +18,0 @@ "gulp-rename": "^1.2.0",

@@ -32,10 +32,2 @@ # lfcdn

## `lfcdn --scope {major|minor|patch}`
By default the project will be deployed to three locations, for a major, minor, and patch distribution.
If you want to deploy only one version withoug affecting the others, this is possible with the `scope`
option.
## output
livefyre-cdn-dev: deploying streamhub-sdk

@@ -42,0 +34,0 @@ [gulp] [cache] libs/streamhub-sdk/2.7.5/streamhub-sdk.min.css

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc