@wkovacs64/add-icon 1.0.0 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +8 -2
  2. package/dist/index.js +59 -9
  3. package/package.json +13 -5
package/README.md CHANGED
@@ -14,19 +14,25 @@ npm install @wkovacs64/add-icon
14
14
  Or use it directly with npx without installing:
15
15
 
16
16
  ```bash
17
- npx @wkovacs64/add-icon <icon> [options]
17
+ npx @wkovacs64/add-icon <icon>... [options]
18
18
  ```
19
19
 
20
20
  ## Usage
21
21
 
22
22
  ### Basic Usage
23
23
 
24
- Download an icon to the specified directory:
24
+ Download a single icon to the specified directory:
25
25
 
26
26
  ```bash
27
27
  npx @wkovacs64/add-icon heroicons:arrow-up-circle --output-dir ./app/assets/svg-icons
28
28
  ```
29
29
 
30
+ Download multiple icons in one command:
31
+
32
+ ```bash
33
+ npx @wkovacs64/add-icon heroicons:arrow-up-circle mdi:home lucide:github --output-dir ./app/assets/svg-icons
34
+ ```
35
+
30
36
  ### Transformations
31
37
 
32
38
  The tool fetches SVG icons directly from the Iconify API with width and height attributes removed
package/dist/index.js CHANGED
@@ -15,16 +15,46 @@ const setupProgram = async () => {
15
15
  return program
16
16
  .name(name.split('/').pop() || name)
17
17
  .description(description)
18
- .version(version, '-v, --version', 'Output the current version')
19
- .argument('<icon>', 'Icon reference (e.g., heroicons:arrow-up-circle)')
20
- .option('-o, --output-dir <dir>', 'Directory to save icon')
18
+ .option('--init', 'Generate a config file in the current directory')
19
+ .option('-o, --output-dir <dir>', 'Directory to save icons')
21
20
  .option('-c, --config <path>', 'Path to config file')
22
- .option('-t, --transform <path>', 'Path to custom transform module (.js or .ts)');
21
+ .option('-t, --transform <path>', 'Path to custom transform module (.js or .ts)')
22
+ .version(version, '-v, --version', 'Output the current version')
23
+ .argument('[icons...]', 'Icon references (e.g., heroicons:arrow-up-circle mdi:home)');
23
24
  };
24
25
  // Initialize the program
25
26
  const initializedProgram = await setupProgram();
26
- initializedProgram.action(async (icon, options) => {
27
+ initializedProgram.action(async (icons, options) => {
27
28
  try {
29
+ // Validate that icons are provided when not using --init
30
+ if (!options.init && (!icons || icons.length === 0)) {
31
+ console.error('Error: At least one icon reference is required.');
32
+ program.help();
33
+ return;
34
+ }
35
+ // Handle --init flag to generate a config file
36
+ if (options.init) {
37
+ const fs = await import('node:fs/promises');
38
+ const configFileContent = `import type { Config } from '@wkovacs64/add-icon';
39
+
40
+ const config = {
41
+ outputDir: 'app/assets/svg-icons',
42
+ } satisfies Config;
43
+
44
+ export default config;
45
+ `;
46
+ try {
47
+ const configFilePath = path.resolve(process.cwd(), 'add-icon.config.ts');
48
+ await fs.writeFile(configFilePath, configFileContent, 'utf-8');
49
+ console.log(`✓ Configuration file created at: ${configFilePath}`);
50
+ process.exit(0);
51
+ }
52
+ catch (error) {
53
+ const errorMessage = error instanceof Error ? error.message : String(error);
54
+ console.error(`Error creating config file: ${errorMessage}`);
55
+ process.exit(1);
56
+ }
57
+ }
28
58
  // Load config (first from config file, then override with CLI options)
29
59
  const config = await loadConfig(options.config);
30
60
  // Override output directory if specified in CLI
@@ -59,10 +89,30 @@ initializedProgram.action(async (icon, options) => {
59
89
  process.exit(1);
60
90
  }
61
91
  }
62
- // Download the icon
63
- console.log(`Downloading icon: ${icon}...`);
64
- const savedPath = await downloadIcon(icon, config);
65
- console.log(`✓ Icon saved to: ${savedPath}`);
92
+ // Download all icons
93
+ const results = [];
94
+ for (const icon of icons) {
95
+ console.log(`Downloading icon: ${icon}...`);
96
+ try {
97
+ const savedPath = await downloadIcon(icon, config);
98
+ console.log(`✓ Icon saved to: ${savedPath}`);
99
+ results.push({ icon, path: savedPath, success: true });
100
+ }
101
+ catch (iconError) {
102
+ const errorMessage = iconError instanceof Error ? iconError.message : String(iconError);
103
+ console.error(`Error downloading ${icon}: ${errorMessage}`);
104
+ results.push({ icon, error: errorMessage, success: false });
105
+ }
106
+ }
107
+ // Report summary if multiple icons
108
+ if (icons.length > 1) {
109
+ const successful = results.filter((r) => r.success).length;
110
+ console.log(`\nSummary: Downloaded ${successful}/${icons.length} icons`);
111
+ // If any failed, exit with error
112
+ if (successful < icons.length) {
113
+ process.exit(1);
114
+ }
115
+ }
66
116
  }
67
117
  catch (error) {
68
118
  const errorMessage = error instanceof Error ? error.message : String(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wkovacs64/add-icon",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "CLI tool to download and transform icons from Iconify",
5
5
  "keywords": [
6
6
  "iconify",
@@ -9,7 +9,17 @@
9
9
  "cli",
10
10
  "download"
11
11
  ],
12
- "author": "Justin R. Hall <justin.r.hall@gmail.com>",
12
+ "author": {
13
+ "name": "Justin Hall",
14
+ "email": "justin.r.hall@gmail.com"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/wKovacs64/add-icon.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/wKovacs64/add-icon/issues"
22
+ },
13
23
  "license": "MIT",
14
24
  "type": "module",
15
25
  "main": "dist/index.js",
@@ -29,8 +39,6 @@
29
39
  "clean": "del-cli dist",
30
40
  "prebuild": "npm run --silent clean",
31
41
  "prepublishOnly": "run-p --silent lint typecheck build",
32
- "start": "node dist/index.js",
33
- "dev": "tsx src/index.ts",
34
42
  "typecheck": "attw --pack --profile esm-only",
35
43
  "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
36
44
  "format": "prettier --cache --write .",
@@ -51,7 +59,7 @@
51
59
  "devDependencies": {
52
60
  "@arethetypeswrong/cli": "0.17.4",
53
61
  "@changesets/changelog-github": "0.5.1",
54
- "@changesets/cli": "2.29.0",
62
+ "@changesets/cli": "2.29.1",
55
63
  "@types/node": "22.14.1",
56
64
  "@wkovacs64/eslint-config": "7.5.2",
57
65
  "@wkovacs64/prettier-config": "4.1.1",