|
1 | 1 | import { join } from 'path';
|
2 | 2 | import { writeFileSync, readFileSync } from 'fs';
|
3 |
| -import { createIfNotExist, getAllDirs } from './utils/utils.mjs'; |
| 3 | +import { getAllDirs } from './utils/utils.mjs'; |
| 4 | +import { node } from 'utils'; |
4 | 5 |
|
5 | 6 | const STATIC_DATA_FOLDER = './static_data';
|
6 | 7 | const RAW_DATA_FILE_NAME = 'raw_data.json';
|
7 | 8 | const DIST_DATA_FILE_NAME = 'data.json';
|
8 | 9 |
|
9 | 10 | function uglifyFileContent(content) {
|
10 |
| - const uglifiedContent = content.replace(/("[^"]*")|\s/g, (match, group1) => { |
11 |
| - if (group1) { |
12 |
| - return group1; |
13 |
| - } |
14 |
| - return ''; |
15 |
| - }); |
16 |
| - |
17 |
| - return uglifiedContent; |
| 11 | + const uglifiedContent = content.replace(/("[^"]*")|\s/g, (match, group1) => { |
| 12 | + if (group1) { |
| 13 | + return group1; |
| 14 | + } |
| 15 | + return ''; |
| 16 | + }); |
| 17 | + |
| 18 | + return uglifiedContent; |
18 | 19 | }
|
19 | 20 |
|
20 | 21 | function processFile(inputFilePath, outputFilePath) {
|
21 |
| - try { |
22 |
| - const content = readFileSync(inputFilePath, 'utf-8'); |
23 |
| - const uglifiedContent = uglifyFileContent(content); |
24 |
| - |
25 |
| - writeFileSync(outputFilePath, uglifiedContent, 'utf-8'); |
26 |
| - console.log(`Data of ${inputFilePath} file prepared`); |
27 |
| - } catch (error) { |
28 |
| - console.error('Error:', error.message); |
29 |
| - } |
| 22 | + try { |
| 23 | + const content = readFileSync(inputFilePath, 'utf-8'); |
| 24 | + const uglifiedContent = uglifyFileContent(content); |
| 25 | + |
| 26 | + writeFileSync(outputFilePath, uglifiedContent, 'utf-8'); |
| 27 | + console.log(`Data of ${inputFilePath} file prepared`); |
| 28 | + } catch (error) { |
| 29 | + console.error('Error:', error.message); |
| 30 | + } |
30 | 31 | }
|
31 | 32 |
|
32 | 33 | function prepareProjects(projectsFolders) {
|
33 |
| - projectsFolders.forEach(projectFolder => { |
34 |
| - const distFolder = join(projectFolder, 'dist'); |
| 34 | + projectsFolders.forEach(projectFolder => { |
| 35 | + const distFolder = join(projectFolder, 'dist'); |
35 | 36 |
|
36 |
| - createIfNotExist(distFolder); |
37 |
| - const inputFilePath = join(projectFolder, RAW_DATA_FILE_NAME); |
38 |
| - const outputFilePath = join(distFolder, DIST_DATA_FILE_NAME); |
| 37 | + node.createFolderRecursiveIfNoExist(distFolder); |
| 38 | + const inputFilePath = join(projectFolder, RAW_DATA_FILE_NAME); |
| 39 | + const outputFilePath = join(distFolder, DIST_DATA_FILE_NAME); |
39 | 40 |
|
40 |
| - processFile(inputFilePath, outputFilePath); |
41 |
| - }); |
| 41 | + processFile(inputFilePath, outputFilePath); |
| 42 | + }); |
42 | 43 | }
|
43 | 44 |
|
44 | 45 | (function main() {
|
45 |
| - const allProjectsFolders = getAllDirs(STATIC_DATA_FOLDER); |
| 46 | + const allProjectsFolders = getAllDirs(STATIC_DATA_FOLDER); |
46 | 47 |
|
47 |
| - prepareProjects(allProjectsFolders); |
| 48 | + prepareProjects(allProjectsFolders); |
48 | 49 | })();
|
0 commit comments