Skip to content

Commit e0c8fa9

Browse files
committed
🚧 Restructure: tools folder
1 parent 41a7b00 commit e0c8fa9

File tree

9 files changed

+33
-28
lines changed

9 files changed

+33
-28
lines changed

svelte.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolve } from 'path'
22
import sveltePreprocess from 'svelte-preprocess'
33
import { typescript } from 'svelte-preprocess-esbuild'
4-
import type { ISvelteESBuildPluginOptions } from './tools/plugins/sveltePlugin'
4+
import type { ISvelteESBuildPluginOptions } from './tools/esbuild-plugins/svelte'
55

66
export const preprocess = [
77
typescript({

tools/plugins/pluginPackagerPlugin.ts renamed to tools/esbuild-plugins/pluginPackager.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ import * as svelteInternal from 'svelte/internal'
88
import type PackageType from '../../package.json'
99
import type ChangelogType from '../../src/plugin/package/changelog.json'
1010

11-
const PLUGIN_PACKAGE_PATH = './src/pluginPackage/'
12-
const SVELTE_FILE = './src/pluginPackage/about.svelte'
13-
const README_DIST_PATH = './dist/pluginPackage/about.md'
14-
const DIST_PATH = './dist/'
15-
const DIST_PACKAGE_PATH = './dist/pluginPackage/'
11+
const SRC = './src/'
12+
const SRC_PACKAGE = pathjs.join(SRC, 'plugin/package/')
13+
const SRC_ABOUT = pathjs.join(SRC_PACKAGE, 'about.svelte')
14+
const SRC_CHANGELOG = pathjs.join(SRC_PACKAGE, 'changelog.json')
15+
16+
const DIST = './dist/'
17+
const DIST_PACKAGE = pathjs.join(DIST, 'package/')
18+
const DIST_README = pathjs.join(DIST_PACKAGE, 'about.md')
19+
1620
const PLUGIN_REPO_PATH = 'D:/github-repos/snavesutit/blockbench-plugins/plugins/animated_java'
1721
const PLUGIN_MANIFEST_PATH = 'D:/github-repos/snavesutit/blockbench-plugins/plugins.json'
18-
const CHANGELOG_PATH = './src/pluginPackage/changelog.json'
19-
const RELEASE_NOTES_TEMPLATES = './tools/plugins/releaseNoteTemplates/'
22+
const RELEASE_NOTES_TEMPLATES = './tools/esbuild-plugins/release-note-templates/'
2023

2124
function replaceTemplateVars(str: string, items: Record<string, string | undefined>) {
2225
return str.replace(/\{(.+?)\}/g, str => items[str.replace(/[\{\}]/g, '')] ?? str)
@@ -32,14 +35,18 @@ function plugin(): Plugin {
3235
const packageJSON: typeof PackageType = JSON.parse(
3336
fs.readFileSync('./package.json', 'utf-8')
3437
)
35-
36-
fs.rmSync(DIST_PACKAGE_PATH, { recursive: true, force: true })
37-
fs.cpSync(PLUGIN_PACKAGE_PATH, DIST_PACKAGE_PATH, { recursive: true })
38+
fs.rmSync(DIST_PACKAGE, { recursive: true, force: true })
39+
fs.cpSync(SRC_PACKAGE, DIST_PACKAGE, { recursive: true })
40+
const pluginBuildPath = `./dist/${packageJSON.name}.js`
41+
if (!fs.existsSync(pluginBuildPath)) {
42+
console.error('❌ Plugin build not found while packaging!')
43+
return
44+
}
3845
fs.copyFileSync(
39-
`./dist/${packageJSON.name}.js`,
40-
pathjs.join(DIST_PACKAGE_PATH, packageJSON.name + '.js')
46+
pluginBuildPath,
47+
pathjs.join(DIST_PACKAGE, packageJSON.name + '.js')
4148
)
42-
const svelteResult = c.compile(readFileSync(SVELTE_FILE, 'utf-8'), {
49+
const svelteResult = c.compile(readFileSync(SRC_ABOUT, 'utf-8'), {
4350
generate: 'ssr',
4451
cssHash({ hash, css }) {
4552
return `animated-java-plugin-page-${hash(css)}`
@@ -54,17 +61,15 @@ function plugin(): Plugin {
5461
)
5562
const result = component(svelteInternal).render()
5663
const html = `${result.html}\n<style>${result.css.code}</style>`
57-
writeFileSync(README_DIST_PATH, html)
58-
if (fs.existsSync(pathjs.join(DIST_PACKAGE_PATH, 'about.svelte')))
59-
fs.unlinkSync(pathjs.join(DIST_PACKAGE_PATH, 'about.svelte'))
64+
writeFileSync(DIST_README, html)
65+
if (fs.existsSync(pathjs.join(DIST_PACKAGE, 'about.svelte')))
66+
fs.unlinkSync(pathjs.join(DIST_PACKAGE, 'about.svelte'))
6067

6168
console.log('📦 Packaged')
6269

6370
if (process.env.NODE_ENV === 'production') {
6471
console.log('📝 Creating changelogs...')
65-
const changelog: Changelog = JSON.parse(
66-
fs.readFileSync(CHANGELOG_PATH, 'utf-8')
67-
)
72+
const changelog: Changelog = JSON.parse(fs.readFileSync(SRC_CHANGELOG, 'utf-8'))
6873
for (const file of fs.readdirSync(RELEASE_NOTES_TEMPLATES)) {
6974
let content = fs.readFileSync(
7075
pathjs.join(RELEASE_NOTES_TEMPLATES, file),
@@ -82,12 +87,12 @@ function plugin(): Plugin {
8287
?.list.map(v => '- ' + v)
8388
.join('\n'),
8489
})
85-
fs.writeFileSync(pathjs.join(DIST_PATH, file), content)
90+
fs.writeFileSync(pathjs.join(DIST, file), content)
8691
}
8792

8893
if (fs.existsSync(PLUGIN_REPO_PATH)) {
8994
fs.rmSync(PLUGIN_REPO_PATH, { recursive: true, force: true })
90-
fs.cpSync(DIST_PACKAGE_PATH, PLUGIN_REPO_PATH, { recursive: true })
95+
fs.cpSync(DIST_PACKAGE, PLUGIN_REPO_PATH, { recursive: true })
9196
const manifest = JSON.parse(fs.readFileSync(PLUGIN_MANIFEST_PATH, 'utf-8'))
9297
manifest.animated_java.title = packageJSON.title
9398
manifest.animated_java.author = packageJSON.author.name
File renamed without changes.
File renamed without changes.

tools/esbuild.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import * as path from 'path'
1616
import { isAbsolute, join } from 'path'
1717
import { TextDecoder } from 'util'
1818
import svelteConfig from '../svelte.config.js'
19-
import assetOverridePlugin from './plugins/assetOverridePlugin'
20-
import mcbCompressionPlugin from './plugins/mcbCompressionPlugin'
21-
import pluginPackagerPlugin from './plugins/pluginPackagerPlugin.js'
22-
import sveltePlugin from './plugins/sveltePlugin'
23-
import inlineWorkerPlugin from './plugins/workerPlugin'
24-
const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
19+
import assetOverridePlugin from './esbuild-plugins/assetOverride.js'
20+
import mcbCompressionPlugin from './esbuild-plugins/mcbCompression.js'
21+
import pluginPackagerPlugin from './esbuild-plugins/pluginPackager.js'
22+
import sveltePlugin from './esbuild-plugins/svelte.js'
23+
import inlineWorkerPlugin from './esbuild-plugins/worker.js'
2524

25+
const PACKAGE = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))
2626
console.log(vsCodeProblemsPatchPlugin)
2727

2828
const INFO_PLUGIN: esbuild.Plugin = {

0 commit comments

Comments
 (0)