-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathget-started.ts
97 lines (77 loc) · 2.88 KB
/
get-started.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
import * as clack from '@clack/prompts';
import fs from 'fs';
import { execSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
import waitOn from 'wait-on';
// @ts-ignore
import packageJson from '../package.json';
// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const packageRoot = path.join(__dirname, '..');
async function main() {
clack.intro('Welcome Restack Get started'!);
const currentDir = process.cwd();
let targetDir: string;
// Copy files
const projectName = (await clack.text({
message: 'Enter the project folder name:',
defaultValue: 'restack-get-started',
initialValue: 'restack-get-started',
validate(value) {
if (value.length === 0) return `⚠️ Project folder name is required`;
}
})) as string;
if (projectName) {
targetDir = path.join(currentDir, projectName);
const filesToCopy = ['src', 'scheduleWorkflow.ts', 'tsconfig.json', '.gitignore'];
filesToCopy.forEach(file => {
fs.cpSync(path.join(packageRoot, file), path.join(targetDir, file), { recursive: true });
});
// Copy package.json separately and modify it
delete packageJson.bin;
delete packageJson.files;
fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2));
}
const installDependencies = (await clack.confirm({
message: 'Install dependencies?',
initialValue: true,
})) as boolean;
if (installDependencies) {
console.log('Installing dependencies...');
execSync('npm install', { stdio: 'inherit', cwd: targetDir });
}
const startRestack = (await clack.confirm({
message: 'Start Restack Engine?',
initialValue: true,
})) as boolean;
if (startRestack) {
console.log('Starting Restack Engine...');
execSync('docker rm -f studio', { stdio: 'inherit', cwd: targetDir });
execSync('docker run -d --pull always --name studio -p 5233:5233 -p 6233:6233 -p 7233:7233 ghcr.io/restackio/engine:main', { stdio: 'inherit', cwd: currentDir });
console.log(`Restack Engine Studio started on http://localhost:5233`);
}
const openRestack = (await clack.confirm({
message: 'Open Restack Engine Studio?',
initialValue: true,
})) as boolean;
if (openRestack) {
const s = clack.spinner();
s.start('Waiting for Restack Engine Studio to start');
await waitOn({ resources: ['http://localhost:5233'] });
s.stop();
execSync('open http://localhost:5233', { stdio: 'inherit', cwd: targetDir });
}
const blue = '\x1b[34m';
const noColor = '\x1b[0m';
clack.outro(`
Project created successfully!
We suggest that you begin with following commands:
To navigate to the project, run: ${blue}cd ${projectName}${noColor}
To start the service, run: ${blue}npm run service${noColor}
To schedule a workflow, run: ${blue}npm run schedule${noColor}
`);
}
main();