Skip to content

Commit

Permalink
Fix base dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bigorn0 committed Sep 20, 2023
1 parent f9cb564 commit 839e9c3
Showing 1 changed file with 62 additions and 67 deletions.
129 changes: 62 additions & 67 deletions rebuild.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,78 @@
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" };
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())
.map(module => {
// Base dir might have changed between runs
const moduleName = module.name;
module.module.baseDir = `${ROOT_DIR}/${moduleName}`;
return module;
});

// Handle our custom module for windows remote desktop detection
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
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
}
'toBuild': true,
};

modulesToBuild.push(remoteDesktopDetectionAddon);
modulesToBuild.push(remoteDesktopDetectionAddon);
}

for (const { module, targetPlatform, targetArch } of modulesToBuild) {
await rm(path.join(module.baseDir, 'build', 'Release'), { recursive: true, force: true });

await rm(
path.join(module.baseDir, "build", "Release"),
{recursive: true, force: true},
);
log('building custom native bindings for module %o', module);
await prebuildNativeModule(module);

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 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);

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,
});
log('normalizing prebuild name: %o - %o', module.baseDir, prebuild);
const prebuildSrc = path.join(module.baseDir, 'build', 'Release', prebuild);

await publishToGitHubPackages(nativeModuleScopedPackage);
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 839e9c3

Please sign in to comment.