@massimo-cassandro/minimo 1.8.4 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dev-tools/README.md +31 -0
- package/dev-tools/create-favicons/README.md +101 -0
- package/dev-tools/create-favicons/index.mjs +70 -0
- package/dev-tools/create-favicons/src/create-favicons.mjs +37 -0
- package/dev-tools/create-favicons/src/create-ico.OLD.mjs +32 -0
- package/dev-tools/create-favicons/src/create-ico.mjs +18 -0
- package/dev-tools/create-favicons/src/create-png.mjs +21 -0
- package/dev-tools/create-favicons/src/create-snippet.mjs +64 -0
- package/dev-tools/create-favicons/src/create-svg.mjs +15 -0
- package/dev-tools/create-favicons/src/create-webmanifest.mjs +64 -0
- package/dev-tools/create-favicons/src/default-params.mjs +91 -0
- package/dev-tools/create-favicons/src/init.mjs +52 -0
- package/dev-tools/create-favicons/src/parse-params.mjs +61 -0
- package/dev-tools/create-favicons/src/print-frame.mjs +56 -0
- package/dev-tools/create-favicons/src/print-result.mjs +60 -0
- package/dev-tools/create-favicons/src/remove-homedir-string.mjs +9 -0
- package/dev-tools/svg-icons-tools/README.md +75 -0
- package/dev-tools/svg-icons-tools/index.mjs +51 -0
- package/dev-tools/svg-icons-tools/src/config-manager.mjs +23 -0
- package/dev-tools/svg-icons-tools/src/create-dest-folder.mjs +20 -0
- package/dev-tools/svg-icons-tools/src/default-config.mjs +343 -0
- package/dev-tools/svg-icons-tools/src/homedir-path-to-tilde.mjs +9 -0
- package/dev-tools/svg-icons-tools/src/init.mjs +38 -0
- package/dev-tools/svg-icons-tools/src/jsx-icon-file-builder.mjs +62 -0
- package/dev-tools/svg-icons-tools/src/parse-svg-filename.mjs +19 -0
- package/dev-tools/svg-icons-tools/src/parse-svg-files.mjs +82 -0
- package/dev-tools/svg-icons-tools/src/parse-svg-markup.mjs +75 -0
- package/dev-tools/svg-icons-tools/src/print-result.mjs +26 -0
- package/dev-tools/svg-icons-tools/src/start.mjs +23 -0
- package/dev-tools/svg-icons-tools/src/svg-to-jsx.mjs +82 -0
- package/dev-tools/svg-icons-tools/src/svg-to-optimized.mjs +44 -0
- package/dev-tools/svg-icons-tools/src/svg-to-scss.mjs +72 -0
- package/dev-tools/svg-icons-tools/src/svg-to-symbols.mjs +70 -0
- package/dev-tools/svg-icons-tools/src/symbols-demo-tpl.html +110 -0
- package/dev-tools/upd@m/README.md +9 -0
- package/dev-tools/upd@m/index.mjs +72 -0
- package/dev-tools/update-version/README.md +19 -0
- package/dev-tools/update-version/convert-changelog.mjs +67 -0
- package/dev-tools/update-version/index.mjs +110 -0
- package/dev-tools/update-version/src/chooser-inquirer.mjs +43 -0
- package/dev-tools/update-version/src/create-log-row.mjs +25 -0
- package/dev-tools/update-version/src/get-cli-params.mjs +28 -0
- package/dev-tools/update-version/src/params.mjs +26 -0
- package/dev-tools/update-version/src/update-log-file.mjs +17 -0
- package/dev-tools/update-version/src/update-packageJson.mjs +10 -0
- package/dev-tools/update-version/src/update-semver.mjs +29 -0
- package/package.json +25 -7
- package/src/components/unsplash-page/fetch-unsplash-data.js +2 -2
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
// https://nodejs.org/api/util.html#utilstyletextformat-text-options
|
|
4
|
+
import { styleText } from 'node:util';
|
|
5
|
+
|
|
6
|
+
export function log(color, string, mode='log') {
|
|
7
|
+
console[mode]( styleText(color, string) );
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function printFrame(options) {
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
stringsArray = [
|
|
14
|
+
{string: '__string__', color: 'green', bg: false, bold: false, underline: false},
|
|
15
|
+
{...}
|
|
16
|
+
]
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const defaults = {
|
|
20
|
+
strings: [],
|
|
21
|
+
frameColor: 'green',
|
|
22
|
+
frametype: 'single'
|
|
23
|
+
},
|
|
24
|
+
string_defaults = { string: '', color: 'green', bg: false, bold: false, underline: false},
|
|
25
|
+
frame_lines = {
|
|
26
|
+
single: ['┌', '┐', '└', '┘', '┈', '│'],
|
|
27
|
+
double: ['╔', '╗', '╚', '╝', '═', '║']
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
options = {...defaults, ...options};
|
|
31
|
+
|
|
32
|
+
const frames_elements = frame_lines[options.frametype];
|
|
33
|
+
|
|
34
|
+
options.strings = options.strings.map(item => {return {...string_defaults, ...item }; });
|
|
35
|
+
|
|
36
|
+
// aggiunta spazi sulle righe `bg`
|
|
37
|
+
options.strings.forEach(item => {
|
|
38
|
+
if(/^bg/.test(item.color)) {
|
|
39
|
+
item.string = ` ${item.string} `;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const total_length = Math.max( ...(options.strings.map(item => item.string.length)) ) + 2;
|
|
44
|
+
|
|
45
|
+
log( options.frameColor, `\n${frames_elements[0]}` + frames_elements[4].repeat(total_length) + frames_elements[1] );
|
|
46
|
+
|
|
47
|
+
options.strings.forEach(item => {
|
|
48
|
+
console.log(
|
|
49
|
+
styleText(options.frameColor, `${frames_elements[5]} `) +
|
|
50
|
+
styleText(item.color, item.string) + ' '.repeat(total_length - item.string.length - 2) +
|
|
51
|
+
styleText(options.frameColor, ` ${frames_elements[5]}`)
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
log(options.frameColor, frames_elements[2] + frames_elements[4].repeat(total_length) + `${frames_elements[3]}\n` );
|
|
56
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { printFrame } from './print-frame.mjs';
|
|
2
|
+
import { remove_homedir_string } from './remove-homedir-string.mjs';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function printResult(params) {
|
|
7
|
+
|
|
8
|
+
function printSize(size) {
|
|
9
|
+
if(size > 1024) {
|
|
10
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
11
|
+
} else {
|
|
12
|
+
return `${size} B`;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// print result
|
|
18
|
+
let extra_strings = [];
|
|
19
|
+
|
|
20
|
+
// immagini generate e dimensioni
|
|
21
|
+
[
|
|
22
|
+
'apple-touch-icon.png',
|
|
23
|
+
'favicon.ico',
|
|
24
|
+
'favicon.svg',
|
|
25
|
+
'icon-192.png',
|
|
26
|
+
'icon-512.png',
|
|
27
|
+
params.manifest_file_name
|
|
28
|
+
].forEach(item => {
|
|
29
|
+
const stats = fs.statSync(`${params.output_dir}/${item}`);
|
|
30
|
+
extra_strings.push({string: `${item}: ${printSize(stats.size)}`, color: 'greenBright'});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if(params.snippet_path !== params.output_dir && params.snippet_name !== null) {
|
|
34
|
+
extra_strings.push(
|
|
35
|
+
{string: ''},
|
|
36
|
+
{string: `Il file snippet '${params.snippet_name}' è stato salvato nella directory:`, color: 'green'},
|
|
37
|
+
{string: remove_homedir_string(params.snippet_path ), color: 'yellow'},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
} else if(params.snippet_name === null) {
|
|
41
|
+
extra_strings.push(
|
|
42
|
+
{string: ''},
|
|
43
|
+
{string: 'Il file snippet non è stato generato', color: 'magentaBright'},
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
printFrame({
|
|
49
|
+
strings: [
|
|
50
|
+
{string: '** Creazione favicons completata **', color: 'bgGreen'},
|
|
51
|
+
{string: ''},
|
|
52
|
+
{string: 'I file generati sono nella directory:', color: 'green'},
|
|
53
|
+
{string: remove_homedir_string(params.output_dir), color: 'yellow'},
|
|
54
|
+
{string: ''},
|
|
55
|
+
...extra_strings
|
|
56
|
+
],
|
|
57
|
+
frameColor: 'green',
|
|
58
|
+
frameType: 'single'
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Svg Icons Tools
|
|
2
|
+
|
|
3
|
+
Svg Icons Tools provides some utilities for manage and optimize SVG icons:
|
|
4
|
+
|
|
5
|
+
* optimize all files with [SVGO](https://svgo.dev/)
|
|
6
|
+
* combine svg files into a single file, where each icon is wrapped within a `<symbol>` element (inspired from [svgstore](https://github.com/svgstore/svgstore))
|
|
7
|
+
* convert svg files to JSX
|
|
8
|
+
* copy optimized svg files to target directory
|
|
9
|
+
* removes *pallets* from the icon markups (see config file for more details).
|
|
10
|
+
* create a scss file with svg icons converted to sass variables
|
|
11
|
+
* jsx and optimized icons only: ability to manage both icons with `fill` and `stroke` adding optional classes to apply different css properties
|
|
12
|
+
|
|
13
|
+
These tools are pretty useless if you download your icons from one of the libraries you can find on the web, but if you design them yourself, *svg-icons-tools* can save you a lot of time in cleaning up and optimizing icons drawn with Illustrator, Figma, Sketch etc.
|
|
14
|
+
|
|
15
|
+
Also, most (or all) libraries only allow you to download icons with a fixed thickness, but you can often download "working" versions where thickness is defined by the stroke attribute. In these cases there is often a *pallet* that you can easily remove.
|
|
16
|
+
|
|
17
|
+
Read more in my [Building an Icon System in React](https://medium.com/better-programming/building-an-icon-system-in-react-16757d73cc35) article.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i -D @massimo-cassandro/svg-icons-tools
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
First, create a config file for you project, you can run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx iconsTools init
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This creates a `svg-icons-tools` directory which contains the `svg-icons-tools.config.mjs` configuration file.
|
|
34
|
+
|
|
35
|
+
Rename the folder as you like and move it where you need. Then open and customize the `svg-icons-tools.config.mjs` file.
|
|
36
|
+
|
|
37
|
+
## Run
|
|
38
|
+
|
|
39
|
+
To launch the script, open your terminal and use the command:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx iconsTools --config ./path/to/svg-icons-tools.config.mjs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
where `--config` must contain the path, relative to the current dir, to the config file.
|
|
46
|
+
|
|
47
|
+
If the `--config` parameter is not set, the script will look for the configuration file in the current directory; if the file is not found, an error will be thrown.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Configuration details
|
|
51
|
+
|
|
52
|
+
See [src/default-config.mjs](src/default-config.mjs) for more info.
|
|
53
|
+
|
|
54
|
+
## Demo
|
|
55
|
+
|
|
56
|
+
See [demo/readme](demo/readme.md).
|
|
57
|
+
|
|
58
|
+
## TODO
|
|
59
|
+
* documentation to jsdoc
|
|
60
|
+
* prettify the jsx output (update docs)
|
|
61
|
+
* SVG attributes to jsx (upd doc)
|
|
62
|
+
* option to clean-up dest folder for jsx and optimized (?)
|
|
63
|
+
* auto changelog
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## Changelog / Breaking Changes
|
|
67
|
+
|
|
68
|
+
### 1.1
|
|
69
|
+
* added default jsx icon builder function
|
|
70
|
+
|
|
71
|
+
#### Breaking Changes
|
|
72
|
+
* in config file, `config.jsx.icon_builder` becomes `config.jsx.custom_icon_builder`, if not defined the default icon builder is used for jsx files.
|
|
73
|
+
|
|
74
|
+
### 1.0
|
|
75
|
+
* First production release
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as process from 'process';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
|
|
6
|
+
import { init } from './src/init.mjs';
|
|
7
|
+
import { homedir_path_to_tilde } from './src/homedir-path-to-tilde.mjs';
|
|
8
|
+
// import default_config from './src/default-config.mjs';
|
|
9
|
+
import { configManager } from './src/config-manager.mjs';
|
|
10
|
+
import { start } from './src/start.mjs';
|
|
11
|
+
import { printResult } from './src/print-result.mjs';
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
|
|
15
|
+
// init: creazione file cfg base
|
|
16
|
+
if(process.argv.indexOf('init') !== -1) {
|
|
17
|
+
|
|
18
|
+
init(process.cwd());
|
|
19
|
+
|
|
20
|
+
} else {
|
|
21
|
+
|
|
22
|
+
let config_file = './svg-icons-tools.config.mjs';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if(process.argv.indexOf('--config') !== -1) {
|
|
26
|
+
config_file = path.resolve(process.cwd(), process.argv[process.argv.indexOf('--config') + 1].trim());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(!config_file) {
|
|
30
|
+
throw new Error('Missing config file path');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
config_file = new URL(config_file, import.meta.url).pathname;
|
|
34
|
+
const work_dir = path.dirname(config_file);
|
|
35
|
+
|
|
36
|
+
if(!fs.existsSync(config_file)) {
|
|
37
|
+
throw new Error(`Config file not found: ${homedir_path_to_tilde(config_file)}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
import(config_file).then((custom_cfg) => {
|
|
41
|
+
|
|
42
|
+
configManager.updCfg({ ...custom_cfg.default, work_dir: work_dir});
|
|
43
|
+
|
|
44
|
+
start();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} catch(err) {
|
|
50
|
+
printResult(err, 'error');
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import default_config from './default-config.mjs';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const configManager = {
|
|
5
|
+
|
|
6
|
+
cfgObj: default_config,
|
|
7
|
+
|
|
8
|
+
updCfg: function(cfg) {
|
|
9
|
+
this.cfgObj = { ...this.cfgObj, ...cfg };
|
|
10
|
+
|
|
11
|
+
// deep merge of cfg objects
|
|
12
|
+
Object.keys(default_config).forEach((key) => {
|
|
13
|
+
if (default_config[key] && typeof default_config[key] === 'object' && !Array.isArray(default_config[key])) {
|
|
14
|
+
this.cfgObj[key] = { ...default_config[key], ...this.cfgObj[key] };
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
getCfg: function() {
|
|
20
|
+
return this.cfgObj;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { printResult } from './print-result.mjs';
|
|
2
|
+
import { rm, mkdir } from 'fs/promises';
|
|
3
|
+
|
|
4
|
+
export async function create_dest_folder(folder_path, removeIfExists = true) {
|
|
5
|
+
try {
|
|
6
|
+
if (removeIfExists) {
|
|
7
|
+
// Rimuovi la cartella se esiste
|
|
8
|
+
await rm(folder_path, { recursive: true, force: true });
|
|
9
|
+
printResult(`dir ${folder_path} cleared`, 'infoDim');
|
|
10
|
+
}
|
|
11
|
+
// Ricrea la cartella (se già esiste non dà errore grazie a recursive: true)
|
|
12
|
+
await mkdir(folder_path, { recursive: true });
|
|
13
|
+
printResult(`dir ${folder_path} created`, 'infoDim');
|
|
14
|
+
|
|
15
|
+
} catch (err) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.error(err);
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* svg-icons-tools configuration file
|
|
3
|
+
* ----------------------------
|
|
4
|
+
* all paths relative to the work directory
|
|
5
|
+
*
|
|
6
|
+
* More info at https://github.com/massimo-cassandro/svg-icons-tools
|
|
7
|
+
*
|
|
8
|
+
* run with (from the svg-icons-tools work dir): `npx iconsTools`
|
|
9
|
+
* or specifing a path for the config file: `npx iconsTools --config path/to/config.mjs`
|
|
10
|
+
*
|
|
11
|
+
* All paths in this config object are relative to the folder containing the config file
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const config = {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* SVG to JSX components
|
|
19
|
+
*/
|
|
20
|
+
jsx: {
|
|
21
|
+
/**
|
|
22
|
+
* Source folders
|
|
23
|
+
*
|
|
24
|
+
* Every file with svg extension in these folders will be processed
|
|
25
|
+
* Sub dirs are ignored.
|
|
26
|
+
* the `fill` array must contains the icons that use the `fill` attribute
|
|
27
|
+
* similarly, the `stroke` one must contains the icons that use the `stroke` attribute
|
|
28
|
+
* It is possible to manage both types of icons at the same time, otherwise leave
|
|
29
|
+
* them empty or remove the ones you don't need.
|
|
30
|
+
* If you don't need this feature, just remove the whole `jsx` object
|
|
31
|
+
*/
|
|
32
|
+
source_folders: {
|
|
33
|
+
fill: [],
|
|
34
|
+
stroke: []
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Custom function to create each JSX icon file
|
|
39
|
+
*
|
|
40
|
+
* If not defined, the default function will be used.
|
|
41
|
+
* See `src/jsx-icon-file-builder.mjs` for more details about function argument and values to be returned
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* custom_icon_builder: (parsed_svg) => { ... your code ... }
|
|
45
|
+
*/
|
|
46
|
+
custom_icon_builder: null,
|
|
47
|
+
|
|
48
|
+
/* path to the folder where the jsx components will be saved */
|
|
49
|
+
dest_folder: '',
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Clear dest_folder folder before save new files
|
|
53
|
+
*/
|
|
54
|
+
clearDestFolder: false,
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* path to jsx icons index file
|
|
59
|
+
*
|
|
60
|
+
* Optional file that contains all generated icons as named exports.
|
|
61
|
+
* Leave empty o remove if you don't need it
|
|
62
|
+
*/
|
|
63
|
+
index_file: '',
|
|
64
|
+
|
|
65
|
+
/** if not null, overrides the global `svgo_config` */
|
|
66
|
+
svgo_config: null
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* svg file to be optimized
|
|
71
|
+
*/
|
|
72
|
+
optimize: {
|
|
73
|
+
/**
|
|
74
|
+
* Source folders
|
|
75
|
+
*
|
|
76
|
+
* See comment at `jsx` for more details
|
|
77
|
+
* Leave empty or remove the whole `optimize` obj if you don't need this feature
|
|
78
|
+
*/
|
|
79
|
+
source_folders: {
|
|
80
|
+
fill: [],
|
|
81
|
+
stroke: []
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/* path to the folder where the optimized files will be saved */
|
|
85
|
+
dest_folder: '',
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Clear dest_folder folder before save new files
|
|
89
|
+
*/
|
|
90
|
+
clearDestFolder: false,
|
|
91
|
+
|
|
92
|
+
/** if not null, overrides the global `svgo_config` */
|
|
93
|
+
svgo_config: null
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* SVG as symbols
|
|
98
|
+
*
|
|
99
|
+
* Parameters to combine many svg files into a single svg file with symbols
|
|
100
|
+
* If you don't need this feature, just remove the `symbols` object or leave paths empty
|
|
101
|
+
*/
|
|
102
|
+
symbols: {
|
|
103
|
+
/**
|
|
104
|
+
* Source folders
|
|
105
|
+
*
|
|
106
|
+
* Every file with svg extension in these folders will be processed
|
|
107
|
+
* Sub dirs are ignored.
|
|
108
|
+
* Leave empty or remove the whole `symbols` obj if you don't need this feature
|
|
109
|
+
*
|
|
110
|
+
* NB: stroke and fill icons are handled by adding some classes to the `symbol` tag.
|
|
111
|
+
* The same goes for non-square icons.
|
|
112
|
+
* Adding classes to the `symbol` tag is useful for styling icons with css,
|
|
113
|
+
* but it is not a well documented feature and may not work as expected in all browsers.
|
|
114
|
+
* Be aware of this if you plan to use this feature.
|
|
115
|
+
*/
|
|
116
|
+
source_folders: {
|
|
117
|
+
fill: [],
|
|
118
|
+
stroke: []
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/* path of the processed svg file */
|
|
122
|
+
dest_file: '',
|
|
123
|
+
|
|
124
|
+
/* if true, the xml declaration (`<?xml version...`) is added to the resulting file */
|
|
125
|
+
add_xml_declaration: true,
|
|
126
|
+
|
|
127
|
+
/* if true, the svg doctype (`<!DOCTYPE svg PUBLIC...`) is added to the resulting file */
|
|
128
|
+
add_svg_doctype: false,
|
|
129
|
+
|
|
130
|
+
/* if true, the `hidden` attribute is added to the svg tag of the resulting file */
|
|
131
|
+
add_hidden_attribute: true,
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* optional path to the js file that will contain the list of icons converted as symbols.
|
|
135
|
+
*
|
|
136
|
+
* Leave empty if you don't need it
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* icons_list_file: './path/to/icons-list.js',
|
|
140
|
+
*/
|
|
141
|
+
icons_list_file: '',
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* optional template for building the icons demo file
|
|
145
|
+
*
|
|
146
|
+
* A basic tpl file is provided when the script is launched with `init` option:
|
|
147
|
+
* you can customize it as you like.
|
|
148
|
+
* If you don't need this feature, remove the tpl file and leave empty or remove
|
|
149
|
+
* the `demo_tpl_path` parameter
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* demo_tpl_path: './path/to/symbols-demo-tpl.html',
|
|
153
|
+
*/
|
|
154
|
+
demo_tpl_path: '',
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* optional path for generated demo file
|
|
158
|
+
*
|
|
159
|
+
* It includes the list of icons converted as symbols and the symbols file itself,
|
|
160
|
+
* so it can be viewed in a browser using the `file:///` protocol.
|
|
161
|
+
* Requires the `demo_tpl_path` parameter to be set.
|
|
162
|
+
* Leave this parameter empty if you don't need it
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* demo_file_path: './symbols-demo.html',
|
|
166
|
+
*/
|
|
167
|
+
demo_file_path: '',
|
|
168
|
+
|
|
169
|
+
/** if not null, overrides the global `svgo_config` */
|
|
170
|
+
svgo_config: null
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* GLOBAL PARAMETERS
|
|
176
|
+
*
|
|
177
|
+
* These parameters are used in all the features
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
/*
|
|
181
|
+
* prefixes of the svg files names to be removed in `symbols` ids and in jsx and
|
|
182
|
+
* optimized files names
|
|
183
|
+
*/
|
|
184
|
+
remove_prefix: [],
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* SVGO configuration
|
|
188
|
+
*
|
|
189
|
+
* see https://svgo.dev/docs/plugins/
|
|
190
|
+
*/
|
|
191
|
+
svgo_config: {
|
|
192
|
+
multipass: true,
|
|
193
|
+
plugins: [
|
|
194
|
+
{ name: 'cleanupIds', params: { remove: true, minify: true } }
|
|
195
|
+
, 'removeDoctype'
|
|
196
|
+
, 'removeComments'
|
|
197
|
+
, 'removeTitle'
|
|
198
|
+
, 'removeDimensions'
|
|
199
|
+
, 'collapseGroups'
|
|
200
|
+
, { name: 'cleanupNumericValues', params: { floatPrecision: 4 } }
|
|
201
|
+
, { name: 'convertColors', params: { names2hex: true, rgb2hex: true } }
|
|
202
|
+
, 'removeStyleElement'
|
|
203
|
+
, 'removeEmptyContainers'
|
|
204
|
+
// , { name: 'removeAttrs', params: { attrs: ['(fill|stroke|class|style|data.*)', 'svg:(width|height)'] } }
|
|
205
|
+
// , { name: 'removeAttrs', params: { attrs: ['(filter|fill|stroke|class|style|data.*)', 'svg:(width|height)'] } }
|
|
206
|
+
, { name: 'removeAttrs', params: { attrs: ['(filter|fill|stroke|fill-rule|clip-rule|stroke-linecap|stroke-linejoin|stroke-width|transform|style|class|data.*)', 'svg:(width|height)'] } }
|
|
207
|
+
, 'removeUselessDefs'
|
|
208
|
+
//, { name: 'addAttributesToSVGElement0, params: {attribute: "#{$attr}"}}
|
|
209
|
+
// , { name: 'addClassesToSVGElement', params: { className: 'line-icon' } }
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* “pallet” markups to be removed from the svg files
|
|
215
|
+
*
|
|
216
|
+
* As clearly explained on the [remixicon site](https://remixicon.com/),
|
|
217
|
+
* the "pallet" is a transparent rectangle that ensures that the SVGs maintain
|
|
218
|
+
* their dimensions in your design software. They are not necessary in the final SVGs,
|
|
219
|
+
* and can even produce unwanted effects, so they are removed.
|
|
220
|
+
* Each item is a regular expression.
|
|
221
|
+
*/
|
|
222
|
+
pallets: [
|
|
223
|
+
/<rect width="256" height="256" fill="none" ?\/?>(<\/rect>)?/gmi, // phosphoricons raw
|
|
224
|
+
/<path fill="none" d="(M0 0h24v24H0z|M0 0h256v256H0z)" ?\/?>(<\/path>)?/gmi, // remixicons with 'pallets' option (and others)
|
|
225
|
+
],
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Opacity classes for duotone icons
|
|
229
|
+
*
|
|
230
|
+
* Convert opacity values to predefined classes
|
|
231
|
+
* the key is the decimal part of the opacity value (e.g.: 2 == 0.2), the value
|
|
232
|
+
* is the class to be added in place of the opacity value.
|
|
233
|
+
* The purpose of this feature is to convert the opacity values of duotone icons
|
|
234
|
+
* to predefined classes, merging similar values to an unique class:
|
|
235
|
+
* the script will assign the class whose key is the closest to the opacity value.
|
|
236
|
+
* For example, both 0.2 and 0.26 opacity values are converted
|
|
237
|
+
* to the class `duotone-light` (whose key is 2). You then only need to set the classes in your css.
|
|
238
|
+
* NB: only opacity attributes applied to elements inside the svg tag will be considered.
|
|
239
|
+
* If you don't want to use this feature, remove the `opacity_classes` object or leave it empty
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* opacity_classes: {
|
|
243
|
+
* 2: 'duotone-light',
|
|
244
|
+
* 4: 'duotone-medium',
|
|
245
|
+
* 6: 'duotone-dark',
|
|
246
|
+
* },
|
|
247
|
+
*/
|
|
248
|
+
opacity_classes: {},
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Icon type classes
|
|
252
|
+
*
|
|
253
|
+
* Optional classes to be added to fill and or stroke icons
|
|
254
|
+
* leave empty or remove if you don't need them
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* icon_type_class: {
|
|
258
|
+
* fill: 'fill-icons',
|
|
259
|
+
* stroke: 'stroke-icons',
|
|
260
|
+
* },
|
|
261
|
+
*/
|
|
262
|
+
icon_type_class: {
|
|
263
|
+
fill: '',
|
|
264
|
+
stroke: ''
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Non-square icons classes
|
|
269
|
+
*
|
|
270
|
+
* Assign specific classes to non-square icons.
|
|
271
|
+
* Assuming that all icons have the viewBox attribute, and that all viewboxes
|
|
272
|
+
* origin is at 0 0, the script analizes all icons widths and heights
|
|
273
|
+
* and detect those with non-square aspect ratio.
|
|
274
|
+
* Then, the values are compared (after being rounded to two decimal places)
|
|
275
|
+
* to find the closest aspect ratio among
|
|
276
|
+
* those listed in the `non_square_icons_classes` array. The class corresponding
|
|
277
|
+
* to the found value is then assigned to the icon.
|
|
278
|
+
* The first value of each subarray of `non_square_icons_classes` is the aspect ratio
|
|
279
|
+
* (width / height), the second is the class to be assigned.
|
|
280
|
+
* If you don't want to use this feature, remove the `non_square_icons_classes`
|
|
281
|
+
* array or leave it empty
|
|
282
|
+
*
|
|
283
|
+
* NB: Although aspect-ratio classes are added to `symbol` tags, this functionality
|
|
284
|
+
* is not supported in SVGs with that element type.
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* non_square_icons_classes: [
|
|
288
|
+
* [ 3/4, 'ratio-3x4'],
|
|
289
|
+
* [ 3/5, 'ratio-3x5'],
|
|
290
|
+
* [ 2/3, 'ratio-2x3'],
|
|
291
|
+
* ],
|
|
292
|
+
*/
|
|
293
|
+
non_square_icons_classes: [],
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Console colors
|
|
298
|
+
*
|
|
299
|
+
* Colors for console output as defined in <https://nodejs.org/api/util.html#customizing-utilinspect-colors>
|
|
300
|
+
* The default colors work well on dark background terminals, if you have a light background terminal, you may
|
|
301
|
+
* need to change the colors.
|
|
302
|
+
*/
|
|
303
|
+
console_colors: {
|
|
304
|
+
error : 'bgRed',
|
|
305
|
+
warning : 'red',
|
|
306
|
+
success : 'bgGreen',
|
|
307
|
+
info : 'yellow',
|
|
308
|
+
infoDim : ['yellow', 'dim'],
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* LEGACY
|
|
314
|
+
* Features mantained for compatibility reasons
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Svg to scss variables
|
|
319
|
+
* Generate scss variables from specified svg icons
|
|
320
|
+
*/
|
|
321
|
+
svg_to_scss: {
|
|
322
|
+
/* icons to be converted to scss variables.
|
|
323
|
+
* Paths of the svg files to be processed (relative to config file).
|
|
324
|
+
* Icons will be parsed and optimized then converted to scss variables.
|
|
325
|
+
* The variable names will be the same as the file names, without extensions
|
|
326
|
+
* and parts removed as per the `remove_prefix` parameter.
|
|
327
|
+
*/
|
|
328
|
+
files: [],
|
|
329
|
+
|
|
330
|
+
/* string to be prefixed to the variable names */
|
|
331
|
+
varname_prefix: 'icon-',
|
|
332
|
+
|
|
333
|
+
/* if true, the svg files are converted to data urls */
|
|
334
|
+
convert_to_css_url: true,
|
|
335
|
+
|
|
336
|
+
/* path of the generated scss file */
|
|
337
|
+
scss_icons_file: '_icons-svg.scss',
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
export default config;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
// import process from 'process';
|
|
5
|
+
|
|
6
|
+
import { printResult } from './print-result.mjs';
|
|
7
|
+
import { homedir_path_to_tilde } from './homedir-path-to-tilde.mjs';
|
|
8
|
+
|
|
9
|
+
export function init(work_dir) {
|
|
10
|
+
|
|
11
|
+
const source_dir = new URL('.', import.meta.url).pathname;
|
|
12
|
+
|
|
13
|
+
// create dest dir
|
|
14
|
+
const dest = path.join(work_dir, 'svg-icons-tools');
|
|
15
|
+
if(fs.existsSync(dest)) {
|
|
16
|
+
throw `${homedir_path_to_tilde(dest)} already exists`;
|
|
17
|
+
}
|
|
18
|
+
fs.mkdirSync(dest);
|
|
19
|
+
|
|
20
|
+
// copy cfg file
|
|
21
|
+
const cfg_file = path.join(dest, '/svg-icons-tools.config.mjs');
|
|
22
|
+
|
|
23
|
+
fs.copyFileSync(
|
|
24
|
+
path.join(source_dir, '/default-config.mjs'),
|
|
25
|
+
cfg_file
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// copy tpl file
|
|
29
|
+
const target_demo_file = path.join(dest, 'symbols-demo-tpl.html');
|
|
30
|
+
fs.copyFileSync(
|
|
31
|
+
path.join(source_dir, 'symbols-demo-tpl.html'),
|
|
32
|
+
target_demo_file
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
printResult('SVG-ICONS-TOOLS', 'success');
|
|
36
|
+
printResult('Created config file: ' + homedir_path_to_tilde(cfg_file));
|
|
37
|
+
printResult('Created symbols demo file: ' + homedir_path_to_tilde(target_demo_file) + '\n\n');
|
|
38
|
+
}
|