forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
94 lines (82 loc) · 3.01 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const color = require('cli-color');
const fs = require('fs');
const Path = require('path');
const util = require('util');
exports.root_path = require('app-root-path').path;
// --------- Pages config ----------
exports.pages = require('./config/pages.js').map(p => ({
save_as : p[0],
tpl_path : p[1],
layout : p[2],
title : p[3],
excludes : p[4],
current_route: p[0].replace(/^(.+)\//, ''),
section : p[5] || '',
}));
// ---------- Sections ----------
exports.sections_config = {
'': { // '' is the default section when no 'section' specified in pages.js (to avoid adding 'app' as section for all)
path : '',
js_files : ['vendor', 'binary'],
css_files: ['common.min', 'app.min', 'static.min'],
has_pjax : true,
},
};
// ---------- Languages ----------
// TODO: add 'DE' after 'EN' in the array below to enable German language
// TODO: add 'TH' after 'RU' in the array below to enable Thai language
exports.languages = ['EN', 'ES', 'FR', 'ID', 'IT', 'KO', 'PL', 'PT', 'RU', 'VI', 'ZH_CN', 'ZH_TW'];
const affiliates_signup_language_map = { // object used instead of array to prevent accidental index changes
EN : 0,
RU : 1,
FR : 2,
IT : 3,
ID : 4,
PL : 5,
VI : 6,
// DE : 7, // TODO: uncomment to enable German language
ES : 8,
PT : 9,
ZH_CN: 10,
ZH_TW: 11,
// TH : 12, // TODO: uncomment to enable Thai language
};
exports.getAffiliateSignupLanguage = (lang = '') => (affiliates_signup_language_map[lang.toUpperCase()] || 0);
// ---------- Helpers ----------
exports.print = (text) => {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(text);
};
exports.messageStart = (msg, no_pad) => `${color.cyan('>')} ${msg} ${no_pad ? '' : '.'.repeat((this.languages.length + 18) - msg.length)}`;
exports.messageEnd = (duration, no_new_line) => (
`${color.green(' ✓ Done')}${duration ? color.blackBright(` (${duration.toLocaleString().padStart(6)} ms)`) : ''}${no_new_line ? '' : '\n'}`
);
const existsAsync = util.promisify(fs.exists);
const mkdirAsync = util.promisify(fs.mkdir);
const ensureDirectoryExistence = async (filePath) => {
try {
const dirname = Path.dirname(filePath);
if (await existsAsync(dirname)) {
return;
}
await ensureDirectoryExistence(dirname);
await mkdirAsync(dirname);
} catch (e) {
//
}
};
const readFileAsync = util.promisify(fs.readFile);
exports.readFile = (path) => readFileAsync(path, 'utf8');
const writefileAsync = util.promisify(fs.writeFile);
exports.writeFile = async (path, data) => {
await ensureDirectoryExistence(path);
return writefileAsync(path, data);
};
exports.isExcluded = (excludes, lang) => {
if (excludes && !/^ACH$/i.test(lang)) {
const language_is_excluded = new RegExp(lang, 'i').test(excludes);
return /^NOT-/i.test(excludes) ? !language_is_excluded : language_is_excluded;
}
return false;
};