Skip to content

Commit b6a7b7c

Browse files
committed
feat: read vulcan.env for build preconfig
1 parent fbcacb8 commit b6a7b7c

File tree

2 files changed

+37
-40
lines changed

2 files changed

+37
-40
lines changed

lib/commands/build.commands.js

+34-28
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { feedback } from '#utils';
2-
31
import { Commands } from '#namespaces';
2+
import { feedback } from '#utils';
3+
import { vulcan } from '#env';
44

55
/**
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.
711
* @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.
1518
* @example
1619
*
1720
* buildCommand({
@@ -22,28 +25,31 @@ import { Commands } from '#namespaces';
2225
* });
2326
*/
2427
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');
2636

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`);
4046

4147
const BuildDispatcher = (await import('#build')).default;
4248
const buildDispatcher = new BuildDispatcher(
43-
preset,
44-
mode,
45-
entryPoint,
46-
useNodePolyfills,
49+
config.preset,
50+
config.mode,
51+
config.entry,
52+
config.useNodePolyfills,
4753
);
4854

4955
await buildDispatcher.run();

lib/main.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,13 @@ function startVulcanProgram() {
7575
program
7676
.command('build')
7777
.description('Build a project for edge deployment')
78-
.option(
79-
'--entry <string>',
80-
'Code entrypoint (default: ./main.js)',
81-
'./main.js',
82-
)
78+
.option('--entry <string>', 'Code entrypoint (default: ./main.js)')
8379
.option(
8480
'--preset <type>',
8581
'Preset of build target (e.g., vue, next, javascript)',
86-
'javascript',
87-
)
88-
.option(
89-
'--mode <type>',
90-
'Mode of build target (e.g., deliver, compute)',
91-
'compute',
9282
)
93-
.option('--useNodePolyfills', 'Use node polyfills in build.', 'false')
83+
.option('--mode <type>', 'Mode of build target (e.g., deliver, compute)')
84+
.option('--useNodePolyfills', 'Use node polyfills in build.')
9485
.action(async (options) => {
9586
const { buildCommand } = await import('#commands');
9687
await buildCommand(options);

0 commit comments

Comments
 (0)