-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
49 lines (40 loc) · 1.69 KB
/
init.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
import path from 'path';
import { execa } from 'execa';
import chalk from 'chalk';
import fs from 'fs';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const Colors = {
cms: chalk.magentaBright,
web: chalk.blueBright
};
const Output = {
cms: (...messages) => console.log(`[${Colors.cms('Burdy')}] ${messages.join(' ')}`),
web: (...messages) => console.log(`[${Colors.web('Next')}] ${messages.join(' ')}`),
};
const rootDirectory = __dirname;
const cmsDirectory = path.join(rootDirectory, 'cms');
const webDirectory = path.join(rootDirectory, 'web');
(async () => {
// Prepare CMS
Output.cms('Installing dependencies...');
await execa('npm', ['install'], { cwd: cmsDirectory, stdio: 'inherit' });
Output.cms('Successfully installed dependencies!');
Output.cms('Preparing database...');
await execa('npm', ['run', 'db:init'], { cwd: cmsDirectory, stdio: 'inherit' });
Output.cms('Database ready.');
Output.cms('Importing data...');
await execa('npm', ['run', 'import'], { cwd: cmsDirectory, stdio: 'inherit' });
Output.cms('Data imported!')
// Generate API Key and import it to .env
Output.cms('Generating key...');
const keyProcess = await execa('npm', ['run', 'generate:key', 'demo'], { cwd: cmsDirectory });
const key = keyProcess.stdout.match(/GENERATED_KEY="(.*)"/)[1];
fs.appendFileSync(path.join(webDirectory, '.env'), `\nBURDY_ACCESS_TOKEN=${key}`);
Output.web('Key added to .env');
// Prepare Frontend
Output.web('Installing dependencies...');
await execa('npm', ['install'], { cwd: webDirectory, stdio: 'inherit' });
Output.web('Successfully installed dependencies!');
})();