Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: bun install --frozen-lockfile

- name: Build
run: bun run build
run: bun run prod

- name: Run tests
run: bun test
174 changes: 55 additions & 119 deletions .scripts/plugins/packagerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { Plugin } from 'esbuild'
import * as fs from 'fs'
import { readFileSync, writeFileSync } from 'fs'
import { basename, join } from 'node:path'
import { Octokit } from 'octokit'
import * as prettier from 'prettier'
import { sveltePreprocess } from 'svelte-preprocess'
// @ts-expect-error - Types are broken in nodenext for this package, but it works fine.
import { typescript } from 'svelte-preprocess-esbuild'
Expand All @@ -13,16 +11,12 @@ import { render } from 'svelte/server'
// @ts-expect-error - Svelte's internal server-side rendering API is not typed, but we need it to render the about.svelte file at build time.
import * as svelteInternalServer from 'svelte/internal/server'

const OCTO_KIT = new Octokit({})

const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
const PLUGIN_PACKAGE_PATH = './src/pluginPackage/'
const SVELTE_FILE = './src/pluginPackage/about.svelte'
const README_DIST_PATH = './dist/pluginPackage/about.md'
const DIST_PATH = './dist/'
const DIST_PACKAGE_PATH = './dist/pluginPackage/'
const PLUGIN_REPO_PATH = 'D:/github-repos/snavesutit/blockbench-plugins/plugins/animated_java'
const PLUGIN_MANIFEST_PATH = 'D:/github-repos/snavesutit/blockbench-plugins/plugins.json'
const CHANGELOG_PATH = './src/pluginPackage/changelog.json'
const RELEASE_NOTES_TEMPLATES = './.scripts/plugins/releaseNoteTemplates/'
const URL_REGEX =
Expand All @@ -32,18 +26,6 @@ function replaceTemplateVars(str: string, items: Record<string, string>) {
return str.replace(/\{(.+?)\}/g, str => items[str.replace(/[\{\}]/g, '')] ?? str)
}

const VERSION_REGEX = /(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9]+))?/

function getVersionNumbers(version: string) {
const match = VERSION_REGEX.exec(version)
if (!match) return null
const major = parseInt(match[1])
const minor = parseInt(match[2])
const patch = parseInt(match[3])
const preRelease = match[4] ?? null
return { major, minor, patch, preRelease }
}

/**
* Convert a warning or error emitted from the svelte compiler for esbuild.
*/
Expand Down Expand Up @@ -160,114 +142,68 @@ function plugin(): Plugin {
fs.unlinkSync(join(DIST_PACKAGE_PATH, 'about.svelte'))

if (process.env.NODE_ENV === 'production') {
try {
console.log('📝 Creating changelogs...')
const rawChangelog = fs.readFileSync(CHANGELOG_PATH, 'utf-8')
const changelog = JSON.parse(rawChangelog)
for (const file of fs.readdirSync(RELEASE_NOTES_TEMPLATES)) {
let content = fs.readFileSync(
join(RELEASE_NOTES_TEMPLATES, file),
'utf-8'
)
let pings = ''
const version = getVersionNumbers(PACKAGE.version)
if (!version) {
throw new Error(
`Version ${PACKAGE.version} in package.json is not valid semver!`
)
}
const latestRelease = getVersionNumbers(
(
await OCTO_KIT.request('GET /repos/{owner}/{repo}/releases', {
owner: 'animated-java',
repo: 'animated-java',
per_page: 1,
headers: {
accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
},
})
).data[0].tag_name
console.log('📝 Creating changelogs...')
const rawChangelog = fs.readFileSync(CHANGELOG_PATH, 'utf-8')
const changelog = JSON.parse(rawChangelog)
for (const file of fs.readdirSync(RELEASE_NOTES_TEMPLATES)) {
let content = fs.readFileSync(join(RELEASE_NOTES_TEMPLATES, file), 'utf-8')

const versionChangelog = changelog[PACKAGE.version]
if (!versionChangelog) {
console.warn(
`⚠️ No changelog found for version ${PACKAGE.version} in ${CHANGELOG_PATH}`
)
if (!latestRelease) {
throw new Error('No latest release found on github!')
}
if (version.major > latestRelease.major) {
pings += `@Major Release Ping`
}
if (version.minor > latestRelease.minor) {
pings += ` @Minor Release Ping`
}
if (version.patch > latestRelease.patch) {
pings += ` @Patch Release Ping`
}
if (latestRelease.preRelease) {
pings += ` @Pre-Release Ping`
}
if (rawChangelog.includes('[BREAKING]')) {
pings += ` @Breaking Changes Ping`
}

const versionChangelog = changelog[PACKAGE.version]
if (!versionChangelog) {
throw new Error(
`No changelog found for version ${PACKAGE.version} in ${CHANGELOG_PATH}`
)
}

let categories = ''
for (const category of versionChangelog.categories) {
categories +=
`\n\n### ${category.title}\n\n` +
category.list
.map((v: string) => '- ' + v)
.join('\n')
.replaceAll('[BREAKING]', '⚠️ **BREAKING** —')
}
return
}

content = replaceTemplateVars(content, {
version: PACKAGE.version,
categories: categories.trim(),
pings: pings.trim(),
})
let categories = ''
for (const category of versionChangelog.categories) {
categories +=
`\n\n### ${category.title}\n\n` +
category.list
.map((v: string) => '- ' + v)
.join('\n')
.replaceAll('[BREAKING]', '⚠️ **BREAKING** —')
}

if (content.includes('[[ESCAPE_URLS]]')) {
content = content
.replace('[[ESCAPE_URLS]]', '')
.replaceAll(URL_REGEX, (match: string) => '<' + match + '>')
}
content = replaceTemplateVars(content, {
version: PACKAGE.version,
categories: categories.trim(),
})

fs.writeFileSync(join(DIST_PATH, file), content)
if (content.includes('[[ESCAPE_URLS]]')) {
content = content
.replace('[[ESCAPE_URLS]]', '')
.replaceAll(URL_REGEX, (match: string) => '<' + match + '>')
}
} catch (e) {
console.error('Error creating changelogs:', e)
throw e
}

if (fs.existsSync(PLUGIN_REPO_PATH)) {
fs.rmSync(PLUGIN_REPO_PATH, { recursive: true, force: true })
fs.cpSync(DIST_PACKAGE_PATH, PLUGIN_REPO_PATH, { recursive: true })
const manifest = JSON.parse(fs.readFileSync(PLUGIN_MANIFEST_PATH, 'utf-8'))
manifest.animated_java.title = PACKAGE.title
manifest.animated_java.author = PACKAGE.author.name
manifest.animated_java.icon = PACKAGE.icon
manifest.animated_java.description = PACKAGE.description
manifest.animated_java.version = PACKAGE.version
manifest.animated_java.min_version = PACKAGE.min_blockbench_version
manifest.animated_java.max_version = PACKAGE.max_blockbench_version
manifest.animated_java.variant = PACKAGE.variant
manifest.animated_java.tags = PACKAGE.tags
manifest.animated_java.has_changelog = true

fs.writeFileSync(
PLUGIN_MANIFEST_PATH,
await prettier.format(JSON.stringify(manifest, null, '\t'), {
useTabs: true,
parser: 'json',
})
)
console.log('📋 Copied to Plugin Repo!')
fs.writeFileSync(join(DIST_PATH, file), content)
}

// if (fs.existsSync(PLUGIN_REPO_PATH)) {
// fs.rmSync(PLUGIN_REPO_PATH, { recursive: true, force: true })
// fs.cpSync(DIST_PACKAGE_PATH, PLUGIN_REPO_PATH, { recursive: true })
// const manifest = JSON.parse(fs.readFileSync(PLUGIN_MANIFEST_PATH, 'utf-8'))
// manifest.animated_java.title = PACKAGE.title
// manifest.animated_java.author = PACKAGE.author.name
// manifest.animated_java.icon = PACKAGE.icon
// manifest.animated_java.description = PACKAGE.description
// manifest.animated_java.version = PACKAGE.version
// manifest.animated_java.min_version = PACKAGE.min_blockbench_version
// manifest.animated_java.max_version = PACKAGE.max_blockbench_version
// manifest.animated_java.variant = PACKAGE.variant
// manifest.animated_java.tags = PACKAGE.tags
// manifest.animated_java.has_changelog = true

// fs.writeFileSync(
// PLUGIN_MANIFEST_PATH,
// await prettier.format(JSON.stringify(manifest, null, '\t'), {
// useTabs: true,
// parser: 'json',
// })
// )
// console.log('📋 Copied to Plugin Repo!')
// }
}
})
},
Expand Down
27 changes: 12 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ Contributions are always welcome, however, please consult @SnaveSutit before sta

### 🛠️ Prerequisites

- #### Required
- #### Required
- [Bun](https://bun.sh/)
- [Git](https://git-scm.com/)

- [Node.js](https://nodejs.org/en/)
- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/#windows-stable)
- [Git](https://git-scm.com/)

- #### Recommended

- [VSCode](https://code.visualstudio.com/)
- #### Recommended
- [VSCode](https://code.visualstudio.com/)
> (or any other code editor, but this project has configurations for VSCode)
- [Blockbench](https://www.blockbench.net/)
- [Blockbench](https://www.blockbench.net/)
> The repository includes [Envbench](https://github.com/SnaveSutit/envbench) to create and manage a dev instance of Blockbench, So installing Blockbench separately is not strictly required.
- [SnaveSutit's Blockbench Types](https://github.com/SnaveSutit/blockbench-types)
> Bleeding edge types for Blockbench plugins.<br/>Install via `yarn add -D https://github.com/SnaveSutit/blockbench-types.git`
- [GitButler](https://gitbutler.com/)
- [SnaveSutit's Blockbench Types](https://github.com/SnaveSutit/blockbench-types)
> Bleeding edge types for Blockbench plugins.<br/>Install via `bun add -D https://github.com/SnaveSutit/blockbench-types.git`
- [GitButler](https://gitbutler.com/)
> A Git client for simultaneous branches on top of your existing workflow.

## 🖇️ Cloning the Repository
Expand All @@ -34,7 +31,7 @@ Contributions are always welcome, however, please consult @SnaveSutit before sta

> [How do I clone a repository?](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)

2. Run `yarn install` to install dependencies.
2. Run `bun install` to install dependencies.

3. Open up `src/blockbenchTypes.d.ts` and replace the first line with the following:

Expand All @@ -44,9 +41,9 @@ Contributions are always welcome, however, please consult @SnaveSutit before sta

> By default this references my local fork of the Blockbench types to quickly add / adjust types as needed. So you need to adjust this to the official Blockbench types, or your own fork, if you're not me.

4. Run `yarn dev` to start the development environment, which will watch for changes and recompile the plugin.
4. Run `bun run dev` to start the development environment, which will watch for changes and recompile the plugin.

5. Open a new terminal, or click `Split` if you're in VSCode's terminal, and run `yarn start` to start the development instance of Blockbench.
5. Open a new terminal, or click `Split` if you're in VSCode's terminal, and run `bun run start` to start the development instance of Blockbench.

6. That's it! You're ready to start developing.

Expand Down
8 changes: 4 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"title": "Animated Java",
"icon": "icon.svg",
"description": "Effortlessly craft complex animations for Minecraft: Java Edition",
"version": "1.10.0-beta.5",
"version": "1.10.0-beta.6",
"min_blockbench_version": "5.1.4",
"max_blockbench_version": "5.1.4",
"variant": "desktop",
"tags": [
"Minecraft: Java Edition",
Expand Down Expand Up @@ -93,8 +92,8 @@
"@types/websocket": "^1.0.10",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"blockbench-patch-manager": "^1.0.2",
"book-and-quill": "^1.0.8",
"blockbench-patch-manager": "^1.1.0",
"book-and-quill": "^1.0.9",
"esbuild": "^0.17.10",
"esbuild-plugin-import-folder": "^1.0.1",
"esbuild-plugin-import-glob": "^0.1.1",
Expand Down
19 changes: 14 additions & 5 deletions src/dialogs/blueprintSettings/blueprintSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import GeneralComponent from './pages/general.svelte'
import MiscComponent from './pages/misc.svelte'
import PluginComponent from './pages/plugin.svelte'
import ResourcepackComponent from './pages/resourcepack.svelte'
import RigComponent from './pages/rig.svelte'

const localize = createScopedTranslator('dialog.blueprint_settings')

Expand All @@ -28,17 +29,25 @@ export function openBlueprintSettings() {
label: localize('pages.general.title'),
icon: 'settings',
},
resourcepack: {
component: ResourcepackComponent,
condition: () => Project.pluginMode.get() === false,
label: localize('pages.resource_pack.title'),
icon: 'image',
},
datapack: {
component: DatapackComponent,
condition: () => Project.pluginMode.get() === false,
label: localize('pages.datapack.title'),
icon: 'database',
},
resourcepack: {
component: ResourcepackComponent,
condition: () => Project.pluginMode.get() === false,
label: localize('pages.resource_pack.title'),
icon: 'image',
rig: {
component: RigComponent,
label: localize('pages.rig.title'),
icon: 'fa-person',
condition: () =>
Project.pluginMode.get() === false &&
Project.animated_java.data_pack_export_mode !== 'none',
},
eventFunctions: {
component: EventFunctionsComponent,
Expand Down
Loading
Loading