-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add cli * chore: removed log * chore: update repo url * chore: updated program name * chore: updated program description * chore: removed yarn lock files
- Loading branch information
Showing
12 changed files
with
301 additions
and
1 deletion.
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
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,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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,7 @@ | ||
## Fal.ai App Generator | ||
|
||
Generate a new full stack app configured with Fal.ai proxy and models. | ||
|
||
```sh | ||
npx @fal-ai/create | ||
``` |
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,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'cli', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/libs/cli', | ||
}; |
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,21 @@ | ||
{ | ||
"name": "@fal-ai/create", | ||
"version": "0.0.1", | ||
"description": "The fal serverless app generator.", | ||
"main": "index.js", | ||
"keywords": [ | ||
"fal", | ||
"next", | ||
"nextjs", | ||
"express" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fal-ai/serverless-js.git", | ||
"directory": "libs/cli" | ||
}, | ||
"type": "module", | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": {} | ||
} |
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,41 @@ | ||
{ | ||
"name": "cli", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/cli/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/libs/cli", | ||
"tsConfig": "libs/cli/tsconfig.lib.json", | ||
"packageJson": "libs/cli/package.json", | ||
"main": "libs/cli/src/index.ts", | ||
"assets": ["LICENSE", "CODE_OF_CONDUCT.md", "libs/cli/README.md"] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["libs/cli/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "libs/cli/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
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,148 @@ | ||
#!/usr/bin/env node | ||
|
||
import chalk from 'chalk'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import childProcess from 'child_process'; | ||
import ora from 'ora'; | ||
import select from '@inquirer/select'; | ||
import { input } from '@inquirer/prompts'; | ||
import { Command } from 'commander'; | ||
import { execa, execaCommand } from 'execa'; | ||
import open from 'open'; | ||
|
||
const program = new Command(); | ||
const log = console.log; | ||
const repoUrl = 'https://github.com/fal-ai/fal-nextjs-template.git'; | ||
const green = chalk.green; | ||
const purple = chalk.hex('#6e40c9'); | ||
|
||
async function main() { | ||
const spinner = ora({ | ||
text: 'Creating codebase', | ||
}); | ||
try { | ||
const kebabRegez = /^([a-z]+)(-[a-z0-9]+)*$/; | ||
|
||
program | ||
.name('Fal.ai App Generator') | ||
.description('Generate full stack AI apps integrated with Fal.ai.'); | ||
|
||
program.parse(process.argv); | ||
|
||
const args = program.args; | ||
let appName = args[0]; | ||
|
||
if (!appName || !kebabRegez.test(args[0])) { | ||
appName = await input({ | ||
message: 'Enter your app name', | ||
default: 'model-playground', | ||
validate: (d) => { | ||
if (!kebabRegez.test(d)) { | ||
return 'please enter your app name in the format of my-app-name'; | ||
} | ||
return true; | ||
}, | ||
}); | ||
} | ||
|
||
const hasFalEnv = await select({ | ||
message: 'Do you have a Fal.ai API key?', | ||
choices: [ | ||
{ | ||
name: 'Yes', | ||
value: true, | ||
}, | ||
{ | ||
name: 'No', | ||
value: false, | ||
}, | ||
], | ||
}); | ||
|
||
if (!hasFalEnv) { | ||
await open('https://www.fal.ai/dashboard'); | ||
} | ||
|
||
const fal_api_key = await input({ message: 'Fal AI API Key' }); | ||
|
||
let envs = ` | ||
# environment, either PRODUCTION or DEVELOPMENT | ||
ENVIRONMENT="PRODUCTION" | ||
# FAL AI API Key | ||
FAL_KEY="${fal_api_key}" | ||
`; | ||
|
||
log(`\nInitializing project. \n`); | ||
|
||
spinner.start(); | ||
await execa('git', ['clone', repoUrl, appName]); | ||
|
||
let packageJson = fs.readFileSync(`${appName}/package.json`, 'utf8'); | ||
const packageObj = JSON.parse(packageJson); | ||
packageObj.name = appName; | ||
packageJson = JSON.stringify(packageObj, null, 2); | ||
fs.writeFileSync(`${appName}/package.json`, packageJson); | ||
fs.writeFileSync(`${appName}/.env.local`, envs); | ||
|
||
process.chdir(path.join(process.cwd(), appName)); | ||
spinner.text = ''; | ||
let startCommand = ''; | ||
|
||
if (isBunInstalled()) { | ||
spinner.text = 'Installing dependencies'; | ||
await execaCommand('bun install').pipeStdout(process.stdout); | ||
spinner.text = ''; | ||
startCommand = 'bun dev'; | ||
console.log('\n'); | ||
} else if (isYarnInstalled()) { | ||
await execaCommand('yarn').pipeStdout(process.stdout); | ||
startCommand = 'yarn dev'; | ||
} else { | ||
spinner.text = 'Installing dependencies'; | ||
await execa('npm', ['install', '--verbose']).pipeStdout(process.stdout); | ||
spinner.text = ''; | ||
startCommand = 'npm run dev'; | ||
} | ||
|
||
spinner.stop(); | ||
process.chdir('../'); | ||
log( | ||
`${green.bold('Success!')} Created ${purple.bold( | ||
appName | ||
)} at ${process.cwd()} \n` | ||
); | ||
log( | ||
`To get started, change into the new directory and run ${chalk.cyan( | ||
startCommand | ||
)}\n` | ||
); | ||
} catch (err) { | ||
log('\n'); | ||
if (err.exitCode == 128) { | ||
log('Error: directory already exists.'); | ||
} | ||
spinner.stop(); | ||
} | ||
} | ||
|
||
main(); | ||
|
||
function isYarnInstalled() { | ||
try { | ||
childProcess.execSync('yarn --version'); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
function isBunInstalled() { | ||
try { | ||
childProcess.execSync('bun --version'); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
} |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,22 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "es6", | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"node_modules/*", | ||
"src/types/*" | ||
] | ||
} | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |
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,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
] | ||
} |
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