1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var path_1 = require("path");
|
4 | var Constants = require("../util/constants");
|
5 | var helpers_1 = require("../util/helpers");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function removeUnusedFonts(context) {
|
23 | var fontDir = helpers_1.getStringPropertyValue(Constants.ENV_VAR_FONTS_DIR);
|
24 | return helpers_1.readDirAsync(fontDir).then(function (fileNames) {
|
25 | fileNames = fileNames.sort();
|
26 | var toPurge = getFontFileNamesToPurge(context.target, context.platform, fileNames);
|
27 | var fullPaths = toPurge.map(function (fileName) { return path_1.join(fontDir, fileName); });
|
28 | var promises = fullPaths.map(function (fullPath) { return helpers_1.unlinkAsync(fullPath); });
|
29 | return Promise.all(promises);
|
30 | });
|
31 | }
|
32 | exports.removeUnusedFonts = removeUnusedFonts;
|
33 | function getFontFileNamesToPurge(target, platform, fileNames) {
|
34 | if (target !== Constants.CORDOVA) {
|
35 | return [];
|
36 | }
|
37 | var filesToDelete = new Set();
|
38 | for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
|
39 | var fileName = fileNames_1[_i];
|
40 | if (platform === 'android') {
|
41 |
|
42 | if (fileName.startsWith('noto-sans') || fileName.startsWith('roboto') || (isIonicons(fileName) && !isWoof(fileName))) {
|
43 | filesToDelete.add(fileName);
|
44 | }
|
45 | }
|
46 | else if (platform === 'ios') {
|
47 |
|
48 | if (fileName.startsWith('noto-sans') || (fileName.startsWith('roboto') && !isWoof(fileName)) || (isIonicons(fileName) && !isWoof(fileName))) {
|
49 | filesToDelete.add(fileName);
|
50 | }
|
51 | }
|
52 |
|
53 | }
|
54 | return Array.from(filesToDelete);
|
55 | }
|
56 | exports.getFontFileNamesToPurge = getFontFileNamesToPurge;
|
57 | function isIonicons(fileName) {
|
58 | return fileName.startsWith('ionicons');
|
59 | }
|
60 |
|
61 | function isWoof(fileName) {
|
62 | return path_1.extname(fileName) === '.woff' || path_1.extname(fileName) === '.woff2';
|
63 | }
|