@yeoman/types 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 The Yeoman Team <admin@simonboudrias.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@yeoman/types",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "description": "Common API for yeoman's generator/environment stack",
6
+ "keywords": [
7
+ "yeoman",
8
+ "types"
9
+ ],
10
+ "homepage": "http://yeoman.io/authoring/testing.html",
11
+ "repository": "yeoman/yeoman-api",
12
+ "license": "MIT",
13
+ "author": "The Yeoman Team",
14
+ "type": "module",
15
+ "main": "",
16
+ "types": "./types/index.d.ts",
17
+ "files": [
18
+ "types"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "clean": "",
23
+ "clean-all": "rimraf node_modules",
24
+ "pretest": "xo",
25
+ "test": ""
26
+ },
27
+ "dependencies": {
28
+ "@types/node": "^16.18.26"
29
+ },
30
+ "devDependencies": {
31
+ "@types/inquirer": "^9.0.3",
32
+ "mem-fs": "^3.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@types/inquirer": "^9.0.3",
36
+ "mem-fs": "^3.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "inquirer": {
40
+ "optional": true
41
+ },
42
+ "mem-fs": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "engines": {
47
+ "node": "^16.13.0 || >=18.12.0"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "gitHead": "c1cb1ef2d571bb6b2a1efdaf808e89ab424afb5f"
54
+ }
@@ -0,0 +1,49 @@
1
+ import type { DistinctQuestion, Answers as InquirerAnswers } from 'inquirer';
2
+ import type { Logger } from './logger.js';
3
+
4
+ /**
5
+ * Represents an answer-hash.
6
+ */
7
+ export type PromptAnswers = InquirerAnswers;
8
+
9
+ export type PromptQuestion<A extends PromptAnswers = PromptAnswers> = DistinctQuestion<A>;
10
+
11
+ /**
12
+ * Provides a set of questions.
13
+ */
14
+ export type PromptQuestions<A extends PromptAnswers = PromptAnswers> = PromptQuestion<A> | Array<PromptQuestion<A>>; // | Observable<Question<A>>;
15
+
16
+ /**
17
+ * Abstraction layer that defines the I/O interactions.
18
+ *
19
+ * It provides a CLI interaction
20
+ */
21
+ export type InputOutputAdapter = {
22
+ /**
23
+ * A component for logging messages.
24
+ */
25
+ log: Logger;
26
+
27
+ /**
28
+ * Prompts the user for one or more questions.
29
+ *
30
+ * @param questions The questions to prompt.
31
+ * @param initialAnswers Initial answers.
32
+ */
33
+ prompt<A extends PromptAnswers = PromptAnswers>(questions: PromptQuestions<A>, initialAnswers?: Partial<A>): Promise<A>;
34
+
35
+ /**
36
+ * Close underline inputs.
37
+ */
38
+ close(): void;
39
+
40
+ /**
41
+ * Shows a color-based diff of two strings.
42
+ *
43
+ * @param actual The actual text.
44
+ * @param expected The expected text.
45
+ * @param changes The changes returned by `diff`.
46
+ * @returns The formatted message.
47
+ */
48
+ diff(actual: string, expected: string, changes: unknown[]): string;
49
+ };
@@ -0,0 +1,103 @@
1
+ import type { Transform } from 'node:stream';
2
+ import type { Store } from 'mem-fs';
3
+
4
+ import type { GeneratorBaseOptions } from '../generator/generator-options.js';
5
+ import type { BaseGenerator } from '../generator/generator.js';
6
+ import type { GetGeneratorConstructor, GetGeneratorOptions } from '../generator/utils.js';
7
+ import type { InputOutputAdapter } from './adapter.js';
8
+
9
+ export type EnvironmentConstructor<A extends InputOutputAdapter = InputOutputAdapter> = new (
10
+ options?: BaseEnvironmentOptions,
11
+ adapter?: A,
12
+ ) => BaseEnvironment<A>;
13
+
14
+ export type BaseEnvironmentOptions = GeneratorBaseOptions & {
15
+ /**
16
+ * The working-directory of the environment.
17
+ */
18
+ cwd?: string | undefined;
19
+
20
+ /**
21
+ * A value indicating whether the experimental features should be enabled.
22
+ */
23
+ experimental?: boolean;
24
+
25
+ /**
26
+ * Options to pass to every generator instantiated by this Environment.
27
+ */
28
+ sharedOptions?: GeneratorBaseOptions;
29
+
30
+ /**
31
+ * `mem-fs` Store.
32
+ */
33
+ sharedFs?: Store;
34
+ };
35
+
36
+ export type BaseEnvironment<A = InputOutputAdapter, S extends Store = Store> = {
37
+ cwd: string;
38
+ adapter: A;
39
+ sharedFs: S;
40
+
41
+ emit(eventName: string | symbol, ...args: any[]): boolean;
42
+
43
+ applyTransforms(transformStreams: Transform[], stream?: NodeJS.ReadableStream): Promise<void>;
44
+
45
+ create<G extends BaseGenerator = BaseGenerator>(
46
+ namespaceOrPath: string | GetGeneratorConstructor<G>,
47
+ args: string[],
48
+ options?: Partial<Omit<GetGeneratorOptions<G>, 'env' | 'resolved' | 'resolvec'>>,
49
+ ): Promise<G>;
50
+
51
+ instantiate<G extends BaseGenerator = BaseGenerator>(
52
+ generator: GetGeneratorConstructor<G>,
53
+ args: string[],
54
+ options?: Partial<Omit<GetGeneratorOptions<G>, 'env' | 'resolved' | 'resolvec'>>,
55
+ ): Promise<G>;
56
+
57
+ /**
58
+ * Converts the specified `filePath` to a namespace.
59
+ *
60
+ * @param filePath The path to convert.
61
+ * @param lookups The path-part to exclude (such as `lib/generators`).
62
+ */
63
+ namespace(filePath: string, lookups?: string[]): string;
64
+
65
+ /**
66
+ * Gets the version of this `Environment` object.
67
+ */
68
+ getVersion(): string;
69
+
70
+ /**
71
+ * Gets the version of the specified `dependency`.
72
+ *
73
+ * @param dependency The name of the dependency.
74
+ */
75
+ // eslint-disable-next-line @typescript-eslint/unified-signatures
76
+ getVersion(dependency: string): string;
77
+
78
+ queueGenerator<G extends BaseGenerator = BaseGenerator>(generator: G, schedule?: boolean): Promise<G>;
79
+
80
+ rootGenerator<G extends BaseGenerator = BaseGenerator>(): G;
81
+
82
+ runGenerator(generator: BaseGenerator): Promise<void>;
83
+
84
+ /**
85
+ * Registers a specific `generator` to this environment.
86
+ * This generator is stored under the provided `namespace` or, if not specified, a default namespace format.
87
+ *
88
+ * @param filePath The filepath to the generator or an npm package name.
89
+ * @param namespace The namespace under which the generator should be registered.
90
+ * @param packagePath The path to the npm package of the generator.
91
+ */
92
+ register(filePath: string, namespace?: string, packagePath?: string): Promise<void>;
93
+
94
+ /**
95
+ * Registers a stubbed generator to this environment.
96
+ *
97
+ * @param generator The generator constructor.
98
+ * @param namespace The namespace under which the generator should be registered.
99
+ * @param resolved The file-path to the generator.
100
+ * @param packagePath The path to the npm package of the generator.
101
+ */
102
+ registerStub(generator: GetGeneratorConstructor, namespace: string, resolved?: string, packagePath?: string): void;
103
+ };
@@ -0,0 +1,53 @@
1
+ import type { format } from 'node:util';
2
+
3
+ /**
4
+ * Provides default color-categories.
5
+ */
6
+ export type DefaultLoggerCategories = 'skip' | 'force' | 'create' | 'invoke' | 'conflict' | 'identical' | 'info';
7
+
8
+ /**
9
+ * Provides the functionality to log messages.
10
+ */
11
+ export type Logger<LoggerCategories extends string | number | symbol = DefaultLoggerCategories> = {
12
+ /**
13
+ * Logs a message of the specified category.
14
+ */
15
+ [P in LoggerCategories]: (...args: Parameters<typeof format>) => Logger<LoggerCategories>;
16
+ } & {
17
+ /**
18
+ * Writes a log-message.
19
+ *
20
+ * @param format
21
+ * The format of the log-messages.
22
+ * See <https://github.com/mikeal/logref> for more info.
23
+ *
24
+ * @param params
25
+ * The parameters to replace variables with.
26
+ */
27
+ (format?: string, parameters?: Record<string, any>): Logger<LoggerCategories>;
28
+
29
+ /**
30
+ * Writes a log-message.
31
+ */
32
+ (message?: any, ...optionalParameters: any[]): Logger<LoggerCategories>;
33
+
34
+ /**
35
+ * Writes a log-message.
36
+ */
37
+ write(...args: Parameters<typeof format>): Logger<LoggerCategories>;
38
+
39
+ /**
40
+ * Writes a log-message with an appended newline character.
41
+ */
42
+ writeln(...args: Parameters<typeof format>): Logger<LoggerCategories>;
43
+
44
+ /**
45
+ * Writes a success status with a check mark `✔`.
46
+ */
47
+ ok(...args: Parameters<typeof format>): Logger<LoggerCategories>;
48
+
49
+ /**
50
+ * Writes an error-message with a prepended cross mark.
51
+ */
52
+ error(...args: Parameters<typeof format>): Logger<LoggerCategories>;
53
+ };
@@ -0,0 +1,6 @@
1
+ export type GeneratorCustomFeatures = Record<string, unknown>;
2
+
3
+ export type GeneratorFeatures = {
4
+ uniqueBy?: string;
5
+ uniqueGlobally?: boolean;
6
+ };
@@ -0,0 +1,66 @@
1
+ import type { BaseEnvironment } from '../environment/environment.js';
2
+
3
+ export type GeneratorCustomOptions = Record<string, unknown>;
4
+
5
+ export type GeneratorBaseOptions = {
6
+ /**
7
+ * Skip package manager install task.
8
+ */
9
+ skipInstall?: boolean;
10
+
11
+ /**
12
+ * Fail on package manager install task failure.
13
+ */
14
+ forceInstall?: boolean;
15
+
16
+ /**
17
+ * Skip working dir cacheable prompts cache.
18
+ */
19
+ skipCache?: boolean;
20
+
21
+ /**
22
+ * Skip working dir cacheable prompts cache.
23
+ */
24
+ skipLocalCache?: boolean;
25
+
26
+ /**
27
+ * Skip options parsing.
28
+ * Options is already parsed.
29
+ */
30
+ skipParseOptions?: boolean;
31
+
32
+ /**
33
+ * Store global storage at working dir.
34
+ */
35
+ localConfigOnly?: boolean;
36
+
37
+ /**
38
+ * Show prompts for already answered questions.
39
+ */
40
+ askAnswered?: boolean;
41
+ };
42
+
43
+ type GeneratorNamespace = {
44
+ namespace: string;
45
+ };
46
+
47
+ type GeneratorEnvironmentOptions = {
48
+ help?: boolean;
49
+
50
+ /** Environment being to run */
51
+ env: BaseEnvironment;
52
+
53
+ /** The path to the current generator */
54
+ resolved: string;
55
+ };
56
+
57
+ type GeneratorHelpOptions<H extends boolean | undefined> = {
58
+ help: H;
59
+ };
60
+
61
+ export type GeneratorOptions = GeneratorBaseOptions &
62
+ GeneratorNamespace &
63
+ (
64
+ | (GeneratorHelpOptions<false | undefined> & GeneratorEnvironmentOptions)
65
+ | (GeneratorHelpOptions<true> & Partial<GeneratorEnvironmentOptions>)
66
+ );
@@ -0,0 +1,25 @@
1
+ import type { BaseEnvironment } from '../environment/environment.js';
2
+ import type { GeneratorCustomFeatures, GeneratorFeatures } from './generator-features.js';
3
+ import type { GeneratorCustomOptions, GeneratorOptions } from './generator-options.js';
4
+
5
+ export type EnvironmentGenerator = {
6
+ readonly env: BaseEnvironment;
7
+ readonly features: unknown;
8
+
9
+ _postConstruct?(): Promise<void>;
10
+
11
+ destinationRoot(): string;
12
+
13
+ // Generator >= v5
14
+ queueTasks?(): Promise<void>;
15
+ };
16
+
17
+ export type BaseGenerator<
18
+ O extends GeneratorOptions = GeneratorOptions,
19
+ F extends GeneratorFeatures = GeneratorFeatures,
20
+ > = EnvironmentGenerator & {
21
+ readonly options: O;
22
+
23
+ // Generator >= v5
24
+ readonly features: F | undefined;
25
+ };
@@ -0,0 +1,9 @@
1
+ import type { BaseGenerator } from './generator.js';
2
+
3
+ export type GetGeneratorOptions<T extends BaseGenerator = BaseGenerator> = T extends BaseGenerator<infer Options> ? Options : never;
4
+
5
+ export type GetGeneratorFeatures<T extends BaseGenerator = BaseGenerator> = T extends BaseGenerator<any, infer features> ? features : never;
6
+
7
+ export type GetGeneratorConstructor<T extends BaseGenerator = BaseGenerator> =
8
+ | (new (args: string[], options: GetGeneratorOptions<T>, features: GetGeneratorFeatures<T>) => BaseGenerator)
9
+ | (new (options: GetGeneratorOptions<T>, features: GetGeneratorFeatures<T>) => BaseGenerator);
@@ -0,0 +1,8 @@
1
+ export * from './environment/adapter.js';
2
+ export * from './environment/environment.js';
3
+ export * from './environment/logger.js';
4
+
5
+ export * from './generator/generator-features.js';
6
+ export * from './generator/generator-options.js';
7
+ export * from './generator/generator.js';
8
+ export * from './generator/utils.js';