@archpublicwebsite/eslint-config 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archpublicwebsite/eslint-config",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "author": "Archipelago International",
5
5
  "description": "Reusable ESLint flat config and git-hook toolkit for Archipelago projects",
6
6
  "type": "module",
@@ -3,6 +3,12 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'n
3
3
  import { join } from 'node:path'
4
4
  import { ensureVscodeSettings } from './vscode.mjs'
5
5
 
6
+ const TAG = '[@archpublicwebsite/eslint-config]'
7
+
8
+ function log(msg) {
9
+ console.log(`${TAG} ${msg}`)
10
+ }
11
+
6
12
  function getProjectRoot() {
7
13
  const root = process.env.INIT_CWD || process.cwd()
8
14
  if (!existsSync(join(root, 'package.json')))
@@ -10,18 +16,67 @@ function getProjectRoot() {
10
16
  return root
11
17
  }
12
18
 
13
- function ensureDir(path) {
14
- if (!existsSync(path))
15
- mkdirSync(path, { recursive: true })
19
+ function ensureDir(dirPath) {
20
+ if (!existsSync(dirPath))
21
+ mkdirSync(dirPath, { recursive: true })
16
22
  }
17
23
 
18
- function writeIfMissing(path, content) {
19
- if (existsSync(path))
24
+ function writeIfMissing(filePath, content) {
25
+ if (existsSync(filePath))
20
26
  return false
21
- writeFileSync(path, content, 'utf8')
27
+ writeFileSync(filePath, content, 'utf8')
22
28
  return true
23
29
  }
24
30
 
31
+ // ─── .editorconfig ──────────────────────────────────────────────────────────
32
+
33
+ function ensureEditorConfig(projectRoot) {
34
+ const editorConfigPath = join(projectRoot, '.editorconfig')
35
+ const content = `# EditorConfig — consistent coding style across editors
36
+ # https://editorconfig.org
37
+
38
+ root = true
39
+
40
+ [*]
41
+ charset = utf-8
42
+ end_of_line = lf
43
+ indent_style = space
44
+ indent_size = 2
45
+ insert_final_newline = true
46
+ trim_trailing_whitespace = true
47
+
48
+ [*.md]
49
+ trim_trailing_whitespace = false
50
+
51
+ [*.{yml,yaml}]
52
+ indent_size = 2
53
+
54
+ [Makefile]
55
+ indent_style = tab
56
+ `
57
+ if (writeIfMissing(editorConfigPath, content))
58
+ log('Created .editorconfig')
59
+ }
60
+
61
+ // ─── eslint.config.mjs ─────────────────────────────────────────────────────
62
+
63
+ function ensureEslintConfig(projectRoot) {
64
+ const eslintConfigPath = join(projectRoot, 'eslint.config.mjs')
65
+ const content = `import { createArchipelagoConfig } from '@archpublicwebsite/eslint-config'
66
+
67
+ export default createArchipelagoConfig({
68
+ name: 'project/overrides',
69
+ rules: {
70
+ // Add your project overrides here
71
+ },
72
+ })
73
+ `
74
+ if (writeIfMissing(eslintConfigPath, content))
75
+ log('Created eslint.config.mjs')
76
+ }
77
+
78
+ // ─── .prettierrc ────────────────────────────────────────────────────────────
79
+
25
80
  function ensurePrettierConfig(projectRoot) {
26
81
  const prettierPath = join(projectRoot, '.prettierrc')
27
82
  const defaults = {
@@ -36,6 +91,7 @@ function ensurePrettierConfig(projectRoot) {
36
91
 
37
92
  if (!existsSync(prettierPath)) {
38
93
  writeFileSync(prettierPath, `${JSON.stringify(defaults, null, 2)}\n`, 'utf8')
94
+ log('Created .prettierrc')
39
95
  return
40
96
  }
41
97
 
@@ -49,17 +105,14 @@ function ensurePrettierConfig(projectRoot) {
49
105
  if (typeof current.semi !== 'boolean')
50
106
  current.semi = false
51
107
  writeFileSync(prettierPath, `${JSON.stringify(current, null, 2)}\n`, 'utf8')
108
+ log('Updated .prettierrc')
52
109
  }
53
110
  catch {
54
111
  // Keep existing file untouched if it is not JSON.
55
112
  }
56
113
  }
57
114
 
58
- function ensureEslintConfig(projectRoot) {
59
- const eslintConfigPath = join(projectRoot, 'eslint.config.mjs')
60
- const content = `import { createArchipelagoConfig } from 'eslint-config'\n\nexport default createArchipelagoConfig({\n name: 'project/overrides',\n rules: {\n // Add your project overrides here\n },\n})\n`
61
- writeIfMissing(eslintConfigPath, content)
62
- }
115
+ // ─── .hooks ─────────────────────────────────────────────────────────────────
63
116
 
64
117
  function ensureHooks(projectRoot) {
65
118
  const hooksDir = join(projectRoot, '.hooks')
@@ -70,33 +123,38 @@ function ensureHooks(projectRoot) {
70
123
  set -euo pipefail
71
124
 
72
125
  cd "$(git rev-parse --show-toplevel)"
73
- node node_modules/eslint-config/tools/git-hooks/pre-commit.mjs
126
+ node node_modules/@archpublicwebsite/eslint-config/tools/git-hooks/pre-commit.mjs
74
127
  `,
75
128
  'prepare-commit-msg': `#!/usr/bin/env bash
76
129
  set -euo pipefail
77
130
 
78
131
  cd "$(git rev-parse --show-toplevel)"
79
- node node_modules/eslint-config/tools/git-hooks/prepare-commit-msg.mjs "$@"
132
+ node node_modules/@archpublicwebsite/eslint-config/tools/git-hooks/prepare-commit-msg.mjs "$@"
80
133
  `,
81
134
  'commit-msg': `#!/usr/bin/env bash
82
135
  set -euo pipefail
83
136
 
84
137
  cd "$(git rev-parse --show-toplevel)"
85
- node node_modules/eslint-config/tools/git-hooks/commit-msg.mjs "$1"
138
+ node node_modules/@archpublicwebsite/eslint-config/tools/git-hooks/commit-msg.mjs "$1"
86
139
  `,
87
140
  'post-commit': `#!/usr/bin/env bash
88
141
  set -euo pipefail
89
142
 
90
143
  cd "$(git rev-parse --show-toplevel)"
91
- node node_modules/eslint-config/tools/git-hooks/post-commit.mjs
144
+ node node_modules/@archpublicwebsite/eslint-config/tools/git-hooks/post-commit.mjs
92
145
  `,
93
146
  }
94
147
 
148
+ let created = false
95
149
  Object.entries(hooks).forEach(([name, content]) => {
96
- const path = join(hooksDir, name)
97
- if (writeIfMissing(path, content))
98
- chmodSync(path, 0o755)
150
+ const hookPath = join(hooksDir, name)
151
+ if (writeIfMissing(hookPath, content)) {
152
+ chmodSync(hookPath, 0o755)
153
+ created = true
154
+ }
99
155
  })
156
+ if (created)
157
+ log('Created .hooks/ (pre-commit, prepare-commit-msg, commit-msg, post-commit)')
100
158
  }
101
159
 
102
160
  function ensureHooksPath(projectRoot) {
@@ -104,18 +162,20 @@ function ensureHooksPath(projectRoot) {
104
162
  return
105
163
  try {
106
164
  execSync('git config core.hooksPath .hooks', { cwd: projectRoot, stdio: 'ignore' })
165
+ log('Set git core.hooksPath → .hooks')
107
166
  }
108
167
  catch {
109
168
  // Ignore setup failures in non-git contexts.
110
169
  }
111
170
  }
112
171
 
172
+ // ─── .vscode/extensions.json ────────────────────────────────────────────────
173
+
113
174
  function ensureVscodeExtensions(projectRoot) {
114
175
  const vscodeDir = join(projectRoot, '.vscode')
115
176
  const extPath = join(vscodeDir, 'extensions.json')
116
177
 
117
- if (!existsSync(vscodeDir))
118
- mkdirSync(vscodeDir, { recursive: true })
178
+ ensureDir(vscodeDir)
119
179
 
120
180
  const recommended = [
121
181
  'dbaeumer.vscode-eslint',
@@ -138,19 +198,27 @@ function ensureVscodeExtensions(projectRoot) {
138
198
  const merged = [...new Set([...current.recommendations, ...recommended])]
139
199
  current.recommendations = merged
140
200
  writeFileSync(extPath, `${JSON.stringify(current, null, 2)}\n`, 'utf8')
201
+ log('Created/updated .vscode/extensions.json')
141
202
  }
142
203
 
204
+ // ─── main ───────────────────────────────────────────────────────────────────
205
+
143
206
  function main() {
144
207
  const projectRoot = getProjectRoot()
145
208
  if (!projectRoot)
146
209
  return
147
210
 
148
- ensureHooks(projectRoot)
149
- ensureHooksPath(projectRoot)
211
+ log('Setting up project...')
212
+
213
+ ensureEditorConfig(projectRoot)
150
214
  ensureEslintConfig(projectRoot)
151
215
  ensurePrettierConfig(projectRoot)
216
+ ensureHooks(projectRoot)
217
+ ensureHooksPath(projectRoot)
152
218
  ensureVscodeSettings(projectRoot)
153
219
  ensureVscodeExtensions(projectRoot)
220
+
221
+ log('Setup complete ✓')
154
222
  }
155
223
 
156
224
  main()
@@ -1,6 +1,8 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
3
 
4
+ const TAG = '[@archpublicwebsite/eslint-config]'
5
+
4
6
  /**
5
7
  * VS Code settings required for ESLint flat config to work properly.
6
8
  * These tell the ESLint extension to use flat config mode and validate
@@ -116,4 +118,5 @@ export function ensureVscodeSettings(projectRoot) {
116
118
 
117
119
  const merged = deepMerge(current, VSCODE_ESLINT_SETTINGS)
118
120
  writeFileSync(settingsPath, `${JSON.stringify(merged, null, 2)}\n`, 'utf8')
121
+ console.log(`${TAG} Created/updated .vscode/settings.json`)
119
122
  }