@tmbr/bundler 1.4.1 → 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.
Files changed (3) hide show
  1. package/cli.js +35 -41
  2. package/package.json +1 -1
  3. package/error.js +0 -107
package/cli.js CHANGED
@@ -6,12 +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
9
 
11
10
  const cwd = process.cwd();
12
11
  const package = require(`${cwd}/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`);
@@ -20,25 +18,18 @@ if (!['build', 'watch'].includes(command)) {
20
18
 
21
19
  exec(`rm -rf ${cwd}/build/*`);
22
20
 
23
- const assets = (options = {}) => ({
24
- name: 'assets',
25
- setup(build) {
26
- build.onResolve({filter: /..\/(fonts|images)\//}, args => ({
27
- path: args.path,
28
- external: true
29
- }))
30
- },
31
- });
21
+ function ok() {
22
+ command === 'watch' && console.clear();
32
23
 
33
- const errors = (options = {}) => ({
34
- name: 'errors',
35
- setup(build) {
36
- build.onEnd(result => {
37
- error = result.errors[0];
38
- error && bs.reload();
39
- });
40
- },
41
- });
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');
28
+
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
+ }
42
33
 
43
34
  function entryPoints(suffix = '') {
44
35
 
@@ -57,6 +48,25 @@ function entryPoints(suffix = '') {
57
48
  }, {});
58
49
  }
59
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
+
60
70
  const defaults = {
61
71
  watch: command === 'watch',
62
72
  outdir: path.resolve(cwd, 'build'),
@@ -88,8 +98,9 @@ const buildConfig = Object.assign({}, defaults, {
88
98
  entryPoints: entryPoints('min'),
89
99
  });
90
100
 
91
- esbuild.build(watchConfig);
92
- esbuild.build(buildConfig);
101
+ const noop = fn => fn;
102
+ esbuild.build(watchConfig).catch(noop);
103
+ esbuild.build(buildConfig).catch(noop);
93
104
 
94
105
  if (command === 'watch') {
95
106
 
@@ -103,15 +114,8 @@ if (command === 'watch') {
103
114
  '**/*.php'
104
115
  ];
105
116
 
106
- const middleware = (proxyRes, req, res) => {
107
- error && res.end(renderError(error));
108
- };
109
-
110
117
  const options = {
111
- proxy: {
112
- target: `${package.name}.test`,
113
- proxyRes: [middleware]
114
- },
118
+ proxy: `${package.name}.test`,
115
119
  host: 'localhost',
116
120
  open: false,
117
121
  notify: false,
@@ -120,15 +124,5 @@ if (command === 'watch') {
120
124
  files
121
125
  };
122
126
 
123
- bs.init(options, () => {
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
- });
127
+ bs.init(options, ok);
134
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.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",
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">&gt;</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>`};