@tmbr/bundler 1.6.1 → 1.7.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.
@@ -0,0 +1,127 @@
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 styles = require('esbuild-sass-plugin').sassPlugin;
8
+ const qrcode = require('qrcode-terminal');
9
+ const server = require('browser-sync').create();
10
+
11
+ const dir = process.cwd();
12
+ const package = require(`${dir}/package.json`);
13
+ const command = process.argv[2];
14
+
15
+ if (!['build', 'watch'].includes(command)) {
16
+ console.log(`Invalid command: ${chalk.red(command)}\n`);
17
+ process.exit();
18
+ }
19
+
20
+ exec(`rm -rf ${dir}/build/*`);
21
+
22
+ function ok() {
23
+ const host = server.getOption('proxy').get('target');
24
+ const port = server.getOption('port');
25
+ const proxying = `${host}:${port}`;
26
+ const external = server.getOption('urls').get('external');
27
+
28
+ console.clear();
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
+ }
33
+
34
+ const assets = (options = {}) => ({
35
+ name: 'assets',
36
+ setup(build) {
37
+ build.onResolve({filter: /..\/(assets|fonts|images)\//}, args => ({
38
+ path: args.path,
39
+ external: true
40
+ }))
41
+ },
42
+ });
43
+
44
+ const errors = (options = {}) => ({
45
+ name: 'errors',
46
+ setup(build) {
47
+ build.onEnd(({warnings, errors}) => {
48
+ (warnings.length || errors.length) ? console.log('\007') : ok();
49
+ });
50
+ },
51
+ });
52
+
53
+ const plugins = [
54
+ assets(),
55
+ styles({sourceMap: true}),
56
+ ];
57
+
58
+ const defaults = {
59
+ outdir: path.resolve(dir, 'build'),
60
+ bundle: true,
61
+ legalComments: 'none',
62
+ target: 'es2019',
63
+ treeShaking: true,
64
+ plugins,
65
+ };
66
+
67
+ const watchConfig = Object.assign({}, defaults, {
68
+ entryPoints: {'main.dev': path.resolve(dir, './src')},
69
+ minify: false,
70
+ logLevel: 'silent',
71
+ sourcemap: 'inline',
72
+ plugins: [
73
+ ...defaults.plugins,
74
+ // errors()
75
+ ]
76
+ });
77
+
78
+ const buildConfig = Object.assign({}, defaults, {
79
+ entryPoints: {'main.min': path.resolve(dir, './src')},
80
+ minify: true,
81
+ logLevel: 'warning',
82
+ sourcemap: false,
83
+ });
84
+
85
+ async function main() {
86
+
87
+ const watcher = await esbuild.context(watchConfig);
88
+ const builder = await esbuild.context(buildConfig);
89
+
90
+ try {
91
+
92
+ await watcher.rebuild();
93
+ await builder.rebuild();
94
+ if (command === 'build') process.exit();
95
+
96
+ // await builder.watch();
97
+ // await watcher.watch();
98
+
99
+ } catch(e) {
100
+ console.log(e)
101
+ }
102
+
103
+ // const watchedBuilds = Object.keys(watchConfig.entryPoints).map(name => (
104
+ // `${watchConfig.outdir}/${name}.*`
105
+ // ));
106
+
107
+ // const files = [
108
+ // ...watchedBuilds,
109
+ // 'images/*',
110
+ // '**/*.php'
111
+ // ];
112
+
113
+ /* const options = {
114
+ // files,
115
+ proxy: `${package.name}.test`,
116
+ host: 'localhost',
117
+ open: false,
118
+ notify: false,
119
+ logLevel: 'silent',
120
+ ui: false,
121
+ };
122
+
123
+ server.init(options, ok); */
124
+ }
125
+
126
+ const noop = fn => fn;
127
+ main();
@@ -0,0 +1,105 @@
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 styles = require('esbuild-sass-plugin').sassPlugin;
8
+ const qrcode = require('qrcode-terminal');
9
+ const server = require('browser-sync').create();
10
+
11
+ const dir = process.cwd();
12
+ const package = require(`${dir}/package.json`);
13
+ const command = process.argv[2];
14
+
15
+ if (!['build', 'watch'].includes(command)) {
16
+ console.log(`Invalid command: ${chalk.red(command)}\n`);
17
+ process.exit();
18
+ }
19
+
20
+ exec(`rm -rf ${dir}/build/*`);
21
+
22
+ function ok() {
23
+ const host = server.getOption('proxy').get('target');
24
+ const port = server.getOption('port');
25
+ const proxying = `${host}:${port}`;
26
+ const external = server.getOption('urls').get('external');
27
+
28
+ console.clear();
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
+ }
33
+
34
+ function entryPoints(suffix = '') {
35
+
36
+ if (!suffix.startsWith('.')) {
37
+ suffix = `.${suffix}`;
38
+ }
39
+
40
+ const entries = Object.entries({
41
+ admin: path.resolve(dir, './src/admin'),
42
+ main: path.resolve(dir, './src'),
43
+ });
44
+
45
+ return entries.reduce((result, [name, path]) => {
46
+ if (fs.existsSync(path)) result[`${name}${suffix}`] = path;
47
+ return result;
48
+ }, {});
49
+ }
50
+
51
+ const errors = (options = {}) => ({
52
+ name: 'errors',
53
+ setup(build) {
54
+ build.onEnd(({warnings, errors}) => {
55
+ (warnings.length || errors.length) ? console.log('\007') : ok();
56
+ });
57
+ },
58
+ });
59
+
60
+ const defaults = {
61
+ watch: command === 'watch',
62
+ alias: {'~': path.resolve(dir, 'src')},
63
+ outdir: path.resolve(dir, 'build'),
64
+ bundle: true,
65
+ minify: true,
66
+ target: 'es2019',
67
+ external: 'jpg,jpeg,webp,png,svg,woff,woff2'.split(',').map(ext => `*.${ext}`),
68
+ logLevel: 'warning',
69
+ sourcemap: false,
70
+ treeShaking: true,
71
+ legalComments: 'none',
72
+ plugins: [styles({sourceMap: true})],
73
+ };
74
+
75
+ const watchConfig = Object.assign({}, defaults, {
76
+ entryPoints: entryPoints('dev'),
77
+ minify: false,
78
+ sourcemap: 'inline',
79
+ logLevel: 'silent',
80
+ plugins: [...defaults.plugins, errors()],
81
+ });
82
+
83
+ const buildConfig = Object.assign({}, defaults, {
84
+ entryPoints: entryPoints('min'),
85
+ });
86
+
87
+ const noop = fn => fn;
88
+ esbuild.build(watchConfig).catch(noop);
89
+ esbuild.build(buildConfig).catch(noop);
90
+
91
+ if (command === 'watch') {
92
+
93
+ const options = {
94
+ proxy: `${package.name}.test`,
95
+ files: ['assets/**', 'build/*', '**/*.php'],
96
+ injectChanges: false,
97
+ host: 'localhost',
98
+ open: false,
99
+ notify: false,
100
+ logLevel: 'silent',
101
+ ui: false,
102
+ };
103
+
104
+ server.init(options, ok);
105
+ }
package/cli.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  const esbuild = require('esbuild');
3
- const fs = require('fs');
4
3
  const path = require('path');
5
4
  const exec = require('child_process').execSync;
6
5
  const chalk = require('chalk');
@@ -17,88 +16,83 @@ if (!['build', 'watch'].includes(command)) {
17
16
  process.exit();
18
17
  }
19
18
 
20
- exec(`rm -rf ${dir}/build/*`);
21
-
22
19
  function ok() {
20
+
21
+ console.clear();
23
22
  const host = server.getOption('proxy').get('target');
24
23
  const port = server.getOption('port');
25
24
  const proxying = `${host}:${port}`;
26
25
  const external = server.getOption('urls').get('external');
27
26
 
28
- console.clear();
29
27
  external && qrcode.generate(external, {small: true}, console.log);
30
28
  console.log(`Proxying: ${chalk.green(proxying)}`);
31
29
  console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
32
30
  }
33
31
 
34
- function entryPoints(suffix = '') {
35
-
36
- if (!suffix.startsWith('.')) {
37
- suffix = `.${suffix}`;
38
- }
39
-
40
- const entries = Object.entries({
41
- admin: path.resolve(dir, './src/admin'),
42
- main: path.resolve(dir, './src'),
43
- });
44
-
45
- return entries.reduce((result, [name, path]) => {
46
- if (fs.existsSync(path)) result[`${name}${suffix}`] = path;
47
- return result;
48
- }, {});
49
- }
50
-
51
32
  const errors = (options = {}) => ({
52
33
  name: 'errors',
53
34
  setup(build) {
54
- build.onEnd(({warnings, errors}) => {
55
- (warnings.length || errors.length) ? console.log('\007') : ok();
56
- });
35
+ // console.log(Object.keys(build));
36
+ // console.log(build)
37
+ // build.onEnd(({warnings, errors}) => (warnings.length || errors.length) ? console.log('\007') : ok());
57
38
  },
58
39
  });
59
40
 
60
- const defaults = {
61
- watch: command === 'watch',
41
+ const buildConfig = {
42
+ entryPoints: {'main.min': path.resolve(dir, './src')},
62
43
  alias: {'~': path.resolve(dir, 'src')},
63
44
  outdir: path.resolve(dir, 'build'),
64
45
  bundle: true,
65
46
  minify: true,
66
47
  target: 'es2019',
67
- external: 'jpg,jpeg,webp,png,svg,woff,woff2'.split(',').map(ext => `*.${ext}`),
48
+ external: 'jpg,jpeg,webp,png,gif,svg,woff,woff2'.split(',').map(ext => `*.${ext}`),
68
49
  logLevel: 'warning',
69
50
  sourcemap: false,
70
51
  treeShaking: true,
71
52
  legalComments: 'none',
72
- plugins: [styles({sourceMap: true})],
53
+ plugins: [styles({sourceMap: true})]
73
54
  };
74
55
 
75
- const watchConfig = Object.assign({}, defaults, {
76
- entryPoints: entryPoints('dev'),
56
+ const watchConfig = Object.assign({}, buildConfig, {
57
+ entryPoints: {'main.dev': path.resolve(dir, './src')},
77
58
  minify: false,
78
- sourcemap: 'inline',
79
59
  logLevel: 'silent',
80
- plugins: [...defaults.plugins, errors()],
60
+ sourcemap: 'inline',
61
+ plugins: [...buildConfig.plugins, errors()]
81
62
  });
82
63
 
83
- const buildConfig = Object.assign({}, defaults, {
84
- entryPoints: entryPoints('min'),
85
- });
64
+ async function main() {
65
+
66
+ const builder = await esbuild.context(buildConfig);
67
+ const watcher = await esbuild.context(watchConfig);
68
+
69
+ try {
86
70
 
87
- const noop = fn => fn;
88
- esbuild.build(watchConfig).catch(noop);
89
- esbuild.build(buildConfig).catch(noop);
71
+ await builder.rebuild();
72
+ await watcher.rebuild();
90
73
 
91
- if (command === 'watch') {
74
+ if (command === 'build') process.exit();
75
+
76
+ await builder.watch();
77
+ await watcher.watch();
78
+
79
+ } catch(e) {
80
+ console.log(e);
81
+ process.exit();
82
+ }
92
83
 
93
84
  const options = {
94
85
  proxy: `${package.name}.test`,
95
- files: ['build/*', '**/*.php'],
86
+ files: ['assets/**', 'build/*', '**/*.php'],
96
87
  host: 'localhost',
97
88
  open: false,
98
89
  notify: false,
99
90
  logLevel: 'silent',
91
+ injectChanges: false,
100
92
  ui: false,
101
93
  };
102
94
 
103
95
  server.init(options, ok);
104
96
  }
97
+
98
+ main();
package/package.json CHANGED
@@ -1,18 +1,15 @@
1
1
  {
2
2
  "name": "@tmbr/bundler",
3
- "author": "TMBR (https://wearetmbr.com/)",
4
- "version": "1.6.1",
5
- "license": "MIT",
6
- "repository": "https://github.com/TMBR/tmbr-bundler",
7
- "description": "WordPress development toolkit built on esbuild and browser-sync",
3
+ "version": "1.7.0",
4
+ "repository": "github:TMBR/tmbr-bundler",
8
5
  "bin": {
9
6
  "tmbr-bundler": "cli.js"
10
7
  },
11
8
  "dependencies": {
12
9
  "browser-sync": "^2.27.10",
13
10
  "chalk": "^4.1.2",
14
- "esbuild": "^0.16.10",
15
- "esbuild-sass-plugin": "^2.3.2",
11
+ "esbuild": "^0.17.11",
12
+ "esbuild-sass-plugin": "^2.6.0",
16
13
  "qrcode-terminal": "^0.12.0"
17
14
  }
18
15
  }