-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73d0839
commit c5b2943
Showing
6 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,45 @@ | ||
import { join } from 'path'; | ||
import { writeFileSync, readFileSync } from 'fs'; | ||
import { createIfNotExist, getAllDirs } from './utils/utils.mjs'; | ||
|
||
import { createIfNotExist } from './utils/utils.mjs'; | ||
|
||
const projectsInfo = [{ | ||
projectPath: './projects/atm_data', | ||
fileName: 'data.json' | ||
}, { | ||
projectPath: './projects/regions_data', | ||
fileName: 'data.json' | ||
}]; | ||
const STATIC_DATA_FOLDER = './static_data'; | ||
const RAW_DATA_FILE_NAME = 'raw_data.json'; | ||
const DIST_DATA_FILE_NAME = 'data.json'; | ||
|
||
function removeSpacesAndNewlinesOutsideQuotes(inputFilePath, outputFilePath) { | ||
try { | ||
const content = readFileSync(inputFilePath, 'utf-8'); | ||
|
||
const processedContent = content.replace(/("[^"]*")|\s/g, (match, group1) => { | ||
if(group1) { | ||
if (group1) { | ||
return group1; | ||
} | ||
return ''; | ||
}); | ||
|
||
writeFileSync(outputFilePath, processedContent, 'utf-8'); | ||
console.log('Data prepared'); | ||
console.log(`Data of ${inputFilePath} file prepared`); | ||
} catch (error) { | ||
console.error('Error:', error.message); | ||
} | ||
} | ||
|
||
function prepareProjects(projects) { | ||
projects.forEach(project => { | ||
const distFolder = join(project.projectPath, 'dist'); | ||
function prepareProjects(projectsFolders) { | ||
projectsFolders.forEach(projectFolder => { | ||
const distFolder = join(projectFolder, 'dist'); | ||
|
||
createIfNotExist(distFolder); | ||
const inputFilePath = join(project.projectPath, project.fileName); | ||
const outputFilePath = join(distFolder, project.fileName); | ||
|
||
|
||
const inputFilePath = join(projectFolder, RAW_DATA_FILE_NAME); | ||
const outputFilePath = join(distFolder, DIST_DATA_FILE_NAME); | ||
|
||
removeSpacesAndNewlinesOutsideQuotes(inputFilePath, outputFilePath); | ||
}); | ||
} | ||
|
||
function main() { | ||
prepareProjects(projectsInfo); | ||
const allProjectsFolders = getAllDirs(STATIC_DATA_FOLDER); | ||
|
||
prepareProjects(allProjectsFolders); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
import { existsSync, mkdirSync } from 'fs'; | ||
import { existsSync, mkdirSync, readdirSync, lstatSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
const isDirectory = fileName => { | ||
return lstatSync(fileName).isDirectory(); | ||
}; | ||
|
||
export function createIfNotExist(dirPath) { | ||
if (!existsSync(dirPath)){ | ||
mkdirSync(dirPath, { recursive: true }); | ||
} | ||
} | ||
} | ||
|
||
export function getAllDirs(path) { | ||
const files = readdirSync(path); | ||
|
||
return files.map(fileName => { | ||
return join(path, fileName); | ||
}).filter(isDirectory); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.