material-icon-generator 0.1.0 → 0.3.0
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/dist/commands.js +78 -0
- package/dist/config.js +25 -0
- package/dist/data/icons.json +1 -0
- package/dist/fsutils.js +8 -0
- package/dist/icon.js +37 -0
- package/dist/main.js +50 -0
- package/dist/templates/SvelteMasterComponent.hbs +32 -0
- package/dist/utils.js +15 -0
- package/package.json +30 -5
package/dist/commands.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { generateMasterComponentOnDisk, icons } from './icon.js';
|
|
2
|
+
import { getSvigConfig, saveSvigConfig, svigConfigPath } from './config.js';
|
|
3
|
+
import { getSvelteComponentPath } from './utils.js';
|
|
4
|
+
export function addIconsCommand(iconNames, props) {
|
|
5
|
+
const { dirpath } = props;
|
|
6
|
+
if (iconNames.length === 0) {
|
|
7
|
+
console.log(`Please provide icons to add!`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const config = getSvigConfig();
|
|
11
|
+
for (const iconName of iconNames) {
|
|
12
|
+
const icon = icons.find(ic => ic.name === iconName);
|
|
13
|
+
if (icon) {
|
|
14
|
+
if (config.icons.includes(iconName)) {
|
|
15
|
+
console.log(`Icon already added: '${iconName}'`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.log(`Icon was added: '${iconName}'`);
|
|
19
|
+
config.icons.push(iconName);
|
|
20
|
+
saveSvigConfig(config);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
console.log(`Icon not found: '${iconName}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
generateMasterComponentOnDisk(config.icons, dirpath);
|
|
28
|
+
}
|
|
29
|
+
export function removeIconsCommand(iconNames, props) {
|
|
30
|
+
const { dirpath } = props;
|
|
31
|
+
if (iconNames.length === 0) {
|
|
32
|
+
console.log(`Please provide icons to remove!`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const config = getSvigConfig();
|
|
36
|
+
if (!config.icons || config.icons.length === 0) {
|
|
37
|
+
console.log(`No icons found in config: '${svigConfigPath}'`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const iconName of iconNames) {
|
|
41
|
+
if (config.icons.includes(iconName)) {
|
|
42
|
+
config.icons = config.icons.filter(ic => ic !== iconName);
|
|
43
|
+
saveSvigConfig(config);
|
|
44
|
+
console.log(`Icon was removed: '${iconName}'`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(`Icon not present in config: '${iconName}'`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
generateMasterComponentOnDisk(config.icons, dirpath);
|
|
51
|
+
}
|
|
52
|
+
export function generateIconsCommand(props, overwrite) {
|
|
53
|
+
const { dirpath } = props;
|
|
54
|
+
const config = getSvigConfig();
|
|
55
|
+
if (config.icons.length === 0) {
|
|
56
|
+
console.log(`No icons found in config: '${svigConfigPath}'`);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
generateMasterComponentOnDisk(config.icons, dirpath);
|
|
60
|
+
}
|
|
61
|
+
export function listIconsCommand(iconArr) {
|
|
62
|
+
for (let i = 0; i < iconArr.length; i++) {
|
|
63
|
+
const icon = iconArr[i];
|
|
64
|
+
console.log(`Icon ${i + 1} => '${icon.name}'`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function generateMasterComponentCommand(props, overwrite) {
|
|
68
|
+
const { dirpath } = props;
|
|
69
|
+
const outputFilePath = getSvelteComponentPath("", dirpath);
|
|
70
|
+
try {
|
|
71
|
+
const config = getSvigConfig();
|
|
72
|
+
generateMasterComponentOnDisk(config.icons, dirpath);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.log(`\tError: ${error}`);
|
|
76
|
+
console.log(`\tCould not generate: '${outputFilePath}'`);
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
export const svigConfigPath = "mi.config.json";
|
|
3
|
+
export function getSvigConfig() {
|
|
4
|
+
try {
|
|
5
|
+
const data = fs.readFileSync(svigConfigPath, 'utf8');
|
|
6
|
+
const config = JSON.parse(data);
|
|
7
|
+
return config;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
const config = {
|
|
11
|
+
icons: []
|
|
12
|
+
};
|
|
13
|
+
return config;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function saveSvigConfig(config) {
|
|
17
|
+
try {
|
|
18
|
+
config.icons = config.icons.sort();
|
|
19
|
+
const jsonString = JSON.stringify(config, null, 2); // Indented with 2 spaces
|
|
20
|
+
fs.writeFileSync(svigConfigPath, jsonString);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.log(`Error while writing json: ${error}`);
|
|
24
|
+
}
|
|
25
|
+
}
|