diff --git a/CHANGELOG.md b/CHANGELOG.md index 330382c18..0a3505f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ Thank you, Daniel Holmes ([@danielholmes](https://github.com/danielholmes)), for #### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149)) -Marking this as a "breaking release" because it might change what deps need to be installed. +Marking this as a "breaking release" because it might change what deps need to be installed. All modules should be exported as valid cjs and esm @@ -97,7 +97,7 @@ Thank you, nopeless ([@nopeless](https://github.com/nopeless)), for all your wor #### switch from browserify to webpack ([#1140](https://github.com/jimp-dev/jimp/pull/1140)) -This PR can be considered a breaking change as it remove the `jimp.min.js` file. +This PR can be considered a breaking change as it remove the `jimp.min.js` file. Instead there is now only the `jimp.js` file and we ship source maps for it. diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md deleted file mode 100644 index cf26b5c36..000000000 --- a/packages/cli/CHANGELOG.md +++ /dev/null @@ -1,36 +0,0 @@ -# v0.16.3 (Sat Feb 04 2023) - -#### ⚠️ Pushed to `master` - -- update linting ([@hipstersmoothie](https://github.com/hipstersmoothie)) -- upgrade prettier ([@hipstersmoothie](https://github.com/hipstersmoothie)) - -#### Authors: 1 - -- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie)) - ---- - -# v0.11.0 (Fri May 15 2020) - -#### 🚀 Enhancement - -- Removed Core-JS as a dependency. [#882](https://github.com/oliver-moran/jimp/pull/882) ([@EricRabil](https://github.com/EricRabil)) - -#### Authors: 1 - -- Eric Rabil ([@EricRabil](https://github.com/EricRabil)) - ---- - -# v0.9.3 (Tue Nov 26 2019) - -#### 🐛 Bug Fix - -- `@jimp/cli`, `@jimp/core`, `@jimp/custom`, `jimp`, `@jimp/plugin-blit`, `@jimp/plugin-blur`, `@jimp/plugin-circle`, `@jimp/plugin-color`, `@jimp/plugin-contain`, `@jimp/plugin-cover`, `@jimp/plugin-crop`, `@jimp/plugin-displace`, `@jimp/plugin-dither`, `@jimp/plugin-fisheye`, `@jimp/plugin-flip`, `@jimp/plugin-gaussian`, `@jimp/plugin-invert`, `@jimp/plugin-mask`, `@jimp/plugin-normalize`, `@jimp/plugin-print`, `@jimp/plugin-resize`, `@jimp/plugin-rotate`, `@jimp/plugin-scale`, `@jimp/plugin-shadow`, `@jimp/plugin-threshold`, `@jimp/plugins`, `@jimp/test-utils`, `@jimp/bmp`, `@jimp/gif`, `@jimp/jpeg`, `@jimp/png`, `@jimp/tiff`, `@jimp/types`, `@jimp/utils` - - Fix regeneratorRuntime errors [#815](https://github.com/oliver-moran/jimp/pull/815) ([@crutchcorn](https://github.com/crutchcorn) [@hipstersmoothie](https://github.com/hipstersmoothie)) - -#### Authors: 2 - -- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie)) -- Corbin Crutchley ([@crutchcorn](https://github.com/crutchcorn)) diff --git a/packages/cli/README.md b/packages/cli/README.md deleted file mode 100644 index 27b5cd5f2..000000000 --- a/packages/cli/README.md +++ /dev/null @@ -1,52 +0,0 @@ -
- - - -

@jimp/cli

-

jimp on the cli

-
- -Jimp on the CLI. - -## Usage - -Run with `--help` to get help information. Further help by running `--help `. The two main functions are `read` and `create`. - -```sh -jimp - -Commands: - jimp read [img] Read and image into jimp. (PNG, JPEG, TIFF, BMP, or GIF) - jimp create Create a new image - jimp distance [img1] [img2] Calculates the hamming distance of two images based on their - perceptual hash - jimp diff [img1] [img2] Diffs two images - jimp rgbaToInt A static helper method that converts RGBA values to a single - integer value. args: r, g, b, a (0 - 255) - jimp intToRGBA A static helper method that converts RGBA values to a single - integer value. args: num (eg 0xFF0000FF) - jimp cssColorToHex Converts a css color (Hex, 8-digit (RGBA) Hex, RGB, RGBA, HSL, - HSLA, HSV, HSVA, Named) to a hex number - jimp limit255 Limits a number to between 0 or 255. args: num - jimp compareHashes Calculates the hamming distance of two images based on their - perceptual hash. args: hash1, hash2 - jimp colorDiff Compute color difference. args: color1, color2 ({r:val, g:val, - b:val, a:val}) - jimp measureText Measure how wide printing a string will be. args: text - jimp measureTextHeight Measure how tall printing a string will be. args: text, width - -Jimp Configuration: - --plugins, -p Jimp plugins to load. [array] - --types, -t Jimp types to load. [array] - --loadFont, -f Path of font to load and be used in text operations [string] - -Options: - --help Show help [boolean] - --version Show version number [boolean] - --verbose, -v enable more logging [boolean] - -Examples: - jimp read path/to/image.png --output output.jpg Convert images from one type to another. See - more under jimp read --help -``` diff --git a/packages/cli/babel.config.js b/packages/cli/babel.config.js deleted file mode 120000 index 426aaf31b..000000000 --- a/packages/cli/babel.config.js +++ /dev/null @@ -1 +0,0 @@ -../../babel.config.js \ No newline at end of file diff --git a/packages/cli/package.json b/packages/cli/package.json deleted file mode 100644 index 8c9096fe3..000000000 --- a/packages/cli/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "@jimp/cli", - "version": "0.21.3", - "description": "jimp on the cli", - "repository": "jimp-dev/jimp", - "bin": { - "jimp": "dist/index.js" - }, - "main": "dist/index.js", - "module": "es/index.js", - "scripts": { - "test": "mocha --require ts-node/register test/*.test.ts", - "test:coverage": "nyc npm run test -- --require source-map-support/register --recursive", - "build": "tsc", - "build:debug": "npm run build -- --sourceMap", - "build:watch": "npm run build -- --watch --sourceMap" - }, - "author": "", - "license": "MIT", - "dependencies": { - "@jimp/custom": "link:../custom", - "chalk": "^2.4.1", - "jimp": "^0.21.3", - "log-symbols": "^2.2.0", - "yargs": "^12.0.2" - }, - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@types/log-symbols": "^2.0.0", - "@types/mocha": "^5.2.7", - "@types/yargs": "^11.1.1", - "ts-node": "^7.0.1", - "typescript": "^3.1.3" - }, - "nyc": { - "extension": [ - ".ts", - ".tsx" - ], - "include": [ - "src/*.ts" - ], - "reporter": [ - "html", - "text" - ] - }, - "yargs": { - "flatten-duplicate-arrays": false - } -} diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts deleted file mode 100644 index 72d4b2d42..000000000 --- a/packages/cli/src/cli.ts +++ /dev/null @@ -1,280 +0,0 @@ -#!/usr/bin/env node - -import yargs from "yargs"; -import custom from "@jimp/custom"; -import Jimp from "jimp"; - -import { logResult, log } from "./log"; -import { loadFont } from "./load-font"; - -const omitFunctions = [ - "read", // configured below - "create", - "appendConstructorOption", - "distance", // configured below - "diff", // configured below - "loadFont", // loaded as flag -]; - -const descriptions = { - rgbaToInt: - "A static helper method that converts RGBA values to a single integer value. args: r, g, b, a (0 - 255)", - intToRGBA: - "A static helper method that converts RGBA values to a single integer value. args: num (eg 0xFF0000FF)", - cssColorToHex: - " Converts a css color (Hex, 8-digit (RGBA) Hex, RGB, RGBA, HSL, HSLA, HSV, HSVA, Named) to a hex number", - limit255: "Limits a number to between 0 or 255. args: num", - compareHashes: - " Calculates the hamming distance of two images based on their perceptual hash. args: hash1, hash2", - colorDiff: - "Compute color difference. args: color1, color2 ({r:val, g:val, b:val, a:val})", - measureText: "Measure how wide printing a string will be. args: text", - measureTextHeight: - "Measure how tall printing a string will be. args: text, width", -}; - -function load(type: string, toLoad: string[], verbose: boolean) { - return toLoad.map((entry) => { - try { - const result = require(entry); - log(` 🔌 Loaded ${type}: ${entry}`, verbose); - return result; - } catch (error) { - log(`Couldn't load ${type} [${entry}]. Make sure it's installed.`, true); - return undefined; - } - }); -} - -function loadConfiguration( - plugins: string[], - types: string[], - verbose: boolean -) { - if (!plugins.length && !types.length) { - return; - } - - log(` 🔄 Loading custom types/plugins into Jimp...`, verbose); - - const loadedPlugins = load("plugin", plugins, verbose); - const loadedTypes = load("type", types, verbose); - - custom({ types: loadedTypes, plugins: loadedPlugins }, Jimp); -} - -function getArgs(args: string[], variations: string[]) { - return args - .map((arg, index) => - variations.indexOf(arg) > -1 ? args[index + 1] : null - ) - .filter(Boolean); -} - -export default function setUpCli(args?: string[], log = logResult) { - // can't call argv before done setting up - const verbose = Boolean( - args.find((arg) => arg === "-v" || arg === "--verbose") - ); - const plugins = getArgs(args, ["--plugins", "-p"]); - const types = getArgs(args, ["--types", "-t"]); - - loadConfiguration(plugins, types, verbose); - - const yargsConfig = yargs(args) - .scriptName("jimp") - .option("plugins", { - alias: "p", - type: "array", - describe: "Jimp plugins to load.", - }) - .option("types", { - alias: "t", - type: "array", - describe: "Jimp types to load.", - }) - .option("verbose", { - alias: "v", - type: "boolean", - describe: "enable more logging", - }) - .option("loadFont", { - alias: "f", - type: "string", - describe: "Path of font to load and be used in text operations", - }) - .group(["plugins", "types", "loadFont"], "Jimp Configuration:") - .example( - "$0 read path/to/image.png --output output.jpg", - "Convert images from one type to another. See more under jimp read --help" - ) - .alias("font", "loadFont") - .demandCommand(1, "You need at least one command before moving on") - .command({ - command: "read [img]", - describe: "Read and image into jimp. (PNG, JPEG, TIFF, BMP, or GIF)", - builder: (yargs) => - yargs - .group(["output", "actions"], "Jimp Configuration:") - .option("output", { - alias: "o", - describe: "file to output from jimp. (PNG, JPEG, TIFF, or BMP)", - }) - .option("actions", { - alias: "a", - type: "array", - describe: `actions (image manipulation) to run on the input image. Loaded functions ${Object.keys( - Jimp.prototype - ) - .sort() - .join(", ")}`, - }) - .example( - "$0 read path/to/image.png -a greyscale -a resize 150 -1 --output output.jpg", - "Apply image manipulations functions" - ) - .example( - '$0 read path/to/image.png --loadFont FONT_SANS_8_WHITE -a yarnprint 0 0 "Some text" --output output.jpg', - "Use fonts" - ) - .example( - "$0 read path/to/image.png --plugins @jimp/plugin-circle -a circle --output output.jpg", - "Use plugins" - ) - .example( - "$0 read path/to/image.png -a blit /path/to/image.png 0 0 --output output.jpg", - "Use blit composite or mask" - ), - }) - .command({ - command: "create", - describe: "Create a new image", - builder: (yargs) => - yargs - .group(["width", "height", "background"], "New Image Configuration:") - .group(["output", "actions"], "Jimp Configuration:") - .demandOption( - ["width", "height"], - "Please provide both height and width to create new image" - ) - .option("width", { - alias: "w", - type: "number", - describe: "Width of new image", - }) - .option("height", { - alias: "he", - type: "number", - describe: "Height of new image", - }) - .option("background", { - alias: "b", - describe: "Background color - either hex value or css string", - }) - .option("output", { - alias: "o", - describe: "file to output from jimp. (PNG, JPEG, TIFF, or BMP)", - }) - .option("actions", { - alias: "a", - type: "array", - describe: `actions (image manipulation) to run on the input image. Loaded functions ${Object.keys( - Jimp.prototype - ) - .sort() - .join(", ")}`, - }) - .example( - "$0 create -w 100 -he 300 -o output.jpg", - "create a blank image" - ) - .example( - "$0 create -w 100 -he 300 -b 0xff0000ff -o output.jpg", - "create a red image" - ) - .example( - '$0 create -w 100 -he 300 -b "#FFJJED" -o output.jpg', - "create a css color image" - ) - .example( - '$0 create -w 100 -he 300 -b 0xff0000ff --loadFont FONT_SANS_8_WHITE -a print 0 0 "Some text" -o output.jpg', - "Run actions on the new image" - ) - .example( - "$0 create path/to/image.png -a blit /path/to/image.png 0 0 --output output.jpg", - "Use blit composite or mask" - ), - }) - .command({ - command: "distance [img1] [img2]", - describe: - "Calculates the hamming distance of two images based on their perceptual hash", - builder: function (yargs) { - return yargs - .example("$0 distance path/to/image.png path/to/another.png", "") - .hide("version") - .hide("font"); - }, - handler: async ({ img1, img2 }) => { - const base = await Jimp.read(img1); - const compare = await Jimp.read(img2); - const distance = Jimp.distance(base, compare); - - log("distance", distance); - }, - }) - .command({ - command: "diff [img1] [img2]", - describe: "Diffs two images", - builder: function (yargs) { - return yargs - .example("$0 diff [img1] [img2]", "-o") - .option("outputDiff", { - alias: "o", - describe: "File to output diff to.", - }) - .hide("version") - .hide("font"); - }, - handler: async ({ img1, img2, outputDiff }) => { - const base = await Jimp.read(img1); - const compare = await Jimp.read(img2); - const diff = Jimp.diff(base, compare); - log("diff", diff.percent); - - if (outputDiff) { - diff.image.writeAsync(outputDiff === true ? "diff.png" : outputDiff); - } - }, - }); - - Object.keys(Jimp).forEach((x) => { - if (omitFunctions.indexOf(x) > -1) { - return; - } - - const utilityFunction = Jimp[x]; - - if (typeof utilityFunction === "function") { - yargsConfig.command( - x, - descriptions[x], - {}, - async ({ _, font, verbose }) => { - const args: any[] = _.slice(1); - - if (x === "measureText" || x === "measureTextHeight") { - const loadedFont = await loadFont(font, verbose); - args.unshift(loadedFont); - } - - const result = utilityFunction(...args); - - log(x, result); - } - ); - } - }); - - return yargsConfig; -} diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts deleted file mode 100644 index 86d32434a..000000000 --- a/packages/cli/src/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env node - -import setUpCli from "./cli"; -import { manipulateImage, createImage } from "./process-image"; - -export async function runCLI(args = process.argv) { - const { argv } = setUpCli(args.slice(2)); - - if (argv._.includes("read")) { - await manipulateImage(argv); - } - - if (argv._.includes("create")) { - await createImage(argv); - } -} - -runCLI(); diff --git a/packages/cli/src/load-font.ts b/packages/cli/src/load-font.ts deleted file mode 100644 index 1f82cf90f..000000000 --- a/packages/cli/src/load-font.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Jimp from "jimp"; -import { log } from "./log"; - -export async function loadFont(font?: string, verbose?: boolean) { - if (font) { - log(` 🔤 Loading font: ${font} ...`, verbose); - return Jimp.loadFont((Jimp[font] as unknown as string) || font); - } -} diff --git a/packages/cli/src/log.ts b/packages/cli/src/log.ts deleted file mode 100644 index f97a6c23c..000000000 --- a/packages/cli/src/log.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as logSymbols from "log-symbols"; -import chalk from "chalk"; - -export const greenCheck = chalk.green(`${logSymbols.success} `); - -export const log = (message, verbose = false) => - verbose && console.log(message); - -export const logResult = (functionName, result) => - log( - `${greenCheck} Result of running '${functionName}': ${JSON.stringify( - result - )}`, - true - ); diff --git a/packages/cli/src/process-image.ts b/packages/cli/src/process-image.ts deleted file mode 100644 index aedad6099..000000000 --- a/packages/cli/src/process-image.ts +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env node - -import Jimp from "jimp"; -import { log, greenCheck } from "./log"; -import { loadFont } from "./load-font"; - -export interface ICliOptions { - img?: string; - output?: string; - actions?: any; - verbose?: boolean; - loadFont?: string; - width?: number; - height?: number; - background?: string | number; -} - -async function runAction( - image, - verbose, - loadedFont, - [action, ...args]: [string, ...any[]] -) { - const argsString = args.length ? ` with args: [ ${args.join(", ")} ]` : ""; - log(`️🖍️ Applying ${action}${argsString}`, verbose); - - const parsedArgs = args.map((arg) => { - try { - return JSON.parse(arg); - } catch (error) { - return arg; - } - }); - - if (action === "print") { - parsedArgs.unshift(loadedFont); - } - - if (action === "composite" || action === "blit" || action === "mask") { - parsedArgs[0] = await Jimp.read(parsedArgs[0]); - } - - image[action](...parsedArgs); -} - -async function runActions( - image: typeof Jimp, - loadedFont: any, - { actions, verbose }: ICliOptions -) { - if (actions) { - if (Array.isArray(actions[0])) { - await Promise.all( - (actions as [string, ...any[]][]).map((action) => - runAction(image, verbose, loadedFont, action) - ) - ); - } else { - await runAction( - image, - verbose, - loadedFont, - actions as [string, ...any[]] - ); - } - } -} - -async function processImage(image, font, actions, output, verbose) { - const loadedFont = await loadFont(font, verbose); - - await runActions(image, loadedFont, { actions, verbose }); - - if (output) { - await image.writeAsync(output); - log(` ${greenCheck}️ Image successfully written to: ${output}`, verbose); - } -} - -export async function manipulateImage({ - img, - output, - actions, - verbose, - loadFont: font, -}: ICliOptions) { - log(` 📷 Loading source image: ${img} ...`, verbose); - - const image = await Jimp.read(img); - - await processImage(image, font, actions, output, verbose); -} - -export async function createImage({ - width, - height, - background, - output, - actions, - verbose, - loadFont: font, -}: ICliOptions) { - const backgroundString = background ? ` with background ${background}` : ""; - log(` 📷 Creating image: [${width} ${height}]${backgroundString}`, verbose); - - let image; - - if (background) { - image = await Jimp.create(width, height, background); - } else { - image = await Jimp.create(width, height); - } - - await processImage(image, font, actions, output, verbose); -} diff --git a/packages/cli/test/cli.test.ts b/packages/cli/test/cli.test.ts deleted file mode 100644 index c9d5a7ff5..000000000 --- a/packages/cli/test/cli.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -import "should"; -import * as fs from "fs"; -import { describe, it } from "mocha"; - -import makePath from "./utils/makePath"; -import setUpCli from "../src/cli"; - -const testImage1 = makePath(__dirname, "./images/qr.jpg"); -const testImage2 = makePath(__dirname, "./images/qr-convoluted.png"); - -describe("CLI", function () { - this.timeout(20 * 1000); - describe("diff helper", () => { - it("diff helper", (done) => { - setUpCli(["diff", testImage1, testImage2], (output, result) => { - output.should.be.exactly("diff"); - result.should.be.exactly(0.9747570461662795); - done(); - }).argv; - }); - - it("outputs a diff image to default path", (done) => { - setUpCli(["diff", testImage1, testImage2, "-o"], () => {}).argv; - - setTimeout(() => { - fs.existsSync("diff.png").should.be.exactly(true); - fs.unlinkSync("diff.png"); - done(); - }, 1000); - }); - - it("outputs a diff image to default path", (done) => { - setUpCli(["diff", testImage1, testImage2, "-o", "custom.png"], () => {}) - .argv; - - setTimeout(() => { - fs.existsSync("custom.png").should.be.exactly(true); - fs.unlinkSync("custom.png"); - done(); - }, 2000); - }); - }); - - describe("distance helper", () => { - it("calculates distance", (done) => { - setUpCli(["distance", testImage1, testImage2], (output, result) => { - output.should.be.exactly("distance"); - result.should.be.exactly(0.125); - done(); - }).argv; - }); - }); - - it("loads other functions", (done) => { - setUpCli(["rgbaToInt", "1", "2", "3", "4"], (output, result) => { - output.should.be.exactly("rgbaToInt"); - result.should.be.exactly(16909060); - done(); - }).argv; - }); - - it("loads fonts for some functions", (done) => { - setUpCli( - ["--font", "FONT_SANS_32_WHITE", "measureText", "some string"], - (output, result) => { - output.should.be.exactly("measureText"); - result.should.be.exactly(167); - done(); - } - ).argv; - }); -}); diff --git a/packages/cli/test/images/action-1.png b/packages/cli/test/images/action-1.png deleted file mode 100644 index 94abc1377..000000000 Binary files a/packages/cli/test/images/action-1.png and /dev/null differ diff --git a/packages/cli/test/images/action-2.png b/packages/cli/test/images/action-2.png deleted file mode 100644 index 30cf695fe..000000000 Binary files a/packages/cli/test/images/action-2.png and /dev/null differ diff --git a/packages/cli/test/images/action-boolean.png b/packages/cli/test/images/action-boolean.png deleted file mode 100644 index 724124580..000000000 Binary files a/packages/cli/test/images/action-boolean.png and /dev/null differ diff --git a/packages/cli/test/images/action-print.png b/packages/cli/test/images/action-print.png deleted file mode 100644 index 9d6d1199d..000000000 Binary files a/packages/cli/test/images/action-print.png and /dev/null differ diff --git a/packages/cli/test/images/blit.png b/packages/cli/test/images/blit.png deleted file mode 100644 index 100f3175d..000000000 Binary files a/packages/cli/test/images/blit.png and /dev/null differ diff --git a/packages/cli/test/images/create-blank.png b/packages/cli/test/images/create-blank.png deleted file mode 100644 index 5d1ef8d30..000000000 Binary files a/packages/cli/test/images/create-blank.png and /dev/null differ diff --git a/packages/cli/test/images/create.png b/packages/cli/test/images/create.png deleted file mode 100644 index bd63844fe..000000000 Binary files a/packages/cli/test/images/create.png and /dev/null differ diff --git a/packages/cli/test/images/qr-convoluted.png b/packages/cli/test/images/qr-convoluted.png deleted file mode 100644 index 9b42e016a..000000000 Binary files a/packages/cli/test/images/qr-convoluted.png and /dev/null differ diff --git a/packages/cli/test/images/qr.jpg b/packages/cli/test/images/qr.jpg deleted file mode 100644 index b2cc618b2..000000000 Binary files a/packages/cli/test/images/qr.jpg and /dev/null differ diff --git a/packages/cli/test/images/tiny-qr.png b/packages/cli/test/images/tiny-qr.png deleted file mode 100644 index 5e1f05fa4..000000000 Binary files a/packages/cli/test/images/tiny-qr.png and /dev/null differ diff --git a/packages/cli/test/index.test.ts b/packages/cli/test/index.test.ts deleted file mode 100644 index 7487ea7af..000000000 --- a/packages/cli/test/index.test.ts +++ /dev/null @@ -1,138 +0,0 @@ -import "should"; -import { describe, it } from "mocha"; - -import * as fs from "fs"; -import { mockConsole } from "./utils/mock-console"; -import makePath from "./utils/makePath"; -import { runCLI } from "../src/index"; - -function run(...args) { - return runCLI(["", "", ...args]); -} - -describe("index", () => { - it("outputs nothing normally", async () => { - const { calls, reset } = mockConsole(); - const output = "verbose-off.png"; - - await run( - "read", - makePath(__dirname, "./images/tiny-qr.png"), - "--output", - output - ); - - reset(); - calls.length.should.be.exactly(0); - fs.unlinkSync(output); - }); - - it("outputs in verbose mode", async () => { - const { calls, reset } = mockConsole(Infinity); - const output = "verbose-on.png"; - - await run( - "read", - makePath(__dirname, "./images/tiny-qr.png"), - "--output", - output, - "-v" - ); - - reset(); - calls.length.should.be.exactly(2); - fs.unlinkSync(output); - }); - - describe("plugins", () => { - it("errors if plugin not found", async () => { - const { reset } = mockConsole(Infinity); - - try { - await run( - "read", - makePath(__dirname, "./images/tiny-qr.png"), - "-p", - "@jimp/plugin-non-existant" - ); - reset(); - } catch (error) { - reset(); - error.should.be.ok(); - } - }); - - it("loads plugins", async () => { - const { calls, reset } = mockConsole(Infinity); - const output = "plugins-on.png"; - - await run( - "read", - makePath(__dirname, "./images/tiny-qr.png"), - "--output", - output, - "-v", - "-p", - "@jimp/plugin-circle" - ); - - reset(); - calls.length.should.be.exactly(4); - fs.unlinkSync(output); - }); - - it("blit", async () => { - const output = "blit.png"; - - await run( - "read", - makePath(__dirname, "./images/create.png"), - "--output", - output, - "-a", - ["blit", makePath(__dirname, "./images/tiny-qr.png"), 0, 0], - "-p", - "@jimp/plugin-circle" - ); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - }); - - describe("create", () => { - it("should create an image with n o background", async () => { - const output = "create-blank.png"; - - await run("create", "-w", "100", "--he", "200", "-o", output); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - - it("should create an image with a background", async () => { - const output = "create.png"; - - await run( - "create", - "-w", - "100", - "--he", - "200", - "-b", - 0xff0000ff, - "-o", - output - ); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - }); -}); diff --git a/packages/cli/test/load-font.test.ts b/packages/cli/test/load-font.test.ts deleted file mode 100644 index 9158cc6e2..000000000 --- a/packages/cli/test/load-font.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import "should"; -import makePath from "./utils/makePath"; -import { loadFont } from "../src/load-font"; - -describe("loadFont", () => { - it("do nothing when no font set", async () => { - const font = await loadFont(); - (font === undefined).should.be.exactly(true); - }); - - it("load font constant", async () => { - const font = await loadFont("FONT_SANS_32_WHITE"); - font.should.not.be.exactly(undefined); - }); - - it("load font path", async () => { - const font = await loadFont( - makePath( - __dirname, - "../../plugin-print/fonts/open-sans/open-sans-8-black/open-sans-8-black.fnt" - ) - ); - font.should.not.be.exactly(undefined); - }); -}); diff --git a/packages/cli/test/log.test.ts b/packages/cli/test/log.test.ts deleted file mode 100644 index d87b31ff0..000000000 --- a/packages/cli/test/log.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import "should"; -import { log, logResult } from "../src/log"; -import { mockConsole } from "./utils/mock-console"; - -describe("log", () => { - it("should print when verbose is set", () => { - const { calls } = mockConsole(); - const testString = "Some string"; - - log(testString, true); - calls[0].should.be.deepEqual([testString]); - }); - - it("shouldn't print when verbose isn't set", () => { - const { calls, reset } = mockConsole(); - const testString = "Some string"; - - log(testString); - reset(); - calls.length.should.be.exactly(0); - }); -}); - -describe("logResult", () => { - it("should print a result", () => { - const { calls } = mockConsole(); - - logResult("function", 100); - (calls[0][0].indexOf("function") > -1).should.be.exactly(true); - (calls[0][0].indexOf("100") > -1).should.be.exactly(true); - }); -}); diff --git a/packages/cli/test/process-image.test.ts b/packages/cli/test/process-image.test.ts deleted file mode 100644 index d46809bc1..000000000 --- a/packages/cli/test/process-image.test.ts +++ /dev/null @@ -1,97 +0,0 @@ -import "should"; -import * as fs from "fs"; - -import makePath from "./utils/makePath"; -import { manipulateImage } from "../src/process-image"; - -describe("manipulateImage", () => { - it("write files correctly", async () => { - const output = "write.png"; - await manipulateImage({ img: makePath(__dirname, "./images/tiny-qr.png") }); - fs.existsSync(output).should.be.exactly(false); - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - output: output, - }); - fs.existsSync(output).should.be.exactly(true); - fs.unlinkSync(output); - }); - - it("runs action with args", async () => { - const output = "action-1.png"; - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - output: output, - actions: [["resize", 20, 20]], - }); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - - it("runs action without args", async () => { - const output = "action-2.png"; - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - output: output, - actions: ["greyscale"], - }); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - - it("runs print", async () => { - const output = "action-print.png"; - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - loadFont: "FONT_SANS_8_WHITE", - output: output, - actions: [["print", 0, 0, "This is a test string!", 50]], - }); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - - it("runs print with object", async () => { - const output = "action-print.png"; - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - loadFont: "FONT_SANS_8_WHITE", - output: output, - actions: [["print", 0, 0, '{ "text": "This is a test string!" }', 50]], - }); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); - - it("transforms boolean args", async () => { - const output = "action-boolean.png"; - - await manipulateImage({ - img: makePath(__dirname, "./images/tiny-qr.png"), - output: output, - actions: [["flip", true, false]], - }); - - fs.readFileSync(output).should.be.deepEqual( - fs.readFileSync(makePath(__dirname, `./images/${output}`)) - ); - fs.unlinkSync(output); - }); -}); diff --git a/packages/cli/test/utils/makePath.ts b/packages/cli/test/utils/makePath.ts deleted file mode 100644 index 9425aebfa..000000000 --- a/packages/cli/test/utils/makePath.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as path from "path"; - -export default function makePath(dir, file) { - return path.resolve(path.join(dir, file)); -} diff --git a/packages/cli/test/utils/mock-console.ts b/packages/cli/test/utils/mock-console.ts deleted file mode 100644 index a1fb730fb..000000000 --- a/packages/cli/test/utils/mock-console.ts +++ /dev/null @@ -1,22 +0,0 @@ -export function mockConsole(times = 1) { - const orig = console.log; - const calls = []; - - function reset() { - console.log = orig; - } - - let callMockedLeft = times; - - console.log = (...output) => { - calls.push(output); - - if (callMockedLeft === 0) { - reset(); - } - - callMockedLeft -= 1; - }; - - return { calls, reset }; -} diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json deleted file mode 100644 index cbd68ba81..000000000 --- a/packages/cli/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "lib": ["es2015"], - "outDir": "dist", - "esModuleInterop": true - }, - "include": ["src/**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 62bfdbeb4..0a30c9d04 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -28,7 +28,7 @@ #### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149)) -Marking this as a "breaking release" because it might change what deps need to be installed. +Marking this as a "breaking release" because it might change what deps need to be installed. All modules should be exported as valid cjs and esm @@ -68,7 +68,7 @@ Thank you, nopeless ([@nopeless](https://github.com/nopeless)), for all your wor #### switch from browserify to webpack ([#1140](https://github.com/jimp-dev/jimp/pull/1140)) -This PR can be considered a breaking change as it remove the `jimp.min.js` file. +This PR can be considered a breaking change as it remove the `jimp.min.js` file. Instead there is now only the `jimp.js` file and we ship source maps for it. diff --git a/packages/plugin-resize/CHANGELOG.md b/packages/plugin-resize/CHANGELOG.md index 2ea341b58..51ce935d0 100644 --- a/packages/plugin-resize/CHANGELOG.md +++ b/packages/plugin-resize/CHANGELOG.md @@ -16,7 +16,7 @@ #### Babel Refactor ([#1149](https://github.com/jimp-dev/jimp/pull/1149)) -Marking this as a "breaking release" because it might change what deps need to be installed. +Marking this as a "breaking release" because it might change what deps need to be installed. All modules should be exported as valid cjs and esm