Skip to content

Commit 1819459

Browse files
committed
Refactor code to use ES6 module syntax and update dependencies; bump version to 2.1.0
1 parent 3bb8881 commit 1819459

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

bin/textures

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

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

7-
const argv = require("yargs")
7+
import yargs from 'yargs';
8+
import { hideBin } from 'yargs/helpers';
9+
10+
const argv = yargs(hideBin(process.argv))
811
.usage('Usage: vikus-viewer-script "/path/to/large/images/*.jpg" [options]')
912
.command('"/path/to/large/images/*.jpg"', "Glob to input images")
1013
.example(
@@ -43,5 +46,5 @@ const argv = require("yargs")
4346
const inputPath = argv._[0];
4447

4548
(async function main() {
46-
await textures.run(inputPath, argv);
49+
await textures(inputPath, argv);
4750
})();

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vikus-viewer-script",
3-
"version": "2.0.7",
3+
"version": "2.1.0",
44
"description": "Preprocessing scripts for vikus-viewer",
55
"author": {
66
"name": "Christopher Pietsch",
@@ -23,13 +23,13 @@
2323
"main": "src/index.js",
2424
"scripts": {},
2525
"engines": {
26-
"node": ">=v16.15.1"
26+
"node": ">=20.3.0"
2727
},
28+
"type": "module",
2829
"dependencies": {
29-
"@mapbox/shelf-pack": "^3.2.0",
30-
"sharpsheet": "^0.0.8",
31-
"glob": "^8.0.3",
32-
"sharp": "^0.30.6",
33-
"yargs": "^17.5.1"
30+
"sharpsheet": "^0.1.2",
31+
"glob": "^11.0.0",
32+
"sharp": "^0.33.5",
33+
"yargs": "^17.7.2"
3434
}
3535
}

src/cascade.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const sharp = require("sharp");
2-
const path = require("path");
3-
const glob = require("glob");
4-
const fs = require("fs");
1+
import sharp from "sharp";
2+
import path from "path";
3+
import { glob } from 'glob';
4+
import fs from "fs";
55

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

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

16-
for (i in files) {
16+
console.log("found ", files);
17+
18+
for (let i in files) {
1719
const file = files[i];
1820
const basename = path.parse(file).name;
1921
const log = [];
2022

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

src/textures.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const fs = require("fs");
2-
const path = require("path");
3-
const cascade = require("./cascade.js");
4-
const sharpsheet = require("sharpsheet");
1+
import fs from "fs";
2+
import path from "path";
3+
import cascade from "./cascade.js";
4+
import sharpsheet from "sharpsheet/src/sharpsheet.js";
55

6-
exports.run = async function textures(inputPath, options) {
6+
export default async function textures(inputPath, options) {
77
const skipTextures = options.skipTextures || false;
88
const textureRes1 = options.largeSize || 4096;
99
const textureRes2 = options.mediumSize || 1024;
@@ -51,7 +51,7 @@ exports.run = async function textures(inputPath, options) {
5151

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

54-
const resizer = cascade.run(inputPath, resizeSteps, { skipExisting });
54+
const resizer = cascade(inputPath, resizeSteps, { skipExisting });
5555

5656
let spritesheetFiles = [];
5757
for await (const operation of resizer) {

0 commit comments

Comments
 (0)