gulp-ws-sender
Advanced tools
Comparing version 1.0.0 to 1.1.0
44
index.js
@@ -1,42 +0,8 @@ | ||
'use strict' | ||
const gutil = require('gulp-util') | ||
const through = require('through2') | ||
const chalk = require('chalk') | ||
const date = require('date-and-time') | ||
const server = require('./src/server') | ||
const broadcast = require('./src/broadcast') | ||
const getMessage = type => { | ||
const time = date.format(new Date(), 'HH:mm:ss') | ||
return `[${chalk.gray(time)}] ${chalk.yellow(type)} was sent` | ||
} | ||
module.exports = options => { | ||
const { client: ws, type } = options | ||
return through.obj(function(file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file) | ||
return | ||
} | ||
if (file.isStream()) { | ||
cb(new gutil.PluginError('gulp-ws-sender', 'Streaming not supported')) | ||
return | ||
} | ||
try { | ||
const prefix = type === 'js' ? 'js' : 'st' | ||
ws.send(prefix + file.contents.toString()) | ||
file.contents = Buffer.from(file.contents) | ||
this.push(file) | ||
console.log(getMessage(type)) | ||
} catch (err) { | ||
this.emit('error', new gutil.PluginError('gulp-ws-sender', err)) | ||
console.log(err) | ||
} | ||
cb() | ||
}) | ||
module.exports = { | ||
server, | ||
broadcast | ||
} |
{ | ||
"name": "gulp-ws-sender", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "to send js and css to your websocket server", | ||
@@ -14,6 +14,10 @@ "main": "index.js", | ||
"chalk": "^2.4.1", | ||
"date-and-time": "^0.6.3", | ||
"gulp-util": "^3.0.8", | ||
"through2": "^3.0.0" | ||
"through2": "^3.0.0", | ||
"ws": "^6.1.0" | ||
}, | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/bercly0b/gulp-ws-sender" | ||
} | ||
} |
## usage | ||
```sh | ||
const gulp = require('gulp') | ||
const sender = require('gulp-ws-sender') | ||
const WebSocket = require('ws') | ||
const broadcast = require('gulp-ws-sender').broadcast(port) | ||
const server = require('gulp-ws-sender').server | ||
const ws = new WebSocket('ws://localhost:9999') | ||
gulp.task('styles', () => { | ||
return gulp.src('src/**/*.css') | ||
.pipe(sender({ | ||
socketClient: ws, | ||
type: 'css' | ||
@@ -17,2 +14,4 @@ })) | ||
}) | ||
gulp.task('server', () => server({ port: port })) | ||
``` |
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
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3332
6
78
0
17
+ Addedws@^6.1.0
+ Addedasync-limiter@1.0.1(transitive)
+ Addedws@6.2.3(transitive)
- Removeddate-and-time@^0.6.3
- Removeddate-and-time@0.6.3(transitive)