Closed lucaorio closed 5 years ago
fs.mkdirSync
doesn't take a callback as an argument since it's synchronous../~/test/abc
which is probably not what you want. If you want to resolve ~
, you can use something like https://github.com/sindresorhus/untildify/@mathieudutour Thanks for helping. The snippet below works well, indeed!
const path = '/Users/myself/test/abc';
!fs.existsSync(path) && fs.mkdirSync(path);
Unfortunately, Untildify returns an empty string :( Do you have any other advice on how I can resolve that path?
const os = require('os');
const home = os.homedir();
const untiltify = input => {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, got ${typeof input}`);
}
return home ? input.replace(/^~(?=$|\/|\\)/, home) : input;
};
console.log(untiltify('~/test'))
works fine for me (which is the code of https://github.com/sindresorhus/untildify/). What version of Sketch are you using?
I'm using 53.1!
By the way, untiltify wasn't working when I was trying to run everything from within a plugin. I'm now slowly moving pretty much everything I can outside of it, and I can confirm you that untiltify works well :)
It seems like
fs.existsSync
doesn't create any folder. No error is returned, either.