@@ -8,15 +8,18 @@ import * as svelteInternal from 'svelte/internal'
8
8
import type PackageType from '../../package.json'
9
9
import type ChangelogType from '../../src/plugin/package/changelog.json'
10
10
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
+
16
20
const PLUGIN_REPO_PATH = 'D:/github-repos/snavesutit/blockbench-plugins/plugins/animated_java'
17
21
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/'
20
23
21
24
function replaceTemplateVars ( str : string , items : Record < string , string | undefined > ) {
22
25
return str . replace ( / \{ ( .+ ?) \} / g, str => items [ str . replace ( / [ \{ \} ] / g, '' ) ] ?? str )
@@ -32,14 +35,18 @@ function plugin(): Plugin {
32
35
const packageJSON : typeof PackageType = JSON . parse (
33
36
fs . readFileSync ( './package.json' , 'utf-8' )
34
37
)
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
+ }
38
45
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' )
41
48
)
42
- const svelteResult = c . compile ( readFileSync ( SVELTE_FILE , 'utf-8' ) , {
49
+ const svelteResult = c . compile ( readFileSync ( SRC_ABOUT , 'utf-8' ) , {
43
50
generate : 'ssr' ,
44
51
cssHash ( { hash, css } ) {
45
52
return `animated-java-plugin-page-${ hash ( css ) } `
@@ -54,17 +61,15 @@ function plugin(): Plugin {
54
61
)
55
62
const result = component ( svelteInternal ) . render ( )
56
63
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' ) )
60
67
61
68
console . log ( '📦 Packaged' )
62
69
63
70
if ( process . env . NODE_ENV === 'production' ) {
64
71
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' ) )
68
73
for ( const file of fs . readdirSync ( RELEASE_NOTES_TEMPLATES ) ) {
69
74
let content = fs . readFileSync (
70
75
pathjs . join ( RELEASE_NOTES_TEMPLATES , file ) ,
@@ -82,12 +87,12 @@ function plugin(): Plugin {
82
87
?. list . map ( v => '- ' + v )
83
88
. join ( '\n' ) ,
84
89
} )
85
- fs . writeFileSync ( pathjs . join ( DIST_PATH , file ) , content )
90
+ fs . writeFileSync ( pathjs . join ( DIST , file ) , content )
86
91
}
87
92
88
93
if ( fs . existsSync ( PLUGIN_REPO_PATH ) ) {
89
94
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 } )
91
96
const manifest = JSON . parse ( fs . readFileSync ( PLUGIN_MANIFEST_PATH , 'utf-8' ) )
92
97
manifest . animated_java . title = packageJSON . title
93
98
manifest . animated_java . author = packageJSON . author . name
0 commit comments