@tmbr/bundler 1.7.0 → 1.9.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 +65 -52
- package/package.json +4 -4
- package/cli-new-backup.js +0 -127
- package/cli-old-backup.js +0 -105
package/cli.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const esbuild = require('esbuild');
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
const path = require('path');
|
|
4
|
-
const exec = require('child_process').execSync;
|
|
5
5
|
const chalk = require('chalk');
|
|
6
|
-
const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
7
|
-
const qrcode = require('qrcode-terminal');
|
|
8
6
|
const server = require('browser-sync').create();
|
|
7
|
+
const styles = require('esbuild-sass-plugin').sassPlugin;
|
|
8
|
+
const silent = require('sass').Logger.silent;
|
|
9
9
|
|
|
10
10
|
const dir = process.cwd();
|
|
11
|
+
const src = path.resolve(dir, 'src');
|
|
11
12
|
const package = require(`${dir}/package.json`);
|
|
12
13
|
const command = process.argv[2];
|
|
13
14
|
|
|
@@ -16,32 +17,33 @@ if (!['build', 'watch'].includes(command)) {
|
|
|
16
17
|
process.exit();
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const logger = (options = {}) => ({
|
|
21
|
+
name: 'logger',
|
|
22
|
+
setup(context) {
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const port = server.getOption('port');
|
|
24
|
-
const proxying = `${host}:${port}`;
|
|
25
|
-
const external = server.getOption('urls').get('external');
|
|
24
|
+
const path = context.initialOptions.outdir;
|
|
25
|
+
const slug = Object.keys(context.initialOptions.entryPoints)[0];
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
context.onStart(() => {
|
|
28
|
+
server.instance.active && server.info();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
context.onEnd(result => {
|
|
32
|
+
if (result.warnings.length || result.errors.length) return console.log('\007');
|
|
33
|
+
|
|
34
|
+
const css = `${path}/${slug}.css`;
|
|
35
|
+
console.log(`${css} ${Math.round(fs.statSync(css).size / 1000)} KB`);
|
|
31
36
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// console.log(build)
|
|
37
|
-
// build.onEnd(({warnings, errors}) => (warnings.length || errors.length) ? console.log('\007') : ok());
|
|
38
|
-
},
|
|
37
|
+
const js = `${path}/${slug}.js`;
|
|
38
|
+
console.log(`${js} ${Math.round(fs.statSync(js).size / 1000)} KB`);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
39
41
|
});
|
|
40
42
|
|
|
41
|
-
const
|
|
42
|
-
entryPoints: {'main.min':
|
|
43
|
-
alias: {'~':
|
|
44
|
-
outdir:
|
|
43
|
+
const buildOptions = {
|
|
44
|
+
entryPoints: {'main.min': src},
|
|
45
|
+
alias: {'~': src},
|
|
46
|
+
outdir: 'build',
|
|
45
47
|
bundle: true,
|
|
46
48
|
minify: true,
|
|
47
49
|
target: 'es2019',
|
|
@@ -50,49 +52,60 @@ const buildConfig = {
|
|
|
50
52
|
sourcemap: false,
|
|
51
53
|
treeShaking: true,
|
|
52
54
|
legalComments: 'none',
|
|
53
|
-
plugins: [
|
|
55
|
+
plugins: [
|
|
56
|
+
styles({sourceMap: false, logger: silent}),
|
|
57
|
+
logger()
|
|
58
|
+
]
|
|
54
59
|
};
|
|
55
60
|
|
|
56
|
-
const
|
|
57
|
-
entryPoints: {'main.dev':
|
|
61
|
+
const watchOptions = Object.assign({}, buildOptions, {
|
|
62
|
+
entryPoints: {'main.dev': src},
|
|
58
63
|
minify: false,
|
|
59
64
|
logLevel: 'silent',
|
|
60
65
|
sourcemap: 'inline',
|
|
61
|
-
plugins: [
|
|
66
|
+
plugins: [
|
|
67
|
+
styles({sourceMap: true})
|
|
68
|
+
]
|
|
62
69
|
});
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
const serveOptions = {
|
|
72
|
+
proxy: `${package.name}.test`,
|
|
73
|
+
files: ['assets/**', 'build/*', '**/*.php'],
|
|
74
|
+
host: 'localhost',
|
|
75
|
+
open: false,
|
|
76
|
+
notify: false,
|
|
77
|
+
logLevel: 'silent',
|
|
78
|
+
injectChanges: false,
|
|
79
|
+
ui: false,
|
|
80
|
+
};
|
|
68
81
|
|
|
69
|
-
|
|
82
|
+
server.info = function() {
|
|
83
|
+
const host = server.getOption('proxy').get('target');
|
|
84
|
+
const port = server.getOption('port');
|
|
85
|
+
const proxying = `${host}:${port}`;
|
|
86
|
+
const external = server.getOption('urls').get('external');
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
console.clear();
|
|
89
|
+
console.log();
|
|
90
|
+
console.log(`Proxying: ${chalk.green(proxying)}`);
|
|
91
|
+
console.log(`External: ${chalk.cyan(external || 'offline')}\n`);
|
|
92
|
+
};
|
|
73
93
|
|
|
74
|
-
|
|
94
|
+
async function main() {
|
|
75
95
|
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
const watcher = await esbuild.context(watchOptions);
|
|
97
|
+
const builder = await esbuild.context(buildOptions);
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
if (command === 'build') {
|
|
100
|
+
await watcher.rebuild();
|
|
101
|
+
await builder.rebuild();
|
|
81
102
|
process.exit();
|
|
82
103
|
}
|
|
83
104
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
open: false,
|
|
89
|
-
notify: false,
|
|
90
|
-
logLevel: 'silent',
|
|
91
|
-
injectChanges: false,
|
|
92
|
-
ui: false,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
server.init(options, ok);
|
|
105
|
+
server.init(serveOptions, () => {
|
|
106
|
+
builder.watch();
|
|
107
|
+
watcher.watch();
|
|
108
|
+
});
|
|
96
109
|
}
|
|
97
110
|
|
|
98
111
|
main();
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmbr/bundler",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"repository": "github:TMBR/tmbr-bundler",
|
|
5
5
|
"bin": {
|
|
6
|
+
"bundler": "cli.js",
|
|
6
7
|
"tmbr-bundler": "cli.js"
|
|
7
8
|
},
|
|
8
9
|
"dependencies": {
|
|
9
|
-
"browser-sync": "^2.
|
|
10
|
+
"browser-sync": "^2.28.3",
|
|
10
11
|
"chalk": "^4.1.2",
|
|
11
12
|
"esbuild": "^0.17.11",
|
|
12
|
-
"esbuild-sass-plugin": "^2.6.0"
|
|
13
|
-
"qrcode-terminal": "^0.12.0"
|
|
13
|
+
"esbuild-sass-plugin": "^2.6.0"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/cli-new-backup.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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();
|
package/cli-old-backup.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
}
|