|
1 | 1 | #!/usr/bin/env node |
2 | | -"use strict"; |
3 | | -Object.defineProperty(exports, "__esModule", { value: true }); |
4 | | -const yargs = require("yargs"); |
5 | | -const os = require("os"); |
6 | | -const processImage_1 = require("./utils/processImage"); |
7 | | -const processPath_1 = require("./utils/processPath"); |
| 2 | +'use strict'; |
| 3 | +Object.defineProperty(exports, '__esModule', { value: true }); |
| 4 | +const yargs = require('yargs'); |
| 5 | +const os = require('os'); |
| 6 | +const processImage_1 = require('./utils/processImage'); |
| 7 | +const processPath_1 = require('./utils/processPath'); |
8 | 8 | // Parse command line arguments |
9 | 9 | const options = yargs |
10 | | - .option("f", { |
11 | | - alias: "filename", |
12 | | - describe: "Input image filename", |
13 | | - type: "string", |
14 | | - }) |
15 | | - .option("i", { |
16 | | - alias: "folderPath", |
17 | | - describe: "Input folder", |
18 | | - type: "string", |
19 | | - }) |
20 | | - .option("w", { |
21 | | - alias: "width", |
22 | | - describe: "Output image width", |
23 | | - type: "number", |
24 | | - demandOption: true, |
25 | | - coerce: (value) => { |
26 | | - if (value < 1) { |
27 | | - throw new Error("width should not be lower than 1"); |
28 | | - } |
29 | | - return Math.round(value); |
30 | | - }, |
31 | | - }) |
32 | | - .option("h", { |
33 | | - alias: "height", |
34 | | - describe: "Output image height", |
35 | | - type: "number", |
36 | | - coerce: (value) => { |
37 | | - if (value !== undefined && value < 1) { |
38 | | - throw new Error("height should not be lower than 1"); |
39 | | - } |
40 | | - return Math.round(value); |
41 | | - }, |
42 | | - }).argv; |
| 10 | + .option('f', { |
| 11 | + alias: 'filename', |
| 12 | + describe: 'Input image filename', |
| 13 | + type: 'string', |
| 14 | + }) |
| 15 | + .option('i', { |
| 16 | + alias: 'folderPath', |
| 17 | + describe: 'Input folder', |
| 18 | + type: 'string', |
| 19 | + }) |
| 20 | + .option('w', { |
| 21 | + alias: 'width', |
| 22 | + describe: 'Output image width', |
| 23 | + type: 'number', |
| 24 | + demandOption: true, |
| 25 | + coerce: (value) => { |
| 26 | + if (value < 1) { |
| 27 | + throw new Error('width should not be lower than 1'); |
| 28 | + } |
| 29 | + return Math.round(value); |
| 30 | + }, |
| 31 | + }) |
| 32 | + .option('h', { |
| 33 | + alias: 'height', |
| 34 | + describe: 'Output image height', |
| 35 | + type: 'number', |
| 36 | + coerce: (value) => { |
| 37 | + if (value !== undefined && value < 1) { |
| 38 | + throw new Error('height should not be lower than 1'); |
| 39 | + } |
| 40 | + return Math.round(value); |
| 41 | + }, |
| 42 | + }).argv; |
43 | 43 | if (options.filename) { |
44 | | - // Process a single image |
45 | | - const { filename, width, height } = options; |
46 | | - (0, processImage_1.sliceImage)(filename, width, height); |
| 44 | + // Process a single image |
| 45 | + const { filename, width, height } = options; |
| 46 | + (0, processImage_1.sliceImage)(filename, width, height); |
47 | 47 | } else if (options.folderPath) { |
48 | | - // Process all images in a folder, splitting the task into threads |
49 | | - let numCores = 2; |
50 | | - try { |
51 | | - numCores = os.cpus().length; |
52 | | - } catch (err) { |
53 | | - console.error(err); |
54 | | - } |
55 | | - numCores = Math.max(numCores - 1, 1); |
56 | | - (0, processPath_1.processPath)(options.folderPath, options, numCores); |
| 48 | + // Process all images in a folder, splitting the task into threads |
| 49 | + let numCores = 2; |
| 50 | + try { |
| 51 | + numCores = os.cpus().length; |
| 52 | + } catch (err) { |
| 53 | + console.error(err); |
| 54 | + } |
| 55 | + numCores = Math.max(numCores - 1, 1); |
| 56 | + (0, processPath_1.processPath)(options.folderPath, options, numCores); |
57 | 57 | } else { |
58 | | - console.log( |
59 | | - "Requires either `filename` or `folderPath`. Run `slice --help` for help.", |
60 | | - ); |
| 58 | + console.log( |
| 59 | + 'Requires either `filename` or `folderPath`. Run `slice --help` for help.', |
| 60 | + ); |
61 | 61 | } |
0 commit comments