From 7bfedc823b015c36f8500780a0fdbba1e6c45d55 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Thu, 21 Jan 2016 09:06:04 +0800 Subject: [PATCH] Make app resource folder contain a short id string, fix #21 --- src/buildApp.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/buildApp.js b/src/buildApp.js index e2e1712..83fd750 100644 --- a/src/buildApp.js +++ b/src/buildApp.js @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import crypto from 'crypto'; import packager from 'electron-packager'; import tmp from 'tmp'; @@ -86,11 +87,18 @@ function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, badge, width, h // change name of packageJson so that temporary files will not be shared across different app instances const packageJsonPath = path.join(tempDir, '/package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); - packageJson.name = _.kebabCase(appArgs.name + '-nativefier'); + packageJson.name = normalizeAppName(appArgs.name); fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson)); callback(null, tempDir); }); -}; +} + +function normalizeAppName(appName) { + // use a simple 3 byte random string to prevent collision + const postFixHash = crypto.randomBytes(3).toString('hex'); + const normalized = _.kebabCase(appName.toLowerCase()); + return `${normalized}-nativefier-${postFixHash}`; +} export default buildApp;