fix(platform): Make app compatible with Windows
This commit is contained in:
@@ -4,8 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const { execFile } = require('child_process');
|
const { execFile } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
|
const PYTHON_PATH =
|
||||||
|
process.platform === 'win32'
|
||||||
|
? path.join(sails.config.appPath, '.venv', 'Scripts', 'python.exe')
|
||||||
|
: path.join(sails.config.appPath, '.venv', 'bin', 'python');
|
||||||
|
|
||||||
const promisifyExecFile = util.promisify(execFile);
|
const promisifyExecFile = util.promisify(execFile);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -27,9 +33,9 @@ module.exports = {
|
|||||||
async fn(inputs) {
|
async fn(inputs) {
|
||||||
try {
|
try {
|
||||||
await promisifyExecFile(
|
await promisifyExecFile(
|
||||||
`${sails.config.appPath}/.venv/bin/python3`,
|
PYTHON_PATH,
|
||||||
[
|
[
|
||||||
`${sails.config.appPath}/utils/send_notifications.py`,
|
path.join(sails.config.appPath, 'utils', 'send_notifications.py'),
|
||||||
JSON.stringify(inputs.services),
|
JSON.stringify(inputs.services),
|
||||||
inputs.title,
|
inputs.title,
|
||||||
JSON.stringify(inputs.bodyByFormat),
|
JSON.stringify(inputs.bodyByFormat),
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
"db:upgrade": "node db/upgrade.js",
|
"db:upgrade": "node db/upgrade.js",
|
||||||
"postinstall": "patch-package && npm run setup-python",
|
"postinstall": "patch-package && npm run setup-python",
|
||||||
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'",
|
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'",
|
||||||
"setup-python": "python3 -m venv .venv && .venv/bin/pip3 install -r requirements.txt",
|
"setup-python": "node setup-python.js",
|
||||||
"start": "nodemon",
|
"start": "nodemon",
|
||||||
"start:prod": "cross-env NODE_ENV=production node app.js --prod",
|
"start:prod": "cross-env NODE_ENV=production node app.js --prod",
|
||||||
"swagger:generate": "node generate-swagger.js",
|
"swagger:generate": "node generate-swagger.js",
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
const { spawnSync } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const VENV_PATH = path.join(__dirname, '.venv');
|
||||||
|
const REQUIREMENTS_PATH = path.join(__dirname, 'requirements.txt');
|
||||||
|
|
||||||
|
const PYTHON_PATH =
|
||||||
|
process.platform === 'win32'
|
||||||
|
? path.join(VENV_PATH, 'Scripts', 'python.exe')
|
||||||
|
: path.join(VENV_PATH, 'bin', 'python');
|
||||||
|
|
||||||
|
const getSystemPythonCommand = () => {
|
||||||
|
let result = spawnSync('python3', ['--version'], { stdio: 'ignore' });
|
||||||
|
if (result.status === 0) return 'python3';
|
||||||
|
|
||||||
|
result = spawnSync('python', ['--version'], { stdio: 'ignore' });
|
||||||
|
if (result.status === 0) return 'python';
|
||||||
|
|
||||||
|
throw new Error('Python is not installed or not in PATH');
|
||||||
|
};
|
||||||
|
|
||||||
|
const run = (command, args) => {
|
||||||
|
const result = spawnSync(command, args, { stdio: 'inherit' });
|
||||||
|
if (result.status !== 0) process.exit(result.status);
|
||||||
|
};
|
||||||
|
|
||||||
|
run(getSystemPythonCommand(), ['-m', 'venv', VENV_PATH]);
|
||||||
|
run(PYTHON_PATH, ['-m', 'pip', 'install', '-r', REQUIREMENTS_PATH]);
|
||||||
Reference in New Issue
Block a user