@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 +159 -155
- package/dist/bash.d.ts +0 -15814
- package/dist/bash.js +47 -364
- package/dist/bash.js.map +5 -5
- package/dist/index.d.ts +4220 -12573
- package/dist/index.js +15 -333
- package/dist/index.js.map +4 -4
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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
|
|
|
@@ -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
|
-
|
|
41
|
+
Usage: xBuild [files..] [options]
|
|
41
42
|
|
|
42
|
-
|
|
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
|
|
70
|
+
entryPoints Specific files to build (supports glob patterns) [array]
|
|
46
71
|
|
|
47
72
|
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
|
-
|
|
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.
|
|
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:
|
|
123
|
-
{
|
|
124
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
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
|
-
|
|
171
|
+
$$ifdef('DEBUG', () => {
|
|
172
|
+
console.log('Debug mode is enabled');
|
|
173
|
+
});
|
|
156
174
|
|
|
157
|
-
|
|
175
|
+
$$ifndef('FEATURE_X', () => {
|
|
176
|
+
console.log('Feature X is not active');
|
|
177
|
+
});
|
|
158
178
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// endif
|
|
179
|
+
const $$logger = $$ifdef('DEBUG', (...args: Array<unknown>) => {
|
|
180
|
+
console.debug(...args);
|
|
181
|
+
});
|
|
163
182
|
|
|
164
|
-
|
|
165
|
-
console.log("Feature X is active");
|
|
166
|
-
// endif
|
|
167
|
-
```
|
|
183
|
+
$$logger('some log that will be in debug mode only');
|
|
168
184
|
|
|
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.
|
|
185
|
+
const result = $$inline(() => {
|
|
186
|
+
console.log('compile time log');
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
return 'run in compile time and retrun string result';
|
|
189
|
+
});
|
|
191
190
|
|
|
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
|
-
}
|
|
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
|
-
*
|
|
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
|
-
|
|
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');
|
|
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
|
-
|
|
243
|
-
|
|
235
|
+
lifecycle: {
|
|
236
|
+
onStart(): void {
|
|
237
|
+
console.log('starting build...');
|
|
238
|
+
}
|
|
244
239
|
}
|
|
245
240
|
},
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
##
|
|
255
|
-
```ts
|
|
256
|
-
// main.ts
|
|
264
|
+
## Hooks
|
|
257
265
|
|
|
258
|
-
|
|
266
|
+
The `LifecycleHooksInterface` interface provides a structure for lifecycle hooks to customize the build process.
|
|
259
267
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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)
|