-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·29 lines (24 loc) · 935 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env node
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
// Constructing the absolute path to script.sh using __dirname
const scriptPath = path.join(__dirname, 'script.sh')
const packageJsonPath = path.join(__dirname, 'package.json');
// Setting up the executable permission on the script.sh file
fs.chmodSync(scriptPath, '755')
const showVersion = () => {
if (!fs.existsSync(packageJsonPath)) {
console.error('Error: package.json not found at ' + packageJsonPath);
process.exit(1);
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
console.log(`v${packageJson.version}`);
};
const args = process.argv.slice(2)
if (args.length === 1 && (args[0] === '--version' || args[0] === '-V')) {
showVersion();
} else {
execSync(`${scriptPath} ${args.join(' ')}`, { stdio: 'inherit' })
}
// and last lets execute it