-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean-types.mjs
More file actions
27 lines (24 loc) · 1023 Bytes
/
clean-types.mjs
File metadata and controls
27 lines (24 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env node
import { readFileSync, writeFileSync } from 'fs';
let code = readFileSync('Code.gs', 'utf-8');
// Remove all the problematic TypeScript constructs
code = code
// Remove type/interface declarations (multi-line)
.replace(/^type\s+\w+\s*=[\s\S]*?;/gm, '')
.replace(/^interface\s+\w+\s*{[\s\S]*?^}/gm, '')
// Remove optional parameter markers FIRST
.replace(/\?\s*:/g, ':')
.replace(/\?(\s*[,)])/g, '$1')
// Remove all ': Type' annotations including union types (function params, variables, return types)
.replace(/:\s*[\w\s|<>\[\].?]+\s*([,)=;{])/g, '$1')
.replace(/:\s*\w+(\[\])?\s*$/gm, '')
.replace(/:\s*{\s*[^}]+}\s*([),])/g, '$1')
.replace(/:\ GoogleAppsScript[^\s]*/g, '')
// Remove 'as Type' assertions
.replace(/\s+as\s+\w+/g, '')
// Remove export statements
.replace(/^export\s*{[^}]*};?\s*$/gm, '')
// Clean up extra blank lines
.replace(/\n\n\n+/g, '\n\n');
writeFileSync('Code.gs', code, 'utf-8');
console.log('✅ Cleaned TypeScript syntax from Code.gs');