forked from lightningpixel/modly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-builtins.mjs
More file actions
62 lines (52 loc) · 2.29 KB
/
Copy pathbuild-builtins.mjs
File metadata and controls
62 lines (52 loc) · 2.29 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Compile built-in extensions (TypeScript → CommonJS JS) and copy manifests.
* Output: out/builtin-extensions/{id}/processor.js + manifest.json
*/
import { execSync } from 'child_process'
import { readdirSync, existsSync, cpSync, mkdirSync, statSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const srcDir = join(root, 'src', 'areas', 'workflows', 'nodes')
const outDir = join(root, 'out', 'builtin-extensions')
if (!existsSync(srcDir)) {
console.log('[build-builtins] No builtin-extensions directory found, skipping.')
process.exit(0)
}
// 1. Compile TypeScript
console.log('[build-builtins] Compiling TypeScript…')
execSync('npx tsc -p tsconfig.builtins.json', { cwd: root, stdio: 'inherit' })
// 2. Copy manifest.json, and optionally package.json + npm install
for (const id of readdirSync(srcDir)) {
const extSrcDir = join(srcDir, id)
if (!statSync(extSrcDir).isDirectory()) continue
// Only process extension folders (those with a manifest.json)
if (!existsSync(join(extSrcDir, 'manifest.json'))) continue
const extOutDir = join(outDir, id)
mkdirSync(extOutDir, { recursive: true })
const manifestSrc = join(extSrcDir, 'manifest.json')
if (existsSync(manifestSrc)) {
cpSync(manifestSrc, join(extOutDir, 'manifest.json'))
console.log(`[build-builtins] ${id}: manifest.json copied`)
} else {
console.warn(`[build-builtins] ${id}: manifest.json missing — skipping`)
}
const pkgSrc = join(extSrcDir, 'package.json')
if (existsSync(pkgSrc)) {
cpSync(pkgSrc, join(extOutDir, 'package.json'))
console.log(`[build-builtins] ${id}: Installing npm dependencies…`)
execSync('npm install --omit=dev --no-audit --no-fund --ignore-scripts=false', {
cwd: extOutDir,
stdio: 'inherit',
})
console.log(`[build-builtins] ${id}: npm install done`)
}
// Copy any Python processor files
for (const file of readdirSync(extSrcDir)) {
if (file.endsWith('.py')) {
cpSync(join(extSrcDir, file), join(extOutDir, file))
console.log(`[build-builtins] ${id}: ${file} copied`)
}
}
}
console.log('[build-builtins] Done.')