@tmbr/bundler 1.3.0 → 1.5.0
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 +34 -73
- package/package.json +6 -7
- package/error.js +0 -107
package/cli.js
CHANGED
|
@@ -6,13 +6,10 @@ const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
|
6
6
|
const qrcode = require('qrcode-terminal');
|
|
7
7
|
const chalk = require('chalk');
|
|
8
8
|
const bs = require('browser-sync').create();
|
|
9
|
-
const renderError = require('./error');
|
|
10
|
-
// const webfontsGenerator = require('webfonts-generator'); // OPTIONAL ICON FONT BUILDER UNCOMMENT TO USE
|
|
11
9
|
|
|
12
10
|
const cwd = process.cwd();
|
|
13
11
|
const package = require(`${cwd}/package.json`);
|
|
14
12
|
const command = process.argv[2];
|
|
15
|
-
let error;
|
|
16
13
|
|
|
17
14
|
if (!['build', 'watch'].includes(command)) {
|
|
18
15
|
console.log(`Invalid command: ${chalk.red(command)}\n`);
|
|
@@ -21,57 +18,18 @@ if (!['build', 'watch'].includes(command)) {
|
|
|
21
18
|
|
|
22
19
|
exec(`rm -rf ${cwd}/build/*`);
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setup(build) {
|
|
27
|
-
build.onResolve({filter: /..\/(fonts|images)\//}, args => ({
|
|
28
|
-
path: args.path,
|
|
29
|
-
external: true
|
|
30
|
-
}))
|
|
31
|
-
},
|
|
32
|
-
});
|
|
21
|
+
function ok() {
|
|
22
|
+
command === 'watch' && console.clear();
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// files: [
|
|
39
|
-
// './icons/angle-left.svg',
|
|
40
|
-
// ],
|
|
41
|
-
// dest: './fonts/',
|
|
42
|
-
// fontName: 'tmbr-icons',
|
|
43
|
-
// templateOptions: {
|
|
44
|
-
// baseClass: 'icon',
|
|
45
|
-
// classPrefix: 'icon-'
|
|
46
|
-
// },
|
|
47
|
-
// types: ['woff2', 'woff', 'svg']
|
|
48
|
-
// }, function(error) {
|
|
49
|
-
// if (error) {
|
|
50
|
-
// console.log('Fail!', error);
|
|
51
|
-
// } else {
|
|
52
|
-
// console.log('Icon Font Built');
|
|
53
|
-
// }
|
|
54
|
-
// });
|
|
24
|
+
const host = bs.getOption('proxy').get('target');
|
|
25
|
+
const port = bs.getOption('port');
|
|
26
|
+
const proxying = `${host}:${port}`;
|
|
27
|
+
const external = bs.getOption('urls').get('external');
|
|
55
28
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
error = result.errors[0];
|
|
61
|
-
error && bs.reload();
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const errors = (options = {}) => ({
|
|
67
|
-
name: 'errors',
|
|
68
|
-
setup(build) {
|
|
69
|
-
build.onEnd(result => {
|
|
70
|
-
error = result.errors[0];
|
|
71
|
-
error && bs.reload();
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
});
|
|
29
|
+
external && qrcode.generate(external, {small: true}, console.log);
|
|
30
|
+
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
31
|
+
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
32
|
+
}
|
|
75
33
|
|
|
76
34
|
function entryPoints(suffix = '') {
|
|
77
35
|
|
|
@@ -90,6 +48,25 @@ function entryPoints(suffix = '') {
|
|
|
90
48
|
}, {});
|
|
91
49
|
}
|
|
92
50
|
|
|
51
|
+
const assets = (options = {}) => ({
|
|
52
|
+
name: 'assets',
|
|
53
|
+
setup(build) {
|
|
54
|
+
build.onResolve({filter: /..\/(fonts|images)\//}, args => ({
|
|
55
|
+
path: args.path,
|
|
56
|
+
external: true
|
|
57
|
+
}))
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const errors = (options = {}) => ({
|
|
62
|
+
name: 'errors',
|
|
63
|
+
setup(build) {
|
|
64
|
+
build.onEnd(({warnings, errors}) => {
|
|
65
|
+
(warnings.length || errors.length) ? console.log('\007') : ok();
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
93
70
|
const defaults = {
|
|
94
71
|
watch: command === 'watch',
|
|
95
72
|
outdir: path.resolve(cwd, 'build'),
|
|
@@ -121,8 +98,9 @@ const buildConfig = Object.assign({}, defaults, {
|
|
|
121
98
|
entryPoints: entryPoints('min'),
|
|
122
99
|
});
|
|
123
100
|
|
|
124
|
-
|
|
125
|
-
esbuild.build(
|
|
101
|
+
const noop = fn => fn;
|
|
102
|
+
esbuild.build(watchConfig).catch(noop);
|
|
103
|
+
esbuild.build(buildConfig).catch(noop);
|
|
126
104
|
|
|
127
105
|
if (command === 'watch') {
|
|
128
106
|
|
|
@@ -136,15 +114,8 @@ if (command === 'watch') {
|
|
|
136
114
|
'**/*.php'
|
|
137
115
|
];
|
|
138
116
|
|
|
139
|
-
const middleware = (proxyRes, req, res) => {
|
|
140
|
-
error && res.end(renderError(error));
|
|
141
|
-
};
|
|
142
|
-
|
|
143
117
|
const options = {
|
|
144
|
-
proxy: {
|
|
145
|
-
target: `${package.name}.test`,
|
|
146
|
-
proxyRes: [middleware]
|
|
147
|
-
},
|
|
118
|
+
proxy: `${package.name}.test`,
|
|
148
119
|
host: 'localhost',
|
|
149
120
|
open: false,
|
|
150
121
|
notify: false,
|
|
@@ -153,15 +124,5 @@ if (command === 'watch') {
|
|
|
153
124
|
files
|
|
154
125
|
};
|
|
155
126
|
|
|
156
|
-
bs.init(options,
|
|
157
|
-
|
|
158
|
-
const host = bs.getOption('proxy').get('target');
|
|
159
|
-
const port = bs.getOption('port');
|
|
160
|
-
const proxying = `${host}:${port}`;
|
|
161
|
-
const external = bs.getOption('urls').get('external');
|
|
162
|
-
|
|
163
|
-
external && qrcode.generate(external, {small: true}, console.log);
|
|
164
|
-
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
165
|
-
console.log(`External: ${chalk.cyan(external || 'offline')}`);
|
|
166
|
-
});
|
|
127
|
+
bs.init(options, ok);
|
|
167
128
|
}
|
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.0",
|
|
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",
|
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
"tmbr-bundler": "cli.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"browser-sync": "^2.27.
|
|
12
|
+
"browser-sync": "^2.27.10",
|
|
13
13
|
"chalk": "^4.1.2",
|
|
14
|
-
"esbuild": "^0.
|
|
15
|
-
"esbuild-sass-plugin": "^2.2
|
|
16
|
-
"html-entities": "^2.3.
|
|
17
|
-
"qrcode-terminal": "^0.12.0"
|
|
18
|
-
"webfonts-generator": "^0.4.0"
|
|
14
|
+
"esbuild": "^0.15.5",
|
|
15
|
+
"esbuild-sass-plugin": "^2.3.2",
|
|
16
|
+
"html-entities": "^2.3.3",
|
|
17
|
+
"qrcode-terminal": "^0.12.0"
|
|
19
18
|
}
|
|
20
19
|
}
|
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>`};
|