Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Get started and publish it to npm #13

Merged
merged 17 commits into from
Oct 23, 2024
Merged
51 changes: 51 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish "get-started" to npm

on:
push:
branches:
- 'main'
paths:
- 'examples/get-started/**'

jobs:
check_version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check_version.outputs.changed }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check if version has changed
id: check_version
run: |
git diff HEAD^ HEAD -- examples/get-started/package.json | grep '"version"' && echo "changed=true" >> $GITHUB_OUTPUT || echo "changed=false" >> $GITHUB_OUTPUT
publish:
needs: check_version
if: needs.check_version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v2
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

# Only install dev dependencies, for the binary. No need to install deps for the source code.
- name: Install dependencies
run: pnpm install --dev
working-directory: ./examples/get-started

- name: Build binary
run: pnpm run build-bin
working-directory: ./examples/get-started

- name: Publish to npm
run: pnpm publish --access public
working-directory: ./examples/get-started
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 7 additions & 0 deletions examples/get-started/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
dist
.env
.env*
.npmrc
tsconfig.tsbuildinfo
.DS_Store
37 changes: 0 additions & 37 deletions examples/get-started/bin/get-started.js

This file was deleted.

736 changes: 736 additions & 0 deletions examples/get-started/bin/get-started.mjs

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions examples/get-started/bin/get-started.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
2,713 changes: 2,518 additions & 195 deletions examples/get-started/package-lock.json

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions examples/get-started/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
{
"name": "@restackio/get-started",
"version": "1.0.4",
"version": "1.0.9",
"description": "Get started with Restack AI SDK",
"bin": {
"get-started": "bin/get-started.js"
"get-started": "bin/get-started.mjs"
},
"files": [
"bin",
"src",
"scheduleWorkflow.ts",
"readme.md",
"tsconfig.json"
],
"keywords": [
"restack",
"starter",
"template"
],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"@restackio/ai": "^0.0.75",
"@restackio/integrations-openai": "^0.0.24",
"@temporalio/workflow": "^1.11.2",
"nodemon": "^2.0.22",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"@restackio/ai": "^0.0.75",
"@temporalio/workflow": "^1.11.2"
"wait-on": "^8.0.1"
},
"scripts": {
"build-bin": "pnpm tsup --outDir bin --format esm bin/get-started.ts",
"service": "ts-node src/services.ts",
"schedule": "ts-node scheduleWorkflow.ts"
},
"devDependencies": {
"@clack/prompts": "^0.7.0",
"tsup": "8.3.0",
"typescript": "5.6.2"
},
"pnpm": {
"overrides": {
"rollup": "npm:@rollup/wasm-node"
}
}
}
1,520 changes: 1,200 additions & 320 deletions examples/get-started/pnpm-lock.yaml

Large diffs are not rendered by default.