@zumerbox/build 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ #### [v0.3.0](https://github.com/zumerlab/zumerbox-build/compare/v0.2.0...v0.3.0)
6
+
7
+ > 27 March 2024
8
+
9
+ - feat: add options to bundle code [`b3b8d57`](https://github.com/zumerlab/zumerbox-build/commit/b3b8d571fa0eff711dc181a6f0410cac38bf5831)
10
+ - Bumped version [`4785829`](https://github.com/zumerlab/zumerbox-build/commit/4785829190d0dee78d19d0e39730c222c2597de8)
11
+
5
12
  #### [v0.2.0](https://github.com/zumerlab/zumerbox-build/compare/v0.1.1...v0.2.0)
6
13
 
7
14
  > 25 March 2024
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @zumerbox/build
2
2
 
3
- A lightweight build tool for compiling and bundling your project assets.
3
+ The Zumerbox build tool is a command-line utility designed to bundle and compile JavaScript and SCSS files into distributable formats. It leverages the esbuild library for efficient bundling and minification, providing developers with a streamlined workflow for frontend development.
4
+
5
+ Refer to the [ZumerBox bundle](https://github.com/zumerlab/zumerbox) for more information and tools.
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,11 +10,31 @@ A lightweight build tool for compiling and bundling your project assets.
8
10
  npm install @zumerbox/build --save-dev
9
11
  ```
10
12
 
11
- ## Usage
13
+ ## Usage:
12
14
 
13
15
  ```bash
14
- npx @zumerbox/build
16
+ npx @zumerbox/build --name <bundler_name> --js <path_to_js_file> --scss <path_to_scss_file> [options]
15
17
  ```
16
18
 
17
- Refer to the [ZumerBox bundle](https://github.com/zumerlab/zumerbox) for more information.
18
- ```
19
+ ## Options:
20
+
21
+ - `--name (-n)`: Specifies the name of the bundler. If not provided, it will attempt to use the name from the package.json file. If the name is not available in package.json, it will default to "MyBundler".
22
+ - `--js (-j)`: Specifies the path to the JavaScript file (optional).
23
+ - `--scss (-s)`: Specifies the path to the SCSS file (optional).
24
+ - `--minify (-m)`: Generates minified output files (JavaScript and CSS) if enabled.
25
+ - `--outdir (-d)`: Specifies the destination folder for the output files. Default is "dist".
26
+ - `--platform (-p)`: Specifies the target platform for esBuild. Default is "browser".
27
+ - `--help (-h)`: Displays the help message.
28
+
29
+
30
+ ## Functionality:
31
+ - **Input files**: Specify the JavaScript and SCSS files to be bundled using the command-line options.
32
+ - **Bundling**: The tool utilizes esbuild to bundle the provided JavaScript and SCSS files into distributable formats.
33
+ - **Minification**: Optionally, the tool can minify the output files by setting the '--minify' flag.
34
+ - **Package information**: The tool reads package.json from the project directory to extract metadata such as name, version, author, and license. This information is included as a banner in the output files.
35
+ - **Output directory**: Output files are saved to the specified output directory ('dist' by default).
36
+ - **Error handling**: The tool gracefully handles errors during the bundling process and exits with an error code if an error occurs.
37
+
38
+ ## Credits:
39
+
40
+ This tools is powered by esbuild (https://esbuild.github.io/)
package/bin/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const esbuild = require('esbuild')
4
- const path = require('path')
5
- const yargs = require('yargs')
6
- const sassPlugin = require('esbuild-plugin-sass')
3
+ const esbuild = require('esbuild');
4
+ const path = require('path');
5
+ const yargs = require('yargs');
6
+ const sassPlugin = require('esbuild-plugin-sass');
7
7
 
8
8
  // Define command-line options using yargs
9
9
  const argv = yargs
@@ -11,24 +11,21 @@ const argv = yargs
11
11
  .option('name', {
12
12
  alias: 'n',
13
13
  describe: 'Name of the bundler',
14
- demandOption: true,
15
14
  type: 'string'
16
15
  })
17
16
  .option('js', {
18
17
  alias: 'j',
19
18
  describe: 'Path to JavaScript file',
20
- demandOption: true,
21
19
  type: 'string'
22
20
  })
23
21
  .option('scss', {
24
22
  alias: 's',
25
23
  describe: 'Path to SCSS file',
26
- demandOption: true,
27
24
  type: 'string'
28
25
  })
29
26
  .option('minify', {
30
27
  alias: 'm',
31
- describe: 'Generate minified output files (JavaScript and CSS)',
28
+ describe: 'Generate minified output files',
32
29
  type: 'boolean',
33
30
  default: false
34
31
  })
@@ -38,46 +35,63 @@ const argv = yargs
38
35
  type: 'string',
39
36
  default: 'dist'
40
37
  })
38
+ .option('platform', {
39
+ alias: 'p',
40
+ describe: 'Target platform for esBuild (e.g., browser, node)',
41
+ type: 'string',
42
+ default: 'browser'
43
+ })
41
44
  .help('h')
42
- .alias('h', 'help').argv
45
+ .alias('h', 'help').argv;
43
46
 
44
47
  // Read package.json from project directory
45
- const packageJsonPath = path.resolve(__dirname, '../package.json')
46
- const pkg = require(packageJsonPath)
48
+ const packageJsonPath = path.resolve(__dirname, '../package.json');
49
+ const pkg = require(packageJsonPath);
50
+
51
+ // Use package name from package.json if no name provided
52
+ const bundlerName = argv.name || pkg.name || 'MyBundler';
47
53
 
48
- // Extract name from package.json
49
- const bundlerName = pkg.name || 'MyBundler'
50
54
  const setBanner = () => `
51
55
  /*
52
56
  * ${pkg.name}
53
57
  * v.${pkg.version}
54
58
  * Author ${pkg.author}
55
59
  * License ${pkg.license}
56
- **/`
60
+ **/`;
57
61
 
58
62
  // Configuration for esbuild
59
63
  const options = {
60
- entryPoints: [argv.scss, argv.js],
61
- entryNames: `${argv.name}`,
64
+ entryPoints: [],
65
+ entryNames: bundlerName,
62
66
  bundle: true,
63
67
  banner: {
64
68
  js: setBanner(),
65
69
  css: setBanner()
66
70
  },
67
- outdir: `${argv.outdir}`,
71
+ outdir: argv.outdir,
68
72
  metafile: true,
69
- plugins: [sassPlugin()]
73
+ plugins: [sassPlugin()],
74
+ platform: argv.platform
75
+ };
76
+
77
+ if (argv.js) {
78
+ options.entryPoints.push(argv.js);
79
+ }
80
+
81
+ if (argv.scss) {
82
+ options.entryPoints.push(argv.scss);
70
83
  }
71
84
 
72
85
  const optionsMinify = {
73
- entryPoints: [argv.scss, argv.js],
74
- entryNames: `${argv.name}.min`,
75
- outdir: `${argv.outdir}`,
86
+ entryPoints: options.entryPoints,
87
+ entryNames: `${bundlerName}.min`,
88
+ outdir: argv.outdir,
76
89
  bundle: true,
77
90
  metafile: true,
78
91
  minify: true,
79
- plugins: [sassPlugin()]
80
- }
92
+ plugins: [sassPlugin()],
93
+ platform: argv.platform
94
+ };
81
95
 
82
96
  // Run esbuild
83
97
  esbuild
@@ -87,5 +101,5 @@ esbuild
87
101
  esbuild.build(optionsMinify)
88
102
  : console.log('⚡ Minify skipped ⚡')
89
103
  )
90
- .then(() => console.log('⚡ Styles & Scripts Compiled! ⚡ '))
91
- .catch(() => process.exit(1))
104
+ .then(() => console.log('⚡ Files compiled! ⚡ '))
105
+ .catch(() => process.exit(1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zumerbox/build",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "author": "Juan Martin Muda",
6
6
  "license": "MIT",
@@ -10,8 +10,8 @@
10
10
  },
11
11
  "scripts": {
12
12
  "start": "node bin/index.js",
13
- "release": "npx @zumerbox/release",
14
- "postversion": "npx @zumerbox/changelog && git add CHANGELOG.md && git commit -m \"Bumped version\" && git push --follow-tags"
13
+ "bump": "npx @zumerbox/bump",
14
+ "postbump": "npx @zumerbox/changelog && git add CHANGELOG.md && git commit -m \"Bumped version\" && git push --follow-tags"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",