packaton 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +11 -0
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/TODO.md +8 -0
- package/index.d.ts +21 -0
- package/index.js +6 -0
- package/package.json +23 -0
- package/src/HtmlCompiler.js +132 -0
- package/src/HtmlCompiler.test.js +71 -0
- package/src/WatcherDevClient.js +18 -0
- package/src/app-dev.js +26 -0
- package/src/app-prod.js +100 -0
- package/src/app-router.js +78 -0
- package/src/app.js +66 -0
- package/src/config.js +72 -0
- package/src/fs-utils.js +49 -0
- package/src/fs-utils.test.js +21 -0
- package/src/http-response.js +46 -0
- package/src/media-remaper.js +51 -0
- package/src/media-remaper.test.js +29 -0
- package/src/mimes.js +99 -0
- package/src/minifyCSS.js +50 -0
- package/src/minifyCSS.test.js +124 -0
- package/src/minifyHTML.js +50 -0
- package/src/minifyHTML.test.js +72 -0
- package/src/minifyJS.js +6 -0
- package/src/openInBrowser.js +23 -0
- package/src/reportSizes.js +23 -0
- package/src/watcherDev.js +32 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const openInBrowser = (async () => {
|
|
5
|
+
try {
|
|
6
|
+
return (await import('open')).default
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
return _openInBrowser
|
|
10
|
+
}
|
|
11
|
+
})()
|
|
12
|
+
|
|
13
|
+
function _openInBrowser(address) {
|
|
14
|
+
switch (process.platform) {
|
|
15
|
+
case 'darwin':
|
|
16
|
+
execFileSync('open', [address])
|
|
17
|
+
break
|
|
18
|
+
case 'win32':
|
|
19
|
+
execFileSync('start', [address])
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { read, sizeOf, sha1, saveAsJSON, isFile } from './fs-utils.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function reportSizes(reportFilename, baseDir, files) {
|
|
6
|
+
const oldReport = isFile(reportFilename)
|
|
7
|
+
? JSON.parse(read(reportFilename))
|
|
8
|
+
: {}
|
|
9
|
+
const newReport = {}
|
|
10
|
+
|
|
11
|
+
for (const f of files) {
|
|
12
|
+
const fPath = join(baseDir, f)
|
|
13
|
+
const size = sizeOf(fPath)
|
|
14
|
+
newReport[f] = {
|
|
15
|
+
hash: sha1(fPath),
|
|
16
|
+
delta: size - (oldReport[f]?.size || 0),
|
|
17
|
+
size
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.table(newReport)
|
|
22
|
+
saveAsJSON(reportFilename, newReport)
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const WATCH_API = '/packaton/watch-dev'
|
|
2
|
+
|
|
3
|
+
longPollDevChanges()
|
|
4
|
+
async function longPollDevChanges() {
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch(WATCH_API)
|
|
7
|
+
if (!response.ok)
|
|
8
|
+
throw response.statusText
|
|
9
|
+
|
|
10
|
+
const file = await response.json() || ''
|
|
11
|
+
if (file.endsWith('.css')) {
|
|
12
|
+
hotReloadCSS(file)
|
|
13
|
+
longPollDevChanges()
|
|
14
|
+
}
|
|
15
|
+
else if (file)
|
|
16
|
+
location.reload()
|
|
17
|
+
else // server timeout
|
|
18
|
+
longPollDevChanges()
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error('hot reload', error?.message || error)
|
|
22
|
+
setTimeout(longPollDevChanges, 3000)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hotReloadCSS(file) {
|
|
27
|
+
const link = document.querySelector(`link[href*="${file}"]`)
|
|
28
|
+
if (link) {
|
|
29
|
+
const [url] = link.href.split('?')
|
|
30
|
+
link.href = url + '?' + Date.now()
|
|
31
|
+
}
|
|
32
|
+
}
|