-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpost-install.js
147 lines (134 loc) · 3.55 KB
/
post-install.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// post-install.js
/**
* Script to run after npm install
*
* Copy selected files to user's directory
*/
'use strict';
const copy = require('recursive-copy');
const sourceAssets = [
'./assets/svgs/barakhadi',
'./assets/svgs/numbers',
'./assets/svgs/barakhadi',
'./assets/svgs/numbers',
'./assets/audio/barakhadi',
'./assets/audio/numbers',
'./assets/audio/barakhadi',
'./assets/audio/numbers',
'./assets/fonts',
'./assets/fonts',
];
const destAssets = [
'./ios/assets/svgs/barakhadi',
'./ios/assets/svgs/numbers',
'./android/app/src/main/assets/svgs/barakhadi',
'./android/app/src/main/assets/svgs/numbers',
'./ios/assets/audio/barakhadi',
'./ios/assets/audio/numbers',
'./android/app/src/main/res/raw',
'./android/app/src/main/res/raw',
'./android/app/src/main/assets/fonts',
'./ios/assets/fonts',
];
for (let i = 0; i < sourceAssets.length; i++) {
const sourceAsset = sourceAssets[i];
const destAsset = destAssets[i];
copy(
sourceAsset,
destAsset,
{
overwrite: true,
expand: true,
dot: true,
junk: true,
debug: true,
filter: path => {
if (i === 6 || i === 7) {
if (!path.includes('.mp3')) {
//Ignore Folder
return null;
}
return `audio_${path.replace('/', '_')}`;
} else {
return path;
}
},
rename: path => {
if (i === 6 || i === 7) {
return `audio_${path.replace('/', '_')}`;
} else {
return path;
}
},
},
error => {
console.log(error);
},
);
}
/*// FOR FUTURE USE
const barakhadiFolder = './assets/test';
const destFolder = './assets/numbers';
const fs = require('fs');
const { XMLParser, XMLBuilder } = require('fast-xml-parser');
const path = require('path');
function modifySVG(filePath) {
const options = {
ignoreAttributes: false,
};
try {
const xmlDataStr = fs.readFileSync(path.resolve(__dirname, filePath));
const parser = new XMLParser(options);
let jsonObj = parser.parse(xmlDataStr);
let groups = jsonObj.svg.g;
if (!Array.isArray(jsonObj.svg.g)) {
groups = [groups];
}
let mappedGroups = groups.map((g, i) => {
const gid = 'g' + i;
return {
...g,
'@_id': gid,
'@_inkscape:label': gid,
path: g.path.map((p, j) => {
const pid = j === 0 ? 'p0' : `s${j - 1}`;
const upid = gid + pid;
return {
...p,
'@_id': upid,
'@_inkscape:label': upid,
};
}),
};
});
jsonObj.svg.g = mappedGroups;
const builder = new XMLBuilder(options);
let xmlDataStr1 = builder.build(jsonObj);
return xmlDataStr1;
} catch (err) {
console.error(err);
return null;
}
}
function getFiles(dir) {
var dirs = fs.readdirSync(dir).filter(v => !v.includes('.DS_Store'));
if (!fs.existsSync(destFolder)) {
fs.mkdirSync(destFolder);
}
for (var i in dirs) {
var current_dir = dir + '/' + dirs[i];
var currentDirName = path.basename(current_dir);
var files = fs.readdirSync(current_dir).filter(v => !v.includes('.DS_Store'));
for (let j = 0; j < files.length; j++) {
const fileName = files[j];
console.log('fileName', fileName);
let newSVGString = modifySVG(current_dir + '/' + fileName);
if (!fs.existsSync(destFolder + '/' + currentDirName)) {
fs.mkdirSync(destFolder + '/' + currentDirName);
}
fs.writeFileSync(destFolder + '/' + fileName, newSVGString);
}
}
}
getFiles(barakhadiFolder);
*/