rn-ai 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +211 -0
- package/package.json +16 -7
package/cli.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import { Command } from 'commander'
|
|
7
|
+
import select from '@inquirer/select'
|
|
8
|
+
import { input } from '@inquirer/prompts';
|
|
9
|
+
import {execa, execaCommand} from 'execa'
|
|
10
|
+
import ora from 'ora'
|
|
11
|
+
import childProcess from 'child_process'
|
|
12
|
+
|
|
13
|
+
const log = console.log
|
|
14
|
+
const program = new Command()
|
|
15
|
+
const green = chalk.green
|
|
16
|
+
|
|
17
|
+
const repoUrl = 'git@github.com:dabit3/react-native-ai.git'
|
|
18
|
+
|
|
19
|
+
const isYarnInstalled = () => {
|
|
20
|
+
try {
|
|
21
|
+
childProcess.execSync('yarn --version');
|
|
22
|
+
return true;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isBunInstalled = () => {
|
|
29
|
+
try {
|
|
30
|
+
childProcess.execSync('bun --version')
|
|
31
|
+
return true;
|
|
32
|
+
} catch(err) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function main() {
|
|
38
|
+
const spinner = ora({
|
|
39
|
+
text: 'Creating codebase'
|
|
40
|
+
})
|
|
41
|
+
try {
|
|
42
|
+
const kebabRegez = /^([a-z]+)(-[a-z0-9]+)*$/
|
|
43
|
+
|
|
44
|
+
program
|
|
45
|
+
.name('React Native AI')
|
|
46
|
+
.description('Full Stack React Native Boilerplate for building streaming AI apps.')
|
|
47
|
+
|
|
48
|
+
program.parse(process.argv)
|
|
49
|
+
|
|
50
|
+
const args = program.args
|
|
51
|
+
let appName = args[0]
|
|
52
|
+
|
|
53
|
+
if (!appName || !kebabRegez.test(args[0])) {
|
|
54
|
+
appName = await input({
|
|
55
|
+
message: 'Enter your app name',
|
|
56
|
+
default: 'rn-ai',
|
|
57
|
+
validate: d => {
|
|
58
|
+
if(!kebabRegez.test(d)) {
|
|
59
|
+
return 'please enter your app name in the format of my-app-name'
|
|
60
|
+
}
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const withEnv = await select({
|
|
67
|
+
message: 'Configure environment variables?',
|
|
68
|
+
choices: [
|
|
69
|
+
{
|
|
70
|
+
name: 'Yes',
|
|
71
|
+
value: 'yes',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'No',
|
|
75
|
+
value: 'no',
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
let envs = `
|
|
81
|
+
# environment, either PRODUCTION or DEVELOPMENT
|
|
82
|
+
ENVIRONMENT="PRODUCTION"
|
|
83
|
+
|
|
84
|
+
# ByteScale
|
|
85
|
+
BYTESCALE_API_KEY=""
|
|
86
|
+
|
|
87
|
+
# OpenAI
|
|
88
|
+
OPENAI_API_KEY=""
|
|
89
|
+
|
|
90
|
+
# Anthropic
|
|
91
|
+
ANTHROPIC_API_KEY=""
|
|
92
|
+
|
|
93
|
+
# Cohere
|
|
94
|
+
COHERE_API_KEY=""
|
|
95
|
+
|
|
96
|
+
# FAL
|
|
97
|
+
FAL_API_KEY=""
|
|
98
|
+
`
|
|
99
|
+
|
|
100
|
+
if (withEnv === 'yes') {
|
|
101
|
+
console.log('Get OpenAI API Key at https://platform.openai.com/')
|
|
102
|
+
const openai_api_key = await input({ message: "OpenAI API Key" })
|
|
103
|
+
|
|
104
|
+
console.log('Get Fal API Key at https://www.fal.ai/')
|
|
105
|
+
const fal_api_key = await input({ message: "Fal API Key" })
|
|
106
|
+
|
|
107
|
+
console.log('Get Anthropic API Key at https://console.anthropic.com/')
|
|
108
|
+
const anthropic_api_key = await input({ message: "Anthropic API Key" })
|
|
109
|
+
|
|
110
|
+
console.log('Get Cohere API Key at https://cohere.com/')
|
|
111
|
+
const cohere_api_key = await input({ message: "Cohere API Key" })
|
|
112
|
+
|
|
113
|
+
console.log('Get Bytescale API Key at https://bytescale.com/')
|
|
114
|
+
const bytescale_api_key = await input({ message: "Bytescale API Key" })
|
|
115
|
+
|
|
116
|
+
envs = `
|
|
117
|
+
# environment, either PRODUCTION or DEVELOPMENT
|
|
118
|
+
ENVIRONMENT="PRODUCTION"
|
|
119
|
+
|
|
120
|
+
# ByteScale
|
|
121
|
+
BYTESCALE_API_KEY="${bytescale_api_key}"
|
|
122
|
+
|
|
123
|
+
# OpenAI
|
|
124
|
+
OPENAI_API_KEY="${openai_api_key}"
|
|
125
|
+
|
|
126
|
+
# Anthropic
|
|
127
|
+
ANTHROPIC_API_KEY="${anthropic_api_key}"
|
|
128
|
+
|
|
129
|
+
# Cohere
|
|
130
|
+
COHERE_API_KEY="${cohere_api_key}"
|
|
131
|
+
|
|
132
|
+
# FAL
|
|
133
|
+
FAL_API_KEY="${fal_api_key}"
|
|
134
|
+
`
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
log(`\nInitializing project. \n`)
|
|
138
|
+
|
|
139
|
+
spinner.start()
|
|
140
|
+
await execa('git', ['clone', repoUrl, appName])
|
|
141
|
+
await execa('rm', ['-rf', `${appName}/cli`])
|
|
142
|
+
|
|
143
|
+
let packageJson = fs.readFileSync(`${appName}/server/package.json`, 'utf8')
|
|
144
|
+
const packageObj = JSON.parse(packageJson)
|
|
145
|
+
packageObj.name = appName
|
|
146
|
+
packageJson = JSON.stringify(packageObj, null, 2)
|
|
147
|
+
fs.writeFileSync(`${appName}/server/package.json`, packageJson)
|
|
148
|
+
|
|
149
|
+
let packageJson2 = fs.readFileSync(`${appName}/app/package.json`, 'utf8')
|
|
150
|
+
const packageObj2 = JSON.parse(packageJson)
|
|
151
|
+
packageObj.name = appName
|
|
152
|
+
packageJson = JSON.stringify(packageObj2, null, 2)
|
|
153
|
+
fs.writeFileSync(`${appName}/app/package.json`, packageJson2)
|
|
154
|
+
fs.writeFileSync(`${appName}/server/.env`, envs)
|
|
155
|
+
|
|
156
|
+
process.chdir(path.join(process.cwd(), `${appName}/server`))
|
|
157
|
+
spinner.text = ''
|
|
158
|
+
let startCommand = ''
|
|
159
|
+
|
|
160
|
+
if (isBunInstalled()) {
|
|
161
|
+
spinner.text = 'Installing server dependencies'
|
|
162
|
+
await execaCommand('bun install').pipeStdout(process.stdout)
|
|
163
|
+
spinner.text = ''
|
|
164
|
+
startCommand = 'bun dev'
|
|
165
|
+
console.log('\n')
|
|
166
|
+
} else if (isYarnInstalled()) {
|
|
167
|
+
await execaCommand('yarn').pipeStdout(process.stdout)
|
|
168
|
+
startCommand = 'yarn dev'
|
|
169
|
+
} else {
|
|
170
|
+
spinner.text = 'Installing server dependencies'
|
|
171
|
+
await execa('npm', ['install', '--verbose']).pipeStdout(process.stdout)
|
|
172
|
+
spinner.text = ''
|
|
173
|
+
startCommand = 'npm run dev'
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
process.chdir('../')
|
|
177
|
+
process.chdir(path.join(process.cwd(), `app`))
|
|
178
|
+
|
|
179
|
+
console.log('cwd:', process.cwd())
|
|
180
|
+
|
|
181
|
+
spinner.text = ''
|
|
182
|
+
startCommand = ''
|
|
183
|
+
|
|
184
|
+
if (isBunInstalled()) {
|
|
185
|
+
spinner.text = 'Installing app dependencies'
|
|
186
|
+
await execaCommand('bun install').pipeStdout(process.stdout)
|
|
187
|
+
spinner.text = ''
|
|
188
|
+
startCommand = 'bun dev'
|
|
189
|
+
console.log('\n')
|
|
190
|
+
} else if (isYarnInstalled()) {
|
|
191
|
+
await execaCommand('yarn').pipeStdout(process.stdout)
|
|
192
|
+
startCommand = 'yarn dev'
|
|
193
|
+
} else {
|
|
194
|
+
spinner.text = 'Installing app dependencies'
|
|
195
|
+
await execa('npm', ['install', '--verbose']).pipeStdout(process.stdout)
|
|
196
|
+
spinner.text = ''
|
|
197
|
+
startCommand = 'npm run dev'
|
|
198
|
+
}
|
|
199
|
+
spinner.stop()
|
|
200
|
+
log(`${green.bold('Success!')} Created ${appName} at ${process.cwd()} \n`)
|
|
201
|
+
log(`To get started, change into the new directory and run ${chalk.cyan(startCommand)}`)
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.log('eror:', err)
|
|
204
|
+
log('\n')
|
|
205
|
+
if (err.exitCode == 128) {
|
|
206
|
+
log('Error: directory already exists.')
|
|
207
|
+
}
|
|
208
|
+
spinner.stop()
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
main()
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-ai",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Create a social app with a single command.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": "cli.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
9
|
},
|
|
9
|
-
"keywords": [],
|
|
10
|
-
"author": "",
|
|
11
|
-
"license": "ISC"
|
|
12
|
-
|
|
10
|
+
"keywords": ["Lens Protocol"],
|
|
11
|
+
"author": "Nader Dabit",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@inquirer/prompts": "^3.1.1",
|
|
15
|
+
"chalk": "^5.3.0",
|
|
16
|
+
"cli-spinners": "^2.9.0",
|
|
17
|
+
"commander": "^11.0.0",
|
|
18
|
+
"execa": "^8.0.1",
|
|
19
|
+
"ora": "^7.0.1"
|
|
20
|
+
}
|
|
21
|
+
}
|