@remotex-labs/xbuild 2.1.4 → 2.1.6

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/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # xBuild
2
- [![npm version](https://img.shields.io/badge/Documentation-orange?logo=typescript&logoColor=f5f5f5)](https://remotex-labs.github.io/xBuild/)
2
+
3
+ [![Documentation](https://img.shields.io/badge/Documentation-orange?logo=typescript&logoColor=f5f5f5)](https://remotex-labs.github.io/xBuild/)
3
4
  [![npm version](https://img.shields.io/npm/v/@remotex-labs/xbuild.svg)](https://www.npmjs.com/package/@remotex-labs/xbuild)
4
5
  [![License: MPL 2.0](https://img.shields.io/badge/License-MPL_2.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
5
- [![Node.js CI](https://github.com/remotex-labs/xBuild/actions/workflows/test.yml/badge.svg)](https://github.com/remotex-labs/xBuild/actions/workflows/test.yml)
6
+ [![Node.js CI](https://github.com/remotex-labs/xbuild/actions/workflows/test.yml/badge.svg)](https://github.com/remotex-labs/xBuild/actions/workflows/test.yml)
7
+ [![Discord](https://img.shields.io/discord/1364348850696884234?logo=Discord&label=Discord)](https://discord.gg/psV9grS9th)
8
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/remotex-labs/xBuild)
6
9
 
7
10
  `@remotex-labs/xbuild` is a versatile TypeScript toolchain build system
8
11
 
@@ -26,8 +29,6 @@ Run the `xBuild -h` CLI tool with various options to build your typeScript proje
26
29
  Command-Line Options
27
30
 
28
31
  ```bash
29
-
30
-
31
32
  ______ _ _ _
32
33
  | ___ \ (_) | | |
33
34
  __ _| |_/ /_ _ _| | __| |
@@ -37,70 +38,69 @@ __ _| |_/ /_ _ _| | __| |
37
38
 
38
39
  Version: <xBuild version>
39
40
 
40
- index.js [file]
41
+ Usage: xBuild [files..] [options]
41
42
 
42
- A versatile JavaScript and TypeScript toolchain build system.
43
+ xBuild Options:
44
+ --entryPoints Specific files to build (supports glob patterns)
45
+ [array]
46
+ --typeCheck, --tc Perform type checking without building output
47
+ [boolean]
48
+ -p, --platform Target platform for the build output
49
+ [string] [choices: "browser", "node", "neutral"]
50
+ -s, --serve Start server to the <folder> [string]
51
+ -o, --outdir Directory for build output files [string]
52
+ --declaration, --de Generate TypeScript declaration files (.d.ts)
53
+ [boolean]
54
+ -w, --watch Watch mode - rebuild on file changes [boolean]
55
+ -c, --config Path to build configuration file
56
+ [string] [default: "config.xbuild.ts"]
57
+ --tsconfig, --tsc Path to TypeScript configuration file [string]
58
+ -m, --minify Minify the build output [boolean]
59
+ -b, --bundle Bundle dependencies into output files [boolean]
60
+ --types, --btc Enable type checking during build process [boolean]
61
+ --failOnError, --foe Fail build when TypeScript errors are detected
62
+ [boolean]
63
+ -f, --format Output module format
64
+ [string] [choices: "cjs", "esm", "iife"]
65
+ -v, --verbose Verbose error stack traces [boolean]
66
+ --build, --xb Select an build configuration variant by names (as
67
+ defined in your config file) [array]
43
68
 
44
69
  Positionals:
45
- entryPoints The file entryPoints to build [string]
70
+ entryPoints Specific files to build (supports glob patterns) [array]
46
71
 
47
72
  Options:
48
- -h, --help Show help [boolean]
49
- --typeCheck, --tc Perform type checking [boolean]
50
- -n, --node Build for node platform [boolean]
51
- -d, --dev Array entryPoints to run as development in Node.js
52
- [array]
53
- --debug, --db Array entryPoints to run in Node.js with debug sta
54
- te [array]
55
- -s, --serve Serve the build folder over HTTP [boolean]
56
- -o, --outdir Output directory [string]
57
- --declaration, --de Add TypeScript declarations [boolean]
58
- -w, --watch Watch for file changes [boolean]
59
- -c, --config Build configuration file (js/ts)
60
- [string] [default: "xbuild.config.ts"]
61
- --tsconfig, --tsc Set TypeScript configuration file to use
62
- [string] [default: "tsconfig.json"]
63
- -m, --minify Minify the code [boolean]
64
- -b, --bundle Bundle the code [boolean]
65
- --noTypeChecker, --ntc Skip TypeScript type checking [boolean]
66
- --buildOnError, --boe Continue building even if there are TypeScript typ
67
- e errors [boolean]
68
- -f, --format Defines the format for the build output ('cjs' | '
69
- esm' | 'iif'). [string]
70
- -v, --version Show version number [boolean] [default: false]
71
-
73
+ -h, --help Show help [boolean]
74
+ --version Show version number [boolean]
75
+
76
+ Examples:
77
+ xBuild src/index.ts Build a single file with default
78
+ settings
79
+ xBuild src/**/*.ts --bundle --minify Bundle and minify all TypeScript
80
+ files
81
+ xBuild src/app.ts -s Development mode with watch and dev
82
+ server
83
+ xBuild src/app.ts -s dist Development mode with watch and dev
84
+ server from dist folder
85
+ xBuild src/lib.ts --format esm Build ESM library with type
86
+ --declaration definitions
87
+ xBuild src/server.ts --platform node Build Node.js application to dist
88
+ --outdir dist folder
89
+ xBuild --typeCheck Type check only without generating
90
+ output
91
+ xBuild --config custom.xbuild.ts Use custom configuration file
92
+
93
+ For more information, check the documentation
94
+ https://remotex-labs.github.io/xBuild/
72
95
  ```
73
96
 
74
97
  ## Configuration
75
98
 
76
99
  The `xBuild` configuration file allows you to customize various settings for the build and development process.
77
- By default, xbuild uses `xbuild.config.ts` (`--config` change it). Heres how you can configure it:
100
+ By default, xbuild uses `config.xbuild.ts` (`--config` change it). Here's how you can configure it:
78
101
 
79
102
  ### Example Configuration
80
- ```ts
81
- const config: ConfigurationInterface = {
82
- declaration: true,
83
- buildOnError: false,
84
- noTypeChecker: false,
85
- esbuild: {
86
- entryPoints: ['./src/index.ts'],
87
- bundle: true,
88
- minify: true,
89
- format: 'esm',
90
- },
91
- serve: {
92
- active: true,
93
- port: 8080,
94
- host: 'localhost',
95
- onRequest: (req, res, next) => {
96
- console.log('Server request received');
97
- next();
98
- }
99
- }
100
- };
101
- ```
102
103
 
103
- You can also define multiple configurations as an array:
104
104
  ```ts
105
105
  /**
106
106
  * Import will remove at compile time
@@ -119,90 +119,85 @@ import pkg from './package.json' with { type: 'json' };
119
119
  * Config build
120
120
  */
121
121
 
122
- const config: Array<xBuildConfig> = [
123
- {
124
- declaration: true,
122
+ export const config: xBuildConfig = {
123
+ common: {
124
+ define: {
125
+ __VERSION: pkg.version
126
+ },
125
127
  esbuild: {
126
128
  bundle: true,
127
129
  minify: true,
128
130
  format: 'esm',
129
- outdir: 'dist/esm',
130
131
  target: [ `node${ version.slice(1) }` ],
131
132
  platform: 'node',
132
133
  packages: 'external',
133
134
  sourcemap: true,
134
- sourceRoot: `https://github.com/remotex-lab/xmap/tree/v${ pkg.version }/`,
135
- entryPoints: [ 'src/index.ts' ]
135
+ external: [ './index.js' ],
136
+ sourceRoot: `https://github.com/remotex-lab/xBuild/tree/v${ pkg.version }/`,
137
+ loader: {
138
+ '.html': 'text'
139
+ }
140
+ },
141
+ lifecycle: {
142
+ onStart(): void {
143
+ console.log('starting build...');
144
+ }
136
145
  }
137
146
  },
138
- {
139
- declaration: false,
140
- noTypeChecker: true,
141
- esbuild: {
142
- bundle: true,
143
- format: 'cjs',
144
- outdir: 'dist/cjs'
147
+ variants: {
148
+ bash: {
149
+ esbuild: {
150
+ entryPoints: {
151
+ bash: 'src/bash.ts'
152
+ }
153
+ }
154
+ },
155
+ index: {
156
+ esbuild: {
157
+ entryPoints: {
158
+ index: 'src/index.ts'
159
+ }
160
+ }
145
161
  }
146
162
  }
147
- ];
148
-
149
- export default config;
163
+ };
150
164
  ```
151
165
 
152
166
  ## Using the ifdef Plugin
153
- The `ifdef` plugin in `xBuild` allows to conditionally include or exclude code based on defined variables. Here’s an example:
167
+
168
+ The `ifdef` in `xBuild` allows to conditionally include or exclude code based on defined variables. Here's an example:
169
+
154
170
  ```ts
155
- // main.ts
171
+ $$ifdef('DEBUG', () => {
172
+ console.log('Debug mode is enabled');
173
+ });
156
174
 
157
- console.log("This code always runs");
175
+ $$ifndef('FEATURE_X', () => {
176
+ console.log('Feature X is not active');
177
+ });
158
178
 
159
- // If the `DEBUG` flag is set in your build config, this block will be included
160
- // ifdef DEBUG
161
- console.log("Debug mode is enabled");
162
- // endif
179
+ const $$logger = $$ifdef('DEBUG', (...args: Array<unknown>) => {
180
+ console.debug(...args);
181
+ });
163
182
 
164
- // ifdef FEATURE_X
165
- console.log("Feature X is active");
166
- // endif
167
- ```
183
+ $$logger('some log that will be in debug mode only');
168
184
 
169
- ### Setting Conditions in Configuration
170
- To enable these blocks during the build, define your conditions in the `xBuild` configuration file:
171
- ```ts
172
- export default {
173
- esbuild: {
174
- entryPoints: ['./src/main.ts'],
175
- outdir: 'dist',
176
- minify: false,
177
- format: 'esm',
178
- bundle: true,
179
- },
180
- define: {
181
- DEBUG: true, // Enables the DEBUG section
182
- FEATURE_X: false, // Excludes the FEATURE_X section
183
- }
184
- };
185
- ```
186
- In this example:
187
- * When `DEBUG` is set to `true`, the `Debug mode is enabled` message is included.
188
- * When `FEATURE_X` is `false`, the `console.log("Feature X is active");` line is excluded.
185
+ const result = $$inline(() => {
186
+ console.log('compile time log');
189
187
 
190
- This approach helps to manage feature toggles and debug code efficiently, making it possible to build different versions of your code based on a configuration.
188
+ return 'run in compile time and retrun string result';
189
+ });
191
190
 
192
- ## Hooks
193
- The `HooksInterface` interface provides a structure for lifecycle hooks to customize the build process.
194
- ```ts
195
- export interface HooksInterface {
196
- onEnd: OnEndType;
197
- onLoad: OnLoadType;
198
- onStart: OnStartType;
199
- onResolve: OnResolveType;
200
- }
191
+ console.log(result);
201
192
  ```
202
193
 
194
+ ### Setting Conditions in Configuration
195
+
196
+ To enable these blocks during the build, define your conditions in the `xBuild` configuration file:
197
+
203
198
  ```ts
204
199
  /**
205
- * Imports will be remove at compile time
200
+ * Import will remove at compile time
206
201
  */
207
202
 
208
203
  import type { xBuildConfig } from '@remotex-labs/xbuild';
@@ -218,61 +213,70 @@ import pkg from './package.json' with { type: 'json' };
218
213
  * Config build
219
214
  */
220
215
 
221
- const config: xBuildConfig = {
222
- dev: true,
223
- watch: true,
224
- declaration: true,
225
- buildOnError: false,
226
- noTypeChecker: false,
227
- esbuild: {
228
- entryPoints: ['./src/index.ts'],
229
- bundle: true,
230
- minify: true,
231
- target: 'es2020'
232
- },
233
- serve: {
234
- port: 8080,
235
- host: 'localhost',
236
- active: true // can be activeate using -s instead
237
- },
238
- hooks: {
239
- onStart: async (build) => {
240
- console.log('Build started');
216
+ export const config: xBuildConfig = {
217
+ common: {
218
+ define: {
219
+ __VERSION: pkg.version,
220
+ },
221
+ esbuild: {
222
+ bundle: true,
223
+ minify: true,
224
+ format: 'esm',
225
+ target: [ `node${ version.slice(1) }` ],
226
+ platform: 'node',
227
+ packages: 'external',
228
+ sourcemap: true,
229
+ external: [ './index.js' ],
230
+ sourceRoot: `https://github.com/remotex-lab/xBuild/tree/v${ pkg.version }/`,
231
+ loader: {
232
+ '.html': 'text'
233
+ }
241
234
  },
242
- onEnd: async (result) => {
243
- console.log('Build finished:', result);
235
+ lifecycle: {
236
+ onStart(): void {
237
+ console.log('starting build...');
238
+ }
244
239
  }
245
240
  },
246
- define: {
247
- '__ENV__': 'development',
241
+ variants: {
242
+ bash: {
243
+ define: {
244
+ DEBUG: true, // Enables the DEBUG section
245
+ FEATURE_X: false, // Excludes the FEATURE_X section
246
+ },
247
+ esbuild: {
248
+ entryPoints: {
249
+ bash: 'src/bash.ts'
250
+ }
251
+ }
252
+ },
253
+ index: {
254
+ esbuild: {
255
+ entryPoints: {
256
+ index: 'src/index.ts'
257
+ }
258
+ }
259
+ }
248
260
  }
249
261
  };
250
-
251
- export default config;
252
262
  ```
253
263
 
254
- ## Using the ifdef and macros
255
- ```ts
256
- // main.ts
264
+ ## Hooks
257
265
 
258
- console.log("This code always runs");
266
+ The `LifecycleHooksInterface` interface provides a structure for lifecycle hooks to customize the build process.
259
267
 
260
- // If the `DEBUG` flag is set in your build config, this block will be included
261
- // ifdef DEBUG
262
- export function $$logger(...args: Array<unknown>): void {
263
- console.log(...args);
268
+ ```ts
269
+ export interface LifecycleHooksInterface {
270
+ onEnd?: OnEndType;
271
+ onLoad?: OnLoadType;
272
+ onStart?: OnStartType;
273
+ onSuccess?: OnEndType;
274
+ onResolve?: OnResolveType;
264
275
  }
265
- // endif
266
-
267
- // ifdef FEATURE_X
268
- console.log("Feature X is active");
269
- // endif
270
-
271
-
272
- $$logger('data'); // will be deleted if $$logger does not exist
273
276
  ```
274
277
 
275
278
  ## Links
279
+
276
280
  - [Documentation](https://remotex-labs.github.io/xBuild/)
277
281
  - [GitHub Repository](https://github.com/remotex-labs/xBuild)
278
282
  - [Issue Tracker](https://github.com/remotex-labs/xBuild/issues)