-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,83 @@ | ||
import { platform, arch } from 'node:os'; | ||
import { log } from '#lib/logger.js'; | ||
import { prebuildNativeModule } from '#lib/prebuilds.js'; | ||
import { npmCommand, exec } from '#lib/commands.js'; | ||
import modules from './modulesToBuild.json' assert { type: 'json' }; | ||
import { ROOT_DIR } from '#root'; | ||
import { mkdir, cp, readdir, rm, writeFile } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { publishToGitHubPackages, writePkgTpl } from '#lib/publish.js'; | ||
import { platform, arch } from "node:os"; | ||
import { log } from "#lib/logger.js"; | ||
import { prebuildNativeModule } from "#lib/prebuilds.js"; | ||
import { npmCommand, exec } from "#lib/commands.js"; | ||
import modules from "./modulesToBuild.json" assert { type: "json" }; | ||
import { ROOT_DIR } from "#root"; | ||
import { mkdir, cp, readdir, rm, writeFile } from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { publishToGitHubPackages, writePkgTpl } from "#lib/publish.js"; | ||
import winAddon from "./winapi-detect-remote-desktop-addon/package.json" assert { type: "json" }; | ||
|
||
// run patch package | ||
await exec(npmCommand, ['run', `patch-package`]); | ||
await exec(npmCommand, ["run", `patch-package`]); | ||
|
||
const modulesToBuild = modules.filter(mod => mod.targetPlatform === platform() && mod.targetArch === arch()); | ||
const modulesToBuild = modules.filter( | ||
(mod) => mod.targetPlatform === platform() && mod.targetArch === arch(), | ||
); | ||
|
||
// Handle our custom module for windows remote desktop detection | ||
if (os.platform() === 'win32') { | ||
if(platform() === "win32" ){ | ||
const remoteDesktopDetectionAddon = { | ||
"targetPlatform": "win32", | ||
"targetArch": "x64", | ||
"name": winAddon.name, | ||
"module": { | ||
"baseDir": `${ROOT_DIR}/${winAddon.name}`, | ||
"name": winAddon.name, | ||
"version": winAddon.version, | ||
"native": true, | ||
"napi": true | ||
}, | ||
"toBuild": true | ||
} | ||
|
||
modulesToBuild.push(remoteDesktopDetectionAddon); | ||
} | ||
|
||
for (const { module, targetPlatform, targetArch } of modulesToBuild) { | ||
await rm(path.join(module.baseDir, 'build', 'Release'), { recursive: true, force: true }); | ||
|
||
log('building custom native bindings for module %o', module); | ||
await prebuildNativeModule(module); | ||
|
||
const nativeModuleScopedPackage = path.join( | ||
ROOT_DIR, | ||
'node_modules', | ||
'@hackolade', | ||
`${module.name}-${targetPlatform}-${targetArch}`, | ||
); | ||
await rm(nativeModuleScopedPackage, { force: true, recursive: true }); | ||
await mkdir(nativeModuleScopedPackage, { force: true, recursive: true }); | ||
|
||
const releaseContent = await readdir(path.resolve(module.baseDir, 'build', 'Release'), { | ||
withFileTypes: true, | ||
}); | ||
const [prebuild] = releaseContent | ||
.filter(entry => entry.isFile() && entry.name.endsWith('.node')) | ||
.map(entry => entry.name); | ||
|
||
log('normalizing prebuild name: %o - %o', module.baseDir, prebuild); | ||
const prebuildSrc = path.join(module.baseDir, 'build', 'Release', prebuild); | ||
|
||
await cp(prebuildSrc, path.join(nativeModuleScopedPackage, 'prebuild.node')); | ||
await writePkgTpl({ | ||
moduleName: module.name, | ||
targetPlatform, | ||
targetArch, | ||
scopedPackagePath: nativeModuleScopedPackage, | ||
version: module.version, | ||
}); | ||
|
||
await publishToGitHubPackages(nativeModuleScopedPackage); | ||
|
||
await rm( | ||
path.join(module.baseDir, "build", "Release"), | ||
{recursive: true, force: true}, | ||
); | ||
|
||
log("building custom native bindings for module %o", module); | ||
await prebuildNativeModule(module); | ||
|
||
const nativeModuleScopedPackage = path.join( | ||
ROOT_DIR, | ||
"node_modules", | ||
"@hackolade", | ||
`${module.name}-${targetPlatform}-${targetArch}`, | ||
); | ||
await rm(nativeModuleScopedPackage, { force: true, recursive: true }); | ||
await mkdir(nativeModuleScopedPackage, { force: true, recursive: true }); | ||
|
||
const releaseContent = await readdir( | ||
path.resolve(module.baseDir, "build", "Release"), | ||
{ | ||
withFileTypes: true, | ||
}, | ||
); | ||
const [prebuild] = releaseContent | ||
.filter((entry) => entry.isFile() && entry.name.endsWith(".node")) | ||
.map((entry) => entry.name); | ||
|
||
log("normalizing prebuild name: %o - %o", module.baseDir, prebuild); | ||
const prebuildSrc = path.join(module.baseDir, "build", "Release", prebuild); | ||
|
||
await cp( | ||
prebuildSrc, | ||
path.join(nativeModuleScopedPackage, "prebuild.node"), | ||
); | ||
await writePkgTpl({ | ||
moduleName: module.name, | ||
targetPlatform, | ||
targetArch, | ||
scopedPackagePath: nativeModuleScopedPackage, | ||
version: module.version, | ||
}); | ||
|
||
await publishToGitHubPackages(nativeModuleScopedPackage); | ||
} |