@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 +156 -159
- package/dist/bash.d.ts +0 -15814
- package/dist/bash.js +43 -360
- package/dist/bash.js.map +5 -5
- package/dist/index.d.ts +4362 -12747
- package/dist/index.js +14 -332
- package/dist/index.js.map +4 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
# xBuild
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
[](https://remotex-labs.github.io/xBuild/)
|
|
3
4
|
[](https://www.npmjs.com/package/@remotex-labs/xbuild)
|
|
4
5
|
[](https://opensource.org/licenses/MPL-2.0)
|
|
5
|
-
[](https://github.com/remotex-labs/xBuild/actions/workflows/test.yml)
|
|
7
|
+
[](https://discord.gg/psV9grS9th)
|
|
8
|
+
[](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
|
-
|
|
39
|
+
Usage: xBuild [files..] [options]
|
|
41
40
|
|
|
42
|
-
|
|
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
|
|
68
|
+
entryPoints Specific files to build (supports glob patterns) [array]
|
|
46
69
|
|
|
47
70
|
Options:
|
|
48
|
-
-h, --help
|
|
49
|
-
--
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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.
|
|
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:
|
|
123
|
-
{
|
|
124
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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`
|
|
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
|
-
|
|
167
|
+
$$ifdef('DEBUG', () => {
|
|
168
|
+
console.log('Debug mode is enabled');
|
|
169
|
+
});
|
|
156
170
|
|
|
157
|
-
|
|
171
|
+
$$ifndef('FEATURE_X', () => {
|
|
172
|
+
console.log('Feature X is not active');
|
|
173
|
+
});
|
|
158
174
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// endif
|
|
175
|
+
const $$logger = $$ifdef('DEBUG', (...args: Array<unknown>) => {
|
|
176
|
+
console.debug(...args);
|
|
177
|
+
});
|
|
163
178
|
|
|
164
|
-
|
|
165
|
-
console.log("Feature X is active");
|
|
166
|
-
// endif
|
|
167
|
-
```
|
|
179
|
+
$$logger('some log that will be in debug mode only');
|
|
168
180
|
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
184
|
+
return 'run in compile time and retrun string result';
|
|
185
|
+
});
|
|
191
186
|
|
|
192
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
243
|
-
|
|
230
|
+
lifecycle: {
|
|
231
|
+
onStart(): void {
|
|
232
|
+
console.log('starting build...');
|
|
233
|
+
}
|
|
244
234
|
}
|
|
245
235
|
},
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
##
|
|
255
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|