Skip to content

Commit

Permalink
Fix imports and tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
bigorn0 committed Sep 20, 2023
1 parent 7661715 commit af552dd
Showing 1 changed file with 74 additions and 46 deletions.
120 changes: 74 additions & 46 deletions rebuild.js
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);
}

0 comments on commit af552dd

Please sign in to comment.