@dcdavidev/spellbookx 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +135 -2
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/init.d.ts +17 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +310 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/context.d.ts +55 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +39 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lefthook.d.ts +24 -0
- package/dist/lefthook.d.ts.map +1 -0
- package/dist/lefthook.js +91 -0
- package/dist/lefthook.js.map +1 -0
- package/dist/merge/editorconfig.d.ts +25 -0
- package/dist/merge/editorconfig.d.ts.map +1 -0
- package/dist/merge/editorconfig.js +123 -0
- package/dist/merge/editorconfig.js.map +1 -0
- package/dist/merge/json.d.ts +21 -0
- package/dist/merge/json.d.ts.map +1 -0
- package/dist/merge/json.js +189 -0
- package/dist/merge/json.js.map +1 -0
- package/dist/merge/lines.d.ts +13 -0
- package/dist/merge/lines.d.ts.map +1 -0
- package/dist/merge/lines.js +36 -0
- package/dist/merge/lines.js.map +1 -0
- package/dist/merge/types.d.ts +23 -0
- package/dist/merge/types.d.ts.map +1 -0
- package/dist/merge/types.js +5 -0
- package/dist/merge/types.js.map +1 -0
- package/dist/merge/yaml.d.ts +26 -0
- package/dist/merge/yaml.d.ts.map +1 -0
- package/dist/merge/yaml.js +163 -0
- package/dist/merge/yaml.js.map +1 -0
- package/dist/output.d.ts +43 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +39 -0
- package/dist/output.js.map +1 -0
- package/dist/package-manager.d.ts +53 -0
- package/dist/package-manager.d.ts.map +1 -0
- package/dist/package-manager.js +85 -0
- package/dist/package-manager.js.map +1 -0
- package/dist/pnpm-workspace.d.ts +33 -0
- package/dist/pnpm-workspace.d.ts.map +1 -0
- package/dist/pnpm-workspace.js +73 -0
- package/dist/pnpm-workspace.js.map +1 -0
- package/dist/run.d.ts +30 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +83 -0
- package/dist/run.js.map +1 -0
- package/dist/tools.d.ts +135 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +254 -0
- package/dist/tools.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +76 -3
- package/skills/spellbookx/SKILL.md +93 -0
package/dist/run.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Argument parsing and dispatch for the `spellbookx` command.
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
6
|
+
import { init } from './commands/init.js';
|
|
7
|
+
import { processContext } from './context.js';
|
|
8
|
+
import { formatHelp, formatMessage } from './output.js';
|
|
9
|
+
/**
|
|
10
|
+
* Name of the command, as installed by the package.
|
|
11
|
+
*/
|
|
12
|
+
export const COMMAND_NAME = 'spellbookx';
|
|
13
|
+
/**
|
|
14
|
+
* Short alias of the command.
|
|
15
|
+
*/
|
|
16
|
+
export const COMMAND_ALIAS = 'sbx';
|
|
17
|
+
/**
|
|
18
|
+
* Text printed by `spellbookx --help`.
|
|
19
|
+
*/
|
|
20
|
+
export const HELP_TEXT = `🧙 ${COMMAND_NAME}: the spellbook command-line interface
|
|
21
|
+
|
|
22
|
+
Usage: ${COMMAND_NAME} <command> [options]
|
|
23
|
+
${COMMAND_ALIAS} <command> [options]
|
|
24
|
+
|
|
25
|
+
Commands:
|
|
26
|
+
init <tool...> Set up the spellbook configuration of one or more tools
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
-h, --help Show this help and exit
|
|
30
|
+
-v, --version Show the version and exit
|
|
31
|
+
|
|
32
|
+
Run "${COMMAND_NAME} <command> --help" for the options of a command.
|
|
33
|
+
`;
|
|
34
|
+
/**
|
|
35
|
+
* The commands, keyed by name.
|
|
36
|
+
*/
|
|
37
|
+
const COMMANDS = { init };
|
|
38
|
+
/**
|
|
39
|
+
* Reads the version of the package from its `package.json`.
|
|
40
|
+
* @returns The version, for example `1.2.3`.
|
|
41
|
+
*/
|
|
42
|
+
export function getVersion() {
|
|
43
|
+
const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
44
|
+
return packageJson.version;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Runs the command with the given arguments.
|
|
48
|
+
* @param args - The arguments, without the Node.js and script paths.
|
|
49
|
+
* @param context - The environment: the working folder, where to write the
|
|
50
|
+
* output and how to run other programs.
|
|
51
|
+
* @returns The exit code: `0` on success, `1` on an error.
|
|
52
|
+
*/
|
|
53
|
+
export function run(args, context = processContext()) {
|
|
54
|
+
const [name, ...rest] = args;
|
|
55
|
+
const command = name === undefined ? undefined : COMMANDS[name];
|
|
56
|
+
if (command)
|
|
57
|
+
return command(rest, context);
|
|
58
|
+
let values;
|
|
59
|
+
try {
|
|
60
|
+
({ values } = parseArgs({
|
|
61
|
+
args: [...args],
|
|
62
|
+
options: {
|
|
63
|
+
help: { type: 'boolean', short: 'h' },
|
|
64
|
+
version: { type: 'boolean', short: 'v' },
|
|
65
|
+
},
|
|
66
|
+
strict: true,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const message = error.message.startsWith('Unexpected argument')
|
|
71
|
+
? `unknown command '${name}'`
|
|
72
|
+
: error.message;
|
|
73
|
+
context.stderr(`${formatMessage(context.chalk, 'error', `${COMMAND_NAME}: ${message}`)}\n${formatHelp(context.chalk, HELP_TEXT)}`);
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (values.version) {
|
|
77
|
+
context.stdout(`${getVersion()}\n`);
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
context.stdout(formatHelp(context.chalk, HELP_TEXT));
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=run.js.map
|
package/dist/run.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sources":["../src/run.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAgB,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAW,MAAM,YAAY;;SAE1C,YAAY;SACZ,aAAa;;;;;;;;;OASf,YAAY;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,QAAQ,GAEV,EAAE,IAAI,EAAE,CAAC;AAEb;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAC3C,CAAC;IAEzB,OAAO,WAAW,CAAC,OAAO,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CACjB,IAAuB,EACvB,OAAO,GAAY,cAAc,EAAE;IAEnC,MAAM,CAAC,IAAI,EAA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rD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The tools that `spellbookx init` can set up.
|
|
3
|
+
*/
|
|
4
|
+
import type { WorkspacePackageManager } from '@dcdavidev/shared-spells/discover-workspace-scopes';
|
|
5
|
+
import type { Merge } from './merge/types.js';
|
|
6
|
+
import type { PnpmListSettings } from './pnpm-workspace.js';
|
|
7
|
+
/**
|
|
8
|
+
* Names of the tools, as typed after `spellbookx init`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TOOL_NAMES: readonly ['commitlint', 'cspell', 'cz', 'czg', 'editorconfig', 'eslint', 'lefthook', 'prettier', 'vscode'];
|
|
11
|
+
/**
|
|
12
|
+
* Name of a tool, as typed after `spellbookx init`.
|
|
13
|
+
*/
|
|
14
|
+
export type ToolName = (typeof TOOL_NAMES)[number];
|
|
15
|
+
/**
|
|
16
|
+
* What a generated configuration file can depend on.
|
|
17
|
+
*/
|
|
18
|
+
export interface GenerateOptions {
|
|
19
|
+
/**
|
|
20
|
+
* The package manager of the project.
|
|
21
|
+
*/
|
|
22
|
+
manager: WorkspacePackageManager;
|
|
23
|
+
/**
|
|
24
|
+
* The tools named after `spellbookx init`.
|
|
25
|
+
*/
|
|
26
|
+
toolNames: ReadonlySet<ToolName>;
|
|
27
|
+
/**
|
|
28
|
+
* The `package.json` of the project.
|
|
29
|
+
*/
|
|
30
|
+
packageJson: Readonly<Record<string, unknown>>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Where the content of a configuration file comes from.
|
|
34
|
+
*/
|
|
35
|
+
export type ToolFileSource = {
|
|
36
|
+
/**
|
|
37
|
+
* The content is written as it is.
|
|
38
|
+
*/
|
|
39
|
+
content: string;
|
|
40
|
+
} | {
|
|
41
|
+
/**
|
|
42
|
+
* The content is copied from this file of an installed package, for
|
|
43
|
+
* example `@dcdavidev/editorconfig/.editorconfig`.
|
|
44
|
+
*/
|
|
45
|
+
copyFrom: string;
|
|
46
|
+
} | {
|
|
47
|
+
/**
|
|
48
|
+
* The content is built for the project.
|
|
49
|
+
*/
|
|
50
|
+
generate: (options: GenerateOptions) => string;
|
|
51
|
+
} | {
|
|
52
|
+
/**
|
|
53
|
+
* The content is a string exported by a module of an installed package.
|
|
54
|
+
*/
|
|
55
|
+
exportFrom: {
|
|
56
|
+
/**
|
|
57
|
+
* The module, for example `@dcdavidev/prettier-config/prettierignore`.
|
|
58
|
+
*/
|
|
59
|
+
module: string;
|
|
60
|
+
/**
|
|
61
|
+
* The name of the export, for example `prettierIgnoreFile`.
|
|
62
|
+
*/
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A configuration file that a tool needs.
|
|
68
|
+
*/
|
|
69
|
+
export interface ToolFile {
|
|
70
|
+
/**
|
|
71
|
+
* The file to create, relative to the project root.
|
|
72
|
+
*/
|
|
73
|
+
path: string;
|
|
74
|
+
/**
|
|
75
|
+
* Where the content of the file comes from.
|
|
76
|
+
*/
|
|
77
|
+
source: ToolFileSource;
|
|
78
|
+
/**
|
|
79
|
+
* Other files that do the same job. If one of them exists, the tool is
|
|
80
|
+
* already configured and the file is not created.
|
|
81
|
+
*/
|
|
82
|
+
alternatives: readonly string[];
|
|
83
|
+
/**
|
|
84
|
+
* Other files that {@link ToolFile.merge} can merge into. If one of them
|
|
85
|
+
* exists, it is merged instead of creating the file.
|
|
86
|
+
*/
|
|
87
|
+
mergeInto?: readonly string[];
|
|
88
|
+
/**
|
|
89
|
+
* The `package.json` field that can hold the same configuration.
|
|
90
|
+
*/
|
|
91
|
+
packageJsonField?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Merges the incoming file into an existing one. Files without it are kept
|
|
94
|
+
* as they are when they exist, unless `--force` is passed.
|
|
95
|
+
*/
|
|
96
|
+
merge?: Merge;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* How to set up a tool.
|
|
100
|
+
*/
|
|
101
|
+
export interface Tool {
|
|
102
|
+
/**
|
|
103
|
+
* The name of the tool.
|
|
104
|
+
*/
|
|
105
|
+
name: ToolName;
|
|
106
|
+
/**
|
|
107
|
+
* The development dependencies to install.
|
|
108
|
+
*/
|
|
109
|
+
dependencies: readonly string[];
|
|
110
|
+
/**
|
|
111
|
+
* The configuration files to create.
|
|
112
|
+
*/
|
|
113
|
+
files: readonly ToolFile[];
|
|
114
|
+
/**
|
|
115
|
+
* Items that list settings of `pnpm-workspace.yaml` must contain when the
|
|
116
|
+
* project uses pnpm. They are written before the packages are installed.
|
|
117
|
+
*/
|
|
118
|
+
pnpmSettings?: PnpmListSettings;
|
|
119
|
+
/**
|
|
120
|
+
* A binary of the installed packages to run, with its arguments, after the
|
|
121
|
+
* files are written. It does not run with `--skip-install`.
|
|
122
|
+
*/
|
|
123
|
+
afterInstall?: readonly string[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* How to set up each tool.
|
|
127
|
+
*/
|
|
128
|
+
export declare const TOOLS: Readonly<Record<ToolName, Tool>>;
|
|
129
|
+
/**
|
|
130
|
+
* Checks whether a string is the name of a tool.
|
|
131
|
+
* @param name - The string to check.
|
|
132
|
+
* @returns `true` if `name` is one of {@link TOOL_NAMES}.
|
|
133
|
+
*/
|
|
134
|
+
export declare function isToolName(name: string): name is ToolName;
|
|
135
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAC;AAMlG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,UAAU,YACrB,YAAY,EACZ,QA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AY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC;;OAEG;IACH,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAyFD;;GAEG;AACH,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAkJlD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,QAAQ,CAEzD"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The tools that `spellbookx init` can set up.
|
|
3
|
+
*/
|
|
4
|
+
import { buildLefthookConfig } from './lefthook.js';
|
|
5
|
+
import { mergeEditorconfig } from './merge/editorconfig.js';
|
|
6
|
+
import { mergeJson } from './merge/json.js';
|
|
7
|
+
import { createLinesMerge } from './merge/lines.js';
|
|
8
|
+
import { mergeYaml } from './merge/yaml.js';
|
|
9
|
+
/**
|
|
10
|
+
* Names of the tools, as typed after `spellbookx init`.
|
|
11
|
+
*/
|
|
12
|
+
export const TOOL_NAMES = [
|
|
13
|
+
'commitlint',
|
|
14
|
+
'cspell',
|
|
15
|
+
'cz',
|
|
16
|
+
'czg',
|
|
17
|
+
'editorconfig',
|
|
18
|
+
'eslint',
|
|
19
|
+
'lefthook',
|
|
20
|
+
'prettier',
|
|
21
|
+
'vscode',
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Builds the names of a configuration file with each JavaScript extension.
|
|
25
|
+
* @param base - The name without the extension, for example `eslint.config`.
|
|
26
|
+
* @returns The names, for example `eslint.config.js` and `eslint.config.mjs`.
|
|
27
|
+
*/
|
|
28
|
+
function withScriptExtensions(base) {
|
|
29
|
+
return ['js', 'cjs', 'mjs', 'ts', 'cts', 'mts'].map((ext) => `${base}.${ext}`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Builds the names of a `.*rc` file with each extension.
|
|
33
|
+
* @param base - The name of the file, for example `.prettierrc`.
|
|
34
|
+
* @returns The name alone and with each JSON, YAML and script extension.
|
|
35
|
+
*/
|
|
36
|
+
function rcFiles(base) {
|
|
37
|
+
return [
|
|
38
|
+
base,
|
|
39
|
+
...['json', 'json5', 'yaml', 'yml', 'toml'].map((ext) => `${base}.${ext}`),
|
|
40
|
+
...withScriptExtensions(base),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Content of a configuration file that re-exports a package.
|
|
45
|
+
* @param packageName - The package to re-export.
|
|
46
|
+
* @returns The content of the file.
|
|
47
|
+
*/
|
|
48
|
+
function reExport(packageName) {
|
|
49
|
+
return `export { default } from '${packageName}';\n`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Content of the ESLint configuration file.
|
|
53
|
+
*/
|
|
54
|
+
const ESLINT_CONFIG = `import { defineConfig } from 'eslint/config';
|
|
55
|
+
import dcdavidev from '@dcdavidev/eslint-plugin';
|
|
56
|
+
|
|
57
|
+
export default defineConfig([dcdavidev.configs.recommended]);
|
|
58
|
+
`;
|
|
59
|
+
/**
|
|
60
|
+
* Builds the Lefthook configuration for the tools of the project: the tools
|
|
61
|
+
* named after `init` and the ones that `package.json` already depends on.
|
|
62
|
+
* @param options - The package manager, the named tools and `package.json`.
|
|
63
|
+
* @returns The content of `lefthook.yml`.
|
|
64
|
+
*/
|
|
65
|
+
function generateLefthook(options) {
|
|
66
|
+
const { manager, toolNames, packageJson } = options;
|
|
67
|
+
const dependencies = {
|
|
68
|
+
...packageJson.dependencies,
|
|
69
|
+
...packageJson.devDependencies,
|
|
70
|
+
};
|
|
71
|
+
const packages = {
|
|
72
|
+
commitlint: '@commitlint/cli',
|
|
73
|
+
cspell: 'cspell',
|
|
74
|
+
eslint: 'eslint',
|
|
75
|
+
prettier: 'prettier',
|
|
76
|
+
};
|
|
77
|
+
const tools = new Set();
|
|
78
|
+
for (const [tool, packageName] of Object.entries(packages)) {
|
|
79
|
+
if (toolNames.has(tool) || Object.hasOwn(dependencies, packageName))
|
|
80
|
+
tools.add(tool);
|
|
81
|
+
}
|
|
82
|
+
const lefthookOptions = { manager, tools };
|
|
83
|
+
return buildLefthookConfig(lefthookOptions);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The czg setup, shared by the `cz` and `czg` names.
|
|
87
|
+
*/
|
|
88
|
+
const czTool = {
|
|
89
|
+
dependencies: ['@dcdavidev/cz-config', 'czg'],
|
|
90
|
+
files: [
|
|
91
|
+
{
|
|
92
|
+
path: 'cz.config.mjs',
|
|
93
|
+
source: { content: reExport('@dcdavidev/cz-config') },
|
|
94
|
+
alternatives: [...withScriptExtensions('cz.config'), '.czrc'],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* How to set up each tool.
|
|
100
|
+
*/
|
|
101
|
+
export const TOOLS = {
|
|
102
|
+
commitlint: {
|
|
103
|
+
name: 'commitlint',
|
|
104
|
+
dependencies: [
|
|
105
|
+
'@dcdavidev/commitlint-config',
|
|
106
|
+
'@commitlint/cli',
|
|
107
|
+
'@commitlint/config-conventional',
|
|
108
|
+
],
|
|
109
|
+
files: [
|
|
110
|
+
{
|
|
111
|
+
path: 'commitlint.config.mjs',
|
|
112
|
+
source: { content: reExport('@dcdavidev/commitlint-config') },
|
|
113
|
+
alternatives: [
|
|
114
|
+
...withScriptExtensions('commitlint.config'),
|
|
115
|
+
...rcFiles('.commitlintrc'),
|
|
116
|
+
],
|
|
117
|
+
packageJsonField: 'commitlint',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
cspell: {
|
|
122
|
+
name: 'cspell',
|
|
123
|
+
dependencies: ['@dcdavidev/cspell-config', 'cspell'],
|
|
124
|
+
files: [
|
|
125
|
+
{
|
|
126
|
+
path: 'cspell.config.mjs',
|
|
127
|
+
source: { content: reExport('@dcdavidev/cspell-config') },
|
|
128
|
+
alternatives: [
|
|
129
|
+
...withScriptExtensions('cspell.config'),
|
|
130
|
+
'cspell.config.json',
|
|
131
|
+
'cspell.config.yaml',
|
|
132
|
+
'cspell.config.yml',
|
|
133
|
+
'cspell.json',
|
|
134
|
+
'cspell.yaml',
|
|
135
|
+
'cspell.yml',
|
|
136
|
+
'.cspell.json',
|
|
137
|
+
'cSpell.json',
|
|
138
|
+
'.cSpell.json',
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
cz: { name: 'cz', ...czTool },
|
|
144
|
+
czg: { name: 'czg', ...czTool },
|
|
145
|
+
editorconfig: {
|
|
146
|
+
name: 'editorconfig',
|
|
147
|
+
dependencies: ['@dcdavidev/editorconfig'],
|
|
148
|
+
files: [
|
|
149
|
+
{
|
|
150
|
+
path: '.editorconfig',
|
|
151
|
+
source: { copyFrom: '@dcdavidev/editorconfig/.editorconfig' },
|
|
152
|
+
alternatives: [],
|
|
153
|
+
merge: mergeEditorconfig,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
eslint: {
|
|
158
|
+
name: 'eslint',
|
|
159
|
+
dependencies: ['@dcdavidev/eslint-plugin', 'eslint', 'typescript'],
|
|
160
|
+
files: [
|
|
161
|
+
{
|
|
162
|
+
path: 'eslint.config.mjs',
|
|
163
|
+
source: { content: ESLINT_CONFIG },
|
|
164
|
+
alternatives: withScriptExtensions('eslint.config'),
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
lefthook: {
|
|
169
|
+
name: 'lefthook',
|
|
170
|
+
dependencies: ['lefthook'],
|
|
171
|
+
files: [
|
|
172
|
+
{
|
|
173
|
+
path: 'lefthook.yml',
|
|
174
|
+
source: { generate: generateLefthook },
|
|
175
|
+
mergeInto: [
|
|
176
|
+
'lefthook.yaml',
|
|
177
|
+
'.lefthook.yml',
|
|
178
|
+
'.lefthook.yaml',
|
|
179
|
+
'.config/lefthook.yml',
|
|
180
|
+
'.config/lefthook.yaml',
|
|
181
|
+
],
|
|
182
|
+
// Lefthook files in other formats, which cannot be merged as YAML.
|
|
183
|
+
alternatives: ['lefthook', '.lefthook', '.config/lefthook'].flatMap((base) => ['json', 'jsonc', 'toml'].map((ext) => `${base}.${ext}`)),
|
|
184
|
+
merge: mergeYaml,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
path: 'package.json',
|
|
188
|
+
source: {
|
|
189
|
+
content: '{ "scripts": { "prepare": "lefthook install" } }\n',
|
|
190
|
+
},
|
|
191
|
+
alternatives: [],
|
|
192
|
+
merge: mergeJson,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
afterInstall: ['lefthook', 'install'],
|
|
196
|
+
},
|
|
197
|
+
prettier: {
|
|
198
|
+
name: 'prettier',
|
|
199
|
+
dependencies: ['@dcdavidev/prettier-config', 'prettier'],
|
|
200
|
+
// pnpm does not hoist the plugins, so Prettier would not find them.
|
|
201
|
+
pnpmSettings: {
|
|
202
|
+
publicHoistPattern: ['*prettier-plugin-*', '@prettier/plugin-*'],
|
|
203
|
+
},
|
|
204
|
+
files: [
|
|
205
|
+
{
|
|
206
|
+
path: 'prettier.config.mjs',
|
|
207
|
+
source: { content: reExport('@dcdavidev/prettier-config') },
|
|
208
|
+
alternatives: [
|
|
209
|
+
...withScriptExtensions('prettier.config'),
|
|
210
|
+
...rcFiles('.prettierrc'),
|
|
211
|
+
],
|
|
212
|
+
packageJsonField: 'prettier',
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
path: '.prettierignore',
|
|
216
|
+
source: {
|
|
217
|
+
exportFrom: {
|
|
218
|
+
module: '@dcdavidev/prettier-config/prettierignore',
|
|
219
|
+
name: 'prettierIgnoreFile',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
alternatives: [],
|
|
223
|
+
merge: createLinesMerge('# @dcdavidev/prettier-config'),
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
vscode: {
|
|
228
|
+
name: 'vscode',
|
|
229
|
+
dependencies: ['@dcdavidev/vscode-config'],
|
|
230
|
+
files: [
|
|
231
|
+
{
|
|
232
|
+
path: '.vscode/settings.json',
|
|
233
|
+
source: { copyFrom: '@dcdavidev/vscode-config/settings.json' },
|
|
234
|
+
alternatives: [],
|
|
235
|
+
merge: mergeJson,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
path: '.vscode/extensions.json',
|
|
239
|
+
source: { copyFrom: '@dcdavidev/vscode-config/extensions.json' },
|
|
240
|
+
alternatives: [],
|
|
241
|
+
merge: mergeJson,
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Checks whether a string is the name of a tool.
|
|
248
|
+
* @param name - The string to check.
|
|
249
|
+
* @returns `true` if `name` is one of {@link TOOL_NAMES}.
|
|
250
|
+
*/
|
|
251
|
+
export function isToolName(name) {
|
|
252
|
+
return TOOL_NAMES.includes(name);
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,mBAAmB,EAAwB,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY;IACZ,QAAQ;IACR,IA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