Skip to content

Commit 5e26ce7

Browse files
authored
Merge pull request #13 from restackio/get-started-new
Update Get started and publish it to npm
2 parents 988fe94 + 9dc506b commit 5e26ce7

File tree

8 files changed

+4627
-558
lines changed

8 files changed

+4627
-558
lines changed

.github/workflows/npm-publish.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Publish "get-started" to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
paths:
8+
- 'examples/get-started/**'
9+
10+
jobs:
11+
check_version:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
version_changed: ${{ steps.check_version.outputs.changed }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 2
19+
- name: Check if version has changed
20+
id: check_version
21+
run: |
22+
git diff HEAD^ HEAD -- examples/get-started/package.json | grep '"version"' && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT
23+
24+
publish:
25+
needs: check_version
26+
if: needs.check_version.outputs.version_changed == 'true'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
- uses: pnpm/action-setup@v4
31+
with:
32+
version: 9
33+
- uses: actions/setup-node@v2
34+
with:
35+
node-version: 20
36+
registry-url: 'https://registry.npmjs.org'
37+
38+
# Only install dev dependencies, for the binary. No need to install deps for the source code.
39+
- name: Install dependencies
40+
run: pnpm install --dev
41+
working-directory: ./examples/get-started
42+
43+
- name: Build binary
44+
run: pnpm run build-bin
45+
working-directory: ./examples/get-started
46+
47+
- name: Publish to npm
48+
run: pnpm publish --access public
49+
working-directory: ./examples/get-started
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

examples/get-started/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist
3+
.env
4+
.env*
5+
.npmrc
6+
tsconfig.tsbuildinfo
7+
.DS_Store

examples/get-started/bin/get-started.js

-37
This file was deleted.

examples/get-started/bin/get-started.mjs

+736
Large diffs are not rendered by default.
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env node
2+
import * as clack from '@clack/prompts';
3+
import fs from 'fs';
4+
import { execSync } from 'child_process';
5+
import path from 'path';
6+
import { fileURLToPath } from 'url';
7+
import waitOn from 'wait-on';
8+
9+
// @ts-ignore
10+
import packageJson from '../package.json';
11+
12+
// @ts-ignore
13+
const __filename = fileURLToPath(import.meta.url);
14+
const __dirname = path.dirname(__filename);
15+
const packageRoot = path.join(__dirname, '..');
16+
17+
async function main() {
18+
clack.intro('Welcome Restack Get started'!);
19+
20+
const currentDir = process.cwd();
21+
let targetDir: string;
22+
23+
// Copy files
24+
const projectName = (await clack.text({
25+
message: 'Enter the project folder name:',
26+
defaultValue: 'restack-get-started',
27+
initialValue: 'restack-get-started',
28+
validate(value) {
29+
if (value.length === 0) return `⚠️ Project folder name is required`;
30+
}
31+
})) as string;
32+
33+
if (projectName) {
34+
targetDir = path.join(currentDir, projectName);
35+
const filesToCopy = ['src', 'scheduleWorkflow.ts', 'tsconfig.json', '.gitignore'];
36+
filesToCopy.forEach(file => {
37+
fs.cpSync(path.join(packageRoot, file), path.join(targetDir, file), { recursive: true });
38+
});
39+
40+
// Copy package.json separately and modify it
41+
delete packageJson.bin;
42+
delete packageJson.files;
43+
fs.writeFileSync(path.join(targetDir, 'package.json'), JSON.stringify(packageJson, null, 2));
44+
}
45+
46+
const installDependencies = (await clack.confirm({
47+
message: 'Install dependencies?',
48+
initialValue: true,
49+
})) as boolean;
50+
51+
if (installDependencies) {
52+
console.log('Installing dependencies...');
53+
execSync('npm install', { stdio: 'inherit', cwd: targetDir });
54+
}
55+
56+
const startRestack = (await clack.confirm({
57+
message: 'Start Restack Engine?',
58+
initialValue: true,
59+
})) as boolean;
60+
61+
if (startRestack) {
62+
console.log('Starting Restack Engine...');
63+
execSync('docker rm -f studio', { stdio: 'inherit', cwd: targetDir });
64+
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 });
65+
console.log(`Restack Engine Studio started on http://localhost:5233`);
66+
}
67+
68+
const openRestack = (await clack.confirm({
69+
message: 'Open Restack Engine Studio?',
70+
initialValue: true,
71+
})) as boolean;
72+
73+
if (openRestack) {
74+
const s = clack.spinner();
75+
s.start('Waiting for Restack Engine Studio to start');
76+
await waitOn({ resources: ['http://localhost:5233'] });
77+
s.stop();
78+
execSync('open http://localhost:5233', { stdio: 'inherit', cwd: targetDir });
79+
}
80+
81+
const blue = '\x1b[34m';
82+
const noColor = '\x1b[0m';
83+
84+
clack.outro(`
85+
Project created successfully!
86+
87+
We suggest that you begin with following commands:
88+
89+
To navigate to the project, run: ${blue}cd ${projectName}${noColor}
90+
91+
To start the service, run: ${blue}npm run service${noColor}
92+
93+
To schedule a workflow, run: ${blue}npm run schedule${noColor}
94+
`);
95+
}
96+
97+
main();

0 commit comments

Comments
 (0)