@tmbr/bundler 1.10.0 → 1.11.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 (2) hide show
  1. package/cli.js +32 -27
  2. package/package.json +6 -5
package/cli.js CHANGED
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/env node
2
- const esbuild = require('esbuild');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const exec = require('child_process').execSync;
6
- const chalk = require('chalk');
7
- const server = require('browser-sync').create();
8
- const styles = require('esbuild-sass-plugin').sassPlugin;
9
- const silent = require('sass').Logger.silent;
2
+ import esbuild from 'esbuild';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import chalk from 'chalk';
6
+ import readline from 'readline';
7
+ import { create } from 'browser-sync';
8
+ import { execSync as exec } from 'child_process';
9
+ import { sassPlugin as styles } from 'esbuild-sass-plugin';
10
+ import * as sass from 'sass';
10
11
 
11
12
  const cwd = process.cwd();
12
13
  const src = path.resolve(cwd, 'src');
13
- const package = require(`${cwd}/package.json`);
14
+ const server = create();
14
15
  const command = process.argv[2];
15
16
 
16
17
  if (!['build', 'watch'].includes(command)) {
@@ -30,14 +31,18 @@ const logger = (options = {}) => ({
30
31
  });
31
32
 
32
33
  context.onEnd(result => {
33
- if (result.warnings.length || result.errors.length) return console.log('\007');
34
+
35
+ if (result.warnings.length || result.errors.length) {
36
+ console.log('\x07');
37
+ return
38
+ }
34
39
 
35
40
  const css = `${path}/${slug}.css`;
36
41
  const js = `${path}/${slug}.js`;
37
42
 
38
43
  console.log(` ${chalk.green('✓')} ${css} ${Math.round(fs.statSync(css).size / 1000)} KB`);
39
44
  console.log(` ${chalk.green('✓')} ${js} ${Math.round(fs.statSync(js).size / 1000)} KB`);
40
- console.log()
45
+ console.log();
41
46
  });
42
47
  }
43
48
  });
@@ -55,7 +60,7 @@ const buildOptions = {
55
60
  treeShaking: true,
56
61
  legalComments: 'none',
57
62
  plugins: [
58
- styles({sourceMap: false, logger: silent}),
63
+ styles({sourceMap: false, logger: sass.Logger.silent}),
59
64
  logger()
60
65
  ]
61
66
  };
@@ -71,7 +76,7 @@ const watchOptions = Object.assign({}, buildOptions, {
71
76
  });
72
77
 
73
78
  const serveOptions = {
74
- proxy: `${package.name}.test`,
79
+ proxy: `${process.env.npm_package_name}.test`,
75
80
  files: ['assets/**', 'build/*', '**/*.php'],
76
81
  host: 'localhost',
77
82
  open: false,
@@ -125,8 +130,7 @@ async function main() {
125
130
  server.init(serveOptions, () => {
126
131
  builder.watch();
127
132
  watcher.watch();
128
-
129
- require('readline').emitKeypressEvents(process.stdin);
133
+ readline.emitKeypressEvents(process.stdin);
130
134
 
131
135
  process.stdin.setRawMode(true);
132
136
  process.stdin.on('keypress', (_, key) => {
@@ -136,17 +140,18 @@ async function main() {
136
140
  });
137
141
  }
138
142
 
139
- function extend(options, config) {
140
- if (!config) return options;
141
- return typeof config === 'function' ? config(options) : Object.assign(options, config);
142
- }
143
-
144
143
  if (fs.existsSync(process.argv[3])) {
145
- const test = require(`${cwd}/${process.argv[3]}`);
146
- console.log(extend(watchOptions, test.watch));
147
- console.log(extend(buildOptions, test.build));
148
- console.log(extend(serveOptions, test.serve));
149
- process.exit();
150
- }
151
144
 
152
- main();
145
+ function extend(options, config) {
146
+ if (typeof config === 'undefined') return;
147
+ Object.assign(options, typeof config === 'function' ? config(options) : config);
148
+ }
149
+
150
+ import(`${cwd}/${process.argv[3]}`).then(settings => {
151
+ extend(watchOptions, settings.watch);
152
+ extend(buildOptions, settings.build);
153
+ extend(serveOptions, settings.serve);
154
+ main();
155
+ });
156
+
157
+ } else { main(); }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@tmbr/bundler",
3
- "version": "1.10.0",
3
+ "type": "module",
4
+ "version": "1.11.0",
4
5
  "repository": "github:TMBR/tmbr-bundler",
5
6
  "bin": {
6
7
  "bundler": "cli.js",
7
8
  "tmbr-bundler": "cli.js"
8
9
  },
9
10
  "dependencies": {
10
- "browser-sync": "^2.28.3",
11
- "chalk": "^4.1.2",
12
- "esbuild": "^0.17.11",
13
- "esbuild-sass-plugin": "^2.6.0"
11
+ "browser-sync": "^3.0.2",
12
+ "chalk": "^5.3.0",
13
+ "esbuild": "^0.19.11",
14
+ "esbuild-sass-plugin": "^2.16.1"
14
15
  }
15
16
  }