-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from palico-ai/fix-template
FIX: Made it simplier and more clear to get started
- Loading branch information
Showing
6 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import * as path from 'path' | ||
import * as chalk from 'chalk' | ||
import { copyDirectory } from '../utils/copy' | ||
import * as path from "path"; | ||
import * as chalk from "chalk"; | ||
import { copyDirectory } from "../utils/copy"; | ||
import { createFile } from "../utils/create_file"; | ||
import { runCommands } from "../utils/run_command"; | ||
|
||
const ENV_FILE_CONTENT = ` | ||
# Add your OpenAI API key | ||
OPENAI_API_KEY="" | ||
# Add the model you want to use | ||
OPENAI_MODEL="gpt-3.5-turbo-0125" | ||
`; | ||
|
||
export const InitHandler = async (projectName: string) => { | ||
console.log(projectName) | ||
if(!projectName || projectName.length === 0) { | ||
throw new Error('Project name is required') | ||
if (!projectName || projectName.length === 0) { | ||
throw new Error("Project name is required"); | ||
} | ||
console.log(`Initializing ${projectName}...`) | ||
const templateDirectory = path.join(__dirname, '..', '..', 'templates', 'base') | ||
const destinationDirectory = path.join(process.cwd(), projectName) | ||
await copyDirectory(templateDirectory, destinationDirectory) | ||
console.log(`Initializing ${projectName}...`); | ||
const templateDirectory = path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"templates", | ||
"base" | ||
); | ||
const destinationDirectory = path.join(process.cwd(), projectName); | ||
await copyDirectory(templateDirectory, destinationDirectory); | ||
await runCommands([`cd ${projectName} && npm install`]); | ||
await createFile(path.join(destinationDirectory, ".env"), ENV_FILE_CONTENT); | ||
const nextSteps = [ | ||
`cd ${projectName}`, | ||
"npm install", | ||
"Update LLM Model Config in src/index.ts", | ||
"Run 'palico-cli dev' to start a local server" | ||
] | ||
console.log(chalk.green('Project initialized!')) | ||
console.log(chalk.blue('Next Steps:')) | ||
`Navigate to the project directory: ${chalk.greenBright(`cd ${projectName}`)}`, | ||
`Update ${chalk.greenBright(".env")} with your OpenAI API key and model`, | ||
`Run ${chalk.greenBright("npm start")} to start the application`, | ||
]; | ||
console.log(chalk.green("Project initialized!")); | ||
console.log(chalk.blue("Next Steps:")); | ||
nextSteps.forEach((step, index) => { | ||
console.log(chalk.blue(`${index + 1}. ${step}`)) | ||
}) | ||
} | ||
console.log(chalk.blue(`${index + 1}. ${step}`)); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as fs from 'fs'; | ||
|
||
export const createFile = async (path: string, content?: string) => { | ||
await fs.promises.writeFile(path, content ?? '', 'utf-8'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { promisify } from 'util' | ||
import { exec } from 'child_process' | ||
|
||
export const runCommands = async (commands: string[]): Promise<void> => { | ||
const execAsync = promisify(exec) | ||
for (const command of commands) { | ||
const { stdout, stderr } = await execAsync(command) | ||
console.log(stdout) | ||
if (stderr) { | ||
throw new Error(stderr) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
dist | ||
palico.out | ||
.DS_Store | ||
.DS_Store | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters