forked from 0140454/hackbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurlconverter.js
More file actions
96 lines (83 loc) · 2.32 KB
/
Copy pathcurlconverter.js
File metadata and controls
96 lines (83 loc) · 2.32 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env node
const child_process = require('child_process')
const fs = require('fs')
const path = require('path')
const buildDir = execEnv.buildDir
const packageJsonPath = path.join(buildDir, 'package.json')
const packageLockPath = path.join(buildDir, 'package-lock.json')
const generatorsDir = path.join(buildDir, 'src', 'generators')
const projectDir = process.env.PROJECT_CWD
const tarballPath = path.join(
projectDir,
'build',
'package-generators',
'curlconverter',
'curlconverter-4.11.0.tgz',
)
const packageLockSourcePath = path.join(
projectDir,
'build',
'package-generators',
'curlconverter',
'package-lock.json',
)
const patchPath = path.join(
projectDir,
'build',
'package-generators',
'curlconverter',
'curlconverter.patch',
)
process.on('uncaughtException', err => {
if (err.stdout?.length) {
console.error(`stdout: ${err.stdout}\n`)
}
if (err.stderr?.length) {
console.error(`stderr: ${err.stderr}\n`)
}
throw err
})
// Prepare source files
child_process.execFileSync(
'tar',
['-xf', tarballPath, '--strip-components=1'],
{ cwd: buildDir },
)
fs.cpSync(packageLockSourcePath, packageLockPath)
// Remove all generators except json
for (const file of fs.readdirSync(generatorsDir)) {
if (file !== 'json.ts') {
fs.rmSync(path.join(generatorsDir, file), { recursive: true, force: true })
}
}
fs.writeFileSync(
path.join(buildDir, 'src/index.ts'),
'export { toJsonString } from "./generators/json.js";',
)
// Patch packages
child_process.execFileSync('patch', ['-p', '1', '-i', patchPath], {
cwd: buildDir,
})
const newPackageJson = child_process
.execFileSync('jq', [
'del(.bin) | del(.browser) | del(.dependencies."@curlconverter/tree-sitter") | del(.scripts.prepare) | .dependencies.nan = "^2.22.0"',
packageJsonPath,
])
.toString()
.trim()
fs.writeFileSync(packageJsonPath, newPackageJson)
child_process.execFileSync('rm', [
'-rf',
path.join(buildDir, 'dist/src'),
path.join(buildDir, 'tools'),
path.join(buildDir, 'src/shell/Parser.ts'),
path.join(buildDir, 'src/cli.ts'),
])
// Prepare package
child_process.execFileSync('npm', ['install'], {
cwd: buildDir,
})
// Build package
child_process.execFileSync('npm', ['run', 'compile'], { cwd: buildDir })
// Cleanup
child_process.execFileSync('rm', ['-rf', path.join(buildDir, 'node_modules')])