Skip to content

Commit

Permalink
[v1.8.3] Merge pull request #390 from bridge-core/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelant05 authored Sep 14, 2021
2 parents 04a2cf0 + e205f66 commit 08b1974
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 28 deletions.
20 changes: 12 additions & 8 deletions app/renderer/src/UI/Windows/Migration/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ async function iterateDir(
// Non JSON files: Functions, scripts etc.
if (!dirent.name.endsWith('.json'))
await fs.writeFile(join(dest, dirent.name), cacheContent)

// JSON files
await writeJSON(
join(dest, dirent.name),
transform(cacheContent.children),
true
)
else
await writeJSON(
join(dest, dirent.name),
transform(cacheContent.children),
true
)
} catch {
// No cache, just copy file
try {
Expand Down Expand Up @@ -112,7 +112,6 @@ function updateConfig(
bridge: {
v1CompatMode: true,
},
capabilities: [],
}
if (config) {
const { prefix: projectPrefix, formatVersion: targetVersion } = config
Expand Down Expand Up @@ -154,7 +153,9 @@ export async function createV2Directory(
targetPath: string,
projects: string[]
) {
console.log('[MIGRATION] Start')
for (const bpPath of projects) {
console.log(`[MIGRATION] Migrating project '${bpPath}''`)
const targetProject = join(targetPath, 'projects', bpPath)

try {
Expand Down Expand Up @@ -194,7 +195,7 @@ export async function createV2Directory(
}
} catch {
console.log(
`No resource pack found linked with pack uuid ${bpManifest.uuid}`
`[MIGRATION] No resource pack found linked with pack uuid ${bpManifest.uuid}`
)
} // No dependencies

Expand All @@ -204,6 +205,7 @@ export async function createV2Directory(
join(targetProject, 'BP'),
join(BP_BASE_PATH, bpPath, 'bridge/cache/BP')
)
console.log('[MIGRATION] BP Transfer complete')

// Copy RP files over if a linked RP exists
if (rpPath) {
Expand All @@ -212,6 +214,7 @@ export async function createV2Directory(
join(targetProject, 'RP'),
join(BP_BASE_PATH, bpPath, 'bridge/cache/RP')
)
console.log('[MIGRATION] RP Transfer complete')
}

// Transfer project config
Expand Down Expand Up @@ -349,4 +352,5 @@ builds
await fs.rmdir(join(RP_BASE_PATH, rpPath))
}
}
console.log('[MIGRATION] Complete')
}
42 changes: 36 additions & 6 deletions app/renderer/src/UI/Windows/Project/Chooser/load.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { promises as fs, Dirent } from 'fs'
import { BP_BASE_PATH, MOJANG_PATH, CURRENT } from '../../../../constants'
import {
BP_BASE_PATH,
MOJANG_PATH,
CURRENT,
APP_VERSION,
} from '../../../../constants'
import { join } from 'path'
import { LoadedProjects } from './definition'
import { readJSON } from '../../../../Utilities/JsonFS'
import { readJSON, writeJSON } from '../../../../Utilities/JsonFS'
import Store from '../../../../../store/index'

export async function loadProjects() {
Expand Down Expand Up @@ -37,13 +42,17 @@ export async function loadProjects() {
}

async function loadManifest(projectPath: string) {
let {
header: { version, name, description },
metadata: { author } = { author: 'Unknown' },
} = await readJSON(join(projectPath, 'manifest.json')).catch(() => ({
const manifestPath = join(projectPath, 'manifest.json')
let manifest = await readJSON(manifestPath).catch(() => ({
header: {},
metadata: {},
}))
let {
header: { version, name, description },
metadata: { author } = {
author: 'Unknown',
},
} = manifest

if (description === 'pack.description') {
try {
Expand All @@ -60,6 +69,27 @@ async function loadManifest(projectPath: string) {
} catch {}
}

const appVersion = APP_VERSION.replace('v', '')
const generatedWithBridge: string[] | undefined =
manifest?.metadata?.generated_with?.bridge
if (generatedWithBridge) {
if (!generatedWithBridge.includes(appVersion))
generatedWithBridge.push(appVersion)
} else {
manifest = {
...(manifest ?? {}),
metadata: {
...(manifest?.metadata ?? {}),
generated_with: {
...(manifest?.metadata?.generated_with ?? {}),
bridge: [appVersion],
},
},
}
}

await writeJSON(manifestPath, manifest, true)

return {
version,
name,
Expand Down
8 changes: 5 additions & 3 deletions app/renderer/src/autoCompletions/Dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,11 @@ export const DYNAMIC = {
.map(e =>
e
.replace(
BASE_PATH.replace(/\//g, '\\') +
Store.state.Explorer.project.explorer +
'\\functions\\',
path.join(
BASE_PATH.replace(/\//g, '\\'),
Store.state.Explorer.project.explorer,
'\\functions\\'
),
''
)
.replace(/\\/g, '/')
Expand Down
27 changes: 18 additions & 9 deletions app/renderer/src/files/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uuidv4 from 'uuid/v4'
import ProjectConfig from '../Project/Config'
import path from 'path'
import { APP_VERSION } from '../constants'

interface Module {
type: string
Expand All @@ -21,12 +22,19 @@ interface Dependency {
version: [number, number, number]
uuid: string
}
interface Metadata {
generated_with: {
[tool: string]: string[]
}
author?: string
}

export default class Manifest {
format_version = 2
header: Header
modules: Module[]
dependencies: Dependency[]
metadata: Metadata

constructor(
type: 'resources' | 'data',
Expand All @@ -48,15 +56,9 @@ export default class Manifest {
description: 'pack.description',
uuid: uuidv4(),
version: [1, 0, 0],
min_engine_version: [1, 13, 0],

/**
* Yay, Minecraft doesn't like our new feature... -.-
* Disabled it until it works
*/
// min_engine_version: <[number, number, number]>(
// targetProjectVersion.split('.').map(n => Number(n))
// ),
min_engine_version: <[number, number, number]>(
targetProjectVersion.split('.').map(n => Number(n))
),
}
}
this.modules = [
Expand All @@ -72,6 +74,13 @@ export default class Manifest {
if (dependency !== undefined) {
this.dependencies = [dependency]
}

const appVersion = APP_VERSION.replace('v', '')
this.metadata = {
generated_with: {
bridge: [appVersion],
},
}
}

addClientData() {
Expand Down
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.2'
export default 'v1.8.3'
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.2",
"version": "1.8.3",
"private": true,
"author": "solvedDev <[email protected]>",
"description": "A powerful add-on editor",
Expand Down

0 comments on commit 08b1974

Please sign in to comment.