Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 134bdd3

Browse files
committed
setup
1 parent d0d9d49 commit 134bdd3

18 files changed

+2189
-2
lines changed

.eslintrc.json

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
11+
],
12+
"overrides": [
13+
{
14+
"files": ["*.js", "*.d.ts"],
15+
"parserOptions": {
16+
"project": "./tsconfig.json",
17+
"tsconfigRootDir": "./"
18+
},
19+
"rules": {}
20+
}
21+
],
22+
"parser": "@typescript-eslint/parser",
23+
"parserOptions": {
24+
"project": "./tsconfig.json",
25+
"tsconfigRootDir": "./"
26+
},
27+
"plugins": ["@typescript-eslint"],
28+
"rules": {
29+
"semi": ["warn", "never"],
30+
"prefer-const": "warn",
31+
"no-mixed-spaces-and-tabs": "off",
32+
"@typescript-eslint/no-explicit-any": "off",
33+
"@typescript-eslint/no-floating-promises": ["error", { "ignoreVoid": true }],
34+
"@typescript-eslint/array-type": ["warn", { "default": "array-simple" }],
35+
"@typescript-eslint/ban-types": "warn",
36+
"@typescript-eslint/consistent-indexed-object-style": ["warn", "record"],
37+
"@typescript-eslint/consistent-generic-constructors": "warn",
38+
"@typescript-eslint/naming-convention": [
39+
"warn",
40+
{
41+
"selector": "class",
42+
"format": ["PascalCase"]
43+
},
44+
{
45+
"selector": ["classProperty", "classMethod"],
46+
"format": ["camelCase"]
47+
},
48+
{
49+
"selector": ["classProperty", "classMethod"],
50+
"filter": {
51+
"regex": "^_.*$",
52+
"match": true
53+
},
54+
"prefix": ["_"],
55+
"format": ["camelCase"]
56+
},
57+
{
58+
"selector": "typeProperty",
59+
"format": null
60+
},
61+
{
62+
"selector": "variable",
63+
"modifiers": ["const"],
64+
"format": null
65+
},
66+
{
67+
"selector": "variable",
68+
"modifiers": ["const", "destructured"],
69+
"format": ["camelCase", "PascalCase", "UPPER_CASE"]
70+
},
71+
{
72+
"selector": "variable",
73+
"modifiers": ["const", "global"],
74+
"format": ["UPPER_CASE"]
75+
},
76+
{
77+
"selector": "variable",
78+
"modifiers": ["const", "global"],
79+
"filter": {
80+
"regex": "^_.*$",
81+
"match": true
82+
},
83+
"prefix": ["_"],
84+
"format": ["UPPER_CASE"]
85+
},
86+
{
87+
"selector": "variable",
88+
"modifiers": ["const", "global"],
89+
"types": ["function"],
90+
"format": ["camelCase", "UPPER_CASE"]
91+
},
92+
{
93+
"selector": "variable",
94+
"modifiers": ["const", "global", "exported"],
95+
"format": ["camelCase", "UPPER_CASE"]
96+
},
97+
{ "selector": "variableLike", "format": ["camelCase"] },
98+
{ "selector": "interface", "format": ["PascalCase"] },
99+
{
100+
"selector": "interface",
101+
"modifiers": ["exported"],
102+
"format": ["PascalCase"],
103+
"prefix": ["I"]
104+
},
105+
{ "selector": "typeLike", "format": ["PascalCase"] },
106+
{ "selector": "objectLiteralProperty", "format": null },
107+
{ "selector": "default", "format": ["camelCase"] }
108+
],
109+
"@typescript-eslint/no-unsafe-member-access": "off",
110+
"@typescript-eslint/no-unsafe-assignment": "off",
111+
"@typescript-eslint/ban-ts-comment": "off",
112+
"@typescript-eslint/require-await": "warn",
113+
"@typescript-eslint/no-unsafe-call": "off",
114+
"@typescript-eslint/unbound-method": "off",
115+
"@typescript-eslint/no-non-null-assertion": "off"
116+
}
117+
}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.prettierrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json.schemastore.org/prettierrc",
3+
"tabWidth": 4,
4+
"useTabs": true,
5+
"semi": false,
6+
"singleQuote": true,
7+
"arrowParens": "avoid",
8+
"printWidth": 100
9+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Animated Java
3+
Copyright (c) 2022 SnaveSutit
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
# animated-java-exporter-plugin-template
1+
# Blockbench Plugin Template
2+
A TypeScript & ESBuild Blockbench plugin template.
3+
4+
Includes everything you need to get started and more with Blockbench plugin development!
5+
6+
## Utilities
7+
- SnaveSutit/blockbench-types - The most up-to-date Blockbench types available, improvements and fixes almost every week!
8+
9+
- util/console - Adds a couple functions for wrapping the console output of a function in a console group without having to remember to open and close it properly.
10+
11+
- util/subscribable - A simple typed subscribable class.
12+
13+
- util/moddingTools - A library of tools that make modding Blockbench much easier. From the simple action of creating an .. Action, to the advanced trickery of injecting custom code into built-in class functions. This library will be super helpful to practically anyone attempting to build a plugin!
14+
15+
- util/events - A simple event manager. that provides much better type completion than the built-in one in Blockbench.
16+
17+
## Setup
18+
- Create a new repo using this template
19+
- Run `yarn` to initialize the development enviornment
20+
- Configure the package.json to use your information
21+
- Configure the plugin definition in `index.ts`
22+
- Rename the global variable in `global.d.ts` to match your plugin's name
23+
24+
## Build commands
25+
- `yarn build:dev` - Builds in dev mode and watches for file changes
26+
- `yarn build:prod` - Builds a production version of the plugin and exits
27+
- `yarn format` - Formats all of the source files using Prettier

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "animated_java_exporter_plugin_template",
3+
"title": "Animated Java Exporter Plugin Template",
4+
"version": "1.0.0",
5+
"tags": [
6+
"Tag A",
7+
"Tag B",
8+
"Tag C"
9+
],
10+
"min_blockbench_version": "4.2.0",
11+
"author": {
12+
"name": "SnaveSutit",
13+
"email": "snavesutit@gmail.com",
14+
"url": "https://discordapp.com/users/213746232923783168"
15+
},
16+
"repository": {
17+
"type": "github",
18+
"url": "https://github.com/animated-java/animated-java-exporter-plugin-template"
19+
},
20+
"description": "An Animated Java Exporter plugin template",
21+
"main": "./dist/index.js",
22+
"types": "./dist/src/index.d.ts",
23+
"private": true,
24+
"scripts": {
25+
"build:scripts": "esbuild --bundle --platform=node --outfile=dist/build.cjs --packages=external ./tools/esbuild.ts",
26+
"build:dev": "yarn build:scripts && node ./dist/build.cjs --mode=dev",
27+
"build:prod": "yarn build:scripts && node ./dist/build.cjs",
28+
"format": "prettier --write ."
29+
},
30+
"devDependencies": {
31+
"@types/eslint": "^8.21.1",
32+
"@types/node": "^17.0.21",
33+
"@typescript-eslint/eslint-plugin": "^5.54.0",
34+
"@typescript-eslint/parser": "^5.54.0",
35+
"animated-java-api-types": "https://github.com/Animated-Java/animated-java-api-types.git",
36+
"blockbench-types": "https://github.com/SnaveSutit/blockbench-types.git",
37+
"esbuild": "^0.17.10",
38+
"eslint": "^8.35.0",
39+
"prettier": "^2.5.1",
40+
"ts-loader": "^9.2.6",
41+
"typescript": "^4.5.5",
42+
"vue": "^3.2.33"
43+
},
44+
"dependencies": {},
45+
"license": "MIT"
46+
}

src/exporter.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @ts-ignore
2+
import en from './lang/en.yaml'
3+
4+
export function loadExporter() {
5+
const API = AnimatedJava.API
6+
7+
API.addTranslations('en', en as Record<string, string>)
8+
9+
new API.Exporter({
10+
id: 'snavesutit:unnamed_exporter',
11+
name: API.translate('snavesutit.unnamed_exporter.name'),
12+
description: API.translate('snavesutit.unnamed_exporter.description'),
13+
getSettings() {
14+
return {
15+
foo: new API.Settings.CheckboxSetting({
16+
id: 'snavesutit:unnamed_exporter/foo',
17+
displayName: API.translate('snavesutit.unnamed_exporter.settings.foo'),
18+
description: API.translate(
19+
'snavesutit.unnamed_exporter.settings.foo.description'
20+
).split('\n'),
21+
defaultValue: false,
22+
}),
23+
}
24+
},
25+
settingsStructure: [
26+
{
27+
type: 'setting',
28+
settingId: 'snavesutit:unnamed_exporter/foo',
29+
},
30+
],
31+
async export(ajSettings, projectSettings, exporterSettings) {
32+
console.log(ajSettings, projectSettings, exporterSettings)
33+
await new Promise(resolve => setTimeout(resolve, 100))
34+
},
35+
})
36+
}

src/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as events from './util/events'
2+
3+
declare global {
4+
const BlockbenchPluginTemplate: {
5+
events: typeof events
6+
}
7+
}

src/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as PACKAGE from '../package.json'
2+
import { consoleGroupCollapsed } from './util/console'
3+
import * as events from './util/events'
4+
import './util/moddingTools'
5+
6+
//-------------------------------
7+
// Import your source files here
8+
//-------------------------------
9+
import { loadExporter } from './exporter'
10+
11+
// Expose this plugin's events globally and to other plugins
12+
// @ts-ignore
13+
globalThis.BlockbenchPluginTemplate = {
14+
events: events,
15+
}
16+
17+
events.LOAD.subscribe(() => {
18+
requestAnimationFrame(function repeat() {
19+
if (AnimatedJava?.loaded) loadExporter()
20+
else requestAnimationFrame(repeat)
21+
})
22+
})
23+
24+
BBPlugin.register(PACKAGE.name, {
25+
title: PACKAGE.title,
26+
author: PACKAGE.author.name,
27+
description: PACKAGE.description,
28+
icon: 'create_session',
29+
variant: 'desktop',
30+
version: PACKAGE.version,
31+
min_version: PACKAGE.min_blockbench_version,
32+
tags: PACKAGE.tags as [string, string, string],
33+
onload: consoleGroupCollapsed(`${PACKAGE.name}:onload`, () => {
34+
events.LOAD.dispatch()
35+
}),
36+
onunload: consoleGroupCollapsed(`${PACKAGE.name}:onunload`, () => {
37+
events.UNLOAD.dispatch()
38+
}),
39+
oninstall: consoleGroupCollapsed(`${PACKAGE.name}:oninstall`, () => {
40+
events.INSTALL.dispatch()
41+
}),
42+
onuninstall: consoleGroupCollapsed(`${PACKAGE.name}:onuninstall`, () => {
43+
events.UNINSTALL.dispatch()
44+
}),
45+
})

src/lang/en.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
snavesutit.unnamed_exporter.name: Unnamed Exporter
2+
3+
snavesutit.unnamed_exporter.settings.foo: Foo
4+
snavesutit.unnamed_exporter.settings.foo.description: |-
5+
Foo is a setting that does something.

0 commit comments

Comments
 (0)