Skip to content

Commit 5bb07ef

Browse files
Lint Plugin Types (#1032)
* fix: add eslint config for types * chore: lint all plugin types * Temp: ts-ignores * fix: tests * fix: disable jsdoc rules for ts
1 parent c371a33 commit 5bb07ef

File tree

153 files changed

+1523
-921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1523
-921
lines changed

package-lock.json

Lines changed: 72 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@gasket/repository",
33
"private": true,
44
"version": "0.0.0",
5-
"description": "Robust, pluggable, & render agnostic framework for rapid deliver modern web applications.",
5+
"description": "Robust, pluggable, & render agnostic framework for rapid delivery of modern web applications.",
66
"scripts": {
77
"lint": "eslint scripts",
88
"lint:fix": "npm run lint -- --fix",
@@ -53,7 +53,7 @@
5353
"@typescript-eslint/eslint-plugin": "^6.21.0",
5454
"eslint": "^8.56.0",
5555
"eslint-config-godaddy": "^7.1.1",
56-
"eslint-plugin-json": "^3.1.0",
56+
"eslint-config-godaddy-typescript": "^4.0.3",
5757
"eslint-plugin-unicorn": "^55.0.0",
5858
"jsdom": "^20.0.0",
5959
"lerna": "^8.1.8",

packages/create-gasket-app/lib/commands/create.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ import { makeCreateContext } from '../scaffold/create-context.js';
44
import { dumpErrorContext } from '../scaffold/dump-error-context.js';
55
import { rm } from 'fs/promises';
66
import { makeGasket } from '@gasket/core';
7-
import {
8-
createHooks,
9-
generateFiles,
10-
globalPrompts,
11-
installModules,
12-
linkModules,
13-
loadPreset,
14-
mkDir,
15-
postCreateHooks,
16-
printReport,
17-
presetPromptHooks,
18-
presetConfigHooks,
19-
promptHooks,
20-
setupPkg,
21-
writeGasketConfig,
22-
writePkg
23-
} from '../scaffold/actions/index.js';
7+
import globalPrompts from '../scaffold/actions/global-prompts.js';
8+
import loadPreset from '../scaffold/actions/load-preset.js';
9+
import presetPromptHooks from '../scaffold/actions/preset-prompt-hooks.js';
10+
import presetConfigHooks from '../scaffold/actions/preset-config-hooks.js';
11+
import promptHooks from '../scaffold/actions/prompt-hooks.js';
12+
import mkDir from '../scaffold/actions/mkdir.js';
13+
import setupPkg from '../scaffold/actions/setup-pkg.js';
14+
import createHooks from '../scaffold/actions/create-hooks.js';
15+
import writePkg from '../scaffold/actions/write-pkg.js';
16+
import generateFiles from '../scaffold/actions/generate-files.js';
17+
import writeGasketConfig from '../scaffold/actions/write-gasket-config.js';
18+
import installModules from '../scaffold/actions/install-modules.js';
19+
import linkModules from '../scaffold/actions/link-modules.js';
20+
import postCreateHooks from '../scaffold/actions/post-create-hooks.js';
21+
import printReport from '../scaffold/actions/print-report.js';
2422

2523
/**
2624
* Parses comma separated option input to array
@@ -94,9 +92,10 @@ const createCommand = {
9492

9593
/**
9694
* createCommand action
97-
* @type {import('../index').createCommandAction}
95+
* @type {import('create-gasket-app').createCommandAction}
9896
*/
9997
createCommand.action = async function run(appname, options, command) {
98+
// eslint-disable-next-line no-process-env
10099
process.env.GASKET_ENV = 'create';
101100
const context = makeCreateContext([appname], options);
102101
const { rawPresets, localPresets } = context;
@@ -105,7 +104,6 @@ createCommand.action = async function run(appname, options, command) {
105104
await globalPrompts({ context });
106105

107106
if (rawPresets.length || localPresets.length) {
108-
109107
await loadPreset({ context });
110108

111109
const presetGasket = makeGasket({
@@ -134,6 +132,7 @@ createCommand.action = async function run(appname, options, command) {
134132
if (context.tmpDir) await rm(context.tmpDir, { recursive: true });
135133
printReport({ context });
136134
} catch (err) {
135+
// eslint-disable-next-line no-console
137136
console.error(chalk.red('Exiting with errors.'));
138137
dumpErrorContext(context, err);
139138
throw err;

packages/create-gasket-app/lib/index.d.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { GasketConfigDefinition, MaybeAsync, Plugin, GasketEngine } from '@gasket/core';
1+
/* eslint-disable no-use-before-define */
2+
import type { GasketConfigDefinition, MaybeAsync, Plugin, GasketEngine, CreateContext } from '@gasket/core';
23
import type { PackageManager } from '@gasket/utils';
34
import type { PromptModule } from 'inquirer';
45
import type ora from 'ora';
6+
import type { Command } from 'commander';
57

68
export interface Dependencies {
79
dependencies?: Record<string, string>;
@@ -48,14 +50,14 @@ interface CommandOption {
4850
export function createCommandAction(
4951
appname: string,
5052
options: CreateCommandOptions,
51-
command: Command
53+
command: Command
5254
): Promise<void>;
5355

5456
export interface CreateCommand {
5557
id: string;
5658
description: string;
5759
args: CommandArgument[];
58-
action?: createGasketAction;
60+
action?: typeof createCommandAction;
5961
options: CommandOption[];
6062
hidden?: boolean;
6163
default?: boolean;
@@ -100,7 +102,6 @@ export interface ConfigBuilder<Config> {
100102
/**
101103
* Performs an intelligent, domain-aware merge of the `value` for
102104
* the given `key` into the package.json fields associated with this instance.
103-
*
104105
* @param key - Field in package.json to add or extend.
105106
* @param value - Target value to set for key provided.
106107
* @param source - Plugin to blame if conflicts arise from this operation.
@@ -214,9 +215,9 @@ interface Files {
214215
/**
215216
* Adds the specified `globby` compatible patterns, `globs`,
216217
* into the set of all sources for this set of files.
217-
* @param {Object} params - Object containing `globs` and `source`.
218+
* @param {object} params - Object containing `globs` and `source`.
218219
* @param {string[]} params.globs - `globby` compatible patterns.
219-
* @param {Object} params.source - Plugin to blame if conflicts arise from this operation.
220+
* @param {object} params.source - Plugin to blame if conflicts arise from this operation.
220221
*/
221222
add(params: { globs: string[], source: object }): void;
222223
add(...globs: string[]): void;
@@ -275,7 +276,7 @@ interface Files {
275276
force?: boolean;
276277
}): void;
277278

278-
/**
279+
/**
279280
* Normalizes a potential semver range into a semver string
280281
* and returns the newest version
281282
* @param {string} r1 Semver string (potentially invalid).
@@ -287,7 +288,7 @@ interface Files {
287288
*/
288289
tryGetNewerRange(r1: string, r2: string): string | undefined;
289290

290-
/**
291+
/**
291292
* Performs a naive attempt to take a transform a semver range
292293
* into a concrete version that may be used for "newness"
293294
* comparison.
@@ -301,9 +302,9 @@ interface Files {
301302
* the `orderFields` options having their keys sorted.
302303
* @returns {object} Ready to be serialized JavaScript object.
303304
*/
304-
toJSON(): object;
305+
toJSON(): object;
305306

306-
/**
307+
/**
307308
* Orders the given object, `obj`, applying any (optional)
308309
* key order specified via `orderBy`. If no `orderBy` is provided
309310
* keys are ordered lexographically.
@@ -384,8 +385,10 @@ declare module 'create-gasket-app' {
384385
/** paths to the local presets packages */
385386
localPresets: Array<string>;
386387

387-
/** Raw preset desc from args. Can include version constraint. Added by
388-
* load-preset if using localPresets. */
388+
/**
389+
* Raw preset desc from args. Can include version constraint. Added by
390+
* load-preset if using localPresets.
391+
*/
389392
rawPresets: Array<string>;
390393

391394
/** Local packages that should be linked */
@@ -461,8 +464,8 @@ declare module 'create-gasket-app' {
461464

462465
/** Use to add content to the README.md */
463466
readme: Readme;
464-
465-
constructor(initContext?: Partial<T>);
467+
468+
constructor(initContext?: Partial<CreateContext>);
466469
runWith(plugin: Plugin): Proxy<CreateContext>;
467470
typescript?: boolean;
468471
}
Lines changed: 92 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Gasket } from '@gasket/core';
21
import type {
32
CreateContext,
43
CreatePrompt,
54
ConfigBuilder,
65
CreateCommand,
76
CommandArgument,
8-
CommandOption
9-
} from './index';
10-
import type { GasketEngine, Plugin } from '@gasket/core';
11-
import type ora from 'ora';
7+
CommandOption,
8+
CreateCommandOptions
9+
} from 'create-gasket-app';
10+
import type { GasketEngine, Plugin, Gasket } from '@gasket/core';
11+
import type { Ora } from 'ora';
1212
import type { Command, Option } from 'commander';
1313

1414

@@ -29,47 +29,91 @@ export function makeCreateContext(argv?: string[], options?: CreateCommandOption
2929

3030
export function makeCreateRuntime(context: PartialCreateContext, source: Plugin): Proxy<CreateContext>;
3131

32-
export function spinnerAction({ gasket, context, spinner } : {
33-
gasket?: GasketEngine;
34-
context?: CreateContext;
35-
spinner?: ora.Ora
36-
}): Promise<void>;
37-
export function withSpinnerWrapper({ gasket, context } : { gasket: GasketEngine, context: CreateContext }): Promise<void>;
32+
/**
33+
* Represents the execution context for a task.
34+
*/
35+
export interface SpinnerContext {
36+
gasket?: Gasket;
37+
context: PartialCreateContext;
38+
spinner: Ora;
39+
}
40+
41+
/**
42+
* Task function type that runs within a spinner wrapper.
43+
*/
44+
export type SpinnerTask = (params: SpinnerContext) => Promise<void>;
45+
46+
/**
47+
* Options for the spinner wrapper.
48+
*/
49+
export interface SpinnerOptions {
50+
startSpinner?: boolean;
51+
}
52+
53+
/**
54+
* Wraps a task with a spinner, handling success and failure states.
55+
*/
56+
export function wrapWithSpinner(
57+
label: string,
58+
task: SpinnerTask,
59+
options?: SpinnerOptions
60+
): (context: { context: SpinnerContext['context'] } & {
61+
errors?: Error[]
62+
}) => Promise<void>;
63+
64+
/**
65+
* Wraps a task with a spinner, using both gasket and context.
66+
*/
67+
export function withGasketSpinner(
68+
label: string,
69+
task: SpinnerTask,
70+
options?: SpinnerOptions
71+
): (context: { gasket: any; context: SpinnerContext['context'] }) => Promise<void>;
72+
73+
/**
74+
* Wraps a task with a spinner, using only context.
75+
*/
3876
export function withSpinner(
3977
label: string,
40-
fn: spinnerAction,
41-
options?: { startSpinner?: boolean }
42-
): withSpinnerWrapper
78+
task: SpinnerTask,
79+
options?: SpinnerOptions
80+
): (context: { context: SpinnerContext['context'] }) => Promise<void>;
81+
82+
export function spinnerAction(params: {
83+
gasket?: GasketEngine;
84+
context: PartialCreateContext;
85+
spinner?: Ora
86+
}): Promise<void>;
87+
88+
export function execute(params: { gasket: Gasket, context: PartialCreateContext } & {
89+
errors?: Error[]
90+
}): Promise<void>;
4391

4492
/** sacaffold/actions */
4593

46-
export function createHooks({ gasket, context } : { gasket: GasketEngine; context: CreateContext }): Promise<void>;
94+
export function createHooks(params: { gasket?: Gasket; context: PartialCreateContext }): Promise<void>;
4795

48-
export function chooseAppDescription(context: CreateContext, prompt: CreatePrompt): Promise<void>;
49-
export function choosePackageManager(context: CreateContext, prompt: CreatePrompt): Promise<void>;
50-
export function chooseTestPlugins(context: CreateContext, prompt: CreatePrompt): Promise<void>;
96+
export function chooseAppDescription(context: PartialCreateContext, prompt: CreatePrompt): Promise<void>;
97+
export function choosePackageManager(context: PartialCreateContext, prompt: CreatePrompt): Promise<void>;
98+
export function chooseTestPlugins(context: PartialCreateContext, prompt: CreatePrompt): Promise<void>;
5199
export function promptForTestPlugin(
52-
prompt: CreatePrompt,
53-
message: string,
100+
prompt: CreatePrompt,
101+
message: string,
54102
choices: { name: string; value: string; }[]
55103
): Promise<string | null>;
56-
export function allowExtantOverwriting(context: CreateContext, prompt: CreatePrompt): Promise<void>;
57-
export function globalPrompts({ context } : { context: CreateContext }): Promise<void>;
58-
59-
export function loadPresets({ context } : { context: CreateContext }): Promise<void>;
60-
61-
export function presetPromptHooks({ gasket, context }: { gasket: GasketEngine; context: CreateContext }): Promise<void>;
104+
export function allowExtantOverwriting(context: PartialCreateContext, prompt: CreatePrompt): Promise<void>;
105+
export function globalPrompts(params: { context: PartialCreateContext }): Promise<void>;
106+
export function loadPresets(params: { context: PartialCreateContext }): Promise<void>;
107+
export function presetPromptHooks(params: { gasket?: Gasket; context: PartialCreateContext }): Promise<void>;
108+
export function presetConfigHooks(params: { gasket?: Gasket; context: PartialCreateContext }): Promise<void>;
109+
export function promptHooks(params: { gasket?: Gasket; context: PartialCreateContext }): Promise<void>;
110+
export function execPluginPrompts(gasket: Gasket, context: PartialCreateContext): Promise<void>;
62111

63-
export function presetConfigHooks({ gasket, context }: { gasket: GasketEngine; context: CreateContext }): Promise<void>;
112+
export function mkDir({ context, spinner }: { context: CreateContext, spinner: Ora }): Promise<void>;
64113

65-
export function promptHooks({ gasket, context }: { gasket: GasketEngine; context: CreateContext }): Promise<void>;
66-
export function execPluginPrompts(gasket: GasketEngine, context: CreateContext): Promise<void>;
114+
export function setupPkg(params: { context: PartialCreateContext }): Promise<void>;
67115

68-
export function mkDir({ context, spinner }: { context: CreateContext, spinner: ora.Ora }): Promise<void>;
69-
70-
export function setupPkg({ context }: { context: CreateContext }): Promise<void>;
71-
72-
export function writePkg({ context }: { context: CreateContext }): Promise<void>;
116+
export function writePkg(params: { context: PartialCreateContext }): Promise<void>;
73117

74118
export type Descriptior = {
75119
pattern: string;
@@ -80,28 +124,30 @@ export type Descriptior = {
80124
from: string;
81125
overrides?: string;
82126
}
83-
export function generateFiles({ context, spinner }: { context: CreateContext, spinner: ora.Ora }): Promise<void>;
127+
export function generateFiles({ context, spinner }: { context: CreateContext, spinner: Ora }): Promise<void>;
84128
export function performGenerate(context: CreateContext, descriptors: Descriptior[]): boolean[];
85129
export function getDescriptors(context: CreateContext): Promise<Descriptior[]>;
86-
export function assembleDescriptors(dest: string, from: string, pattern: string, srcPaths: sring[]): Descriptior[];
130+
export function assembleDescriptors(dest: string, from: string, pattern: string, srcPaths: string[]): Descriptior[];
87131
export function reduceDescriptors(descriptors: Descriptior[]): Descriptior[];
88132

89-
export function writeGasketConfig({ context }: { context: CreateContext }): Promise<void>;
133+
export function writeGasketConfig(params: { context: PartialCreateContext }): Promise<void>;
90134
export function writeImports(imports: object | null): string;
91135
export function writeExpressions(expressions: string[] | null): string;
92136
export function createInjectionAssignments(config: object, assignments: (object | null)): string;
93137
export function cleanupFields(config: ConfigBuilder): void;
94138
export function writePluginImports(plugins: string[]): string;
95139
export function replaceInjectionAssignments(content: string, assignments: (object | null)): string;
96140

97-
export function installModules({ context }: { context: CreateContext }): Promise<void>;
141+
export function installModules(params: { context: PartialCreateContext }): Promise<void>;
98142

99-
export function linkModules({context, spinner}: { context: CreateContext, spinner: ora.Ora }): Promise<void>;
143+
export function linkModules(params: { context: CreateContext, spinner: Ora }): Promise<void>;
100144

101-
export function postCreateHooks({ gasket, context }: { gasket: GasketEngine, context: CreateContext }): Promise<void>;
145+
export function postCreateHooks(params: { gasket?: Gasket, context: PartialCreateContext }): Promise<void>;
102146

103-
export function printReport({ context }: { context: CreateContext }): Promise<void>;
104-
export function buildReport(context: CreateContext): {
147+
export function printReport(params: {
148+
context: PartialCreateContext
149+
}): Promise<void>;
150+
export function buildReport(context: PartialCreateContext): {
105151
appName?: string;
106152
output?: string;
107153
generatedFiles?: string[];
@@ -119,15 +165,14 @@ export function isValidCommand(command: CreateCommand): boolean;
119165
export function processArgs(args: CommandArgument[]): [string, string?, any?][];
120166
export function isValidArg(arg: CommandArgument): boolean;
121167

122-
interface OptionDefinition {
168+
interface OptionDefinition {
123169
options: [string, string];
124170
conflicts: CommandOption['conflicts'];
125171
hidden: CommandOption['hidden'];
126172
required: CommandOption['required'];
127173
defaultValue: CommandOption['default'];
128174
parse: CommandOption['parse']
129-
};
175+
}
130176
export function isValidOption(option: CommandOption): boolean;
131-
export function processOptions(options: CommandOption[]): OptionDefinition[]
132-
133-
export function createOption(definition: OptionDefinition): Option
177+
export function processOptions(options: CommandOption[]): OptionDefinition[];
178+
export function createOption(definition: OptionDefinition): Option;

0 commit comments

Comments
 (0)