New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

asset-pipe-client

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-pipe-client - npm Package Compare versions

Comparing version 1.0.0-beta.4 to 1.0.0

LICENSE.md

6

bin/cli.js

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

program
.version(pckage.version);
program.version(pckage.version);

@@ -17,3 +16,2 @@ /*

program

@@ -27,3 +25,2 @@ .command('write')

program.on('--help', () => {

@@ -33,3 +30,2 @@ console.log(' Help here:');

if (!process.argv.slice(2).length) {

@@ -36,0 +32,0 @@ program.outputHelp();

@@ -7,4 +7,3 @@ 'use strict';

module.exports.js = (options) => {
module.exports.js = options => {
if (options.source && options.destination) {

@@ -21,5 +20,4 @@ const writeStream = fs.createWriteStream(options.destination);

module.exports.help = () => {
console.log(' Examples here:');
};

@@ -6,9 +6,55 @@ 'use strict';

const request = require('request');
const Writer = require('asset-pipe-js-writer');
const JsWriter = require('asset-pipe-js-writer');
const CssWriter = require('asset-pipe-css-writer');
const assert = require('assert');
const { extname } = require('path');
const isStream = require('is-stream');
const extensions = Object.freeze({
JS: '.js',
CSS: '.css',
});
const endpoints = Object.freeze({
UPLOAD: 'feed',
BUNDLE: 'bundle',
});
function post(options) {
const opts = {
url: options.url,
timeout: 5000,
headers: {
'content-type': 'application/json',
accept: 'application/json',
},
};
if (!isStream(options.body)) {
opts.body = options.body;
}
return new Promise((resolve, reject) => {
const req = request.post(opts, (error, response, body) => {
if (error) return reject(error);
try {
body = JSON.parse(body);
} catch (err) {}
resolve({ response, body });
});
if (isStream(options.body)) {
options.body.pipe(req);
}
});
}
module.exports = class Client {
constructor (options = {}) {
this.options = Object.assign({
buildServerUri: 'http://127.0.0.1:7100',
}, options);
constructor(options = {}) {
this.options = Object.assign(
{
buildServerUri: 'http://127.0.0.1:7100',
},
options
);

@@ -19,3 +65,3 @@ this.transforms = [];

transform (transform, options) {
transform(transform, options) {
this.transforms.push({

@@ -27,3 +73,3 @@ transform,

plugin (plugin, options) {
plugin(plugin, options) {
this.plugins.push({

@@ -35,3 +81,27 @@ plugin,

uploadJsFeed(files, options) {
const writer = new JsWriter(files, options, false, true);
this.transforms.forEach(entry => {
writer.transform(entry.transform, entry.options);
});
this.plugins.forEach(entry => {
writer.plugin(entry.plugin, entry.options);
});
return post({
url: url.resolve(this.options.buildServerUri, endpoints.UPLOAD),
body: writer.bundle().pipe(JSONStream.stringify()),
});
}
uploadCssFeed(files) {
const writer = new CssWriter(files);
return post({
url: url.resolve(this.options.buildServerUri, endpoints.UPLOAD),
body: writer.pipe(JSONStream.stringify()),
});
}
/**

@@ -41,36 +111,45 @@ * Upload asset feed to asset server

uploadFeed (files = [], options = {}) {
return new Promise((resolve, reject) => {
const writer = new Writer(files, options, false, true);
async uploadFeed(files, options = {}) {
assert(
Array.isArray(files),
`Expected 'files' to be an array, instead got ${files}`
);
assert(
files.length,
`Expected 'files' array to contain at least 1 item`
);
assert(
files.every(file => typeof file == 'string'),
`Expected each item in array 'files' to be a string, got ${files}`
);
assert(
files.every(file => file.includes('.js')) ||
files.every(file => file.includes('.css')),
`Expected ALL items in array 'files' to end with .js
or ALL items in array 'files' to end with .css, got ${files}`
);
this.transforms.forEach((entry) => {
writer.transform(entry.transform, entry.options);
});
let upload;
this.plugins.forEach((entry) => {
writer.plugin(entry.plugin, entry.options);
});
switch (extname(files[0])) {
case extensions.CSS:
upload = await this.uploadCssFeed(files);
break;
case extensions.JS:
upload = await this.uploadJsFeed(files, options);
break;
}
writer
.bundle()
.pipe(JSONStream.stringify())
.pipe(request.post({
url: url.resolve(this.options.buildServerUri, 'feed'),
json: true,
}, (error, response, body) => {
if (error) {
return reject(error);
}
if (response.statusCode === 200) {
return resolve(body);
}
if (response.statusCode === 400) {
return reject(new Error(body.message));
}
reject(new Error(`Asset build server responded with unknown error. Http status ${response.statusCode}`));
}));
});
const { response, body } = upload;
if (response.statusCode === 200) {
return Promise.resolve(body);
}
if (response.statusCode === 400) {
throw new Error(body.message);
}
throw new Error(
`Asset build server responded with unknown error. Http status ${response.statusCode}`
);
}
/**

@@ -80,25 +159,18 @@ * Make a bundle out of asset feeds on the asset server

createRemoteBundle (sources) {
return new Promise((resolve, reject) => {
request.post({
url: url.resolve(this.options.buildServerUri, 'bundle'),
body: sources,
json: true,
}, (error, response, body) => {
if (error) {
return reject(error);
}
if (response.statusCode === 200) {
return resolve(body);
}
if (response.statusCode === 202) {
return resolve(body);
}
if (response.statusCode === 400) {
return reject(new Error(body.message));
}
reject(new Error(`Asset build server responded with unknown error. Http status ${response.statusCode}`));
});
async createRemoteBundle(sources) {
const { response, body } = await post({
url: url.resolve(this.options.buildServerUri, endpoints.BUNDLE),
body: JSON.stringify(sources),
});
if ([200, 202].includes(response.statusCode)) {
return Promise.resolve(body);
}
if (response.statusCode === 400) {
throw new Error(body.message);
}
throw new Error(
`Asset build server responded with unknown error. Http status ${response.statusCode}`
);
}
};

@@ -1,49 +0,1 @@

{
"name": "asset-pipe-client",
"version": "1.0.0-beta.4",
"author": {
"name": "Trygve Lie",
"email": "post@trygve-lie.com"
},
"files": [
"bin",
"lib"
],
"description": "Asset pipe client",
"main": "./lib/main.js",
"bin": "./bin/cli.js",
"repository": {
"type": "git",
"url": "git@github.com:asset-pipe/asset-pipe-cli.git"
},
"keywords": [
"assets"
],
"contributors": [
{
"name": "Trygve Lie",
"email": "post@trygve-lie.com"
}
],
"bugs": {
"url": "https://github.com/asset-pipe/asset-pipe-cli/issues"
},
"license": "MIT",
"dependencies": {
"JSONStream": "^1.3.0",
"asset-pipe-js-writer": "1.0.0-beta.5",
"commander": "2.10.0",
"request": "^2.79.0"
},
"devDependencies": {
"asset-pipe-test-es5a": "^1.0.0",
"asset-pipe-test-es5b": "^1.0.0",
"tap": "10.7.0",
"eslint": "^4.1.0",
"eslint-config-finn": "^1.0.1"
},
"scripts": {
"lint": "eslint lib test",
"test": "tap test/*.js"
}
}
{"name":"asset-pipe-client","version":"1.0.0","author":"Trygve Lie <post@trygve-lie.com>","files":["bin","lib"],"description":"Asset pipe client","main":"./lib/main.js","bin":"./bin/cli.js","repository":{"type":"git","url":"https://github.com/asset-pipe/asset-pipe-client.git"},"keywords":["assets"],"contributors":["Trygve Lie <post@trygve-lie.com>","Richard Walker <digitalsadhu@gmail.com>","Sveinung Røsaker <sveinung.rosaker@gmail.com>","Trygve Lie (http://www.trygve-lie.com/)","Sveinung Røsaker (https://github.com/sveisvei)","Greenkeeper (http://greenkeeper.io/)"],"bugs":{"url":"https://github.com/asset-pipe/asset-pipe-client/issues"},"license":"MIT","dependencies":{"JSONStream":"^1.3.0","asset-pipe-css-writer":"^1.0.0-alpha.1","asset-pipe-js-writer":"1.0.0-beta.5","commander":"2.10.0","is-stream":"^1.1.0","request":"^2.79.0"},"devDependencies":{"asset-pipe-test-es5a":"^1.0.0","asset-pipe-test-es5b":"^1.0.0","body-parser":"^1.18.2","commitizen":"^2.9.6","cz-conventional-changelog":"^2.0.0","eslint":"^4.9.0","eslint-config-finn":"^2.0.0","eslint-config-finn-prettier":"^3.0.1","express":"^4.16.2","husky":"^0.14.3","jest":"^21.2.1","lint-staged":"^4.2.3","prettier":"^1.7.4","projectz":"^1.4.0","semantic-release":"^8.2.0"},"scripts":{"lint:format":"eslint --fix .","lint":"eslint .","test":"jest --coverage","precommit":"lint-staged","cm":"git-cz","readme":"projectz compile","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"jest":{"clearMocks":true,"coverageThreshold":{"global":{"branches":100,"functions":100,"lines":100,"statements":100}}},"lint-staged":{"*.js":["eslint --fix --config ./.eslintrc","git add"],"{package.json,README.md,LICENSE.md}":["projectz compile","git add"]},"config":{"commitizen":{"path":"cz-conventional-changelog"}},"badges":{"list":["travisci","npmversion","daviddm","daviddmdev"]},"maintainers":[]}

@@ -1,3 +0,18 @@

# asset-pipe-client
<!-- TITLE/ -->
<h1>asset-pipe-client</h1>
<!-- /TITLE -->
<!-- BADGES/ -->
<span class="badge-travisci"><a href="http://travis-ci.org/asset-pipe/asset-pipe-client" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/asset-pipe/asset-pipe-client/master.svg" alt="Travis CI Build Status" /></a></span>
<span class="badge-npmversion"><a href="https://npmjs.org/package/asset-pipe-client" title="View this project on NPM"><img src="https://img.shields.io/npm/v/asset-pipe-client.svg" alt="NPM version" /></a></span>
<span class="badge-daviddm"><a href="https://david-dm.org/asset-pipe/asset-pipe-client" title="View the status of this project's dependencies on DavidDM"><img src="https://img.shields.io/david/asset-pipe/asset-pipe-client.svg" alt="Dependency Status" /></a></span>
<span class="badge-daviddmdev"><a href="https://david-dm.org/asset-pipe/asset-pipe-client#info=devDependencies" title="View the status of this project's development dependencies on DavidDM"><img src="https://img.shields.io/david/dev/asset-pipe/asset-pipe-client.svg" alt="Dev Dependency Status" /></a></span>
<!-- /BADGES -->
[![Greenkeeper badge](https://badges.greenkeeper.io/asset-pipe/asset-pipe-client.svg)](https://greenkeeper.io/)

@@ -143,36 +158,11 @@

## Contributing
The contribution process is as follows:
## License
The MIT License (MIT)
Copyright (c) 2017 - Trygve Lie - post@trygve-lie.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[commonjs]: https://nodejs.org/docs/latest/api/modules.html
[asset-pipe]: https://github.com/asset-pipe
[asset-pipe-build-server]: https://github.com/asset-pipe/asset-pipe-build-server
[browserify]: https://github.com/substack/node-browserify
[browserify-opts]: https://github.com/substack/node-browserify#browserifyfiles--opts
[browserify-plugin]: https://github.com/substack/node-browserify#bpluginplugin-opts
[browserify-transform]: https://github.com/substack/node-browserify#btransformtr-opts
- Fork this repository.
- Make your changes as desired.
- Run the tests using `npm test`. This will also check to ensure that 100% code coverage is maintained. If not you may need to add additional tests.
- Stage your changes.
- Run `git commit` or, if you are not familiar with [sematic commit messages](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), please run `npm run cm` and follow the prompts instead which will help you write a correct semantic commit message.
- Push your changes and submit a PR.
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc