@wkovacs64/add-icon 0.1.0-dev.d95c15e4 → 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/README.md +5 -2
- package/bin/add-icon.js +1 -1
- package/dist/import-module.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ npx @wkovacs64/add-icon heroicons:arrow-up-circle --output-dir ./app/assets/svg-
|
|
|
29
29
|
|
|
30
30
|
### Transformations
|
|
31
31
|
|
|
32
|
-
The tool fetches SVG icons directly from the Iconify API with width and height attributes removed
|
|
32
|
+
The tool fetches SVG icons directly from the Iconify API with width and height attributes removed
|
|
33
|
+
automatically. You can optionally provide a transform file using either JavaScript or TypeScript
|
|
34
|
+
containing custom transformations for more advanced modifications.
|
|
33
35
|
|
|
34
36
|
#### TypeScript Transform Example
|
|
35
37
|
|
|
@@ -56,7 +58,8 @@ npx @wkovacs64/add-icon heroicons:arrow-up-circle --transform ./my-transform.ts
|
|
|
56
58
|
|
|
57
59
|
### Configuration File
|
|
58
60
|
|
|
59
|
-
You can create a configuration file in your project root, using either JavaScript
|
|
61
|
+
You can create a configuration file in your project root, using either JavaScript
|
|
62
|
+
(`add-icon.config.js`) or TypeScript (`add-icon.config.ts`).
|
|
60
63
|
|
|
61
64
|
#### TypeScript Configuration Example
|
|
62
65
|
|
package/bin/add-icon.js
CHANGED
package/dist/import-module.js
CHANGED
|
@@ -10,20 +10,20 @@ export async function importModule(filePath) {
|
|
|
10
10
|
const absolutePath = path.resolve(filePath);
|
|
11
11
|
try {
|
|
12
12
|
// Read the module file content
|
|
13
|
-
const code = await fs.readFile(absolutePath,
|
|
13
|
+
const code = await fs.readFile(absolutePath, 'utf-8');
|
|
14
14
|
// Determine the appropriate loader based on file extension
|
|
15
15
|
const loader = absolutePath.endsWith('.ts') ? 'ts' : 'js';
|
|
16
16
|
// Use esbuild to transform the code to ESM JS
|
|
17
17
|
const result = await esbuild.transform(code, {
|
|
18
18
|
loader, // Automatically use the appropriate loader
|
|
19
|
-
format:
|
|
19
|
+
format: 'esm', // Output format
|
|
20
20
|
sourcemap: false, // Disable source maps for data URI
|
|
21
21
|
sourcefile: absolutePath, // Helps with error messages
|
|
22
22
|
target: 'esnext',
|
|
23
23
|
});
|
|
24
24
|
const jsCode = result.code;
|
|
25
25
|
// Create data URI and import
|
|
26
|
-
const base64Code = Buffer.from(jsCode).toString(
|
|
26
|
+
const base64Code = Buffer.from(jsCode).toString('base64');
|
|
27
27
|
const dataUri = `data:text/javascript;base64,${base64Code}`;
|
|
28
28
|
// Import the transformed code as a module
|
|
29
29
|
return await import(dataUri);
|