1
- import { feedback } from '#utils' ;
2
-
3
1
import { Commands } from '#namespaces' ;
2
+ import { feedback } from '#utils' ;
3
+ import { vulcan } from '#env' ;
4
4
5
5
/**
6
- * @function
6
+ * A command to initiate the build process.
7
+ * This command prioritizes parameters over .vulcan file configurations.
8
+ * If a parameter is provided, it uses the parameter value,
9
+ * otherwise, it tries to use the .vulcan file configuration.
10
+ * If neither is available, it resorts to default configurations.
7
11
* @memberof Commands
8
- * @description A command to initiate the build process.
9
- * @param {object } options - Configuration options for the build command
10
- * @param {string } options.entry - The entry point file for the build
11
- * @param {string } options.preset - Preset to be used (e.g., 'javascript', 'typescript')
12
- * @param {string } options.mode - Mode in which to run the build (e.g., 'deliver', 'compute')
13
- * @param {boolean } options.useNodePolyfills - Whether to use Node.js polyfills
14
- * @returns {Promise<void> } - A promise that resolves when the build is complete
12
+ * @param {object } options - Configuration options for the build command.
13
+ * @param {string } [options.entry] - The entry point file for the build.
14
+ * @param {string } [options.preset] - Preset to be used (e.g., 'javascript', 'typescript').
15
+ * @param {string } [options.mode] - Mode in which to run the build (e.g., 'deliver', 'compute').
16
+ * @param {boolean } [options.useNodePolyfills] - Whether to use Node.js polyfills.
17
+ * @returns {Promise<void> } - A promise that resolves when the build is complete.
15
18
* @example
16
19
*
17
20
* buildCommand({
@@ -22,28 +25,31 @@ import { Commands } from '#namespaces';
22
25
* });
23
26
*/
24
27
async function buildCommand ( { entry, preset, mode, useNodePolyfills } ) {
25
- let entryPoint = null ;
28
+ let config = {
29
+ entry,
30
+ preset,
31
+ mode,
32
+ useNodePolyfills,
33
+ } ;
34
+
35
+ const vulcanVariables = await vulcan . readVulcanEnv ( 'local' ) ;
26
36
27
- if ( preset === 'javascript' ) {
28
- entryPoint = entry ;
29
- feedback . info ( 'Using main.js as entrypoint by default' ) ;
30
- }
31
- if ( preset === 'typescript' ) {
32
- if ( entry ) {
33
- entryPoint = entry ;
34
- }
35
- feedback . info ( 'Using main.ts as entrypoint by default' ) ;
36
- if ( ! entry ) {
37
- entryPoint = './main.ts' ;
38
- }
39
- }
37
+ // If no arguments are provided, use the .vulcan file configurations
38
+ config = {
39
+ entry : entry ?? vulcanVariables ?. entry ?? './main.js' ,
40
+ preset : preset ?? vulcanVariables ?. preset ?? 'javascript' ,
41
+ mode : mode ?? vulcanVariables ?. mode ?? 'compute' ,
42
+ useNodePolyfills :
43
+ useNodePolyfills ?? vulcanVariables ?. useNodePolyfills ?? false ,
44
+ } ;
45
+ feedback . info ( `Using ${ config . entry } as entry point by default` ) ;
40
46
41
47
const BuildDispatcher = ( await import ( '#build' ) ) . default ;
42
48
const buildDispatcher = new BuildDispatcher (
43
- preset ,
44
- mode ,
45
- entryPoint ,
46
- useNodePolyfills ,
49
+ config . preset ,
50
+ config . mode ,
51
+ config . entry ,
52
+ config . useNodePolyfills ,
47
53
) ;
48
54
49
55
await buildDispatcher . run ( ) ;
0 commit comments