Skip to content

Commit

Permalink
[v1.8.0] Merge pull request #374 from bridge-core/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelant05 authored Jul 18, 2021
2 parents 5fd05c6 + e95479c commit 667e82e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 81 deletions.
18 changes: 6 additions & 12 deletions app/renderer/src/UI/Windows/Migration/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import { ipcRenderer, shell } from 'electron'
import LoadingWindow from '../../../../windows/LoadingWindow'
import { createV2Directory } from './create'
import { promises as fs } from 'fs'
import { createInformationWindow } from '../Common/CommonDefinitions'
import { join } from 'path'
export default {
Expand All @@ -112,13 +111,16 @@ export default {
},
async onConfirm() {
const lw = new LoadingWindow()
await createV2Directory(this.projectPath, this.selectedProjects)
await createV2Directory(
this.projectPath,
this.selectedProjects
)
lw.close()
this.projectsCreated = true
},
goToV2() {
shell.openExternal('https://bridge-core.github.io/editor')
shell.openExternal('https://editor.bridge-core.app')
this.currentWindow.close()
},
showProjects() {
Expand All @@ -139,16 +141,8 @@ export default {
lw.close()
// Ensure chosen directory is empty
if (path[0]) {
fs.readdir(path[0]).then(files => {
if (files.length > 0)
createInformationWindow(
'Invalid directory',
'Please select an empty directory!'
)
else this.projectPath = path[0]
})
this.projectPath = path[0]
}
},
},
Expand Down
152 changes: 85 additions & 67 deletions app/renderer/src/UI/Windows/Migration/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ async function iterateDir(src: string, dest: string, cache: string) {
const { cache_content: cacheContent } = await readJSON(
join(cache, dirent.name)
)

await writeJSON(
join(dest, dirent.name),
transform(cacheContent.children),
Expand All @@ -41,20 +40,25 @@ async function iterateDir(src: string, dest: string, cache: string) {
}

function transform(children: any[]) {
const res: any = {}
let res: any = {}
let resArr: any[] = []

if (!children) return {}

for (const c of children) {
if (c.is_disabled) continue
if (c.is_minified) res[c.key] = c.data || c.children || c.array
else if (Array.isArray(c.children)) {
if (c.key === undefined) res.push(transform(c.children))
res[c.key] = transform(c.children)
} else if (c.key && c.data) {

if (c.is_minified && !c.key) resArr.push(c.children)
else if (c.is_minified && c.key)
res[c.key] = c.data || c.children || c.array
else if (Array.isArray(c.children)) res[c.key] = transform(c.children)
else if (c.key && c.data) {
if (c.key == 'format_version') res[c.key] = c.data
else res[c.key] = convertValues(c.data)
}
} else if (c.array) res[c.key] = transform(c.array)
}
return res

return resArr.length > 0 ? resArr : res
}

function convertValues(value: string) {
Expand All @@ -71,15 +75,18 @@ function updateConfig(
config: any,
bpManifest: any,
projectName: string,
lang: string
lang: string,
hasRP: boolean
) {
let newConfig: any = {
type: 'minecraftBedrock',
packs: {
behaviorPack: './BP',
resourcePack: './RP',
resourcePack: hasRP ? './RP' : undefined,
},
bridge: {
v1CompatMode: true,
},
bridge: {},
capabilities: [],
}
if (config) {
Expand Down Expand Up @@ -122,24 +129,28 @@ export async function createV2Directory(
targetPath: string,
projects: string[]
) {
const projectPath = join(targetPath, 'projects')

for (const bpPath of projects) {
const targetProject = join(targetPath, 'projects', bpPath)

try {
// If project already exists in target directory, don't copy it over
await fs.access(targetProject)
continue
} catch {}

// Find linked RP
let rpPath = undefined
let bpManifest = undefined
let rpManifest = undefined
let projectConfig = undefined
let lang = undefined

// Get linked RP
try {
bpManifest = await readJSON(
join(BP_BASE_PATH, bpPath, 'manifest.json')
)
} catch {}

if (bpManifest) {
// Check RPs
const resourcePacks = await fs.readdir(RP_BASE_PATH)
for (const rp of resourcePacks) {
try {
Expand All @@ -156,20 +167,20 @@ export async function createV2Directory(
}
}
}
}
} catch {} // No dependencies

// Copy BP files over
await iterateDir(
join(BP_BASE_PATH, bpPath),
join(targetPath, 'projects', bpPath, 'BP'),
join(targetProject, 'BP'),
join(BP_BASE_PATH, bpPath, 'bridge/cache/BP')
)

// Copy RP files over if a linked RP exists
if (rpPath) {
await iterateDir(
join(RP_BASE_PATH, rpPath),
join(targetPath, 'projects', bpPath, 'RP'),
join(targetProject, 'RP'),
join(BP_BASE_PATH, bpPath, 'bridge/cache/RP')
)
}
Expand All @@ -188,19 +199,20 @@ export async function createV2Directory(
} catch {}

await writeJSON(
join(targetPath, 'projects', bpPath, 'config.json'),
join(targetProject, 'config.json'),
updateConfig(
projectConfig,
bpManifest,
bpPath.replace(/BP|behaviors/gi, ''),
lang
lang,
rpPath ? true : false
),
true
)

// Create other project files
await fs.writeFile(
join(targetPath, 'projects', bpPath, '.gitignore'),
join(targetProject, '.gitignore'),
`Desktop.ini
.DS_Store
!.bridge/
Expand All @@ -212,30 +224,25 @@ builds
`
)

await fs.mkdir(
join(targetPath, 'projects', bpPath, '.bridge/compiler'),
{ recursive: true }
)
await fs.mkdir(join(targetProject, '.bridge/compiler'), {
recursive: true,
})
await writeJSON(
join(
targetPath,
'projects',
bpPath,
'.bridge/compiler/default.json'
),
join(targetProject, '.bridge/compiler/default.json'),
{
icon: 'mdi-cogs',
name: 'Deafult Script',
name: '[Default Script]',
description:
'Transforms the "bridge." folder structure to "com.mojang". "bridge." runs it automatically in dev mode in the background to enable fast, incremental builds for testing.',
'[Transforms the "bridge." folder structure to "com.mojang". "bridge." runs it automatically in dev mode in the background to enable fast, incremental builds for testing. Includes bridge. v1 backwards compatibility.]',
plugins: [
'typeScript',
'customEntitySyntax',
'entityIdentifierAlias',
'customEntityComponents',
['customEntityComponents', { v1CompatMode: true }],
'customItemComponents',
'customBlockComponents',
['customBlockComponents', { v1CompatMode: true }],
'customEntitySyntax',
'moLang',
['customCommands', { v1CompatMode: true }],
['simpleRewrite', { packName: `${bpPath} v2` }],
],
},
Expand All @@ -246,37 +253,48 @@ builds
const EXTENSION_PATH = 'https://bridge-core.github.io/plugins/plugins'
const GLOBAL_EXTENSIONS_PATH = join(targetPath, 'extensions')

await fetch(join(EXTENSION_PATH, CUSTOM_ENTITY_SYNTAX_EXTENSION))
.then(data => data.arrayBuffer())
.then(async data => {
const EXT_PATH = join(
GLOBAL_EXTENSIONS_PATH,
'CustomEntitySyntax'
)

await fs.mkdir(
join(GLOBAL_EXTENSIONS_PATH, 'CustomEntitySyntax'),
{ recursive: true }
)
await fs.writeFile(
join(
// If the extension already exists, don't install it
try {
await fs.access(join(GLOBAL_EXTENSIONS_PATH, 'CustomEntitySyntax'))
} catch {
await fetch(join(EXTENSION_PATH, CUSTOM_ENTITY_SYNTAX_EXTENSION))
.then(data => data.arrayBuffer())
.then(async data => {
const EXT_PATH = join(
GLOBAL_EXTENSIONS_PATH,
CUSTOM_ENTITY_SYNTAX_EXTENSION
),
new Buffer(data)
)
'CustomEntitySyntax'
)

await createReadStream(
join(GLOBAL_EXTENSIONS_PATH, CUSTOM_ENTITY_SYNTAX_EXTENSION)
)
.pipe(unzipper.Extract({ path: EXT_PATH }))
.promise()
await fs.mkdir(
join(GLOBAL_EXTENSIONS_PATH, 'CustomEntitySyntax'),
{ recursive: true }
)
await fs.writeFile(
join(
GLOBAL_EXTENSIONS_PATH,
CUSTOM_ENTITY_SYNTAX_EXTENSION
),
new Buffer(data)
)

await fs.unlink(
join(GLOBAL_EXTENSIONS_PATH, CUSTOM_ENTITY_SYNTAX_EXTENSION)
)
await fs.writeFile(join(EXT_PATH, '.installed'), '')
})
.catch(console.error)
await createReadStream(
join(
GLOBAL_EXTENSIONS_PATH,
CUSTOM_ENTITY_SYNTAX_EXTENSION
)
)
.pipe(unzipper.Extract({ path: EXT_PATH }))
.promise()

await fs.unlink(
join(
GLOBAL_EXTENSIONS_PATH,
CUSTOM_ENTITY_SYNTAX_EXTENSION
)
)
await fs.writeFile(join(EXT_PATH, '.installed'), '')
})
.catch(console.error)
}
}
}
2 changes: 1 addition & 1 deletion app/shared/app_version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Current bridge. app version
*/
export default 'v1.8.0-pre1'
export default 'v1.8.0'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bridge",
"version": "1.8.0-pre1",
"version": "1.8.0",
"private": true,
"author": "solvedDev <[email protected]>",
"description": "A powerful add-on editor",
Expand Down

0 comments on commit 667e82e

Please sign in to comment.