@dimensional-innovations/tool-config 3.1.0 ā 5.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.
- package/LICENSE +1 -1
- package/README.md +7 -120
- package/package.json +21 -14
- package/bin/lib/ci-setup.js +0 -142
- package/bin/lib/formatting.js +0 -103
- package/bin/lib/handlers/eslint.js +0 -61
- package/bin/lib/handlers/prettier.js +0 -83
- package/bin/lib/handlers/semantic-release.js +0 -60
- package/bin/lib/handlers/stylelint.js +0 -85
- package/bin/lib/handlers/typescript.js +0 -156
- package/bin/lib/package-manager.js +0 -201
- package/bin/lib/ui.js +0 -239
- package/bin/lib/uninstall.js +0 -199
- package/bin/lib/validators.js +0 -28
- package/bin/setup-tool-config.js +0 -442
- package/src/detectors.js +0 -286
- package/src/index.js +0 -69
- package/src/tools/eslint/index.js +0 -282
- package/src/tools/eslint/presets/base.js +0 -82
- package/src/tools/eslint/presets/environments/browser.js +0 -16
- package/src/tools/eslint/presets/environments/node.js +0 -21
- package/src/tools/eslint/presets/environments/universal.js +0 -18
- package/src/tools/eslint/presets/frameworks/angular.js +0 -74
- package/src/tools/eslint/presets/frameworks/astro.js +0 -38
- package/src/tools/eslint/presets/frameworks/node.js +0 -57
- package/src/tools/eslint/presets/frameworks/react.js +0 -76
- package/src/tools/eslint/presets/frameworks/solid.js +0 -45
- package/src/tools/eslint/presets/frameworks/svelte.js +0 -78
- package/src/tools/eslint/presets/frameworks/vanilla.js +0 -16
- package/src/tools/eslint/presets/frameworks/vue.js +0 -154
- package/src/tools/eslint/presets/imports.js +0 -47
- package/src/tools/eslint/presets/typescript.js +0 -142
- package/src/tools/prettier/README.md +0 -398
- package/src/tools/prettier/index.js +0 -132
- package/src/tools/prettier/presets/base.js +0 -36
- package/src/tools/prettier/presets/frameworks/astro.js +0 -15
- package/src/tools/prettier/presets/frameworks/react.js +0 -15
- package/src/tools/prettier/presets/frameworks/svelte.js +0 -22
- package/src/tools/prettier/presets/frameworks/vanilla.js +0 -13
- package/src/tools/prettier/presets/frameworks/vue.js +0 -21
- package/src/tools/prettier/presets/prettierignore.js +0 -56
- package/src/tools/semantic-release/CI_SETUP.md +0 -66
- package/src/tools/semantic-release/README.md +0 -533
- package/src/tools/semantic-release/index.js +0 -130
- package/src/tools/semantic-release/presets/default.js +0 -37
- package/src/tools/semantic-release/presets/library.js +0 -58
- package/src/tools/semantic-release/presets/monorepo.js +0 -48
- package/src/tools/semantic-release/templates/.gitlab-ci.yml +0 -89
- package/src/tools/semantic-release/templates/bitbucket-pipelines.yml +0 -100
- package/src/tools/semantic-release/templates/github-workflow.yml +0 -107
- package/src/tools/stylelint/README.md +0 -425
- package/src/tools/stylelint/index.js +0 -195
- package/src/tools/stylelint/presets/base.js +0 -50
- package/src/tools/stylelint/presets/css-modules.js +0 -43
- package/src/tools/stylelint/presets/frameworks/react.js +0 -18
- package/src/tools/stylelint/presets/frameworks/svelte.js +0 -28
- package/src/tools/stylelint/presets/frameworks/vanilla.js +0 -14
- package/src/tools/stylelint/presets/frameworks/vue.js +0 -38
- package/src/tools/stylelint/presets/scss.js +0 -83
- package/src/tools/stylelint/presets/tailwind.js +0 -49
- package/src/tools/typescript/README.md +0 -665
- package/src/tools/typescript/checker-detection.js +0 -113
- package/src/tools/typescript/index.js +0 -202
- package/src/tools/typescript/presets/base.js +0 -58
- package/src/tools/typescript/presets/environments/browser.js +0 -10
- package/src/tools/typescript/presets/environments/node.js +0 -11
- package/src/tools/typescript/presets/environments/universal.js +0 -11
- package/src/tools/typescript/presets/frameworks/angular.js +0 -11
- package/src/tools/typescript/presets/frameworks/astro.js +0 -11
- package/src/tools/typescript/presets/frameworks/electron.js +0 -100
- package/src/tools/typescript/presets/frameworks/node.js +0 -12
- package/src/tools/typescript/presets/frameworks/react.js +0 -10
- package/src/tools/typescript/presets/frameworks/solid.js +0 -11
- package/src/tools/typescript/presets/frameworks/svelte.js +0 -10
- package/src/tools/typescript/presets/frameworks/vanilla.js +0 -9
- package/src/tools/typescript/presets/frameworks/vue.js +0 -17
- package/src/utils/ignore-patterns.js +0 -157
- package/src/utils/package-reader.js +0 -42
package/src/detectors.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
|
-
import { join } from 'path'
|
|
4
|
-
|
|
5
|
-
import { getAllDependencies, readPackageJson } from './utils/package-reader.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check for React meta-frameworks
|
|
9
|
-
*/
|
|
10
|
-
function detectReactMetaFramework(deps) {
|
|
11
|
-
return (
|
|
12
|
-
deps.next ||
|
|
13
|
-
deps['@next/core'] ||
|
|
14
|
-
deps.remix ||
|
|
15
|
-
deps['@remix-run/react'] ||
|
|
16
|
-
deps['@remix-run/node'] ||
|
|
17
|
-
deps.gatsby ||
|
|
18
|
-
deps['gatsby-link']
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Check for Vue meta-frameworks
|
|
24
|
-
*/
|
|
25
|
-
function detectVueMetaFramework(deps) {
|
|
26
|
-
return deps.nuxt || deps['nuxt3']
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Check for Svelte meta-frameworks
|
|
31
|
-
*/
|
|
32
|
-
function detectSvelteMetaFramework(deps) {
|
|
33
|
-
return deps['@sveltejs/kit']
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Check for base framework dependencies
|
|
38
|
-
*/
|
|
39
|
-
function detectBaseFramework(deps) {
|
|
40
|
-
if (deps.react || deps['react-dom']) return 'react'
|
|
41
|
-
if (deps.vue || deps['@vue/runtime-core'] || deps['vue-router'] || deps.pinia) return 'vue'
|
|
42
|
-
if (deps['@angular/core']) return 'angular'
|
|
43
|
-
if (deps.svelte) return 'svelte'
|
|
44
|
-
if (deps['solid-js']) return 'solid'
|
|
45
|
-
if (deps.astro) return 'astro'
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Check if project is a Node.js backend
|
|
51
|
-
*/
|
|
52
|
-
function isNodeBackend(pkg, deps, cwd) {
|
|
53
|
-
if (pkg.type !== 'module') return false
|
|
54
|
-
|
|
55
|
-
const hasNodeFramework = deps.express || deps.fastify || deps.koa || deps['@hapi/hapi']
|
|
56
|
-
const hasServerFiles =
|
|
57
|
-
existsSync(join(cwd, 'server.js')) ||
|
|
58
|
-
existsSync(join(cwd, 'app.js')) ||
|
|
59
|
-
(existsSync(join(cwd, 'index.js')) && existsSync(join(cwd, 'routes')))
|
|
60
|
-
|
|
61
|
-
return hasNodeFramework || hasServerFiles
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Detect the framework being used in the project
|
|
66
|
-
* @param {string} cwd - Current working directory
|
|
67
|
-
* @returns {string} Detected framework name
|
|
68
|
-
*/
|
|
69
|
-
export function detectFramework(cwd = process.cwd()) {
|
|
70
|
-
const pkg = readPackageJson(cwd)
|
|
71
|
-
|
|
72
|
-
if (!pkg) {
|
|
73
|
-
console.warn('ā ļø Could not find package.json, defaulting to vanilla JavaScript')
|
|
74
|
-
return 'vanilla'
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const deps = getAllDependencies(pkg)
|
|
78
|
-
|
|
79
|
-
// Check meta-frameworks first
|
|
80
|
-
if (detectReactMetaFramework(deps)) return 'react'
|
|
81
|
-
if (detectVueMetaFramework(deps)) return 'vue'
|
|
82
|
-
if (detectSvelteMetaFramework(deps)) return 'svelte'
|
|
83
|
-
|
|
84
|
-
// Check base frameworks
|
|
85
|
-
const baseFramework = detectBaseFramework(deps)
|
|
86
|
-
if (baseFramework) return baseFramework
|
|
87
|
-
|
|
88
|
-
// Check Node.js backend
|
|
89
|
-
if (isNodeBackend(pkg, deps, cwd)) return 'node'
|
|
90
|
-
|
|
91
|
-
// Default to vanilla JavaScript
|
|
92
|
-
return 'vanilla'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Detect the environment (browser, node, or universal)
|
|
97
|
-
* @param {string} framework - Detected framework
|
|
98
|
-
* @param {string} cwd - Current working directory
|
|
99
|
-
* @returns {string} Environment type
|
|
100
|
-
*/
|
|
101
|
-
export function detectEnvironment(framework, cwd = process.cwd()) {
|
|
102
|
-
// Framework-specific defaults
|
|
103
|
-
if (framework === 'node') {
|
|
104
|
-
return 'node'
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Frontend frameworks default to browser
|
|
108
|
-
if (['react', 'vue', 'svelte', 'solid', 'angular'].includes(framework)) {
|
|
109
|
-
return 'browser'
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Astro uses islands architecture (both browser and node)
|
|
113
|
-
if (framework === 'astro') {
|
|
114
|
-
return 'universal'
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Check for mixed environment indicators
|
|
118
|
-
const hasServerCode =
|
|
119
|
-
existsSync(join(cwd, 'server')) ||
|
|
120
|
-
existsSync(join(cwd, 'api')) ||
|
|
121
|
-
existsSync(join(cwd, 'backend'))
|
|
122
|
-
|
|
123
|
-
if (hasServerCode) {
|
|
124
|
-
return 'universal'
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Default to browser for frontend projects
|
|
128
|
-
return 'browser'
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Detect if TypeScript is being used
|
|
133
|
-
* @param {string} cwd - Current working directory
|
|
134
|
-
* @returns {boolean} True if TypeScript is detected
|
|
135
|
-
*/
|
|
136
|
-
export function detectTypeScript(cwd = process.cwd()) {
|
|
137
|
-
// Check for tsconfig.json
|
|
138
|
-
if (existsSync(join(cwd, 'tsconfig.json'))) {
|
|
139
|
-
return true
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Check for TypeScript in dependencies or devDependencies
|
|
143
|
-
const pkg = readPackageJson(cwd)
|
|
144
|
-
if (!pkg) return false
|
|
145
|
-
|
|
146
|
-
// TypeScript is typically a devDependency
|
|
147
|
-
return !!(pkg.dependencies?.typescript || pkg.devDependencies?.typescript)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Detect Git provider from repository URL
|
|
152
|
-
* @param {string} cwd - Current working directory
|
|
153
|
-
* @returns {string} Git provider ('gitlab', 'github', 'bitbucket', or null)
|
|
154
|
-
*/
|
|
155
|
-
export function detectGitProvider(cwd = process.cwd()) {
|
|
156
|
-
// Try package.json repository field first
|
|
157
|
-
const pkg = readPackageJson(cwd)
|
|
158
|
-
if (pkg?.repository) {
|
|
159
|
-
const repoUrl = typeof pkg.repository === 'string' ? pkg.repository : pkg.repository.url || ''
|
|
160
|
-
|
|
161
|
-
if (repoUrl.includes('gitlab.com')) return 'gitlab'
|
|
162
|
-
if (repoUrl.includes('github.com')) return 'github'
|
|
163
|
-
if (repoUrl.includes('bitbucket.org')) return 'bitbucket'
|
|
164
|
-
|
|
165
|
-
// If repository field exists but provider not recognized, return null
|
|
166
|
-
// Don't fallback to git remote if package.json explicitly specifies a repo
|
|
167
|
-
return null
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Try git remote as fallback only if no repository field in package.json
|
|
171
|
-
try {
|
|
172
|
-
const remoteUrl = execSync('git remote get-url origin', {
|
|
173
|
-
cwd,
|
|
174
|
-
encoding: 'utf8',
|
|
175
|
-
stdio: ['pipe', 'pipe', 'ignore']
|
|
176
|
-
}).trim()
|
|
177
|
-
|
|
178
|
-
if (remoteUrl.includes('gitlab.com')) return 'gitlab'
|
|
179
|
-
if (remoteUrl.includes('github.com')) return 'github'
|
|
180
|
-
if (remoteUrl.includes('bitbucket.org')) return 'bitbucket'
|
|
181
|
-
} catch {
|
|
182
|
-
// Git command failed or not a git repository
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Default to null (no provider detected)
|
|
186
|
-
return null
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Detect CSS type and variants
|
|
191
|
-
* @param {string} cwd - Current working directory
|
|
192
|
-
* @returns {Object} CSS type detection results
|
|
193
|
-
*/
|
|
194
|
-
export function detectCssType(cwd = process.cwd()) {
|
|
195
|
-
const pkg = readPackageJson(cwd)
|
|
196
|
-
|
|
197
|
-
const results = {
|
|
198
|
-
preprocessor: null, // 'scss', 'sass', 'less', null
|
|
199
|
-
tailwind: false,
|
|
200
|
-
modules: false,
|
|
201
|
-
postcss: false
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Detect SCSS/Sass
|
|
205
|
-
const hasSass =
|
|
206
|
-
pkg?.dependencies?.sass ||
|
|
207
|
-
pkg?.devDependencies?.sass ||
|
|
208
|
-
pkg?.dependencies?.['node-sass'] ||
|
|
209
|
-
pkg?.devDependencies?.['node-sass'] ||
|
|
210
|
-
pkg?.dependencies?.['sass-embedded'] ||
|
|
211
|
-
pkg?.devDependencies?.['sass-embedded']
|
|
212
|
-
|
|
213
|
-
if (hasSass) {
|
|
214
|
-
results.preprocessor = 'scss'
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Detect Less
|
|
218
|
-
const hasLess = pkg?.dependencies?.less || pkg?.devDependencies?.less
|
|
219
|
-
|
|
220
|
-
if (hasLess && !hasSass) {
|
|
221
|
-
// SCSS takes precedence if both exist
|
|
222
|
-
results.preprocessor = 'less'
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Detect Tailwind CSS
|
|
226
|
-
const hasTailwind = pkg?.dependencies?.tailwindcss || pkg?.devDependencies?.tailwindcss
|
|
227
|
-
|
|
228
|
-
if (hasTailwind) {
|
|
229
|
-
// Check for config file
|
|
230
|
-
results.tailwind =
|
|
231
|
-
existsSync(join(cwd, 'tailwind.config.js')) ||
|
|
232
|
-
existsSync(join(cwd, 'tailwind.config.ts')) ||
|
|
233
|
-
existsSync(join(cwd, 'tailwind.config.mjs')) ||
|
|
234
|
-
existsSync(join(cwd, 'tailwind.config.cjs'))
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Detect PostCSS config
|
|
238
|
-
results.postcss =
|
|
239
|
-
existsSync(join(cwd, 'postcss.config.js')) ||
|
|
240
|
-
existsSync(join(cwd, 'postcss.config.cjs')) ||
|
|
241
|
-
existsSync(join(cwd, 'postcss.config.mjs')) ||
|
|
242
|
-
existsSync(join(cwd, '.postcssrc')) ||
|
|
243
|
-
existsSync(join(cwd, '.postcssrc.json'))
|
|
244
|
-
|
|
245
|
-
// Note: CSS Modules detection is tricky without scanning files
|
|
246
|
-
// Framework-based heuristic: React/Next.js projects often use CSS Modules
|
|
247
|
-
// Will be set to true if React/Next.js detected (handled in Stylelint factory)
|
|
248
|
-
|
|
249
|
-
return results
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Detect if project is an Electron application
|
|
254
|
-
* @param {string} cwd - Current working directory
|
|
255
|
-
* @returns {boolean} True if Electron project detected
|
|
256
|
-
*/
|
|
257
|
-
export function detectElectron(cwd = process.cwd()) {
|
|
258
|
-
const pkg = readPackageJson(cwd)
|
|
259
|
-
if (!pkg) return false
|
|
260
|
-
|
|
261
|
-
const deps = getAllDependencies(pkg)
|
|
262
|
-
return !!(deps.electron || deps['@electron-toolkit/utils'] || deps['@electron-toolkit/preload'])
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Auto-detect all configuration options
|
|
267
|
-
* @param {string} cwd - Current working directory
|
|
268
|
-
* @returns {Object} Detected configuration
|
|
269
|
-
*/
|
|
270
|
-
export function autoDetect(cwd = process.cwd()) {
|
|
271
|
-
const framework = detectFramework(cwd)
|
|
272
|
-
const environment = detectEnvironment(framework, cwd)
|
|
273
|
-
const typescript = detectTypeScript(cwd)
|
|
274
|
-
const gitProvider = detectGitProvider(cwd)
|
|
275
|
-
const cssType = detectCssType(cwd)
|
|
276
|
-
const electron = detectElectron(cwd)
|
|
277
|
-
|
|
278
|
-
return {
|
|
279
|
-
framework,
|
|
280
|
-
environment,
|
|
281
|
-
typescript,
|
|
282
|
-
gitProvider,
|
|
283
|
-
cssType,
|
|
284
|
-
electron
|
|
285
|
-
}
|
|
286
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @dimensional-innovations/tool-config
|
|
3
|
-
* Universal configuration package for development tools
|
|
4
|
-
*
|
|
5
|
-
* Supports: ESLint, Prettier, Stylelint, semantic-release, TypeScript
|
|
6
|
-
* Auto-detects: React, Vue, Svelte, Solid, Astro, Angular, Vanilla JS, Node.js
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create a configuration for a specific tool
|
|
11
|
-
*
|
|
12
|
-
* @param {string} tool - Tool name ('eslint' | 'prettier' | 'stylelint' | 'semantic-release' | 'typescript')
|
|
13
|
-
* @param {Object} options - Configuration options
|
|
14
|
-
* @returns {Promise<any>|any} Tool-specific configuration
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* // ESLint configuration
|
|
18
|
-
* import { createConfig } from '@dimensional-innovations/tool-config';
|
|
19
|
-
* export default await createConfig('eslint', {
|
|
20
|
-
* framework: 'auto',
|
|
21
|
-
* environment: 'auto',
|
|
22
|
-
* typescript: 'auto'
|
|
23
|
-
* });
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Prettier configuration
|
|
27
|
-
* import { createConfig } from '@dimensional-innovations/tool-config';
|
|
28
|
-
* export default createConfig('prettier', {
|
|
29
|
-
* framework: 'auto'
|
|
30
|
-
* });
|
|
31
|
-
*/
|
|
32
|
-
export async function createConfig(tool, options = {}) {
|
|
33
|
-
switch (tool) {
|
|
34
|
-
case 'eslint': {
|
|
35
|
-
const { createEslintConfig } = await import('./tools/eslint/index.js')
|
|
36
|
-
return createEslintConfig(options)
|
|
37
|
-
}
|
|
38
|
-
case 'prettier': {
|
|
39
|
-
const { createPrettierConfig } = await import('./tools/prettier/index.js')
|
|
40
|
-
return createPrettierConfig(options)
|
|
41
|
-
}
|
|
42
|
-
case 'stylelint': {
|
|
43
|
-
const { createStylelintConfig } = await import('./tools/stylelint/index.js')
|
|
44
|
-
return createStylelintConfig(options)
|
|
45
|
-
}
|
|
46
|
-
case 'semantic-release': {
|
|
47
|
-
const { createReleaseConfig } = await import('./tools/semantic-release/index.js')
|
|
48
|
-
return createReleaseConfig(options)
|
|
49
|
-
}
|
|
50
|
-
case 'typescript': {
|
|
51
|
-
const { createTypescriptConfig } = await import('./tools/typescript/index.js')
|
|
52
|
-
return createTypescriptConfig(options)
|
|
53
|
-
}
|
|
54
|
-
default:
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Unknown tool: "${tool}". Supported tools: eslint, prettier, stylelint, semantic-release, typescript`
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Named exports for convenience
|
|
62
|
-
export { createEslintConfig } from './tools/eslint/index.js'
|
|
63
|
-
export { createPrettierConfig } from './tools/prettier/index.js'
|
|
64
|
-
export { createStylelintConfig } from './tools/stylelint/index.js'
|
|
65
|
-
export { createReleaseConfig } from './tools/semantic-release/index.js'
|
|
66
|
-
export { createTypescriptConfig } from './tools/typescript/index.js'
|
|
67
|
-
|
|
68
|
-
// Re-export detection utilities for advanced users
|
|
69
|
-
export { autoDetect, detectFramework, detectEnvironment, detectTypeScript } from './detectors.js'
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js'
|
|
2
|
-
import tseslint from 'typescript-eslint'
|
|
3
|
-
|
|
4
|
-
import { autoDetect } from '../../detectors.js'
|
|
5
|
-
import { getEslintIgnores } from '../../utils/ignore-patterns.js'
|
|
6
|
-
|
|
7
|
-
import basePreset from './presets/base.js'
|
|
8
|
-
import browserEnv from './presets/environments/browser.js'
|
|
9
|
-
import nodeEnv from './presets/environments/node.js'
|
|
10
|
-
import universalEnv from './presets/environments/universal.js'
|
|
11
|
-
import createAngularPreset from './presets/frameworks/angular.js'
|
|
12
|
-
import createNodePreset from './presets/frameworks/node.js'
|
|
13
|
-
import createReactPreset from './presets/frameworks/react.js'
|
|
14
|
-
import createVanillaPreset from './presets/frameworks/vanilla.js'
|
|
15
|
-
import createVuePreset from './presets/frameworks/vue.js'
|
|
16
|
-
import importsPreset from './presets/imports.js'
|
|
17
|
-
import typescriptPreset from './presets/typescript.js'
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* File patterns for all supported source file types
|
|
21
|
-
*/
|
|
22
|
-
const SOURCE_FILES = [
|
|
23
|
-
'**/*.js',
|
|
24
|
-
'**/*.ts',
|
|
25
|
-
'**/*.tsx',
|
|
26
|
-
'**/*.vue',
|
|
27
|
-
'**/*.jsx',
|
|
28
|
-
'**/*.svelte',
|
|
29
|
-
'**/*.astro'
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Add framework-specific configuration to config array
|
|
34
|
-
* Supports lazy loading for Svelte, Solid, and Astro to avoid requiring optional peer dependencies
|
|
35
|
-
*
|
|
36
|
-
* @param {Array} config - ESLint flat config array to append framework presets to
|
|
37
|
-
* @param {string} framework - Framework name ('react' | 'vue' | 'svelte' | 'solid' | 'astro' | 'angular' | 'vanilla' | 'node')
|
|
38
|
-
* @returns {Promise<void>}
|
|
39
|
-
*/
|
|
40
|
-
async function addFrameworkConfig(config, framework) {
|
|
41
|
-
switch (framework) {
|
|
42
|
-
case 'react':
|
|
43
|
-
config.push(...createReactPreset())
|
|
44
|
-
break
|
|
45
|
-
case 'vue':
|
|
46
|
-
config.push(...createVuePreset())
|
|
47
|
-
break
|
|
48
|
-
case 'svelte': {
|
|
49
|
-
const { default: createSveltePreset } = await import('./presets/frameworks/svelte.js')
|
|
50
|
-
config.push(...createSveltePreset())
|
|
51
|
-
break
|
|
52
|
-
}
|
|
53
|
-
case 'solid': {
|
|
54
|
-
const { default: createSolidPreset } = await import('./presets/frameworks/solid.js')
|
|
55
|
-
config.push(...createSolidPreset())
|
|
56
|
-
break
|
|
57
|
-
}
|
|
58
|
-
case 'astro': {
|
|
59
|
-
const { default: createAstroPreset } = await import('./presets/frameworks/astro.js')
|
|
60
|
-
config.push(...createAstroPreset())
|
|
61
|
-
break
|
|
62
|
-
}
|
|
63
|
-
case 'vanilla':
|
|
64
|
-
config.push(...createVanillaPreset())
|
|
65
|
-
break
|
|
66
|
-
case 'node':
|
|
67
|
-
config.push(...createNodePreset())
|
|
68
|
-
break
|
|
69
|
-
case 'angular':
|
|
70
|
-
config.push(...createAngularPreset())
|
|
71
|
-
break
|
|
72
|
-
default:
|
|
73
|
-
console.warn(`ā ļø Unknown framework "${framework}", defaulting to vanilla JavaScript`)
|
|
74
|
-
config.push(...createVanillaPreset())
|
|
75
|
-
break
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Get environment configuration based on detected or specified environment
|
|
81
|
-
* Returns globals and languageOptions for browser, node, or universal environments
|
|
82
|
-
*
|
|
83
|
-
* @param {string} environment - Environment type ('browser' | 'node' | 'universal')
|
|
84
|
-
* @returns {Object} Environment configuration object with languageOptions
|
|
85
|
-
*/
|
|
86
|
-
function getEnvironmentConfig(environment) {
|
|
87
|
-
switch (environment) {
|
|
88
|
-
case 'node':
|
|
89
|
-
return nodeEnv
|
|
90
|
-
case 'universal':
|
|
91
|
-
return universalEnv
|
|
92
|
-
case 'browser':
|
|
93
|
-
default:
|
|
94
|
-
return browserEnv
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Add TypeScript configuration to config array
|
|
100
|
-
* Includes recommended TypeScript rules with relaxed settings for .d.ts and .js files
|
|
101
|
-
*
|
|
102
|
-
* @param {Array} config - ESLint flat config array to append TypeScript presets to
|
|
103
|
-
* @returns {void}
|
|
104
|
-
*/
|
|
105
|
-
function addTypeScriptConfig(config) {
|
|
106
|
-
config.push(...tseslint.configs.recommended)
|
|
107
|
-
config.push({
|
|
108
|
-
files: SOURCE_FILES,
|
|
109
|
-
...typescriptPreset
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
config.push({
|
|
113
|
-
files: ['**/*.d.ts'],
|
|
114
|
-
rules: {
|
|
115
|
-
'@typescript-eslint/no-explicit-any': 'off'
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
config.push({
|
|
120
|
-
files: ['**/*.js'],
|
|
121
|
-
rules: {
|
|
122
|
-
'@typescript-eslint/no-var-requires': 'off'
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Add test and script overrides to config array
|
|
129
|
-
* Relaxes rules for test files and CLI scripts, and applies user-provided rule overrides
|
|
130
|
-
*
|
|
131
|
-
* @param {Array} config - ESLint flat config array to append overrides to
|
|
132
|
-
* @param {Object} options - Configuration options containing user rule overrides
|
|
133
|
-
* @param {Object} [options.rules] - User-provided rule overrides
|
|
134
|
-
* @returns {void}
|
|
135
|
-
*/
|
|
136
|
-
function addOverrides(config, options) {
|
|
137
|
-
// Test files override
|
|
138
|
-
config.push({
|
|
139
|
-
files: ['tests/**/*.{js,ts,jsx,tsx,vue,svelte,astro}'],
|
|
140
|
-
rules: {
|
|
141
|
-
'no-console': 'off',
|
|
142
|
-
'max-lines-per-function': 'off',
|
|
143
|
-
complexity: 'off',
|
|
144
|
-
'max-statements': 'off',
|
|
145
|
-
'max-nested-callbacks': 'off',
|
|
146
|
-
'no-magic-numbers': 'off',
|
|
147
|
-
'@typescript-eslint/no-explicit-any': 'off'
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
// Node.js scripts override
|
|
152
|
-
config.push({
|
|
153
|
-
files: ['**/bin/**/*.js', '**/scripts/**/*.js'],
|
|
154
|
-
languageOptions: {
|
|
155
|
-
globals: {
|
|
156
|
-
...nodeEnv.languageOptions.globals
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
rules: {
|
|
160
|
-
'no-console': 'off',
|
|
161
|
-
'max-lines-per-function': 'off'
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
// User-provided rule overrides
|
|
166
|
-
if (options.rules && Object.keys(options.rules).length > 0) {
|
|
167
|
-
config.push({
|
|
168
|
-
files: SOURCE_FILES,
|
|
169
|
-
rules: options.rules
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Create an ESLint flat config
|
|
176
|
-
*
|
|
177
|
-
* Supports: React, Vue.js, Svelte, Solid, Astro, Angular, Vanilla JS/TS, and auto-detection
|
|
178
|
-
*
|
|
179
|
-
* @param {Object} options - Configuration options
|
|
180
|
-
* @param {string} [options.framework='auto'] - Framework: 'auto' | 'react' | 'vue' | 'svelte' | 'solid' | 'astro' | 'angular' | 'vanilla' | 'node'
|
|
181
|
-
* @param {string} [options.environment='auto'] - Environment: 'auto' | 'browser' | 'node' | 'universal'
|
|
182
|
-
* @param {boolean|string} [options.typescript='auto'] - TypeScript: 'auto' | true | false
|
|
183
|
-
* @param {string[]} [options.ignorePaths=[]] - Additional paths to ignore during linting
|
|
184
|
-
* @param {Object} [options.rules={}] - Additional rule overrides
|
|
185
|
-
* @param {string} [options.cwd] - Current working directory for detection
|
|
186
|
-
* @returns {Promise<Array>} ESLint flat config array
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* // Zero config - auto-detects everything
|
|
190
|
-
* import { createEslintConfig } from '@dimensional-innovations/tool-config';
|
|
191
|
-
* export default await createEslintConfig();
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* // Explicit configuration
|
|
195
|
-
* import { createEslintConfig } from '@dimensional-innovations/tool-config';
|
|
196
|
-
* export default await createEslintConfig({
|
|
197
|
-
* framework: 'react',
|
|
198
|
-
* environment: 'browser',
|
|
199
|
-
* typescript: true
|
|
200
|
-
* });
|
|
201
|
-
*
|
|
202
|
-
* @example
|
|
203
|
-
* // With custom rules
|
|
204
|
-
* import { createEslintConfig } from '@dimensional-innovations/tool-config';
|
|
205
|
-
* export default await createEslintConfig({
|
|
206
|
-
* rules: {
|
|
207
|
-
* 'no-console': 'off'
|
|
208
|
-
* }
|
|
209
|
-
* });
|
|
210
|
-
*/
|
|
211
|
-
export async function createEslintConfig(options = {}) {
|
|
212
|
-
const cwd = options.cwd || process.cwd()
|
|
213
|
-
const detected = autoDetect(cwd)
|
|
214
|
-
|
|
215
|
-
const framework =
|
|
216
|
-
options.framework === 'auto' || !options.framework ? detected.framework : options.framework
|
|
217
|
-
const environment =
|
|
218
|
-
options.environment === 'auto' || !options.environment
|
|
219
|
-
? detected.environment
|
|
220
|
-
: options.environment
|
|
221
|
-
const typescript =
|
|
222
|
-
options.typescript === 'auto' || options.typescript === undefined
|
|
223
|
-
? detected.typescript
|
|
224
|
-
: options.typescript
|
|
225
|
-
|
|
226
|
-
console.log(
|
|
227
|
-
`š¦ ESLint Config: ${framework} | ${environment} | TypeScript: ${typescript ? 'Yes' : 'No'}`
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
if (framework === 'angular') {
|
|
231
|
-
console.warn(
|
|
232
|
-
'\nā ļø Angular detected. This package provides basic TypeScript linting.\n' +
|
|
233
|
-
' For Angular-specific rules, install: @angular-eslint/eslint-plugin\n' +
|
|
234
|
-
' See: https://github.com/angular-eslint/angular-eslint\n'
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const defaultIgnorePaths = getEslintIgnores()
|
|
239
|
-
const allIgnorePaths = [...defaultIgnorePaths, ...(options.ignorePaths || [])]
|
|
240
|
-
|
|
241
|
-
const config = []
|
|
242
|
-
|
|
243
|
-
// 1. Ignore paths
|
|
244
|
-
config.push({ ignores: allIgnorePaths })
|
|
245
|
-
|
|
246
|
-
// 2. ESLint recommended rules
|
|
247
|
-
config.push(js.configs.recommended)
|
|
248
|
-
|
|
249
|
-
// 3. TypeScript configuration
|
|
250
|
-
if (typescript) {
|
|
251
|
-
addTypeScriptConfig(config)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// 4. Environment configuration
|
|
255
|
-
const envConfig = getEnvironmentConfig(environment)
|
|
256
|
-
config.push({
|
|
257
|
-
files: SOURCE_FILES,
|
|
258
|
-
...envConfig
|
|
259
|
-
})
|
|
260
|
-
|
|
261
|
-
// 5. Base JavaScript rules
|
|
262
|
-
config.push({
|
|
263
|
-
files: SOURCE_FILES,
|
|
264
|
-
...basePreset
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
// 6. Import/export rules
|
|
268
|
-
config.push({
|
|
269
|
-
files: SOURCE_FILES,
|
|
270
|
-
...importsPreset
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
// 7. Framework-specific configuration
|
|
274
|
-
await addFrameworkConfig(config, framework)
|
|
275
|
-
|
|
276
|
-
// 8. Test files and script overrides
|
|
277
|
-
addOverrides(config, options)
|
|
278
|
-
|
|
279
|
-
return config
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export default createEslintConfig
|