0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

chore: download and install logto (#668)

* chore: download and install logto

* fix: remove `detached`

* refactor: query instead of throwing error when postgres not found
This commit is contained in:
Gao Sun 2022-04-27 15:48:03 +08:00 committed by GitHub
parent dc976d8248
commit e7fe1200ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 1 deletions

64
install.js Normal file
View file

@ -0,0 +1,64 @@
const { execSync, spawn, spawnSync } = require('child_process');
const { existsSync } = require('fs');
const readline = require('readline');
const isVersionGreaterThan = (version, targetMajor) => Number(version.split('.')[0]) >= targetMajor;
const trimV = (version) => version.startsWith('v') ? version.slice(1) : version;
const question = async (query) => new Promise((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(query, (answer) => {
rl.close();
resolve(answer);
});
});
const confirm = async (query) => {
const answer = await question(`${query} (Y/n) `);
return answer === '' || ['y', 'yes', 'yep', 'yeah'].includes(answer);
};
const directory = 'logto';
(async () => {
if (existsSync(directory)) {
throw new Error(`\`${directory}\` already exists in the current directory.`);
}
const nodeVersion = execSync('node -v', { encoding: 'utf-8' });
if (!isVersionGreaterThan(trimV(nodeVersion), 16)) {
throw new Error('Logto requires NodeJS >= 16.0.0.');
}
const pgOutput = execSync('postgres --version', { encoding: 'utf-8' });
const pgArray = pgOutput.split(' ');
const pgVersion = pgArray[pgArray.length - 1];
if (!isVersionGreaterThan(trimV(pgVersion), 18)) {
const answer = await confirm('Logto requires PostgreSQL >= 14.0.0 but cannot find in the current environment.\nDo you have a remote PostgreSQL instance ready?');
if (!answer) {
process.exit(1);
}
}
spawnSync(
'sh',
['-c', 'curl -L https://github.com/logto-io/logto/releases/latest/download/logto.tar.gz | tar -xz'],
{ stdio: 'inherit' },
);
const startCommand = `cd ${directory} && npm start`;
const answer = await confirm('Would you like to start Logto now?');
if (answer) {
spawn('sh', ['-c', startCommand], { stdio: 'inherit' });
} else {
console.log(`You can use \`${startCommand}\` to start Logto. Happy hacking!`);
}
})();

View file

@ -9,7 +9,7 @@
"prepare": "if test \"$NODE_ENV\" != \"production\" && test \"$CI\" != \"true\" ; then husky install ; fi",
"prepack": "lerna run --stream prepack",
"dev": "lerna run --stream prepack && lerna --scope=@logto/{core,ui,console} exec -- pnpm dev",
"start": "cd packages/core && node . --from-root"
"start": "cd packages/core && NODE_ENV=production node . --from-root"
},
"devDependencies": {
"@commitlint/cli": "^16.0.0",