Skip to content

Commit

Permalink
fix(compiler): Allow OutputTargetCustom to be called on devMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukaato committed Mar 23, 2024
1 parent 05205f8 commit d04bea0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/compiler/output-targets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { outputCollection } from './dist-collection';
import { outputCustomElements } from './dist-custom-elements';
import { outputHydrateScript } from './dist-hydrate-script';
import { outputLazy } from './dist-lazy/lazy-output';
import { outputCustom } from './output-custom';
import { outputDocs } from './output-docs';
import { outputLazyLoader } from './output-lazy-loader';
import { outputTypes } from './output-types';
Expand Down Expand Up @@ -45,6 +46,7 @@ export const generateOutputTargets = async (
// since it validates files were created
await outputDocs(config, compilerCtx, buildCtx);
await outputTypes(config, compilerCtx, buildCtx);
await outputCustom(config, compilerCtx, buildCtx);

timeSpan.finish('generate outputs finished');
};
Expand Down
17 changes: 8 additions & 9 deletions src/compiler/output-targets/output-custom.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { catchError, isOutputTargetCustom } from '@utils';

import type * as d from '../../declarations';
import { generateDocData } from '../docs/generate-doc-data';

export const outputCustom = async (
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
docs: d.JsonDocs,
outputTargets: d.OutputTarget[],
) => {
const customOutputTargets = outputTargets.filter(isOutputTargetCustom);
export const outputCustom = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
const task = config.devMode ? 'run' : 'build';
const docsData = await generateDocData(config, compilerCtx, buildCtx);
const customOutputTargets = config.outputTargets
.filter(isOutputTargetCustom)
.filter((o) => (o.task === undefined ? true : o.task === task));
if (customOutputTargets.length === 0) {
return;
}
Expand All @@ -18,7 +17,7 @@ export const outputCustom = async (
customOutputTargets.map(async (o) => {
const timespan = buildCtx.createTimeSpan(`generating ${o.name} started`);
try {
await o.generator(config, compilerCtx, buildCtx, docs);
await o.generator(config, compilerCtx, buildCtx, docsData);
} catch (e: any) {
catchError(buildCtx.diagnostics, e);
}
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/output-targets/output-docs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
isOutputTargetCustom,
isOutputTargetDocsCustom,
isOutputTargetDocsJson,
isOutputTargetDocsReadme,
Expand All @@ -12,7 +11,6 @@ import { generateDocData } from '../docs/generate-doc-data';
import { generateJsonDocs } from '../docs/json';
import { generateReadmeDocs } from '../docs/readme';
import { generateVscodeDocs } from '../docs/vscode';
import { outputCustom } from './output-custom';

/**
* Generate documentation-related output targets
Expand All @@ -30,7 +28,6 @@ export const outputDocs = async (
}
const docsOutputTargets = config.outputTargets.filter(
(o) =>
isOutputTargetCustom(o) ||
isOutputTargetDocsReadme(o) ||
isOutputTargetDocsJson(o) ||
isOutputTargetDocsCustom(o) ||
Expand All @@ -51,6 +48,5 @@ export const outputDocs = async (
generateJsonDocs(config, compilerCtx, docsData, docsOutputTargets),
generateVscodeDocs(compilerCtx, docsData, docsOutputTargets),
generateCustomDocs(config, docsData, docsOutputTargets),
outputCustom(config, compilerCtx, buildCtx, docsData, docsOutputTargets),
]);
};
10 changes: 9 additions & 1 deletion src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ConfigFlags } from '../cli/config-flags';
import type { PrerenderUrlResults, PrintLine } from '../internal';
import type { BuildCtx, CompilerCtx } from './stencil-private';
import type { JsonDocs } from './stencil-public-docs';

export * from './stencil-public-docs';
Expand Down Expand Up @@ -2233,8 +2234,15 @@ export interface OutputTargetHydrate extends OutputTargetBase {
export interface OutputTargetCustom extends OutputTargetBase {
type: 'custom';
name: string;
/**
* Indicate in wich mode the output target has to be executed.
* By default if nothing is specified it run for both.
* - `"run"`: Executed in dev mode on every change in your code
* - `"build"`: Executed only on build
*/
task?: 'run' | 'build';
validate?: (config: Config, diagnostics: Diagnostic[]) => void;
generator: (config: Config, compilerCtx: any, buildCtx: any, docs: any) => Promise<void>;
generator: (config: Config, compilerCtx: CompilerCtx, buildCtx: BuildCtx, docs: JsonDocs) => Promise<void>;
copy?: CopyTask[];
}

Expand Down

0 comments on commit d04bea0

Please sign in to comment.