diff --git a/.gitignore b/.gitignore index 1607824..e53fe2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,11 @@ -bin +bin/* +!bin/ldd build -ldd # misc *.log .DS_Store node_modules -.cache -dist - -# dependencies -/node_modules # debug npm-debug.log* diff --git a/bin/ldd b/bin/ldd new file mode 100755 index 0000000..2bec4f7 --- /dev/null +++ b/bin/ldd @@ -0,0 +1,6 @@ +#!/bin/bash + +# Inspired by https://github.com/yarnpkg/yarn/issues/3421#issuecomment-1399393547 + +echo "This file is just a stub; it is not meant to be executed. +It will be replaced by the postinstall script with the binary for the target platform." \ No newline at end of file diff --git a/lifecycle.js b/lifecycle.js index 8734693..a390d04 100644 --- a/lifecycle.js +++ b/lifecycle.js @@ -5,10 +5,12 @@ const fs = require('fs'); const path = require('path'); -const BIN_BASE_DIR = `${__dirname}/bin/@mep-agency`; -const BIN_BASE_NAME = `${BIN_BASE_DIR}/local-dev-db`; +const BIN_BASE_DIR = `${__dirname}/bin`; +const BIN_OUTPUT_PATH = `${BIN_BASE_DIR}/ldd`; +const BIN_OPTIONS_DIR = `${BIN_BASE_DIR}/@mep-agency`; +const BIN_OPTIONS_BASE_NAME = `${BIN_OPTIONS_DIR}/local-dev-db`; -if (!fs.existsSync(path.dirname(BIN_BASE_DIR)) || !fs.statSync(path.dirname(BIN_BASE_DIR)).isDirectory()) { +if (!fs.existsSync(BIN_OPTIONS_DIR) || !fs.statSync(BIN_OPTIONS_DIR).isDirectory()) { console.info('Binaries are not available, this probably means we are in a development environment... skipping!'); process.exit(0); @@ -24,7 +26,7 @@ const PLATFORM_MAPPING = { win32: 'win.exe', }; -async function install(callback) { +async function postinstall(callback) { if (PLATFORM_MAPPING[process.platform] === undefined) { callback(`Unsupported platform: "${process.platform}"`); } @@ -33,20 +35,20 @@ async function install(callback) { callback(`Unsupported architecture: "${process.arch}"`); } - const binaryNameTokens = [BIN_BASE_NAME, PLATFORM_MAPPING[process.platform], ARCH_MAPPING[process.arch]].filter( + const binaryNameTokens = [BIN_OPTIONS_BASE_NAME, PLATFORM_MAPPING[process.platform], ARCH_MAPPING[process.arch]].filter( (token) => token.length > 0, ); console.info(`Copying the relevant binary for your platform ${process.platform} (${process.arch})`); - fs.copyFileSync(binaryNameTokens.join('-'), './ldd'); + fs.copyFileSync(binaryNameTokens.join('-'), BIN_OUTPUT_PATH); callback(null); } // Parse command line arguments and call the right method var actions = { - install: install, + postinstall: postinstall, }; const argv = process.argv; diff --git a/package.json b/package.json index eca475b..7f65320 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mep-agency/local-dev-db", - "version": "1.0.0-alpha4", + "version": "1.0.0-alpha5", "private": false, "description": "A zero-config local MariaDB instance for local development (using Docker)", "author": "Marco Lipparini ", @@ -25,10 +25,10 @@ "watch": "tsc --watch", "format": "prettier --write \"**/*.{ts,md,scss,css,js}\"", "lint": "prettier --check \"**/*.{ts,md,scss,css,js}\"", - "install": "node lifecycle.js install" + "postinstall": "node lifecycle.js postinstall" }, "bin": { - "ldd": "./ldd" + "ldd": "./bin/ldd" }, "files": [ "bin",