Skip to content

Commit 34aa552

Browse files
committed
refactor(scripts): organize validation scripts into subdirectory
Move all validate-* scripts to scripts/validation/ and remove the validate- prefix for cleaner organization. Changes: - Created scripts/validation/ directory - Moved and renamed 7 validation scripts: - validate-bundle-deps.mjs → validation/bundle-deps.mjs - validate-esbuild-minify.mjs → validation/esbuild-minify.mjs - validate-file-count.mjs → validation/file-count.mjs - validate-file-size.mjs → validation/file-size.mjs - validate-markdown-filenames.mjs → validation/markdown-filenames.mjs - validate-no-cdn-refs.mjs → validation/no-cdn-refs.mjs - validate-no-link-deps.mjs → validation/no-link-deps.mjs - Updated scripts/check.mjs to reference new paths - Updated rootPath in all validation scripts (../..) - Updated self-reference in no-cdn-refs.mjs
1 parent 07c23b7 commit 34aa552

File tree

12 files changed

+148
-566
lines changed

12 files changed

+148
-566
lines changed

scripts/bump.mjs

Lines changed: 77 additions & 415 deletions
Large diffs are not rendered by default.

scripts/check.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ async function main() {
4040
command: 'pnpm',
4141
},
4242
{
43-
args: ['scripts/validate-no-link-deps.mjs'],
43+
args: ['scripts/validation/no-link-deps.mjs'],
4444
command: 'node',
4545
},
4646
{
47-
args: ['scripts/validate-bundle-deps.mjs'],
47+
args: ['scripts/validation/bundle-deps.mjs'],
4848
command: 'node',
4949
},
5050
{
51-
args: ['scripts/validate-esbuild-minify.mjs'],
51+
args: ['scripts/validation/esbuild-minify.mjs'],
5252
command: 'node',
5353
},
5454
{
55-
args: ['scripts/validate-no-cdn-refs.mjs'],
55+
args: ['scripts/validation/no-cdn-refs.mjs'],
5656
command: 'node',
5757
},
5858
{
59-
args: ['scripts/validate-markdown-filenames.mjs'],
59+
args: ['scripts/validation/markdown-filenames.mjs'],
6060
command: 'node',
6161
},
6262
{
63-
args: ['scripts/validate-file-size.mjs'],
63+
args: ['scripts/validation/file-size.mjs'],
6464
command: 'node',
6565
},
6666
{
67-
args: ['scripts/validate-file-count.mjs'],
67+
args: ['scripts/validation/file-count.mjs'],
6868
command: 'node',
6969
},
7070
]

scripts/generate-sdk.mjs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,55 @@
1010
* node scripts/generate-sdk.mjs
1111
*/
1212

13-
import { spawn } from 'node:child_process'
1413
import { readFileSync, writeFileSync } from 'node:fs'
1514
import { resolve } from 'node:path'
1615

1716
import * as parser from '@babel/parser'
1817
import traverse from '@babel/traverse'
1918
import * as t from '@babel/types'
2019
import MagicString from 'magic-string'
20+
import openapiTS from 'openapi-typescript'
2121

2222
import { getDefaultLogger } from '@socketsecurity/lib/logger'
2323

2424
import { getRootPath } from './utils/path-helpers.mjs'
2525
import { runCommand } from './utils/run-command.mjs'
2626

2727
const rootPath = getRootPath(import.meta.url)
28+
const openApiJsonPath = resolve(rootPath, 'openapi.json')
2829
const typesPath = resolve(rootPath, 'types/api.d.ts')
2930

3031
// Initialize logger
3132
const logger = getDefaultLogger()
3233

33-
async function generateTypes() {
34-
return new Promise((resolve, reject) => {
35-
const child = spawn('node', ['scripts/generate-types.mjs'], {
36-
cwd: rootPath,
37-
stdio: ['inherit', 'pipe', 'inherit'],
38-
})
39-
40-
let output = ''
41-
42-
child.stdout.on('data', data => {
43-
output += data.toString()
44-
})
45-
46-
child.on('exit', code => {
47-
if (code !== 0) {
48-
reject(new Error(`Type generation failed with exit code ${code}`))
49-
return
50-
}
34+
/**
35+
* Prettifies the OpenAPI JSON file.
36+
*/
37+
async function prettifyOpenApiJson() {
38+
const openApiData = readFileSync(openApiJsonPath, 'utf8')
39+
writeFileSync(
40+
openApiJsonPath,
41+
JSON.stringify(JSON.parse(openApiData), null, 2),
42+
)
43+
}
5144

52-
try {
53-
writeFileSync(typesPath, output, 'utf8')
54-
// Fix array syntax after writing to disk
55-
fixArraySyntax(typesPath)
56-
// Add SDK v3 method name aliases
57-
addSdkMethodAliases(typesPath)
58-
resolve()
59-
} catch (error) {
60-
reject(error)
45+
/**
46+
* Generates TypeScript types from OpenAPI schema.
47+
*/
48+
async function generateTypes() {
49+
const output = await openapiTS(openApiJsonPath, {
50+
transform(schemaObject) {
51+
if ('format' in schemaObject && schemaObject.format === 'binary') {
52+
return 'never'
6153
}
62-
})
63-
64-
child.on('error', reject)
54+
},
6555
})
56+
57+
writeFileSync(typesPath, output, 'utf8')
58+
// Fix array syntax after writing to disk
59+
fixArraySyntax(typesPath)
60+
// Add SDK v3 method name aliases
61+
addSdkMethodAliases(typesPath)
6662
}
6763

6864
/**
@@ -213,19 +209,15 @@ async function main() {
213209

214210
// Step 1: Prettify OpenAPI JSON
215211
logger.log(' 1. Prettifying OpenAPI JSON...')
216-
let exitCode = await runCommand('node', ['scripts/prettify-base-json.mjs'])
217-
if (exitCode !== 0) {
218-
process.exitCode = exitCode
219-
return
220-
}
212+
await prettifyOpenApiJson()
221213

222214
// Step 2: Generate types
223215
logger.log(' 2. Generating TypeScript types...')
224216
await generateTypes()
225217

226218
// Step 3: Format generated files
227219
logger.log(' 3. Formatting generated files...')
228-
exitCode = await runCommand('pnpm', [
220+
let exitCode = await runCommand('pnpm', [
229221
'exec',
230222
'biome',
231223
'format',

scripts/generate-types.mjs

Lines changed: 0 additions & 37 deletions
This file was deleted.

scripts/prettify-base-json.mjs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
1919
const logger = getDefaultLogger()
2020

2121
const __dirname = path.dirname(fileURLToPath(import.meta.url))
22-
const rootPath = path.join(__dirname, '..')
22+
const rootPath = path.join(__dirname, '..', '..')
2323

2424
// Node.js builtins to ignore (including node: prefix variants)
2525
const BUILTIN_MODULES = new Set([
@@ -371,12 +371,12 @@ async function main() {
371371
}
372372

373373
if (violations.length > 0) {
374-
logger.error('❌ Bundle dependencies validation failed\n')
374+
logger.fail('Bundle dependencies validation failed\n')
375375

376376
for (const violation of violations) {
377-
logger.error(` ${violation.message}`)
378-
logger.error(` ${violation.fix}`)
379-
logger.error('')
377+
logger.log(` ${violation.message}`)
378+
logger.log(` ${violation.fix}`)
379+
logger.log('')
380380
}
381381
}
382382

@@ -392,7 +392,7 @@ async function main() {
392392
// Only fail on violations, not warnings
393393
process.exitCode = violations.length > 0 ? 1 : 0
394394
} catch (error) {
395-
logger.error('Validation failed:', error.message)
395+
logger.fail('Validation failed:', error.message)
396396
process.exitCode = 1
397397
}
398398
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
1212
const logger = getDefaultLogger()
1313

1414
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15-
const rootPath = path.join(__dirname, '..')
15+
const rootPath = path.join(__dirname, '..', '..')
1616

1717
/**
1818
* Validate esbuild configuration has minify: false.
@@ -52,7 +52,7 @@ async function validateEsbuildMinify() {
5252

5353
return violations
5454
} catch (error) {
55-
logger.error(`Failed to load esbuild config: ${error.message}`)
55+
logger.fail(`Failed to load esbuild config: ${error.message}`)
5656
process.exitCode = 1
5757
return []
5858
}
@@ -67,25 +67,23 @@ async function main() {
6767
return
6868
}
6969

70-
logger.error('❌ esbuild minify validation failed\n')
70+
logger.fail('esbuild minify validation failed\n')
7171

7272
for (const violation of violations) {
73-
logger.error(` ${violation.message}`)
74-
logger.error(` Found: minify: ${violation.value}`)
75-
logger.error(' Expected: minify: false')
76-
logger.error(` Location: ${violation.location}`)
77-
logger.error('')
73+
logger.log(` ${violation.message}`)
74+
logger.log(` Found: minify: ${violation.value}`)
75+
logger.log(' Expected: minify: false')
76+
logger.log(` Location: ${violation.location}`)
77+
logger.log('')
7878
}
7979

80-
logger.error(
81-
'Minification breaks ESM/CJS interop and makes debugging harder.',
82-
)
83-
logger.error('')
80+
logger.log('Minification breaks ESM/CJS interop and makes debugging harder.')
81+
logger.log('')
8482

8583
process.exitCode = 1
8684
}
8785

8886
main().catch(error => {
89-
logger.error('Validation failed:', error)
87+
logger.fail('Validation failed:', error)
9088
process.exitCode = 1
9189
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const logger = getDefaultLogger()
1919
const execAsync = promisify(exec)
2020

2121
const __dirname = path.dirname(fileURLToPath(import.meta.url))
22-
const rootPath = path.join(__dirname, '..')
22+
const rootPath = path.join(__dirname, '..', '..')
2323

2424
// Maximum number of files in a single commit
2525
const MAX_FILES_PER_COMMIT = 50
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
1717
const logger = getDefaultLogger()
1818

1919
const __dirname = path.dirname(fileURLToPath(import.meta.url))
20-
const rootPath = path.join(__dirname, '..')
20+
const rootPath = path.join(__dirname, '..', '..')
2121

2222
// Maximum file size: 2MB (2,097,152 bytes)
2323
const MAX_FILE_SIZE = 2 * 1024 * 1024
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { getDefaultLogger } from '@socketsecurity/lib/logger'
2626
const logger = getDefaultLogger()
2727

2828
const __dirname = path.dirname(fileURLToPath(import.meta.url))
29-
const rootPath = path.join(__dirname, '..')
29+
const rootPath = path.join(__dirname, '..', '..')
3030

3131
// Allowed SCREAMING_CASE markdown files (without .md extension for comparison)
3232
const ALLOWED_SCREAMING_CASE = new Set([

0 commit comments

Comments
 (0)