@remotex-labs/xbuild 2.1.3 → 2.1.5

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,21 +1,22 @@
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
 
9
12
  ## Installation
10
13
 
11
14
  Install `@remotex-labs/xbuild` globally using npm:
12
-
13
15
  ```bash
14
16
  npm install -g @remotex-labs/xbuild
15
17
  ```
16
18
 
17
19
  Or using Yarn:
18
-
19
20
  ```bash
20
21
  yarn global add @remotex-labs/xbuild
21
22
  ```
@@ -26,8 +27,6 @@ Run the `xBuild -h` CLI tool with various options to build your typeScript proje
26
27
  Command-Line Options
27
28
 
28
29
  ```bash
29
-
30
-
31
30
  ______ _ _ _
32
31
  | ___ \ (_) | | |
33
32
  __ _| |_/ /_ _ _| | __| |
@@ -37,71 +36,69 @@ __ _| |_/ /_ _ _| | __| |
37
36
 
38
37
  Version: <xBuild version>
39
38
 
40
- index.js [file]
39
+ Usage: xBuild [files..] [options]
41
40
 
42
- A versatile JavaScript and TypeScript toolchain build system.
41
+ xBuild Options:
42
+ --entryPoints Specific files to build (supports glob patterns)
43
+ [array]
44
+ --typeCheck, --tc Perform type checking without building output
45
+ [boolean]
46
+ -p, --platform Target platform for the build output
47
+ [string] [choices: "browser", "node", "neutral"]
48
+ -s, --serve Start server to the <folder> [string]
49
+ -o, --outdir Directory for build output files [string]
50
+ --declaration, --de Generate TypeScript declaration files (.d.ts)
51
+ [boolean]
52
+ -w, --watch Watch mode - rebuild on file changes [boolean]
53
+ -c, --config Path to build configuration file
54
+ [string] [default: "config.xbuild.ts"]
55
+ --tsconfig, --tsc Path to TypeScript configuration file [string]
56
+ -m, --minify Minify the build output [boolean]
57
+ -b, --bundle Bundle dependencies into output files [boolean]
58
+ --types, --btc Enable type checking during build process [boolean]
59
+ --failOnError, --foe Fail build when TypeScript errors are detected
60
+ [boolean]
61
+ -f, --format Output module format
62
+ [string] [choices: "cjs", "esm", "iife"]
63
+ -v, --verbose Verbose error stack traces [boolean]
64
+ --build, --xb Select an build configuration variant by names (as
65
+ defined in your config file) [array]
43
66
 
44
67
  Positionals:
45
- entryPoints The file entryPoints to build [string]
68
+ entryPoints Specific files to build (supports glob patterns) [array]
46
69
 
47
70
  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
-
71
+ -h, --help Show help [boolean]
72
+ --version Show version number [boolean]
73
+
74
+ Examples:
75
+ xBuild src/index.ts Build a single file with default
76
+ settings
77
+ xBuild src/**/*.ts --bundle --minify Bundle and minify all TypeScript
78
+ files
79
+ xBuild src/app.ts -s Development mode with watch and dev
80
+ server
81
+ xBuild src/app.ts -s dist Development mode with watch and dev
82
+ server from dist folder
83
+ xBuild src/lib.ts --format esm Build ESM library with type
84
+ --declaration definitions
85
+ xBuild src/server.ts --platform node Build Node.js application to dist
86
+ --outdir dist folder
87
+ xBuild --typeCheck Type check only without generating
88
+ output
89
+ xBuild --config custom.xbuild.ts Use custom configuration file
90
+
91
+ For more information, check the documentation
92
+ https://remotex-labs.github.io/xBuild/
72
93
  ```
73
94
 
74
95
  ## Configuration
75
96
 
76
97
  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:
98
+ By default, xbuild uses `config.xbuild.ts` (`--config` change it). Here's how you can configure it:
78
99
 
79
100
  ### Example Configuration
80
101
  ```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
- You can also define multiple configurations as an array:
104
- ```ts
105
102
  /**
106
103
  * Import will remove at compile time
107
104
  */
@@ -119,90 +116,83 @@ import pkg from './package.json' with { type: 'json' };
119
116
  * Config build
120
117
  */
121
118
 
122
- const config: Array<xBuildConfig> = [
123
- {
124
- declaration: true,
119
+ export const config: xBuildConfig = {
120
+ common: {
121
+ define: {
122
+ __VERSION: pkg.version
123
+ },
125
124
  esbuild: {
126
125
  bundle: true,
127
126
  minify: true,
128
127
  format: 'esm',
129
- outdir: 'dist/esm',
130
128
  target: [ `node${ version.slice(1) }` ],
131
129
  platform: 'node',
132
130
  packages: 'external',
133
131
  sourcemap: true,
134
- sourceRoot: `https://github.com/remotex-lab/xmap/tree/v${ pkg.version }/`,
135
- entryPoints: [ 'src/index.ts' ]
132
+ external: [ './index.js' ],
133
+ sourceRoot: `https://github.com/remotex-lab/xBuild/tree/v${ pkg.version }/`,
134
+ loader: {
135
+ '.html': 'text'
136
+ }
137
+ },
138
+ lifecycle: {
139
+ onStart(): void {
140
+ console.log('starting build...');
141
+ }
136
142
  }
137
143
  },
138
- {
139
- declaration: false,
140
- noTypeChecker: true,
141
- esbuild: {
142
- bundle: true,
143
- format: 'cjs',
144
- outdir: 'dist/cjs'
144
+ variants: {
145
+ bash: {
146
+ esbuild: {
147
+ entryPoints: {
148
+ bash: 'src/bash.ts'
149
+ }
150
+ }
151
+ },
152
+ index: {
153
+ esbuild: {
154
+ entryPoints: {
155
+ index: 'src/index.ts'
156
+ }
157
+ }
145
158
  }
146
159
  }
147
- ];
148
-
149
- export default config;
160
+ };
150
161
  ```
151
162
 
152
163
  ## Using the ifdef Plugin
153
- The `ifdef` plugin in `xBuild` allows to conditionally include or exclude code based on defined variables. Heres an example:
164
+ The `ifdef` in `xBuild` allows to conditionally include or exclude code based on defined variables. Here's an example:
165
+
154
166
  ```ts
155
- // main.ts
167
+ $$ifdef('DEBUG', () => {
168
+ console.log('Debug mode is enabled');
169
+ });
156
170
 
157
- console.log("This code always runs");
171
+ $$ifndef('FEATURE_X', () => {
172
+ console.log('Feature X is not active');
173
+ });
158
174
 
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
175
+ const $$logger = $$ifdef('DEBUG', (...args: Array<unknown>) => {
176
+ console.debug(...args);
177
+ });
163
178
 
164
- // ifdef FEATURE_X
165
- console.log("Feature X is active");
166
- // endif
167
- ```
179
+ $$logger('some log that will be in debug mode only');
168
180
 
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.
181
+ const result = $$inline(() => {
182
+ console.log('compile time log');
189
183
 
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.
184
+ return 'run in compile time and retrun string result';
185
+ });
191
186
 
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
- }
187
+ console.log(result);
201
188
  ```
202
189
 
190
+ ### Setting Conditions in Configuration
191
+ To enable these blocks during the build, define your conditions in the `xBuild` configuration file:
192
+
203
193
  ```ts
204
194
  /**
205
- * Imports will be remove at compile time
195
+ * Import will remove at compile time
206
196
  */
207
197
 
208
198
  import type { xBuildConfig } from '@remotex-labs/xbuild';
@@ -218,58 +208,65 @@ import pkg from './package.json' with { type: 'json' };
218
208
  * Config build
219
209
  */
220
210
 
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');
211
+ export const config: xBuildConfig = {
212
+ common: {
213
+ define: {
214
+ __VERSION: pkg.version,
215
+ },
216
+ esbuild: {
217
+ bundle: true,
218
+ minify: true,
219
+ format: 'esm',
220
+ target: [ `node${ version.slice(1) }` ],
221
+ platform: 'node',
222
+ packages: 'external',
223
+ sourcemap: true,
224
+ external: [ './index.js' ],
225
+ sourceRoot: `https://github.com/remotex-lab/xBuild/tree/v${ pkg.version }/`,
226
+ loader: {
227
+ '.html': 'text'
228
+ }
241
229
  },
242
- onEnd: async (result) => {
243
- console.log('Build finished:', result);
230
+ lifecycle: {
231
+ onStart(): void {
232
+ console.log('starting build...');
233
+ }
244
234
  }
245
235
  },
246
- define: {
247
- '__ENV__': 'development',
236
+ variants: {
237
+ bash: {
238
+ define: {
239
+ DEBUG: true, // Enables the DEBUG section
240
+ FEATURE_X: false, // Excludes the FEATURE_X section
241
+ },
242
+ esbuild: {
243
+ entryPoints: {
244
+ bash: 'src/bash.ts'
245
+ }
246
+ }
247
+ },
248
+ index: {
249
+ esbuild: {
250
+ entryPoints: {
251
+ index: 'src/index.ts'
252
+ }
253
+ }
254
+ }
248
255
  }
249
256
  };
250
-
251
- export default config;
252
257
  ```
253
258
 
254
- ## Using the ifdef and macros
255
- ```ts
256
- // main.ts
257
-
258
- console.log("This code always runs");
259
+ ## Hooks
260
+ The `LifecycleHooksInterface` interface provides a structure for lifecycle hooks to customize the build process.
259
261
 
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);
262
+ ```ts
263
+ export interface LifecycleHooksInterface {
264
+ onEnd?: OnEndType;
265
+ onLoad?: OnLoadType;
266
+ onStart?: OnStartType;
267
+ onSuccess?: OnEndType;
268
+ onResolve?: OnResolveType;
264
269
  }
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
270
  ```
274
271
 
275
272
  ## Links