The complete migration from `minecraft-assets` to [`mc-assets`](https://npmjs.com/mc-assets). Now all block states & block models are processed dynamically! So it is now easily possible to implement custom models - no post-install work anymore: the building is now 3x faster and 4x faster in docker - drop 10x total deploy size - display world ~1.5x faster - fix snow & repeater state parser (they didn't render correctly) rsbuild pipeline! - the initial app load is faster ~1.2 - much fewer requests are made & cached - dev reloads are fast now Resource pack changes: - now textures are reloaded much more quickly on the fly - add hotkey to quickly reload textures (for debugging) assigned to F3+T (open dev widget is now assigned to F3+Y) - add a way to disable resource pack instead of uninstalling it - items render from resource pack are now support - resource pack widgets & icons are now supported
110 lines
3.6 KiB
JavaScript
110 lines
3.6 KiB
JavaScript
//@ts-check
|
|
const fsExtra = require('fs-extra')
|
|
const defaultLocalServerOptions = require('../src/defaultLocalServerOptions')
|
|
const glob = require('glob')
|
|
const fs = require('fs')
|
|
const crypto = require('crypto')
|
|
const path = require('path')
|
|
|
|
const prismarineViewerBase = "./node_modules/prismarine-viewer"
|
|
|
|
// these files could be copied at build time eg with copy plugin, but copy plugin slows down the config so we copy them there, alternative we could inline it in esbuild config
|
|
const filesToCopy = [
|
|
{ from: `${prismarineViewerBase}/public/mesher.js`, to: 'dist/mesher.js' },
|
|
{ from: './assets/', to: './dist/' },
|
|
{ from: './config.json', to: 'dist/config.json' },
|
|
// { from: path.join(entityMcAssets.directory, 'entity'), to: 'dist/textures/1.16.4/entity' },
|
|
]
|
|
exports.filesToCopy = filesToCopy
|
|
exports.copyFiles = (dev = false) => {
|
|
console.time('copy files')
|
|
if (!dev) {
|
|
// copy glob
|
|
const cwd = `${prismarineViewerBase}/public/textures/`
|
|
const files = glob.sync('*.png', { cwd: cwd, nodir: true, })
|
|
for (const file of files) {
|
|
const copyDest = path.join('dist/textures/', file)
|
|
fs.mkdirSync(path.dirname(copyDest), { recursive: true, })
|
|
fs.copyFileSync(path.join(cwd, file), copyDest)
|
|
}
|
|
}
|
|
|
|
filesToCopy.forEach(file => {
|
|
fsExtra.copySync(file.from, file.to)
|
|
})
|
|
|
|
console.timeEnd('copy files')
|
|
}
|
|
|
|
exports.copyFilesDev = () => {
|
|
if (fsExtra.existsSync('dist/config.json')) return
|
|
exports.copyFiles()
|
|
}
|
|
|
|
exports.getSwAdditionalEntries = () => {
|
|
// need to be careful with this
|
|
const filesToCachePatterns = [
|
|
'index.html',
|
|
`mc-data/${defaultLocalServerOptions.versionMajor}.js`,
|
|
'background/**',
|
|
// todo-low copy from assets
|
|
'*.mp3',
|
|
'*.ttf',
|
|
'*.png',
|
|
'*.woff',
|
|
'mesher.js',
|
|
'worldSaveWorker.js',
|
|
`textures/entity/squid/squid.png`,
|
|
// everything but not .map
|
|
'static/**/!(*.map)',
|
|
]
|
|
const filesNeedsCacheKey = [
|
|
'index.html',
|
|
'mesher.js',
|
|
'worldSaveWorker.js',
|
|
]
|
|
const output = []
|
|
console.log('Generating sw additional entries...')
|
|
for (const pattern of filesToCachePatterns) {
|
|
const files = glob.sync(pattern, { cwd: 'dist' })
|
|
for (const file of files) {
|
|
const fullPath = path.join('dist', file)
|
|
if (!fs.lstatSync(fullPath).isFile()) continue
|
|
let revision = null
|
|
const url = './' + file.replace(/\\/g, '/')
|
|
if (filesNeedsCacheKey.includes(file)) {
|
|
const fileContents = fs.readFileSync(fullPath, 'utf-8')
|
|
const md5Hash = crypto.createHash('md5').update(fileContents).digest('hex')
|
|
revision = md5Hash
|
|
}
|
|
output.push({ url, revision })
|
|
}
|
|
}
|
|
if (output.length > 40) {
|
|
throw new Error(`SW: Ios has a limit of 40 urls to cache (now ${output.length})`)
|
|
}
|
|
console.log(`Got ${output.length} additional sw entries to cache`)
|
|
return output
|
|
}
|
|
|
|
exports.moveStorybookFiles = () => {
|
|
fsExtra.moveSync('storybook-static', 'dist/storybook', { overwrite: true, })
|
|
fsExtra.copySync('dist/storybook', '.vercel/output/static/storybook')
|
|
}
|
|
|
|
exports.getSwFilesSize = () => {
|
|
const files = exports.getSwAdditionalEntries()
|
|
let size = 0
|
|
for (const { url } of files) {
|
|
const file = path.join(__dirname, '../dist', url)
|
|
size += fs.statSync(file).size
|
|
}
|
|
console.log('mb', size / 1024 / 1024)
|
|
}
|
|
|
|
const fn = require.main === module && exports[process.argv[2]]
|
|
|
|
if (fn) {
|
|
const result = fn()
|
|
if (result) console.log(result)
|
|
}
|