Skip to content

Commit

Permalink
feat: Add init method to service API
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Dec 18, 2024
1 parent d5b8fdb commit 1d81ab7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/commands/build/core/vars/VarsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {AsyncParallelHook, AsyncSeriesWaterfallHook} from 'tapable';
export type VarsServiceConfig = {
varsPreset: string;
vars: Hash;
ignore: string[];
};

type VarsServiceHooks = {
Expand Down Expand Up @@ -48,6 +49,17 @@ export class VarsService {
};
}

async init() {
const presets = (await this.run.glob('**/presets.yaml', {
cwd: this.run.input,
ignore: this.config.ignore,
})) as RelativePath[];

for (const preset of presets) {
await this.load(preset);
}
}

async load(path: RelativePath) {
const varsPreset = this.config.varsPreset || 'default';
const file = join(dirname(path), 'presets.yaml');
Expand Down
8 changes: 1 addition & 7 deletions src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,7 @@ export class Build

await run.copy(run.originalInput, run.input, ['node_modules/**', '*/node_modules/**']);

const presets = (await run.glob('**/presets.yaml', {
cwd: run.input,
ignore: run.config.ignore,
})) as RelativePath[];
for (const preset of presets) {
await run.vars.load(preset);
}
await run.vars.init();

await Promise.all([handler(run), this.hooks.Run.promise(run)]);

Expand Down

0 comments on commit 1d81ab7

Please sign in to comment.