diff --git a/src/linux/index.js b/src/linux/index.js index e47f611..79694e0 100644 --- a/src/linux/index.js +++ b/src/linux/index.js @@ -1,4 +1,5 @@ const ejs = require('ejs'); +const os = require('os'); const fs = require('fs'); const { join } = require('path'); const shell = require('../utils/shell'); @@ -54,6 +55,7 @@ const checkifExists = async (protocol) => { const register = async (options, cb) => { let res = null; + const tmpDir = fs.mkdtempSync(`${os.tmpdir()}/register-protocol-`); const validOptions = validator(registerSchema, options); const { protocol, @@ -72,10 +74,10 @@ const register = async (options, cb) => { } const desktopFileName = `${protocol}.desktop`; - const desktopFilePath = join(__dirname, '../../temp', desktopFileName); + const desktopFilePath = join(tmpDir, desktopFileName); const desktopTemplate = join(__dirname, './templates', 'desktop.ejs'); const scriptTemplate = join(__dirname, './templates', 'script.ejs'); - const scriptFilePath = join(__dirname, '../../temp', 'script.sh'); + const scriptFilePath = join(tmpDir, 'script.sh'); command = await preProcessCommands( protocol, @@ -121,6 +123,8 @@ const register = async (options, cb) => { } catch (e) { if (!cb) throw e; res = e; + } finally { + fs.rmSync(rmDir, { recursive: true, force: true }); } if (cb) return cb(res); }; diff --git a/src/macos/index.js b/src/macos/index.js index 1b368c3..808a309 100644 --- a/src/macos/index.js +++ b/src/macos/index.js @@ -1,4 +1,5 @@ const ejs = require('ejs'); +const os = require('os'); const fs = require('fs'); const { join } = require('path'); const shell = require('../utils/shell'); @@ -50,6 +51,7 @@ const checkifExists = async (protocol) => { const register = async (options, cb) => { let res = null; + const tmpDir = fs.mkdtempSync(`${os.tmpdir()}/register-protocol-`); const validOptions = validator(registerSchema, options); const { protocol, @@ -77,19 +79,15 @@ const register = async (options, cb) => { const plistMutator = join(__dirname, 'plistMutator.js'); const appTemplate = join(__dirname, './templates', 'app.ejs'); - const appSource = join(__dirname, '../../temp', `app-${protocol}.txt`); + const appSource = join(tmpDir, `app-${protocol}.txt`); const appPath = join(homedir, `APP-${protocol}.app`); const urlAppTemplate = join(__dirname, './templates', 'url-app.ejs'); - const urlAppSource = join( - __dirname, - '../../temp', - `URL-${protocol}.txt` - ); + const urlAppSource = join(tmpDir,`URL-${protocol}.txt`); const urlAppPath = join(homedir, `URL-${protocol}.app`); const scriptTemplate = join(__dirname, './templates', 'script.ejs'); - const scriptFilePath = join(__dirname, '../../temp', 'script.sh'); + const scriptFilePath = join(tmpDir, 'script.sh'); const appSourceContent = await new Promise((resolve, reject) => { ejs.renderFile( @@ -149,6 +147,8 @@ const register = async (options, cb) => { } catch (e) { if (!cb) throw e; res = e; + } finally { + fs.rmSync(rmDir, { recursive: true, force: true }); } if (cb) return cb(res); }; diff --git a/temp/.gitkeep b/temp/.gitkeep deleted file mode 100644 index e69de29..0000000