-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Sinetheta/seed
Add project seed task
- Loading branch information
Showing
33 changed files
with
450,121 additions
and
263,643 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as fs from 'fs'; | ||
|
||
import { BExport } from "../../../lib/index"; | ||
|
||
interface BuildMenuItem { | ||
category: number; | ||
buildingId: string; | ||
} | ||
|
||
interface BuildingTranslator { | ||
buildMenuItems: { | ||
from: BuildMenuItem, | ||
to: BuildMenuItem | ||
}[]; | ||
} | ||
|
||
const readJson = (filePath: string) => JSON.parse(fs.readFileSync(filePath).toString()); | ||
const writeJson = (filePath: string, data: object) => fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); | ||
export const updateJsonFile = (filePath: string, mutator: Function) => writeJson(filePath, mutator(readJson(filePath))) | ||
|
||
// Uses a list of "alterations" needed for the build menu items | ||
// Each entry contains an optional from and to. | ||
// No "to" present? Delete the menu item. | ||
// No "from" present? TODO: new building? | ||
// Both present? Update the buildingId accordingly. | ||
export const renameBuildings = (database: BExport, instructionsPath: string) => { | ||
const instructions = readJson(instructionsPath) as BuildingTranslator; | ||
instructions.buildMenuItems.forEach(({ from, to }) => { | ||
const finder = (b: BuildMenuItem) => b.buildingId == from.buildingId; | ||
const menuItem = database.buildMenuItems.find(finder); | ||
if (from && to) { | ||
menuItem!.buildingId = to.buildingId; | ||
} else if (from && !to) { | ||
database.buildMenuItems.splice(database.buildMenuItems.findIndex(finder), 1); | ||
} | ||
}); | ||
return database | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as fs from 'fs'; | ||
import { | ||
copySync // fs.cpSync available in Node v16.7.0 | ||
} from 'fs-extra'; | ||
import path from 'path'; | ||
import AdmZip from 'adm-zip'; | ||
import { BExport } from "../../../lib/index"; | ||
import { FixHtmlLabels } from "./fix-html-labels"; | ||
import { AddInfoIcons } from './add-info-icons'; | ||
import { GenerateIcons } from './generate-icons'; | ||
import { GenerateGroups } from './generate-groups'; | ||
import { GenerateWhite } from './generate-white'; | ||
import { GenerateRepack } from './generate-repack'; | ||
import { renameBuildings, updateJsonFile } from './database-massager'; | ||
|
||
|
||
const projectRoot = path.join(__dirname, '../../../../'); | ||
// Transform project relative path to absolute paths | ||
const absolutePath = (projectPathFromRoot: string) => path.join(projectRoot, projectPathFromRoot); | ||
const databasePath = absolutePath('export/database/database.json'); | ||
// Clean working export dir and unzip extract export.zip | ||
const freshExport = () => { | ||
fs.rmdirSync(absolutePath('export'), { recursive: true }); | ||
const zip = new AdmZip(absolutePath('export.zip')); | ||
zip.extractAllTo(absolutePath('/')); | ||
} | ||
|
||
// Move newly extracted images to the backend images directory | ||
const replaceImages = () => { | ||
fs.rmdirSync(absolutePath('assets/images'), { recursive: true }); | ||
fs.renameSync(absolutePath('export/images'), absolutePath('assets/images')) | ||
copySync(absolutePath('assets/manual'), absolutePath('assets/images')); | ||
} | ||
|
||
const generateDatabase = () => { | ||
new FixHtmlLabels(databasePath); | ||
new AddInfoIcons(databasePath); | ||
updateJsonFile(databasePath, (database: BExport) => { | ||
return renameBuildings(database, absolutePath('assets/manual-buildMenuRename.json')); | ||
}) | ||
} | ||
|
||
const processImages = () => { | ||
new GenerateIcons(databasePath); | ||
new GenerateGroups(databasePath); | ||
new GenerateWhite(databasePath); | ||
new GenerateRepack(databasePath); | ||
} | ||
|
||
const replaceDatabase = () => { | ||
var zip = new AdmZip(); | ||
zip.addLocalFile(databasePath); | ||
zip.writeZip('assets/database/database.zip'); | ||
fs.copyFileSync('assets/database/database.zip', 'frontend/src/assets/database/database.zip'); | ||
fs.copyFileSync('assets/database/database-repack.json', 'frontend/src/assets/database.json'); | ||
} | ||
|
||
export const extractExport = () => { | ||
freshExport(); | ||
replaceImages(); | ||
generateDatabase(); | ||
processImages(); | ||
replaceDatabase(); | ||
} | ||
|
||
// Only execute this script if loaded directly with node | ||
if (require.main === module) { | ||
extractExport(); | ||
console.log('extractExport complete') | ||
} |
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
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
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
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
Oops, something went wrong.