Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gulp Version and Add Tests #12

Merged
merged 5 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
35 changes: 35 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- master
pull_request:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 17.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

env:
KRAKEN_API_KEY: ${{ secrets.KRAKEN_API_KEY }}
KRAKEN_API_SECRET: ${{ secrets.KRAKEN_API_SECRET }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm install
- run: npm test
61 changes: 61 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 15.x, 16.x, 17.x, 18.x, 20.x]

env:
KRAKEN_API_KEY: ${{ secrets.KRAKEN_API_KEY }}
KRAKEN_API_SECRET: ${{ secrets.KRAKEN_API_SECRET }}

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm install
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
KRAKEN_API_KEY: ${{ secrets.KRAKEN_API_KEY }}
KRAKEN_API_SECRET: ${{ secrets.KRAKEN_API_SECRET }}
# Notify Slack on success or failure
- name: Notify Slack
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: "gulp-kraken npm package published successfully!"
SLACK_COLOR: "#00FF00"
if: success()

- name: Notify Slack for Failure
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: "gulp-kraken npm package publishing failed!"
SLACK_COLOR: "#FF0000"
if: failure()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.env
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- '0.10'
- "18"
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
gulp-kraken
===========
# gulp-kraken

Gulp plugin to optimize all your images with the powerful [Kraken.io API](https://kraken.io)


## Installation

````
```
$ npm install gulp-kraken --save-dev
````
```

## Options

* `key` - your Kraken API Key
* `secret` - your Kraken API Secret
* `lossy` - enable/disable intelligent lossy optimization. Defaults to `true`
* `concurrency` - image processing concurrency (1 - 16). Defaults to `4`
- `key` - your Kraken API Key
- `secret` - your Kraken API Secret
- `lossy` - enable/disable intelligent lossy optimization. Defaults to `true`
- `concurrency` - image processing concurrency (1 - 16). Defaults to `4`

## Example

````
var gulp = require('gulp'),
kraken = require('gulp-kraken');

gulp.task('kraken', function () {
gulp.src('images/**/*.*')
.pipe(kraken({
key: 'kraken-api-key-here',
secret: 'kraken-api-secret-here',
lossy: true,
concurrency: 6
}));
});
```
const gulp = require("gulp");
const kraken = require("gulp-kraken");

gulp.task('default', function() {
gulp.start('kraken');
//optional task to copy images to a new folder
gulp.task("copy", function () {
return gulp.src("./fixtures/*.*").pipe(gulp.dest("optimized_images"));
});
````

gulp.task(
"kraken",
gulp.series("copy", function () {
return gulp.src("./optimized_images/*.*").pipe(
kraken({
key: process.env.KRAKEN_API_KEY,
secret: process.env.KRAKEN_API_SECRET,
lossy: true,
concurrency: 6,
})
);
})
);
```
Binary file added fixtures/original.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const gulp = require("gulp");
const kraken = require("./index");

//optional task to copy images to a new folder
gulp.task("copy", function () {
return gulp.src("./fixtures/*.*").pipe(gulp.dest("optimized_images"));
});

gulp.task(
"kraken",
gulp.series("copy", function () {
return gulp.src("./optimized_images/*.*").pipe(
kraken({
key: process.env.KRAKEN_API_KEY,
secret: process.env.KRAKEN_API_SECRET,
lossy: true,
concurrency: 6,
})
);
})
);
33 changes: 33 additions & 0 deletions gulpfile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const gulp = require("gulp");
const fs = require("fs");
const path = require("path");
require("./gulpfile");
require("dotenv").config();

describe("Gulp Kraken Task", () => {
const inputPath = path.join(__dirname, "/fixtures/original.png");
const inputSizeInBytes = fs.statSync(inputPath).size;

afterAll(() => {
fs.rmdirSync(path.join(__dirname, "/optimized_images"), {
recursive: true,
});
});

test("should optimize image", (done) => {
gulp.series("kraken")(function (err) {
const outputPath = path.join(__dirname, "/optimized_images/original.png");

fs.access(outputPath, fs.constants.F_OK, (err) => {
expect(err).toBeFalsy();

const stats = fs.statSync(outputPath);
const fileSizeInBytes = stats.size;

expect(fileSizeInBytes).toBeLessThan(inputSizeInBytes);

done();
});
});
});
});
Loading