@dimensional-innovations/tool-config 1.4.1 → 3.0.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.
Files changed (32) hide show
  1. package/README.md +128 -23
  2. package/bin/lib/ci-setup.js +142 -0
  3. package/bin/lib/formatting.js +103 -0
  4. package/bin/lib/handlers/eslint.js +61 -0
  5. package/bin/lib/handlers/prettier.js +83 -0
  6. package/bin/lib/handlers/semantic-release.js +60 -0
  7. package/bin/lib/handlers/stylelint.js +85 -0
  8. package/bin/lib/handlers/typescript.js +156 -0
  9. package/bin/lib/package-manager.js +201 -0
  10. package/bin/lib/ui.js +239 -0
  11. package/bin/lib/uninstall.js +199 -0
  12. package/bin/lib/validators.js +28 -0
  13. package/bin/setup-tool-config.js +270 -576
  14. package/package.json +17 -4
  15. package/src/detectors.js +27 -2
  16. package/src/index.js +8 -3
  17. package/src/tools/typescript/README.md +665 -0
  18. package/src/tools/typescript/checker-detection.js +113 -0
  19. package/src/tools/typescript/index.js +202 -0
  20. package/src/tools/typescript/presets/base.js +58 -0
  21. package/src/tools/typescript/presets/environments/browser.js +10 -0
  22. package/src/tools/typescript/presets/environments/node.js +11 -0
  23. package/src/tools/typescript/presets/environments/universal.js +11 -0
  24. package/src/tools/typescript/presets/frameworks/angular.js +11 -0
  25. package/src/tools/typescript/presets/frameworks/astro.js +11 -0
  26. package/src/tools/typescript/presets/frameworks/electron.js +100 -0
  27. package/src/tools/typescript/presets/frameworks/node.js +12 -0
  28. package/src/tools/typescript/presets/frameworks/react.js +10 -0
  29. package/src/tools/typescript/presets/frameworks/solid.js +11 -0
  30. package/src/tools/typescript/presets/frameworks/svelte.js +10 -0
  31. package/src/tools/typescript/presets/frameworks/vanilla.js +9 -0
  32. package/src/tools/typescript/presets/frameworks/vue.js +17 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Uninstall utilities for setup-tool-config CLI
3
+ * Handles safe removal of config files, CI templates, and scripts
4
+ */
5
+
6
+ import { existsSync, readdirSync, readFileSync, rmSync } from 'fs'
7
+ import { join } from 'path'
8
+
9
+ /**
10
+ * Detect which tools are currently installed
11
+ * @param {string} cwd - Current working directory
12
+ * @returns {string[]} Array of installed tool names
13
+ */
14
+ export function detectInstalledTools(cwd) {
15
+ const toolFiles = {
16
+ eslint: 'eslint.config.js',
17
+ prettier: 'prettier.config.js',
18
+ stylelint: 'stylelint.config.js',
19
+ typescript: 'tsconfig.json',
20
+ 'semantic-release': 'release.config.js'
21
+ }
22
+
23
+ const installed = []
24
+ for (const [tool, filename] of Object.entries(toolFiles)) {
25
+ if (existsSync(join(cwd, filename))) {
26
+ installed.push(tool)
27
+ }
28
+ }
29
+
30
+ return installed
31
+ }
32
+
33
+ /**
34
+ * Detect which CI provider is installed
35
+ * @param {string} cwd - Current working directory
36
+ * @returns {string|null} Provider name or null
37
+ */
38
+ export function detectInstalledCI(cwd) {
39
+ const ciFiles = {
40
+ gitlab: '.gitlab-ci.yml',
41
+ github: '.github/workflows/ci.yml',
42
+ bitbucket: 'bitbucket-pipelines.yml'
43
+ }
44
+
45
+ for (const [provider, filepath] of Object.entries(ciFiles)) {
46
+ if (existsSync(join(cwd, filepath))) {
47
+ return provider
48
+ }
49
+ }
50
+
51
+ return null
52
+ }
53
+
54
+ /**
55
+ * Check if a file's content matches the expected template
56
+ * @param {string} filepath - Path to file
57
+ * @param {string} expectedContent - Expected content
58
+ * @returns {boolean} True if content matches
59
+ */
60
+ function contentMatches(filepath, expectedContent) {
61
+ if (!existsSync(filepath)) {
62
+ return false
63
+ }
64
+
65
+ try {
66
+ const actualContent = readFileSync(filepath, 'utf8')
67
+ return actualContent.trim() === expectedContent.trim()
68
+ } catch {
69
+ return false
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Uninstall a tool by removing its config file
75
+ * @param {string} _tool - Tool name
76
+ * @param {Object} handler - Tool handler with getConfigFilename and generateConfigContent
77
+ * @param {string} cwd - Current working directory
78
+ * @param {boolean} dryRun - Preview mode
79
+ * @returns {boolean} True if uninstalled successfully
80
+ */
81
+ export function uninstallTool(_tool, handler, cwd, dryRun = false) {
82
+ const filename = handler.getConfigFilename()
83
+ const filepath = join(cwd, filename)
84
+
85
+ if (!existsSync(filepath)) {
86
+ console.log(` ℹ️ ${filename} not found - already uninstalled`)
87
+ return false
88
+ }
89
+
90
+ // Check if file was modified by user
91
+ const expectedContent = handler.generateConfigContent()
92
+ const isUnmodified = contentMatches(filepath, expectedContent)
93
+
94
+ if (!isUnmodified) {
95
+ console.log(` ⚠️ ${filename} has been modified - skipping for safety`)
96
+ console.log(' Remove manually if you want to delete it')
97
+ return false
98
+ }
99
+
100
+ if (dryRun) {
101
+ console.log(` 🗑️ Would remove: ${filename}`)
102
+ return true
103
+ }
104
+
105
+ try {
106
+ rmSync(filepath)
107
+ console.log(` ✅ Removed: ${filename}`)
108
+ return true
109
+ } catch (error) {
110
+ console.error(` ❌ Failed to remove ${filename}:`, error.message)
111
+ return false
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Uninstall CI/CD configuration
117
+ * @param {string} provider - CI provider (gitlab, github, bitbucket)
118
+ * @param {string} cwd - Current working directory
119
+ * @param {boolean} dryRun - Preview mode
120
+ * @returns {boolean} True if uninstalled successfully
121
+ */
122
+ export function uninstallCIConfig(provider, cwd, dryRun = false) {
123
+ const ciPaths = {
124
+ gitlab: '.gitlab-ci.yml',
125
+ github: '.github/workflows/ci.yml',
126
+ bitbucket: 'bitbucket-pipelines.yml'
127
+ }
128
+
129
+ const ciPath = ciPaths[provider]
130
+ if (!ciPath) {
131
+ console.log(` ⚠️ Unknown provider: ${provider}`)
132
+ return false
133
+ }
134
+
135
+ const filepath = join(cwd, ciPath)
136
+
137
+ if (!existsSync(filepath)) {
138
+ console.log(` ℹ️ ${ciPath} not found - already uninstalled`)
139
+ return false
140
+ }
141
+
142
+ if (dryRun) {
143
+ console.log(` 🗑️ Would remove: ${ciPath}`)
144
+ if (provider === 'github') {
145
+ console.log(` 🗑️ Would clean up empty directories if needed`)
146
+ }
147
+ return true
148
+ }
149
+
150
+ try {
151
+ rmSync(filepath)
152
+ console.log(` ✅ Removed: ${ciPath}`)
153
+
154
+ // Clean up empty directories for GitHub
155
+ if (provider === 'github') {
156
+ cleanupGitHubDirectories(cwd)
157
+ }
158
+
159
+ return true
160
+ } catch (error) {
161
+ console.error(` ❌ Failed to remove ${ciPath}:`, error.message)
162
+ return false
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Clean up empty GitHub directories
168
+ * @param {string} cwd - Current working directory
169
+ */
170
+ function cleanupGitHubDirectories(cwd) {
171
+ const workflowDir = join(cwd, '.github/workflows')
172
+ const githubDir = join(cwd, '.github')
173
+
174
+ // Remove .github/workflows if empty
175
+ if (existsSync(workflowDir)) {
176
+ try {
177
+ const files = readdirSync(workflowDir)
178
+ if (files.length === 0) {
179
+ rmSync(workflowDir, { recursive: true })
180
+ console.log(` ✅ Removed empty directory: .github/workflows`)
181
+ }
182
+ } catch {
183
+ // Ignore cleanup errors
184
+ }
185
+ }
186
+
187
+ // Remove .github if empty
188
+ if (existsSync(githubDir)) {
189
+ try {
190
+ const files = readdirSync(githubDir)
191
+ if (files.length === 0) {
192
+ rmSync(githubDir, { recursive: true })
193
+ console.log(` ✅ Removed empty directory: .github`)
194
+ }
195
+ } catch {
196
+ // Ignore cleanup errors
197
+ }
198
+ }
199
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Input validation for setup-tool-config CLI
3
+ */
4
+
5
+ export const VALID_TOOLS = ['eslint', 'prettier', 'stylelint', 'typescript', 'semantic-release']
6
+ export const VALID_PROVIDERS = ['gitlab', 'github', 'bitbucket']
7
+
8
+ /**
9
+ * Validate tool name
10
+ * @param {string} tool - Tool name to validate
11
+ * @throws {Error} If tool is invalid
12
+ */
13
+ export function validateTool(tool) {
14
+ if (!VALID_TOOLS.includes(tool)) {
15
+ throw new Error(`Unknown tool: ${tool}. Valid tools: ${VALID_TOOLS.join(', ')}`)
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Validate CI provider
21
+ * @param {string} provider - Provider name to validate
22
+ * @throws {Error} If provider is invalid
23
+ */
24
+ export function validateProvider(provider) {
25
+ if (!VALID_PROVIDERS.includes(provider)) {
26
+ throw new Error(`Unknown provider: ${provider}. Valid providers: ${VALID_PROVIDERS.join(', ')}`)
27
+ }
28
+ }