Skip to content

Commit

Permalink
feat(docs): remove deprecated 'docs' type
Browse files Browse the repository at this point in the history
Use 'docs-readme' instead.
  • Loading branch information
adamdbradley committed Aug 5, 2020
1 parent bfb1271 commit 043e2d8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
16 changes: 3 additions & 13 deletions src/compiler/config/outputs/validate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export const validateDocs = (config: d.Config, diagnostics: d.Diagnostic[], user
if (config.flags.docs || config.flags.task === 'docs') {
if (!userOutputs.some(isOutputTargetDocsReadme)) {
// didn't provide a docs config, so let's add one
docsOutputs.push(validateReadmeOutputTarget(config, diagnostics, { type: 'docs-readme' }));
docsOutputs.push(validateReadmeOutputTarget(config, { type: 'docs-readme' }));
}
}

// readme docs
const readmeDocsOutputs = userOutputs.filter(isOutputTargetDocsReadme);
readmeDocsOutputs.forEach(readmeDocsOutput => {
docsOutputs.push(validateReadmeOutputTarget(config, diagnostics, readmeDocsOutput));
docsOutputs.push(validateReadmeOutputTarget(config, readmeDocsOutput));
});

// custom docs
Expand All @@ -51,17 +51,7 @@ export const validateDocs = (config: d.Config, diagnostics: d.Diagnostic[], user
return docsOutputs;
};

const validateReadmeOutputTarget = (config: d.Config, diagnostics: d.Diagnostic[], outputTarget: d.OutputTargetDocsReadme) => {
if (outputTarget.type === 'docs') {
diagnostics.push({
type: 'config',
level: 'warn',
header: 'Deprecated "docs"',
messageText: `The output target { type: "docs" } has been deprecated, please use "docs-readme" instead.`,
absFilePath: config.configPath,
});
outputTarget.type = 'docs-readme';
}
const validateReadmeOutputTarget = (config: d.Config, outputTarget: d.OutputTargetDocsReadme) => {
if (typeof outputTarget.dir !== 'string') {
outputTarget.dir = config.srcDir;
}
Expand Down
35 changes: 14 additions & 21 deletions src/compiler/config/test/validate-docs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
import * as d from '@stencil/core/declarations';
import { mockLogger, mockStencilSystem } from '@stencil/core/testing';
import { mockConfig } from '@stencil/core/testing';
import { validateConfig } from '../validate-config';

describe('validateDocs', () => {
let config: d.Config;
const logger = mockLogger();
const sys = mockStencilSystem();
let userConfig: d.Config;

beforeEach(() => {
config = {
sys: sys,
logger: logger,
rootDir: '/User/some/path/',
flags: {},
outputTargets: [{ type: 'www' }],
namespace: 'Testing',
};
userConfig = mockConfig();
});

it('readme docs dir', () => {
config.flags.docs = true;
config.outputTargets.push({
type: 'docs',
dir: 'my-dir',
} as d.OutputTargetDocsReadme);
validateConfig(config, [], false);
userConfig.flags.docs = true;
userConfig.outputTargets = [
{
type: 'docs-readme',
dir: 'my-dir',
} as d.OutputTargetDocsReadme,
];
const { config } = validateConfig(userConfig);
const o = config.outputTargets.find(o => o.type === 'docs-readme') as d.OutputTargetDocsReadme;
expect(o.dir).toContain('my-dir');
});

it('default no docs, not remove docs output target', () => {
config.outputTargets.push({ type: 'docs' });
validateConfig(config, [], false);
userConfig.outputTargets = [{ type: 'docs-readme' }];
const { config } = validateConfig(userConfig);
expect(config.outputTargets.some(o => o.type === 'docs-readme')).toBe(true);
});

it('default no docs, no output target', () => {
validateConfig(config, [], false);
const { config } = validateConfig(userConfig);
expect(config.outputTargets.some(o => o.type === 'docs-readme')).toBe(false);
});
});
7 changes: 2 additions & 5 deletions src/compiler/output-targets/output-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export const isOutputTargetHydrate = (o: d.OutputTarget): o is d.OutputTargetHyd
export const isOutputTargetCustom = (o: d.OutputTarget): o is d.OutputTargetCustom => o.type === CUSTOM;

export const isOutputTargetDocs = (o: d.OutputTarget): o is d.OutputTargetDocsJson | d.OutputTargetDocsReadme | d.OutputTargetDocsVscode | d.OutputTargetDocsCustom =>
o.type === DOCS || o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;
o.type === DOCS_README || o.type === DOCS_JSON || o.type === DOCS_CUSTOM || o.type === DOCS_VSCODE;

export const isOutputTargetDocsReadme = (o: d.OutputTarget): o is d.OutputTargetDocsReadme => o.type === DOCS_README || o.type === DOCS;
export const isOutputTargetDocsReadme = (o: d.OutputTarget): o is d.OutputTargetDocsReadme => o.type === DOCS_README;

export const isOutputTargetDocsJson = (o: d.OutputTarget): o is d.OutputTargetDocsJson => o.type === DOCS_JSON;

Expand Down Expand Up @@ -110,7 +110,6 @@ export const DIST_LAZY = `dist-lazy`;
export const DIST_LAZY_LOADER = `dist-lazy-loader`;
export const DIST_SELF_CONTAINED = `dist-self-contained`;
export const DIST_GLOBAL_STYLES = 'dist-global-styles';
export const DOCS = `docs`;
export const DOCS_CUSTOM = 'docs-custom';
export const DOCS_JSON = `docs-json`;
export const DOCS_README = `docs-readme`;
Expand All @@ -130,7 +129,6 @@ export const VALID_TYPES = [
DIST_HYDRATE_SCRIPT,
DIST_LAZY,
DIST_SELF_CONTAINED,
DOCS,
DOCS_JSON,
DOCS_README,
DOCS_VSCODE,
Expand All @@ -151,7 +149,6 @@ export const VALID_TYPES_NEXT = [
DIST_HYDRATE_SCRIPT,

// DOCS
DOCS,
DOCS_JSON,
DOCS_README,
DOCS_VSCODE,
Expand Down
2 changes: 1 addition & 1 deletion src/declarations/stencil-public-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ export interface OutputTargetDocsVscode extends OutputTargetBase {
}

export interface OutputTargetDocsReadme extends OutputTargetBase {
type: 'docs-readme' | 'docs';
type: 'docs-readme';
dir?: string;
dependencies?: boolean;
footer?: string;
Expand Down

0 comments on commit 043e2d8

Please sign in to comment.