Skip to content

Commit

Permalink
1.3.0 - Sostituito to-ico con sharp.ico. Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
massimo-cassandro committed Mar 2, 2024
1 parent f5ac381 commit 15d4a3b
Show file tree
Hide file tree
Showing 18 changed files with 819 additions and 1,504 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
2023-09-17T15:14:01.301Z | 1.0.12 | favicon: new `snippet_target_file` parameter
2024-02-28T16:57:28.850Z | 1.1.0 | Prima release as standalone package (from dev_utilities)
2024-02-29T16:00:00.800Z | 1.2.0 | Rimozione imagemin
2024-03-02T13:41:19.527Z | 1.3.0 | Sostituito `to-ico` con `sharp.ico`. Refactoring
37 changes: 19 additions & 18 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import * as path from 'path';

import chalk from 'chalk';

import { parseParams } from './src/parse-params.mjs';
import { default_params } from './src/default-params.mjs';
import { createFavicons } from './src/create-favicons.mjs';
import { defaults } from './src/defaults.mjs';
import { init } from './src/init.mjs';

// nome del file di configurazione, se utilizzato
const cfg_filename = 'create-favicons-cfg.mjs';
const config_filename = 'create-favicons-cfg.mjs';

try {

Expand All @@ -25,39 +26,39 @@ try {

} else {

let params = {};
let work_dir;
const dir_param_idx = process.argv.findIndex(el => /^--dir/.test(el) );

if(dir_param_idx !== -1) {
[, params.work_dir] = process.argv[dir_param_idx].split('=');
[, work_dir] = process.argv[dir_param_idx].split('=');

} else {
params.work_dir = './';
work_dir = './';
}

if(fs.existsSync(path.resolve(params.work_dir, cfg_filename))) {
work_dir = path.resolve(process.cwd(), work_dir) ;

import(path.resolve(params.work_dir, cfg_filename))
.then((custom_params) => {

if(Array.isArray(custom_params.default)) {
if(fs.existsSync(path.resolve(work_dir, config_filename))) {

custom_params.default.forEach(item => {
createFavicons({ ...defaults, ...params, ...item });
});
import(path.resolve(work_dir, config_filename))
.then((config_params) => {

const imported_params = [...(Array.isArray(config_params.default)? config_params.default : [config_params.default])];

imported_params.forEach(params_item => {
createFavicons(parseParams(params_item, work_dir));
});

} else {
createFavicons({ ...defaults, ...params, ...custom_params.default });
}
});

} else if(fs.existsSync(path.resolve(params.work_dir, defaults.src_img))) {
} else if(default_params.src_img && fs.existsSync(path.resolve(work_dir, default_params.src_img))) {

createFavicons({...defaults, ...params});
createFavicons(parseParams(null, work_dir));

} else {

throw `'${cfg_filename}' e '${defaults.src_img}' non presenti`;
throw new Error( `'${config_filename}' e '${defaults.src_img}' non presenti`);
}

}
Expand Down
Loading

0 comments on commit 15d4a3b

Please sign in to comment.