@minimalstuff/tooling 0.5.0 → 0.6.0

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.
@@ -1,5 +1,5 @@
1
1
  //#region src/cli/index.d.ts
2
- type ConfigTool = 'editorconfig' | 'oxc';
2
+ type ConfigTool = 'editorconfig' | 'oxc' | 'vscode';
3
3
  declare const DEFAULT_SELECTED_TOOLS: ConfigTool[];
4
4
  interface PromptResult {
5
5
  tools: ConfigTool[];
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import color from "picocolors";
3
+ import { existsSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
3
5
  import * as p from "@clack/prompts";
4
6
  import { cancel, confirm, intro, isCancel, log, multiselect } from "@clack/prompts";
5
- import { join } from "node:path";
6
- import { existsSync } from "node:fs";
7
7
  import { installPackage } from "@antfu/install-pkg";
8
8
  import { mkdir, readFile, writeFile } from "node:fs/promises";
9
9
  import { parse, printParseErrorCode } from "jsonc-parser";
@@ -80,7 +80,7 @@ async function updateOxc(result) {
80
80
  const projectType = await getProjectType(cwd);
81
81
  await writeFile(join(cwd, "oxlint.config.ts"), buildOxlintConfigContent(projectType));
82
82
  await writeFile(join(cwd, "oxfmt.config.ts"), projectType.adonisjs ? oxfmtAdonisConfigContent : oxfmtConfigContent);
83
- await updateVscodeSettings(cwd);
83
+ if (result.tools.includes("vscode")) await updateVscodeSettings(cwd);
84
84
  await addScriptsToPackageJson(cwd);
85
85
  await installPackage(oxcPackages, {
86
86
  dev: true,
@@ -135,7 +135,7 @@ async function addScriptsToPackageJson(cwd) {
135
135
  }
136
136
  //#endregion
137
137
  //#region package.json
138
- var version = "0.5.0";
138
+ var version = "0.6.0";
139
139
  //#endregion
140
140
  //#region src/cli/update_pkg.json.ts
141
141
  async function updatePkgJson(_) {
@@ -166,26 +166,57 @@ async function updateEditorConfig(result) {
166
166
  }
167
167
  //#endregion
168
168
  //#region src/cli/index.ts
169
- const DEFAULT_SELECTED_TOOLS = ["editorconfig", "oxc"];
169
+ const DEFAULT_SELECTED_TOOLS = [
170
+ "editorconfig",
171
+ "oxc",
172
+ "vscode"
173
+ ];
170
174
  function exit() {
171
175
  cancel("Cancelled");
172
176
  return process.exit(0);
173
177
  }
178
+ function findGitRoot(startDir) {
179
+ let dir = startDir;
180
+ while (true) {
181
+ if (existsSync(join(dir, ".git"))) return dir;
182
+ const parent = dirname(dir);
183
+ if (parent === dir) return null;
184
+ dir = parent;
185
+ }
186
+ }
174
187
  async function main() {
175
188
  const cwd = process.cwd();
176
189
  intro(color.blue(TOOLING_PACKAGE_NAME));
177
190
  log.info(`You are about to configure ${TOOLING_PACKAGE_NAME} in the current directory: ${color.green(cwd)}`);
178
191
  if (isCancel(await confirm({ message: `Continue ?` }))) return exit();
192
+ const gitRoot = findGitRoot(cwd);
193
+ const rootToCheck = gitRoot && gitRoot !== cwd ? gitRoot : null;
194
+ const hasEditorConfig = existsSync(join(cwd, ".editorconfig")) || rootToCheck !== null && existsSync(join(rootToCheck, ".editorconfig"));
195
+ const hasVscode = existsSync(join(cwd, ".vscode")) || rootToCheck !== null && existsSync(join(rootToCheck, ".vscode"));
196
+ const initialValues = DEFAULT_SELECTED_TOOLS.filter((tool) => {
197
+ if (tool === "editorconfig" && hasEditorConfig) return false;
198
+ if (tool === "vscode" && hasVscode) return false;
199
+ return true;
200
+ });
179
201
  const tools = await multiselect({
180
202
  message: "Select tools to configure",
181
- options: [{
182
- value: "editorconfig",
183
- label: "EditorConfig"
184
- }, {
185
- value: "oxc",
186
- label: "OXC (oxlint + oxfmt)"
187
- }],
188
- initialValues: DEFAULT_SELECTED_TOOLS,
203
+ options: [
204
+ {
205
+ value: "editorconfig",
206
+ label: "EditorConfig",
207
+ ...hasEditorConfig && { hint: "already exists" }
208
+ },
209
+ {
210
+ value: "oxc",
211
+ label: "OXC (oxlint + oxfmt)"
212
+ },
213
+ {
214
+ value: "vscode",
215
+ label: "VSCode settings (.vscode/settings.json)",
216
+ ...hasVscode && { hint: "already exists" }
217
+ }
218
+ ],
219
+ initialValues,
189
220
  required: true
190
221
  });
191
222
  if (isCancel(tools)) return exit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minimalstuff/tooling",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Shared tooling configs: EditorConfig, OXC (oxlint + oxfmt)",
5
5
  "keywords": [
6
6
  "editorconfig",