UNPKG

7.62 kBTypeScriptView Raw
1import type { LogLevel, TaskCommand } from '../internal/index';
2/**
3 * All the Boolean options supported by the Stencil CLI
4 */
5export declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "e2e", "es5", "esm", "help", "log", "open", "prerender", "prerenderExternal", "prod", "profile", "serviceWorker", "screenshot", "serve", "skipNodeCheck", "spec", "ssr", "stats", "updateScreenshot", "verbose", "version", "watch", "all", "automock", "bail", "changedFilesWithAncestor", "clearCache", "clearMocks", "collectCoverage", "color", "colors", "coverage", "detectLeaks", "detectOpenHandles", "errorOnDeprecated", "expand", "findRelatedTests", "forceExit", "init", "injectGlobals", "json", "lastCommit", "listTests", "logHeapUsage", "noStackTrace", "notify", "onlyChanged", "onlyFailures", "passWithNoTests", "resetMocks", "resetModules", "restoreMocks", "runInBand", "runTestsByPath", "showConfig", "silent", "skipFilter", "testLocationInResults", "updateSnapshot", "useStderr", "watchAll", "watchman"];
6/**
7 * All the Number options supported by the Stencil CLI
8 */
9export declare const NUMBER_CLI_FLAGS: readonly ["port", "maxConcurrency", "testTimeout"];
10/**
11 * All the String options supported by the Stencil CLI
12 */
13export declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsApi", "docsJson", "emulate", "root", "screenshotConnector", "cacheDirectory", "changedSince", "collectCoverageFrom", "coverageDirectory", "coverageThreshold", "env", "filter", "globalSetup", "globalTeardown", "globals", "haste", "moduleNameMapper", "notifyMode", "outputFile", "preset", "prettierPath", "resolver", "rootDir", "runner", "testEnvironment", "testEnvironmentOptions", "testFailureExitCode", "testNamePattern", "testResultsProcessor", "testRunner", "testSequencer", "testURL", "timers", "transform"];
14export declare const STRING_ARRAY_CLI_FLAGS: readonly ["collectCoverageOnlyFrom", "coveragePathIgnorePatterns", "coverageReporters", "moduleDirectories", "moduleFileExtensions", "modulePathIgnorePatterns", "modulePaths", "projects", "reporters", "roots", "selectProjects", "setupFiles", "setupFilesAfterEnv", "snapshotSerializers", "testMatch", "testPathIgnorePatterns", "testPathPattern", "testRegex", "transformIgnorePatterns", "unmockedModulePathPatterns", "watchPathIgnorePatterns"];
15/**
16 * All the CLI arguments which may have string or number values
17 *
18 * `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
19 * which means that we need to support parsing both string and number values.
20 */
21export declare const STRING_NUMBER_CLI_FLAGS: readonly ["maxWorkers"];
22/**
23 * All the CLI arguments which may have boolean or string values.
24 */
25export declare const BOOLEAN_STRING_CLI_FLAGS: readonly ["headless"];
26/**
27 * All the LogLevel-type options supported by the Stencil CLI
28 *
29 * This is a bit silly since there's only one such argument atm,
30 * but this approach lets us make sure that we're handling all
31 * our arguments in a type-safe way.
32 */
33export declare const LOG_LEVEL_CLI_FLAGS: readonly ["logLevel"];
34/**
35 * A type which gives the members of a `ReadonlyArray<string>` as
36 * an enum-like type which can be used for e.g. keys in a `Record`
37 * (as in the `AliasMap` type below)
38 */
39type ArrayValuesAsUnion<T extends ReadonlyArray<string>> = T[number];
40export type BooleanCLIFlag = ArrayValuesAsUnion<typeof BOOLEAN_CLI_FLAGS>;
41export type StringCLIFlag = ArrayValuesAsUnion<typeof STRING_CLI_FLAGS>;
42export type StringArrayCLIFlag = ArrayValuesAsUnion<typeof STRING_ARRAY_CLI_FLAGS>;
43export type NumberCLIFlag = ArrayValuesAsUnion<typeof NUMBER_CLI_FLAGS>;
44export type StringNumberCLIFlag = ArrayValuesAsUnion<typeof STRING_NUMBER_CLI_FLAGS>;
45export type BooleanStringCLIFlag = ArrayValuesAsUnion<typeof BOOLEAN_STRING_CLI_FLAGS>;
46export type LogCLIFlag = ArrayValuesAsUnion<typeof LOG_LEVEL_CLI_FLAGS>;
47export type KnownCLIFlag = BooleanCLIFlag | StringCLIFlag | StringArrayCLIFlag | NumberCLIFlag | StringNumberCLIFlag | BooleanStringCLIFlag | LogCLIFlag;
48type AliasMap = Partial<Record<string, KnownCLIFlag>>;
49/**
50 * For a small subset of CLI options we support a short alias e.g. `'h'` for `'help'`
51 */
52export declare const CLI_FLAG_ALIASES: AliasMap;
53/**
54 * A regular expression which can be used to match a CLI flag for one of our
55 * short aliases.
56 */
57export declare const CLI_FLAG_REGEX: RegExp;
58/**
59 * Given two types `K` and `T` where `K` extends `ReadonlyArray<string>`,
60 * construct a type which maps the strings in `K` as keys to values of type `T`.
61 *
62 * Because we use types derived this way to construct an interface (`ConfigFlags`)
63 * for which we want optional keys, we make all the properties optional (w/ `'?'`)
64 * and possibly null.
65 */
66type ObjectFromKeys<K extends ReadonlyArray<string>, T> = {
67 [key in K[number]]?: T | null;
68};
69/**
70 * Type containing the possible Boolean configuration flags, to be included
71 * in ConfigFlags, below
72 */
73type BooleanConfigFlags = ObjectFromKeys<typeof BOOLEAN_CLI_FLAGS, boolean>;
74/**
75 * Type containing the possible String configuration flags, to be included
76 * in ConfigFlags, below
77 */
78type StringConfigFlags = ObjectFromKeys<typeof STRING_CLI_FLAGS, string>;
79/**
80 * Type containing the possible String Array configuration flags. This is
81 * one of the 'constituent types' for `ConfigFlags`.
82 */
83type StringArrayConfigFlags = ObjectFromKeys<typeof STRING_ARRAY_CLI_FLAGS, string[]>;
84/**
85 * Type containing the possible numeric configuration flags, to be included
86 * in ConfigFlags, below
87 */
88type NumberConfigFlags = ObjectFromKeys<typeof NUMBER_CLI_FLAGS, number>;
89/**
90 * Type containing the configuration flags which may be set to either string
91 * or number values.
92 */
93type StringNumberConfigFlags = ObjectFromKeys<typeof STRING_NUMBER_CLI_FLAGS, string | number>;
94/**
95 * Type containing the configuration flags which may be set to either string
96 * or boolean values.
97 */
98type BooleanStringConfigFlags = ObjectFromKeys<typeof BOOLEAN_STRING_CLI_FLAGS, boolean | string>;
99/**
100 * Type containing the possible LogLevel configuration flags, to be included
101 * in ConfigFlags, below
102 */
103type LogLevelFlags = ObjectFromKeys<typeof LOG_LEVEL_CLI_FLAGS, LogLevel>;
104/**
105 * The configuration flags which can be set by the user on the command line.
106 * This interface captures both known arguments (which are enumerated and then
107 * parsed according to their types) and unknown arguments which the user may
108 * pass at the CLI.
109 *
110 * Note that this interface is constructed by extending `BooleanConfigFlags`,
111 * `StringConfigFlags`, etc. These types are in turn constructed from types
112 * extending `ReadonlyArray<string>` which we declare in another module. This
113 * allows us to record our known CLI arguments in one place, using a
114 * `ReadonlyArray<string>` to get both a type-level representation of what CLI
115 * options we support and a runtime list of strings which can be used to match
116 * on actual flags passed by the user.
117 */
118export interface ConfigFlags extends BooleanConfigFlags, StringConfigFlags, StringArrayConfigFlags, NumberConfigFlags, StringNumberConfigFlags, BooleanStringConfigFlags, LogLevelFlags {
119 task: TaskCommand | null;
120 args: string[];
121 knownArgs: string[];
122 unknownArgs: string[];
123}
124/**
125 * Helper function for initializing a `ConfigFlags` object. Provide any overrides
126 * for default values and off you go!
127 *
128 * @param init an object with any overrides for default values
129 * @returns a complete CLI flag object
130 */
131export declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
132export {};