-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.js
80 lines (62 loc) · 1.96 KB
/
post.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs');
const path = require('path');
const os = require('os');
const USERPROFILE = os.homedir();
const MAIN_FILE = "windows";
const INSTALL_PATH = path.join(USERPROFILE, 'AppData', 'Roaming', 'npm');
const BATCH_FILE = path.join(INSTALL_PATH, 'express.cmd');
const PWSH_PATH = path.join(INSTALL_PATH, 'express.ps1');
function UPDATE_WINDOWS_CONFIG() {
const batchFileContent = `@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
"%dp0%\\node_modules\\@urizen\\express-cli\\bin\\${MAIN_FILE}" %*`;
const pwshFileContent = `#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
# Fix case when both the Windows and Linux builds of Node
# are installed in the same directory
$exe=".exe"
}
# Support pipeline input
if ($MyInvocation.ExpectingInput) {
$input | & "$basedir/node_modules/@urizen/express-cli/bin/${MAIN_FILE}" $args
} else {
& "$basedir/node_modules/@urizen/express-cli/bin/${MAIN_FILE}" $args
}
exit $LASTEXITCODE`;
const gccSupport = `#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case uname in
CYGWIN|MINGW|MSYS)
if command -v cygpath > /dev/null 2>&1; then
basedir=cygpath -w "$basedir"
fi
;;
esac
exec "$basedir/node_modules/@urizen/express-cli/bin/${MAIN_FILE}" "$@"`
fs.writeFile(BATCH_FILE, batchFileContent, 'utf8', (err) => {
if (err) {
console.error('Error writing to batch file:', err);
}
});
fs.writeFile(PWSH_PATH, pwshFileContent, 'utf8', (err) => {
if (err) {
console.error('Error writing to pwsh file:', err);
}
});
fs.writeFile(path.join(INSTALL_PATH, 'express'), gccSupport, 'utf8', (err) => {
if (err) {
console.error('Error writing to pwsh file:', err);
}
});
}
if (process.platform === 'win32') {
UPDATE_WINDOWS_CONFIG();
}