@tmbr/bundler 1.4.1 → 1.5.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/cli.js +42 -49
- package/package.json +1 -2
- package/error.js +0 -107
package/cli.js
CHANGED
|
@@ -2,43 +2,33 @@
|
|
|
2
2
|
const esbuild = require('esbuild');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const exec = require('child_process').execSync;
|
|
5
|
+
const chalk = require('chalk');
|
|
5
6
|
const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
6
7
|
const qrcode = require('qrcode-terminal');
|
|
7
|
-
const
|
|
8
|
-
const bs = require('browser-sync').create();
|
|
9
|
-
const renderError = require('./error');
|
|
8
|
+
const server = require('browser-sync').create();
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
const package = require(`${
|
|
10
|
+
const dir = process.cwd();
|
|
11
|
+
const package = require(`${dir}/package.json`);
|
|
13
12
|
const command = process.argv[2];
|
|
14
|
-
let error;
|
|
15
13
|
|
|
16
14
|
if (!['build', 'watch'].includes(command)) {
|
|
17
15
|
console.log(`Invalid command: ${chalk.red(command)}\n`);
|
|
18
16
|
process.exit();
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
exec(`rm -rf ${
|
|
19
|
+
exec(`rm -rf ${dir}/build/*`);
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
external: true
|
|
29
|
-
}))
|
|
30
|
-
},
|
|
31
|
-
});
|
|
21
|
+
function ok() {
|
|
22
|
+
const host = server.getOption('proxy').get('target');
|
|
23
|
+
const port = server.getOption('port');
|
|
24
|
+
const proxying = `${host}:${port}`;
|
|
25
|
+
const external = server.getOption('urls').get('external');
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
error && bs.reload();
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
});
|
|
27
|
+
console.clear();
|
|
28
|
+
external && qrcode.generate(external, {small: true}, console.log);
|
|
29
|
+
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
30
|
+
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
31
|
+
}
|
|
42
32
|
|
|
43
33
|
function entryPoints(suffix = '') {
|
|
44
34
|
|
|
@@ -47,8 +37,8 @@ function entryPoints(suffix = '') {
|
|
|
47
37
|
}
|
|
48
38
|
|
|
49
39
|
const entries = Object.entries({
|
|
50
|
-
admin: path.resolve(
|
|
51
|
-
main: path.resolve(
|
|
40
|
+
admin: path.resolve(dir, './src/admin'),
|
|
41
|
+
main: path.resolve(dir, './src'),
|
|
52
42
|
});
|
|
53
43
|
|
|
54
44
|
return entries.reduce((result, [name, path]) => {
|
|
@@ -57,9 +47,28 @@ function entryPoints(suffix = '') {
|
|
|
57
47
|
}, {});
|
|
58
48
|
}
|
|
59
49
|
|
|
50
|
+
const assets = (options = {}) => ({
|
|
51
|
+
name: 'assets',
|
|
52
|
+
setup(build) {
|
|
53
|
+
build.onResolve({filter: /..\/(assets|fonts|images)\//}, args => ({
|
|
54
|
+
path: args.path,
|
|
55
|
+
external: true
|
|
56
|
+
}))
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const errors = (options = {}) => ({
|
|
61
|
+
name: 'errors',
|
|
62
|
+
setup(build) {
|
|
63
|
+
build.onEnd(({warnings, errors}) => {
|
|
64
|
+
(warnings.length || errors.length) ? console.log('\007') : ok();
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
60
69
|
const defaults = {
|
|
61
70
|
watch: command === 'watch',
|
|
62
|
-
outdir: path.resolve(
|
|
71
|
+
outdir: path.resolve(dir, 'build'),
|
|
63
72
|
bundle: true,
|
|
64
73
|
minify: true,
|
|
65
74
|
sourcemap: false,
|
|
@@ -88,8 +97,9 @@ const buildConfig = Object.assign({}, defaults, {
|
|
|
88
97
|
entryPoints: entryPoints('min'),
|
|
89
98
|
});
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
esbuild.build(
|
|
100
|
+
const noop = fn => fn;
|
|
101
|
+
esbuild.build(watchConfig).catch(noop);
|
|
102
|
+
esbuild.build(buildConfig).catch(noop);
|
|
93
103
|
|
|
94
104
|
if (command === 'watch') {
|
|
95
105
|
|
|
@@ -103,15 +113,8 @@ if (command === 'watch') {
|
|
|
103
113
|
'**/*.php'
|
|
104
114
|
];
|
|
105
115
|
|
|
106
|
-
const middleware = (proxyRes, req, res) => {
|
|
107
|
-
error && res.end(renderError(error));
|
|
108
|
-
};
|
|
109
|
-
|
|
110
116
|
const options = {
|
|
111
|
-
proxy: {
|
|
112
|
-
target: `${package.name}.test`,
|
|
113
|
-
proxyRes: [middleware]
|
|
114
|
-
},
|
|
117
|
+
proxy: `${package.name}.test`,
|
|
115
118
|
host: 'localhost',
|
|
116
119
|
open: false,
|
|
117
120
|
notify: false,
|
|
@@ -120,15 +123,5 @@ if (command === 'watch') {
|
|
|
120
123
|
files
|
|
121
124
|
};
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const host = bs.getOption('proxy').get('target');
|
|
126
|
-
const port = bs.getOption('port');
|
|
127
|
-
const proxying = `${host}:${port}`;
|
|
128
|
-
const external = bs.getOption('urls').get('external');
|
|
129
|
-
|
|
130
|
-
external && qrcode.generate(external, {small: true}, console.log);
|
|
131
|
-
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
132
|
-
console.log(`External: ${chalk.cyan(external || 'offline')}`);
|
|
133
|
-
});
|
|
126
|
+
server.init(options, ok);
|
|
134
127
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmbr/bundler",
|
|
3
3
|
"author": "TMBR (https://wearetmbr.com/)",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/TMBR/tmbr-bundler",
|
|
7
7
|
"description": "WordPress development toolkit built on esbuild and browser-sync",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"chalk": "^4.1.2",
|
|
14
14
|
"esbuild": "^0.15.5",
|
|
15
15
|
"esbuild-sass-plugin": "^2.3.2",
|
|
16
|
-
"html-entities": "^2.3.3",
|
|
17
16
|
"qrcode-terminal": "^0.12.0"
|
|
18
17
|
}
|
|
19
18
|
}
|
package/error.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const encode = require('html-entities').encode;
|
|
3
|
-
|
|
4
|
-
module.exports = error => {
|
|
5
|
-
|
|
6
|
-
const { file, line, column } = error.location;
|
|
7
|
-
|
|
8
|
-
const lines = fs.readFileSync(file, 'UTF-8').split(/\r?\n/);
|
|
9
|
-
const index = line - 1;
|
|
10
|
-
const inset = String((lines[index + 2] && line + 2) || (lines[index + 1] && line + 1) || line).split('').length;
|
|
11
|
-
|
|
12
|
-
const print = offset => (
|
|
13
|
-
`<span class="c-gray">${String(line + offset).padStart(2 + inset, ' ')} | </span>` + encode(lines[index + offset])
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const space = length => {
|
|
17
|
-
return ' '.repeat(length);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const output = [
|
|
21
|
-
(index - 2) >= 0 && print(-2),
|
|
22
|
-
(index - 1) >= 0 && print(-1),
|
|
23
|
-
`<span class="c-red fw-700">></span><span class="c-gray"> ${line} | </span>${encode(lines[index])}`,
|
|
24
|
-
` <span class="c-gray">${space(2 + inset)}| </span>${space(column ? column - 1 : 0)}<span class="c-red fw-700">^</span>`,
|
|
25
|
-
(index + 1) <= lines.length - 1 && print(1),
|
|
26
|
-
(index + 2) <= lines.length - 1 && print(2),
|
|
27
|
-
].filter(Boolean).join('\n');
|
|
28
|
-
|
|
29
|
-
return /* html */`
|
|
30
|
-
<!DOCTYPE html>
|
|
31
|
-
<html>
|
|
32
|
-
<head>
|
|
33
|
-
|
|
34
|
-
<meta charset="UTF-8">
|
|
35
|
-
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
|
36
|
-
|
|
37
|
-
<title>Build Error: ${file}</title>
|
|
38
|
-
|
|
39
|
-
<style>
|
|
40
|
-
|
|
41
|
-
* {
|
|
42
|
-
margin: 0;
|
|
43
|
-
padding: 0;
|
|
44
|
-
box-sizing: border-box;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.c-red { color: #ff5555; }
|
|
48
|
-
.c-cyan { color: #88ddff; }
|
|
49
|
-
.c-gray { color: #666666; }
|
|
50
|
-
.fw-700 { font-weight: 700; }
|
|
51
|
-
|
|
52
|
-
::selection {
|
|
53
|
-
background-color: rgba(95, 126, 151, 0.48);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
html {
|
|
57
|
-
font: 1rem / 1.5 sans-serif;
|
|
58
|
-
color: #FFF;
|
|
59
|
-
background-color: #151515;
|
|
60
|
-
}
|
|
61
|
-
main {
|
|
62
|
-
max-width: 1280px;
|
|
63
|
-
margin: 3em auto;
|
|
64
|
-
padding: 1rem;
|
|
65
|
-
}
|
|
66
|
-
h1 {
|
|
67
|
-
font-size: 1.5rem;
|
|
68
|
-
line-height: 1.5;
|
|
69
|
-
margin-bottom: 0.25em;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.terminal {
|
|
73
|
-
color: #CCC;
|
|
74
|
-
border-radius: 0.25rem;
|
|
75
|
-
}
|
|
76
|
-
.terminal pre {
|
|
77
|
-
font-family: Menlo, Monaco, monospace;
|
|
78
|
-
overflow: scroll;
|
|
79
|
-
}
|
|
80
|
-
.terminal > * {
|
|
81
|
-
padding: 1rem 0;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
</style>
|
|
85
|
-
|
|
86
|
-
</head>
|
|
87
|
-
<body>
|
|
88
|
-
|
|
89
|
-
<main>
|
|
90
|
-
|
|
91
|
-
<h1>Build Error</h1>
|
|
92
|
-
|
|
93
|
-
<div class="terminal">
|
|
94
|
-
|
|
95
|
-
<pre>
|
|
96
|
-
<span class="c-cyan">${file}</span><span class="c-gray">:</span>${line}<span class="c-gray">:</span>${column}
|
|
97
|
-
<span class="c-red fw-700">${error.text}</span>
|
|
98
|
-
|
|
99
|
-
${output}
|
|
100
|
-
</pre>
|
|
101
|
-
|
|
102
|
-
</div>
|
|
103
|
-
|
|
104
|
-
</main>
|
|
105
|
-
|
|
106
|
-
</body>
|
|
107
|
-
</html>`};
|