x3-install-compiler
Version:
Sage X3 Compiler Installer
95 lines (83 loc) • 2.33 kB
JavaScript
import prompts from 'prompts';
import { exec } from 'child_process';
import fs from 'fs';
import cli_spinner from 'cli-spinner';
const Spinner = cli_spinner.Spinner;
const __dirname = fs.realpathSync(process.cwd());
if (fs.existsSync('sagex3-compiler-server')) {
console.error('sagex3-compiler-server already exists!');
process.exit(1);
}
const questions = [
{
type: 'text',
name: 'x3_path',
message: 'Enter the path to the x3 folder: ',
initial: 'C:\\Sage\\SAGEX3'
},
{
type: 'text',
name: 'x3_url',
message: 'Enter the url to the x3 folder: ',
},
{
type: 'text',
name: 'username',
message: 'Username: ',
initial: 'admin'
},
{
type: 'text',
name: 'password',
message: 'Password: ',
initial: 'admin'
},
{
type: 'number',
name: 'port',
message: 'Port: ',
initial: '3001'
},
];
(async () => {
const response = await prompts(questions);
const commands = [
'git clone https://github.com/azatakmyradov/sagex3-compiler-server.git',
'cd sagex3-compiler-server',
'echo "" > .env',
'npm install',
'npm run build',
'npm install -g pm2',
'pm2 start app.config.cjs'
]
const spinner = new Spinner('Installing.. %s');
spinner.setSpinnerString('|/-\\');
spinner.start();
exec(commands.join(' && '), (err) => {
if (err) {
console.error(err);
spinner.stop(true);
process.exit(1);
}
createConfigFile(response);
spinner.stop(true);
console.log('Successfully installed!');
process.exit(0);
});
})();
function createConfigFile(config) {
const X3_PATH = `X3_PATH=${config.x3_path}`;
const X3_URL = `X3_URL=${config.x3_url}`;
const USERNAME = `CUSERNAME=${config.username}`;
const PASSWORD = `CPASSWORD=${config.password}`;
const PORT = `PORT=${config.port}`;
const ENV = `ENV=PRODUCTION`;
try {
fs.writeFileSync(__dirname + '/sagex3-compiler-server/.env', [X3_PATH, X3_URL, USERNAME, PASSWORD, PORT, ENV]
.join('\n'));
} catch (err) {
console.error(err);
process.exit(1);
}
}