@tmbr/bundler 1.9.2 → 1.10.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/README.md +14 -8
  2. package/cli.js +35 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,30 @@
1
- # tmbr-bundler
1
+ # TMBR Bundler
2
2
 
3
- A configurable JavaScript and CSS bundler built on [esbuild](https://esbuild.github.io) and [browser-sync](https://browsersync.io). Specifically developed for WordPress development where CI/CD is not available, allowing for concurrent development and production bundles.
3
+ A configurable JavaScript and [SASS](https://sass-lang.com/documentation/) bundler built on [esbuild](https://esbuild.github.io) and [browser-sync](https://browsersync.io). Intended for WordPress development or projects where a CI/CD workflow is not available, allowing for concurrent development and production bundles.
4
4
 
5
5
  **Why [esbuild](https://esbuild.github.io)?**
6
6
 
7
- Compared to the mess of webpack loaders and dependencies, esbuild is faster, has better documentation and zero dependencies by default. It was created by Evan Wallace, who built this amazing [WebGL demo](https://madebyevan.com/webgl-water) ... and yeah, and co-founded [Figma](https://www.figma.com/)!
7
+ Compared to the mess of webpack loaders and dependencies, esbuild is faster, has better documentation and zero dependencies by default. It was created by Evan Wallace, who built this amazing [WebGL demo](https://madebyevan.com/webgl-water) in 2011 ... oh yeah, and he also co-founded [Figma](https://www.figma.com/)!
8
8
 
9
- ## Installation
9
+ ## Installation
10
10
 
11
11
  ```bash
12
- npm install @tmbr/bundler --save-dev
12
+ npm install --save-dev @tmbr/bundler
13
13
  ```
14
14
 
15
15
  ## Usage
16
- `@tmbr/bundler` has two commands - `build` and `watch` - that both create concurrent builds:
16
+ `@tmbr/bundler` has two commands - `build` and `watch` - that both create concurrent builds:
17
17
  - `build/main.dev.[css|js]` development version with sourcemaps
18
18
  - `build/main.min.[css|js]` minified production version
19
19
 
20
- ### ``tmbr-bundler build``
21
- ### ``tmbr-bundler watch``
20
+ ### ``bundler build``
21
+
22
+ This command creates the build files noted above and displays KB sizes for the minified css and js build files.
23
+
24
+ ### ``bundler watch``
25
+
26
+ This command will create initial build files noted above and start watching for changes. By default, it will look at the **name** field in your `package.json` file, append `.test` and proxy
27
+ `http://example.test:3000` for auto-reloading.
22
28
 
23
29
  ## Configuration
24
30
 
package/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const esbuild = require('esbuild');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
+ const exec = require('child_process').execSync;
5
6
  const chalk = require('chalk');
6
7
  const server = require('browser-sync').create();
7
8
  const styles = require('esbuild-sass-plugin').sassPlugin;
@@ -34,8 +35,8 @@ const logger = (options = {}) => ({
34
35
  const css = `${path}/${slug}.css`;
35
36
  const js = `${path}/${slug}.js`;
36
37
 
37
- console.log(`${css} ${Math.round(fs.statSync(css).size / 1000)} KB`);
38
- console.log(`${js} ${Math.round(fs.statSync(js).size / 1000)} KB`);
38
+ console.log(` ${chalk.green('✓')} ${css} ${Math.round(fs.statSync(css).size / 1000)} KB`);
39
+ console.log(` ${chalk.green('✓')} ${js} ${Math.round(fs.statSync(js).size / 1000)} KB`);
39
40
  console.log()
40
41
  });
41
42
  }
@@ -81,15 +82,33 @@ const serveOptions = {
81
82
  };
82
83
 
83
84
  server.info = function() {
84
- const host = server.getOption('proxy').get('target');
85
- const port = server.getOption('port');
86
- const proxying = `${host}:${port}`;
87
- const external = server.getOption('urls').get('external');
85
+ const proxying = this.url();
86
+ const external = this.getOption('urls').get('external');
88
87
 
89
88
  console.clear();
90
89
  console.log();
91
- console.log(`Proxying: ${chalk.green(proxying)}`);
92
- console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
90
+ console.log(` ➜ ${chalk.bold('Proxying')}: ${chalk.green(proxying)}`);
91
+ console.log(` ➜ ${chalk.bold('External')}: ${chalk.cyan(external || 'offline')}\n`);
92
+ console.log(` ${chalk.bold('Shortcuts')}`);
93
+
94
+ for (const [key, [_, tip]] of Object.entries(shortcuts)) {
95
+ tip && console.log(chalk.grey(` press ${chalk.white.bold(key)} to ${tip}`));
96
+ }
97
+
98
+ console.log();
99
+ };
100
+
101
+ server.url = function() {
102
+ const host = this.getOption('proxy').get('target');
103
+ const port = this.getOption('port');
104
+ return `${host}:${port}`;
105
+ };
106
+
107
+ const shortcuts = {
108
+ o: [() => exec(`open ${server.url()}`), 'open in browser'],
109
+ r: [() => server.reload(), 'reload the page'],
110
+ q: [() => process.exit(), 'quit'],
111
+ '\x03': [() => process.exit()],
93
112
  };
94
113
 
95
114
  async function main() {
@@ -106,6 +125,14 @@ async function main() {
106
125
  server.init(serveOptions, () => {
107
126
  builder.watch();
108
127
  watcher.watch();
128
+
129
+ require('readline').emitKeypressEvents(process.stdin);
130
+
131
+ process.stdin.setRawMode(true);
132
+ process.stdin.on('keypress', (_, key) => {
133
+ if (!key) return;
134
+ shortcuts[key.sequence]?.[0]();
135
+ });
109
136
  });
110
137
  }
111
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmbr/bundler",
3
- "version": "1.9.2",
3
+ "version": "1.10.0",
4
4
  "repository": "github:TMBR/tmbr-bundler",
5
5
  "bin": {
6
6
  "bundler": "cli.js",