itc-converter 1.0.3 → 1.0.6

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 +28 -0
  2. package/converter.js +36 -19
  3. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # itc-converter 🤖
2
+
3
+ An automated CLI tool for Termux (Android) that automatically scans your phone storage for a black and white PNG icon, converts it into optimized SVG code, wraps it in a responsive HTML template, and saves the result directly to your user-accessible storage.
4
+
5
+ ## Features ✨
6
+ * 🔍 **Auto-Scan:** Automatically searches your `/sdcard` storage to find the source file.
7
+ * 📦 **Zero Directory Mess:** No need to manually move files into Termux hidden folders.
8
+ * 📂 **Auto-Folder Creation:** Creates `Download/Codex` in your internal storage if it doesn't exist.
9
+ * 🧼 **Auto-Cleanup:** Completely wipes temporary conversion artifacts and deletes the original heavy PNG from your phone to save space.
10
+
11
+ ## Installation 🚀
12
+
13
+ Before installing, make sure you have granted storage access to Termux and installed Node.js:
14
+
15
+ ```bash
16
+ termux-setup-storage
17
+ pkg update && pkg install nodejs -y
18
+ npm install -g itc-converter
19
+
20
+
21
+ How to Use 🏁
22
+ ​Place any black and white image or silhouette into any folder on your phone and rename it exactly to Icons.png.
23
+ ​Open Termux (from any directory) and run:
24
+
25
+ trace-png
26
+
27
+
28
+ 3. ​Find your ready-to-use vector web page in the Download/Codex/Icons.html file on your phone!
package/converter.js CHANGED
@@ -4,12 +4,15 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const potrace = require('potrace');
6
6
 
7
- const FILE_NAME = 'Icons.png';
7
+ // Определяем, какую команду вызвал пользователь (из бинарника npm)
8
+ const command = process.argv[1] && process.argv[1].endsWith('trace-svg') ? 'svg' : 'png';
9
+
10
+ const FILE_NAME = command === 'svg' ? 'Icons.svg' : 'Icons.png';
8
11
  const OUTPUT_HTML = 'Icons.html';
9
- const START_DIR = '/sdcard';
12
+ const START_DIR = '/sdcard';
10
13
  const TARGET_DIR = '/sdcard/Download/Codex';
11
14
 
12
- const localPngPath = path.join(__dirname, FILE_NAME);
15
+ const localFilePath = path.join(__dirname, FILE_NAME);
13
16
  const tempHtmlPath = path.join(__dirname, OUTPUT_HTML);
14
17
  const finalHtmlPath = path.join(TARGET_DIR, OUTPUT_HTML);
15
18
 
@@ -22,12 +25,12 @@ function findFile(dir, fileName) {
22
25
  for (let i = 0; i < list.length; i++) {
23
26
  const file = path.join(dir, list[i]);
24
27
  const stat = fs.statSync(file);
25
-
28
+
26
29
  if (list[i].startsWith('.') || list[i] === 'Android') continue;
27
30
 
28
31
  if (stat && stat.isDirectory()) {
29
32
  results = results.concat(findFile(file, fileName));
30
- if (results.length > 0) return results;
33
+ if (results.length > 0) return results;
31
34
  } else if (list[i] === fileName) {
32
35
  results.push(file);
33
36
  return results;
@@ -46,12 +49,12 @@ if (foundFiles.length === 0) {
46
49
  process.exit(1);
47
50
  }
48
51
 
49
- const originalPngPath = foundFiles[0];
50
- console.log(`🎯 File successfully located at: ${originalPngPath}`);
52
+ const originalFilePath = foundFiles[0];
53
+ console.log(`🎯 File successfully located at: ${originalFilePath}`);
51
54
 
52
55
  try {
53
- fs.copyFileSync(originalPngPath, localPngPath);
54
- console.log('📦 Source PNG successfully copied to Termux environment.');
56
+ fs.copyFileSync(originalFilePath, localFilePath);
57
+ console.log(`📦 Source ${command.toUpperCase()} successfully copied to Termux environment.`);
55
58
  } catch (copyErr) {
56
59
  console.error('❌ Error copying file to Termux:', copyErr.message);
57
60
  process.exit(1);
@@ -67,13 +70,7 @@ if (!fs.existsSync(TARGET_DIR)) {
67
70
  }
68
71
  }
69
72
 
70
- potrace.trace(localPngPath, function(err, svgCode) {
71
- if (err) {
72
- console.error('❌ Error converting PNG to SVG:', err.message);
73
- process.exit(1);
74
- }
75
- console.log('✅ Step 1: Black and white icon successfully converted to SVG!');
76
-
73
+ function generateHtmlAndCleanup(svgCode) {
77
74
  const htmlContent = `<!DOCTYPE html>
78
75
  <html lang="en">
79
76
  <head>
@@ -115,8 +112,8 @@ potrace.trace(localPngPath, function(err, svgCode) {
115
112
  console.log(`✅ Step 4: Output HTML copied to storage: ${finalHtmlPath}`);
116
113
 
117
114
  fs.unlinkSync(tempHtmlPath);
118
- fs.unlinkSync(localPngPath);
119
- fs.unlinkSync(originalPngPath);
115
+ fs.unlinkSync(localFilePath);
116
+ fs.unlinkSync(originalFilePath);
120
117
  console.log(`✅ Step 5: Temporary files and source ${FILE_NAME} completely cleared!`);
121
118
  console.log('🏁 Application finished successfully. Shutting down.');
122
119
  } catch (finalErr) {
@@ -124,4 +121,24 @@ potrace.trace(localPngPath, function(err, svgCode) {
124
121
  process.exit(1);
125
122
  }
126
123
  });
127
- });
124
+ }
125
+
126
+ if (command === 'png') {
127
+ potrace.trace(localFilePath, function(err, svgCode) {
128
+ if (err) {
129
+ console.error('❌ Error converting PNG to SVG:', err.message);
130
+ process.exit(1);
131
+ }
132
+ console.log('✅ Step 1: Black and white icon successfully converted to SVG!');
133
+ generateHtmlAndCleanup(svgCode);
134
+ });
135
+ } else {
136
+ try {
137
+ const svgCode = fs.readFileSync(localFilePath, 'utf8');
138
+ console.log('✅ Step 1: Existing SVG file successfully read from memory!');
139
+ generateHtmlAndCleanup(svgCode);
140
+ } catch (readErr) {
141
+ console.error('❌ Error reading SVG file:', readErr.message);
142
+ process.exit(1);
143
+ }
144
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "itc-converter",
3
- "version": "1.0.3",
4
- "description": "An automated CLI tool to scan phone storage, convert PNG icons to SVG, and pack them into an HTML view.",
3
+ "version": "1.0.6",
4
+ "description": "Automated CLI tool to scan phone storage, convert PNG icons to SVG or wrap existing SVG into HTML.",
5
5
  "main": "converter.js",
6
6
  "bin": {
7
- "trace-png": "./converter.js"
7
+ "trace-png": "./converter.js",
8
+ "trace-svg": "./converter.js"
8
9
  },
9
10
  "dependencies": {
10
11
  "potrace": "^2.1.8"
@@ -15,8 +16,7 @@
15
16
  "html",
16
17
  "converter",
17
18
  "termux",
18
- "cli",
19
- "automation"
19
+ "cli"
20
20
  ],
21
21
  "author": "Elisey",
22
22
  "license": "MIT"