Skip to content

Commit

Permalink
🍱 Add bin/*
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Jan 9, 2025
1 parent 3b90c8b commit be41170
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bin/xmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node
const os = require('os');
const { spawnSync } = require('child_process');
const { resolve } = require('path');
const bin = resolve(__dirname, '..', 'prebuilds', `xmake-${os.platform()}-${os.arch()}`, 'bin', __filename);
const cmd = spawnSync(bin, process.argv.slice(2))
console.log(cmd.stdout.toString())
console.error(cmd.stderr.toString())
8 changes: 8 additions & 0 deletions bin/xrepo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node
const os = require('os');
const { spawnSync } = require('child_process');
const { resolve } = require('path');
const bin = resolve(__dirname, '..', 'prebuilds', `xmake-${os.platform()}-${os.arch()}`, 'bin', __filename);
const cmd = spawnSync(bin, process.argv.slice(2))
console.log(cmd.stdout.toString())
console.error(cmd.stderr.toString())
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"keywords": [
"xmake"
],
"bin": {
"xmake": "bin/xmake",
"xrepo": "bin/xrepo"
},
"scripts": {
"build": "scripts/build.py",
"prepack": ""
"build": "scripts/build.py && scripts/install.js"
}
}
13 changes: 8 additions & 5 deletions scripts/build.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
r"""Build
=========
Expand All @@ -8,8 +9,7 @@
import subprocess
import tarfile
import urllib.request

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from contextlib import suppress

try:
import tomllib
Expand Down Expand Up @@ -40,9 +40,12 @@ def main():
subprocess.run(["make", "install"], cwd=cwd)


class CustomHook(BuildHookInterface):
def initialize(self, version, build_data) -> None:
main()
with suppress(ImportError):
from hatchling.builders.hooks.plugin.interface import BuildHookInterface

class CustomHook(BuildHookInterface):
def initialize(self, version, build_data) -> None:
main()


if __name__ == "__main__":
Expand Down
26 changes: 26 additions & 0 deletions scripts/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node
const os = require('os');
const fs = require('fs');
const path = require('path');

function copyDirectory(src, dest) {
fs.mkdirSync(dest, {recursive: true});

const entries = fs.readdirSync(src, {withFileTypes: true});

for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
copyDirectory(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}

const sourceDir = 'usr';
const destinationDir = `prebuilds/xmake-${os.platform()}-${os.arch()}`;

copyDirectory(sourceDir, destinationDir);

0 comments on commit be41170

Please sign in to comment.