itc-converter 1.0.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/converter.js +127 -0
- package/package.json +23 -0
package/converter.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const potrace = require('potrace');
|
|
6
|
+
|
|
7
|
+
const FILE_NAME = 'Icons.png';
|
|
8
|
+
const OUTPUT_HTML = 'Icons.html';
|
|
9
|
+
const START_DIR = '/sdcard';
|
|
10
|
+
const TARGET_DIR = '/sdcard/Download/Codex';
|
|
11
|
+
|
|
12
|
+
const localPngPath = path.join(__dirname, FILE_NAME);
|
|
13
|
+
const tempHtmlPath = path.join(__dirname, OUTPUT_HTML);
|
|
14
|
+
const finalHtmlPath = path.join(TARGET_DIR, OUTPUT_HTML);
|
|
15
|
+
|
|
16
|
+
console.log('🤖 Starting the application...');
|
|
17
|
+
|
|
18
|
+
function findFile(dir, fileName) {
|
|
19
|
+
let results = [];
|
|
20
|
+
try {
|
|
21
|
+
const list = fs.readdirSync(dir);
|
|
22
|
+
for (let i = 0; i < list.length; i++) {
|
|
23
|
+
const file = path.join(dir, list[i]);
|
|
24
|
+
const stat = fs.statSync(file);
|
|
25
|
+
|
|
26
|
+
if (list[i].startsWith('.') || list[i] === 'Android') continue;
|
|
27
|
+
|
|
28
|
+
if (stat && stat.isDirectory()) {
|
|
29
|
+
results = results.concat(findFile(file, fileName));
|
|
30
|
+
if (results.length > 0) return results;
|
|
31
|
+
} else if (list[i] === fileName) {
|
|
32
|
+
results.push(file);
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
}
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(`🔍 Step 0: Searching for ${FILE_NAME} in phone storage...`);
|
|
42
|
+
const foundFiles = findFile(START_DIR, FILE_NAME);
|
|
43
|
+
|
|
44
|
+
if (foundFiles.length === 0) {
|
|
45
|
+
console.error(`❌ Error: File ${FILE_NAME} not found in storage!`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const originalPngPath = foundFiles[0];
|
|
50
|
+
console.log(`🎯 File successfully located at: ${originalPngPath}`);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
fs.copyFileSync(originalPngPath, localPngPath);
|
|
54
|
+
console.log('📦 Source PNG successfully copied to Termux environment.');
|
|
55
|
+
} catch (copyErr) {
|
|
56
|
+
console.error('❌ Error copying file to Termux:', copyErr.message);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!fs.existsSync(TARGET_DIR)) {
|
|
61
|
+
try {
|
|
62
|
+
fs.mkdirSync(TARGET_DIR, { recursive: true });
|
|
63
|
+
console.log(`📂 Directory ${TARGET_DIR} created successfully!`);
|
|
64
|
+
} catch (dirErr) {
|
|
65
|
+
console.error('❌ Error creating Codex directory:', dirErr.message);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
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
|
+
|
|
77
|
+
const htmlContent = `<!DOCTYPE html>
|
|
78
|
+
<html lang="en">
|
|
79
|
+
<head>
|
|
80
|
+
<meta charset="UTF-8">
|
|
81
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
82
|
+
<title>SVG View</title>
|
|
83
|
+
<style>
|
|
84
|
+
body {
|
|
85
|
+
margin: 0;
|
|
86
|
+
display: flex;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
align-items: center;
|
|
89
|
+
min-height: 100vh;
|
|
90
|
+
background-color: #f0f2f5;
|
|
91
|
+
}
|
|
92
|
+
svg {
|
|
93
|
+
max-width: 90vw;
|
|
94
|
+
max-height: 90vh;
|
|
95
|
+
height: auto;
|
|
96
|
+
}
|
|
97
|
+
</style>
|
|
98
|
+
</head>
|
|
99
|
+
<body>
|
|
100
|
+
${svgCode}
|
|
101
|
+
</body>
|
|
102
|
+
</html>`;
|
|
103
|
+
|
|
104
|
+
console.log('✅ Step 2: SVG code wrapped in HTML template!');
|
|
105
|
+
|
|
106
|
+
fs.writeFile(tempHtmlPath, htmlContent, 'utf8', (writeErr) => {
|
|
107
|
+
if (writeErr) {
|
|
108
|
+
console.error('❌ Error saving temporary HTML:', writeErr.message);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
console.log('✅ Step 3: HTML file generated successfully in temp folder!');
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
fs.copyFileSync(tempHtmlPath, finalHtmlPath);
|
|
115
|
+
console.log(`✅ Step 4: Output HTML copied to storage: ${finalHtmlPath}`);
|
|
116
|
+
|
|
117
|
+
fs.unlinkSync(tempHtmlPath);
|
|
118
|
+
fs.unlinkSync(localPngPath);
|
|
119
|
+
fs.unlinkSync(originalPngPath);
|
|
120
|
+
console.log(`✅ Step 5: Temporary files and source ${FILE_NAME} completely cleared!`);
|
|
121
|
+
console.log('🏁 Application finished successfully. Shutting down.');
|
|
122
|
+
} catch (finalErr) {
|
|
123
|
+
console.error('❌ Error during final cleanup or copy stage:', finalErr.message);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "itc-converter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An automated CLI tool to scan phone storage, convert PNG icons to SVG, and pack them into an HTML view.",
|
|
5
|
+
"main": "converter.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"trace-png": "./converter.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"potrace": "^0.2.0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"png",
|
|
14
|
+
"svg",
|
|
15
|
+
"html",
|
|
16
|
+
"converter",
|
|
17
|
+
"termux",
|
|
18
|
+
"cli",
|
|
19
|
+
"automation"
|
|
20
|
+
],
|
|
21
|
+
"author": "Elisey",
|
|
22
|
+
"license": "MIT"
|
|
23
|
+
}
|