Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not work on multiple files #8

Closed
dnamyslak opened this issue Jun 7, 2020 · 11 comments · Fixed by #10
Closed

does not work on multiple files #8

dnamyslak opened this issue Jun 7, 2020 · 11 comments · Fixed by #10
Labels
bug Something isn't working windows issue Only occurring on windows platform

Comments

@dnamyslak
Copy link

It just works with 1 specified file.
Not working with whole folder

@Ghustavh97
Copy link
Contributor

@dnamyslak Hi, what is the full error message you are getting and what does your code look like?

@Ghustavh97 Ghustavh97 added the needs more info Needs more information label Jun 7, 2020
@dnamyslak
Copy link
Author

i am using node express with yarp and sharp resolution ( to exclude the other issue I mentioned )
package.json

{
"name": "nodejs",
"version": "0.0.0",
"private": false,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"morgan": "~1.9.1",
"oslllo-svg-fixer": "^0.4.3",
"yarn": "^1.22.4"
},
"resolutions": {
"sharp": "^0.23.1"
}
}

and using your function in bin/www.js

svgfixerFixExample();

async function svgfixerFixExample() {
// You can use a path that points to a directory with SVGs.
await svgfixer.fix('svg/example.svg', 'svg/fixed-svgs');
}

works fine but just witn explicit ONE file so I needet to change for each filename and run this several times

does not work when tried to use => await svgfixer.fix('svg', 'svg/fixed-svgs');

@Ghustavh97
Copy link
Contributor

@dnamyslak

  • await only works inside async functions
  • You can try this.
svgfixer.fix('path/to/folder/with/multiple/svgs', 'path/to/store/fixed/svgs')
.then(() => {
    console.log('finished')
})
.catch((error) => {
    console.log(error)
})
  • If you want to fix all svg files in a folder do not include the .svg at the end of the path, just pass in the directory/folder path like this: path/to/folder not path/to/folder.svg

  • My paths use / because i'm on ubuntu, if you are on windows use \ or just copy the folder path from explorer.

@Ghustavh97
Copy link
Contributor

@dnamyslak could I also see what www.js looks like?

@dnamyslak
Copy link
Author

`#!/usr/bin/env node

/**

  • Module dependencies.
    */

var app = require('../app');
var debug = require('debug')('nodejs:server');
var http = require('http');
var svgfixer = require('oslllo-svg-fixer');

/**

  • Get port from environment and store in Express.
    */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**

  • Create HTTP server.
    */

var server = http.createServer(app);

/**

  • Listen on provided port, on all network interfaces.
    */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**

  • Normalize a port into a number, string, or false.
    */

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**

  • Event listener for HTTP server "error" event.
    */

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**

  • Event listener for HTTP server "listening" event.
    */

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

svgfixerFixExample();

async function svgfixerFixExample() {
// You can use a path that points to a directory with SVGs.
await svgfixer.fix('svg', 'svg/fixed-svgs2');
}
`

@Ghustavh97
Copy link
Contributor

@dnamyslak is the svg folder in the same location as the www.js file? Also do you just want to fix icons or you really want to run the package on a web server?

@dnamyslak
Copy link
Author

the svg folder is 1 level up
just want to fixed the icons which I did doing one by one :)
thanks for your app - its great !
I use iconmoon constantly and always had problem with stroked icons there

@dnamyslak
Copy link
Author

dnamyslak commented Jun 8, 2020 via email

@Ghustavh97
Copy link
Contributor

Ghustavh97 commented Jun 8, 2020

@dnamyslak Glad to hear that is solved that issue for you too, but I really don't want you do have to do the icons one by one, especially if the app supports doing a whole folder. If you only want to fix icons you don't need node server to do it, try doing this.

  1. Create a new folder somewhere and call it icon-fixer
  2. cd into the folder and run npm init
  3. Press enter until its done.
  4. create a file inside this folder and call it index.js
  5. Open the package.json file inside the folder.
  6. Inside the scripts object add this key value pair "fixer": "node index.js", so it looks something like this:
  "scripts": {
    "fixer": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  1. run npm i oslllo-svg-fixer --save inside the folder

  2. Open the index.js file and type this inside of it:

const svgfixer = require("oslllo-svg-fixer");

var source = "path/to/folder/with/multiple/svgs";
var destination = "path/to/store/fixed/svgs";

var options = {
    throwIfPathDoesNotExist: true,
    showProgressBar: true,
};

svgfixer.fix(source, destination, options)
.then(() => {
    console.log("Finished fixing svgs")
})
.catch((err) => {
    console.log("Error fixing svgs")
    console.log(err)
})
  1. change source to the path pointing to the svgs you want to fix.
  2. change destination to the path where you want to store the fixed svgs.
  3. save the file and then run npm run fixer

@Ghustavh97 Ghustavh97 added bug Something isn't working windows issue Only occurring on windows platform labels Jun 12, 2020
@Ghustavh97 Ghustavh97 linked a pull request Jun 12, 2020 that will close this issue
@Ghustavh97
Copy link
Contributor

@dnamyslak fixed the multiple bugs with the issue, update and try the latest version, 0.5.0. You also no more need/require sharp anymore.

@Ghustavh97 Ghustavh97 removed the needs more info Needs more information label Jan 13, 2021
@ayusman33
Copy link

ayusman33 commented Aug 25, 2021

Just a small correction on the above wrong code:

SVGfixer(source, destination, options).fix()
.then(() => {
    console.log("Finished fixing svgs");
})
.catch((err) => {
    console.log("Error fixing svgs");
    console.log(err);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows issue Only occurring on windows platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants