diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/array-helpers.js | 6 | ||||
-rw-r--r-- | src/helpers/async-helpers.js | 2 | ||||
-rw-r--r-- | src/helpers/plan-helpers.js | 53 | ||||
-rw-r--r-- | src/helpers/recipe-helpers.js | 11 | ||||
-rw-r--r-- | src/helpers/service-helpers.js | 18 | ||||
-rw-r--r-- | src/helpers/userAgent-helpers.js | 5 | ||||
-rw-r--r-- | src/helpers/validation-helpers.js | 2 |
7 files changed, 20 insertions, 77 deletions
diff --git a/src/helpers/array-helpers.js b/src/helpers/array-helpers.js index ffb3b63dc..5e592b7f7 100644 --- a/src/helpers/array-helpers.js +++ b/src/helpers/array-helpers.js | |||
@@ -1,4 +1,4 @@ | |||
1 | export const shuffleArray = arr => arr | 1 | export const shuffleArray = (arr) => arr |
2 | .map(a => [Math.random(), a]) | 2 | .map((a) => [Math.random(), a]) |
3 | .sort((a, b) => a[0] - b[0]) | 3 | .sort((a, b) => a[0] - b[0]) |
4 | .map(a => a[1]); | 4 | .map((a) => a[1]); |
diff --git a/src/helpers/async-helpers.js b/src/helpers/async-helpers.js index 2ef01ee09..c6c57e28e 100644 --- a/src/helpers/async-helpers.js +++ b/src/helpers/async-helpers.js | |||
@@ -1,5 +1,5 @@ | |||
1 | /* eslint-disable import/prefer-default-export */ | 1 | /* eslint-disable import/prefer-default-export */ |
2 | 2 | ||
3 | export function sleep(ms = 0) { | 3 | export function sleep(ms = 0) { |
4 | return new Promise(r => setTimeout(r, ms)); | 4 | return new Promise((r) => setTimeout(r, ms)); |
5 | } | 5 | } |
diff --git a/src/helpers/plan-helpers.js b/src/helpers/plan-helpers.js deleted file mode 100644 index b474f8bbd..000000000 --- a/src/helpers/plan-helpers.js +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | import { defineMessages } from 'react-intl'; | ||
2 | import { PLANS_MAPPING, PLANS } from '../config'; | ||
3 | |||
4 | const messages = defineMessages({ | ||
5 | [PLANS.PRO]: { | ||
6 | id: 'pricing.plan.pro', | ||
7 | defaultMessage: '!!!Professional', | ||
8 | }, | ||
9 | [PLANS.PERSONAL]: { | ||
10 | id: 'pricing.plan.personal', | ||
11 | defaultMessage: '!!!Personal', | ||
12 | }, | ||
13 | [PLANS.FREE]: { | ||
14 | id: 'pricing.plan.free', | ||
15 | defaultMessage: '!!!Free', | ||
16 | }, | ||
17 | [PLANS.LEGACY]: { | ||
18 | id: 'pricing.plan.legacy', | ||
19 | defaultMessage: '!!!Premium', | ||
20 | }, | ||
21 | }); | ||
22 | |||
23 | export function cleanupPlanId(id) { | ||
24 | return id.replace(/(.*)-x[0-9]/, '$1'); | ||
25 | } | ||
26 | |||
27 | export function i18nPlanName(planId, intl) { | ||
28 | if (!planId) { | ||
29 | throw new Error('planId is required'); | ||
30 | } | ||
31 | |||
32 | if (!intl) { | ||
33 | throw new Error('intl context is required'); | ||
34 | } | ||
35 | |||
36 | const id = cleanupPlanId(planId); | ||
37 | |||
38 | const plan = PLANS_MAPPING[id]; | ||
39 | |||
40 | return intl.formatMessage(messages[plan]); | ||
41 | } | ||
42 | |||
43 | export function getPlan(planId) { | ||
44 | if (!planId) { | ||
45 | throw new Error('planId is required'); | ||
46 | } | ||
47 | |||
48 | const id = cleanupPlanId(planId); | ||
49 | |||
50 | const plan = PLANS_MAPPING[id]; | ||
51 | |||
52 | return plan; | ||
53 | } | ||
diff --git a/src/helpers/recipe-helpers.js b/src/helpers/recipe-helpers.js index 7daa0aaab..7e4bfa85a 100644 --- a/src/helpers/recipe-helpers.js +++ b/src/helpers/recipe-helpers.js | |||
@@ -1,12 +1,12 @@ | |||
1 | import path from 'path'; | 1 | import { parse } from 'path'; |
2 | import { app } from '@electron/remote'; | 2 | import { userDataRecipesPath } from '../environment'; |
3 | 3 | ||
4 | export function getRecipeDirectory(id = '') { | 4 | export function getRecipeDirectory(id = '') { |
5 | return path.join(app.getPath('userData'), 'recipes', id); | 5 | return userDataRecipesPath(id); |
6 | } | 6 | } |
7 | 7 | ||
8 | export function getDevRecipeDirectory(id = '') { | 8 | export function getDevRecipeDirectory(id = '') { |
9 | return path.join(app.getPath('userData'), 'recipes', 'dev', id); | 9 | return userDataRecipesPath('dev', id); |
10 | } | 10 | } |
11 | 11 | ||
12 | export function loadRecipeConfig(recipeId) { | 12 | export function loadRecipeConfig(recipeId) { |
@@ -19,8 +19,7 @@ export function loadRecipeConfig(recipeId) { | |||
19 | let config = require(configPath); | 19 | let config = require(configPath); |
20 | 20 | ||
21 | const moduleConfigPath = require.resolve(configPath); | 21 | const moduleConfigPath = require.resolve(configPath); |
22 | const paths = path.parse(moduleConfigPath); | 22 | config.path = parse(moduleConfigPath).dir; |
23 | config.path = paths.dir; | ||
24 | 23 | ||
25 | return config; | 24 | return config; |
26 | } catch (e) { | 25 | } catch (e) { |
diff --git a/src/helpers/service-helpers.js b/src/helpers/service-helpers.js index f6363aca8..745f40dd9 100644 --- a/src/helpers/service-helpers.js +++ b/src/helpers/service-helpers.js | |||
@@ -1,18 +1,16 @@ | |||
1 | import path from 'path'; | 1 | import { readdirSync, removeSync } from 'fs-extra'; |
2 | import { app } from '@electron/remote'; | 2 | import { userDataPath } from '../environment'; |
3 | import fs from 'fs-extra'; | ||
4 | 3 | ||
5 | export function getServicePartitionsDirectory() { | 4 | export function getServicePartitionsDirectory(...segments) { |
6 | return path.join(app.getPath('userData'), 'Partitions'); | 5 | return userDataPath('Partitions', ...([segments].flat())); |
7 | } | 6 | } |
8 | 7 | ||
9 | export function removeServicePartitionDirectory(id = '', addServicePrefix = false) { | 8 | export function removeServicePartitionDirectory(id = '', addServicePrefix = false) { |
10 | const servicePartition = path.join(getServicePartitionsDirectory(), `${addServicePrefix ? 'service-' : ''}${id}`); | 9 | const servicePartition = getServicePartitionsDirectory(`${addServicePrefix ? 'service-' : ''}${id}`); |
11 | 10 | return removeSync(servicePartition); | |
12 | return fs.remove(servicePartition); | ||
13 | } | 11 | } |
14 | 12 | ||
15 | export async function getServiceIdsFromPartitions() { | 13 | export async function getServiceIdsFromPartitions() { |
16 | const files = await fs.readdir(getServicePartitionsDirectory()); | 14 | const files = readdirSync(getServicePartitionsDirectory()); |
17 | return files.filter(n => n !== '__chrome_extension'); | 15 | return files.filter((n) => n !== '__chrome_extension'); |
18 | } | 16 | } |
diff --git a/src/helpers/userAgent-helpers.js b/src/helpers/userAgent-helpers.js index 9c9c8f132..ede5e6dc4 100644 --- a/src/helpers/userAgent-helpers.js +++ b/src/helpers/userAgent-helpers.js | |||
@@ -1,11 +1,10 @@ | |||
1 | import os from 'os'; | 1 | import os from 'os'; |
2 | import macosVersion from 'macos-version'; | 2 | import macosVersion from 'macos-version'; |
3 | import { chrome } from 'useragent-generator'; | ||
3 | import { | 4 | import { |
4 | chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease, | 5 | chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease, |
5 | } from '../environment'; | 6 | } from '../environment'; |
6 | 7 | ||
7 | const uaGenerator = require('useragent-generator'); | ||
8 | |||
9 | function macOS() { | 8 | function macOS() { |
10 | const version = macosVersion(); | 9 | const version = macosVersion(); |
11 | let cpuName = os.cpus()[0].model.split(' ')[0]; | 10 | let cpuName = os.cpus()[0].model.split(' ')[0]; |
@@ -38,5 +37,5 @@ export default function userAgent() { | |||
38 | platformString = linux(); | 37 | platformString = linux(); |
39 | } | 38 | } |
40 | 39 | ||
41 | return uaGenerator.chrome({ os: platformString, version: chromeVersion }); | 40 | return chrome({ os: platformString, version: chromeVersion }); |
42 | } | 41 | } |
diff --git a/src/helpers/validation-helpers.js b/src/helpers/validation-helpers.js index f489ec65e..116f19905 100644 --- a/src/helpers/validation-helpers.js +++ b/src/helpers/validation-helpers.js | |||
@@ -61,7 +61,7 @@ export function minLength(length) { | |||
61 | 61 | ||
62 | export function oneRequired(targets) { | 62 | export function oneRequired(targets) { |
63 | return ({ field, form }) => { | 63 | return ({ field, form }) => { |
64 | const invalidFields = targets.filter(target => form.$(target).value === ''); | 64 | const invalidFields = targets.filter((target) => form.$(target).value === ''); |
65 | return [targets.length !== invalidFields.length, window.ferdi.intl.formatMessage(messages.required, { field: field.label })]; | 65 | return [targets.length !== invalidFields.length, window.ferdi.intl.formatMessage(messages.required, { field: field.label })]; |
66 | }; | 66 | }; |
67 | } | 67 | } |