asset-resizer
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -5,3 +5,3 @@ import * as fs from "fs"; | ||
import chalk from "chalk"; | ||
const PROJ_ROOT = path.resolve("./"); | ||
const PROJ_ROOT = path.resolve("."); | ||
const PROJ_CFG_FILENAME = "assetresizer.config"; | ||
@@ -22,6 +22,2 @@ const PROJ_CFG_FILE = path.join(PROJ_ROOT, PROJ_CFG_FILENAME); | ||
export async function loadConfig(file) { | ||
async function importConfigFromFile(filepath) { | ||
const cfg = await dynamicImport(`file://${filepath}`); | ||
return cfg.default; | ||
} | ||
if (!file) { | ||
@@ -42,8 +38,15 @@ for (const ext of [".js", ".mjs", ".cjs"]) { | ||
log.msg(`Loading config from ${chalk.cyan(file)}...`); | ||
const filePath = path.join(PROJ_ROOT, file); | ||
if (!fs.existsSync(filePath)) { | ||
// Make absolute if relative. | ||
if (!file.match(/^(?:\/|[a-z]:[/\\])/i)) { | ||
file = path.join(PROJ_ROOT, file); | ||
} | ||
if (!fs.existsSync(file)) { | ||
log.err("Config not found."); | ||
return null; | ||
} | ||
const cfg = await importConfigFromFile(filePath); | ||
// Windows fix for file:// protocol. | ||
if (file.match(/^[a-z]:[/\\]/i)) { | ||
file = `/${file.replace(/\\/g, "/")}`; | ||
} | ||
const { default: cfg } = await dynamicImport(`file://${file}`); | ||
if (!validateConfig(cfg)) { | ||
@@ -50,0 +53,0 @@ return null; |
@@ -5,3 +5,3 @@ { | ||
"description": "Resize assets as part of build workflow.", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/main.js", | ||
@@ -8,0 +8,0 @@ "type": "module", |
# asset-resizer | ||
<!-- ![build](https://img.shields.io/github/actions/workflow/status/reiniiriarios/asset-resizer/publish?branch=main) --> | ||
![downloads](https://img.shields.io/npm/dt/asset-resizer) | ||
![types: Typescript](https://img.shields.io/badge/types-Typescript-blue) | ||
![license: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blueviolet) | ||
![build](https://img.shields.io/github/actions/workflow/status/reiniiriarios/asset-resizer/publish.yaml) | ||
@@ -19,7 +17,5 @@ A minimal package to easily automate image asset resizing as a part of a build process. Uses [sharp](https://github.com/lovell/sharp). | ||
Then add a config file to your root directory specifying what assets should be resized and where. | ||
The config file may be `assetresizer.config.js`, `assetresizer.config.mjs`, or `assetresizer.config.cjs`. | ||
Alternatively, you may specify a custom config file. | ||
Then add `assetresizer.config.js` to your root directory, specifying what assets should be resized and where. Alternatively, you may specify a custom config file. | ||
[See example config.](examples/assetresizer.config.mjs) | ||
[See example config.](examples/assetresizer.config.js) | ||
@@ -26,0 +22,0 @@ ```js |
Sorry, the diff of this file is not supported yet
75776
338
149