Skip to content

Commit

Permalink
Refactor code to use ES6 module syntax and update dependencies; bump …
Browse files Browse the repository at this point in the history
…version to 2.1.0
  • Loading branch information
cpietsch committed Nov 20, 2024
1 parent 3bb8881 commit 1819459
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
9 changes: 6 additions & 3 deletions bin/textures
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

// https://github.com/cpietsch/vikus-viewer-script
// by Christopher Pietsch 2020
const textures = require("../src/textures.js");
import textures from "../src/textures.js";

const argv = require("yargs")
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const argv = yargs(hideBin(process.argv))
.usage('Usage: vikus-viewer-script "/path/to/large/images/*.jpg" [options]')
.command('"/path/to/large/images/*.jpg"', "Glob to input images")
.example(
Expand Down Expand Up @@ -43,5 +46,5 @@ const argv = require("yargs")
const inputPath = argv._[0];

(async function main() {
await textures.run(inputPath, argv);
await textures(inputPath, argv);
})();
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vikus-viewer-script",
"version": "2.0.7",
"version": "2.1.0",
"description": "Preprocessing scripts for vikus-viewer",
"author": {
"name": "Christopher Pietsch",
Expand All @@ -23,13 +23,13 @@
"main": "src/index.js",
"scripts": {},
"engines": {
"node": ">=v16.15.1"
"node": ">=20.3.0"
},
"type": "module",
"dependencies": {
"@mapbox/shelf-pack": "^3.2.0",
"sharpsheet": "^0.0.8",
"glob": "^8.0.3",
"sharp": "^0.30.6",
"yargs": "^17.5.1"
"sharpsheet": "^0.1.2",
"glob": "^11.0.0",
"sharp": "^0.33.5",
"yargs": "^17.7.2"
}
}
16 changes: 9 additions & 7 deletions src/cascade.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sharp = require("sharp");
const path = require("path");
const glob = require("glob");
const fs = require("fs");
import sharp from "sharp";
import path from "path";
import { glob } from 'glob';
import fs from "fs";

exports.run = async function* cascade(input, resizeSteps, options) {
export default async function* cascade(input, resizeSteps, options) {
const skipExisting = options.skipExisting || true;
let files = [];

Expand All @@ -13,14 +13,16 @@ exports.run = async function* cascade(input, resizeSteps, options) {
files = input
}

for (i in files) {
console.log("found ", files);

for (let i in files) {
const file = files[i];
const basename = path.parse(file).name;
const log = [];

try {
let instance = await sharp(file);
for (step of resizeSteps) {
for (let step of resizeSteps) {
instance = instance.resize(step.width, step.height, { fit: "inside" });
const outFilePath = step.path + "/" + basename + "." + step.format

Expand Down
12 changes: 6 additions & 6 deletions src/textures.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require("fs");
const path = require("path");
const cascade = require("./cascade.js");
const sharpsheet = require("sharpsheet");
import fs from "fs";
import path from "path";
import cascade from "./cascade.js";
import sharpsheet from "sharpsheet/src/sharpsheet.js";

exports.run = async function textures(inputPath, options) {
export default async function textures(inputPath, options) {
const skipTextures = options.skipTextures || false;
const textureRes1 = options.largeSize || 4096;
const textureRes2 = options.mediumSize || 1024;
Expand Down Expand Up @@ -51,7 +51,7 @@ exports.run = async function textures(inputPath, options) {

console.log("\nlooking for images at ", inputPath);

const resizer = cascade.run(inputPath, resizeSteps, { skipExisting });
const resizer = cascade(inputPath, resizeSteps, { skipExisting });

let spritesheetFiles = [];
for await (const operation of resizer) {
Expand Down

0 comments on commit 1819459

Please sign in to comment.