upd cli
- added rpc tests - removed git clone
This commit is contained in:
+12
-18
@@ -1,7 +1,7 @@
|
||||
import c from 'chalk'
|
||||
import { input, select } from '@inquirer/prompts'
|
||||
import clone from 'git-clone'
|
||||
import path from 'node:path'
|
||||
import { cloneBranch } from '../utils/cloner'
|
||||
|
||||
export async function initProject() {
|
||||
let folder
|
||||
@@ -10,7 +10,7 @@ export async function initProject() {
|
||||
if (!folder) {
|
||||
folder = await input({
|
||||
message: c.gray('Enter project name:'),
|
||||
default: 'rage-fw',
|
||||
default: 'rage-fw-example',
|
||||
})
|
||||
} else {
|
||||
console.log(c.gray('Project name:'), folder)
|
||||
@@ -19,19 +19,14 @@ export async function initProject() {
|
||||
if (!framework) {
|
||||
framework = await select({
|
||||
message: c.gray('Select frontend:'),
|
||||
default: 'react',
|
||||
default: 'react-18',
|
||||
loop: true,
|
||||
choices: [
|
||||
{
|
||||
name: 'React + TypeScript (Vite)',
|
||||
value: 'react',
|
||||
value: 'react-18',
|
||||
description: 'React + TypeScript (Vite) as a frontend',
|
||||
},
|
||||
// {
|
||||
// name: 'vue',
|
||||
// value: 'vue',
|
||||
// description: 'npm is the most popular package manager',
|
||||
// },
|
||||
],
|
||||
})
|
||||
} else {
|
||||
@@ -46,21 +41,20 @@ export async function initProject() {
|
||||
c.gray('as a frontend..'),
|
||||
)
|
||||
|
||||
clone(
|
||||
cloneBranch(
|
||||
'https://git.entityseven.com/entityseven/rage-framework-example',
|
||||
path.join(process.cwd(), folder),
|
||||
{},
|
||||
err => {
|
||||
if (err) {
|
||||
console.log(c.red('Error occured: \n', err))
|
||||
return
|
||||
}
|
||||
framework,
|
||||
)
|
||||
.then(() => {
|
||||
console.log(c.gray('Scaffolded project into'), folder)
|
||||
console.log(
|
||||
c.gray(
|
||||
`Project was created ar dir: ${path.join(process.cwd(), folder)}`,
|
||||
),
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(c.red('Error occured: \n', e))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import axios from 'axios'
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
const latestReleases =
|
||||
@@ -13,25 +12,33 @@ type Asset = {
|
||||
}
|
||||
|
||||
export async function downloadUpdater(): Promise<void> {
|
||||
const ky = await import('ky').then(ky => ky.default)
|
||||
const id = await getLatestReleaseID()
|
||||
|
||||
const latestAssets = `https://git.entityseven.com/api/v1/repos/entityseven/rage-server-downloader/releases/${id}/assets?page=1&limit=1`
|
||||
|
||||
axios.get<Asset[]>(latestAssets).then(async ({ data }) => {
|
||||
const downloadURL = data[0].browser_download_url
|
||||
ky.get<Asset[]>(latestAssets)
|
||||
.then(response => response.json())
|
||||
.then(async data => {
|
||||
const downloadURL = data[0].browser_download_url
|
||||
|
||||
const file = await axios.get(data[0].browser_download_url, {
|
||||
responseType: 'arraybuffer',
|
||||
const file = await ky.get(data[0].browser_download_url)
|
||||
const fileData = Buffer.from(
|
||||
file as unknown as WithImplicitCoercion<string>,
|
||||
'binary',
|
||||
)
|
||||
|
||||
const fileSplit = downloadURL.split('/')
|
||||
const fileName = fileSplit[fileSplit.length - 1]
|
||||
|
||||
fs.writeFileSync(`./${fileName}`, fileData)
|
||||
})
|
||||
const fileData = Buffer.from(file.data, 'binary')
|
||||
|
||||
const fileSplit = downloadURL.split('/')
|
||||
const fileName = fileSplit[fileSplit.length - 1]
|
||||
|
||||
fs.writeFileSync(`./${fileName}`, fileData)
|
||||
})
|
||||
}
|
||||
|
||||
async function getLatestReleaseID() {
|
||||
return axios.get<Release[]>(latestReleases).then(({ data }) => data[0].id)
|
||||
const ky = await import('ky').then(ky => ky.default)
|
||||
return ky
|
||||
.get<Release[]>(latestReleases)
|
||||
.then(response => response.json())
|
||||
.then(data => data[0].id)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import c from 'chalk'
|
||||
import { input, select } from '@inquirer/prompts'
|
||||
import path from 'node:path'
|
||||
import { cloneBranch } from '../utils/cloner'
|
||||
|
||||
const choices = {
|
||||
'rpc-react-18': {
|
||||
name: 'Vite + React 18 + TypeScript',
|
||||
value: 'rpc-react-18',
|
||||
description: 'Vite + React 18 + TypeScript as a frontend',
|
||||
},
|
||||
'rpc-svelte-5': {
|
||||
name: 'Vite + Svelte 5 + TypeScript',
|
||||
value: 'rpc-svelte-5',
|
||||
description: 'Vite + Svelte 5 + TypeScript as a frontend',
|
||||
},
|
||||
} as const
|
||||
|
||||
export async function testRpc() {
|
||||
let folder
|
||||
let framework
|
||||
|
||||
if (!folder) {
|
||||
folder = await input({
|
||||
message: c.gray('Enter project name:'),
|
||||
default: 'rage-fw-rpc-example',
|
||||
})
|
||||
} else {
|
||||
console.log(c.gray('Project name:'), folder)
|
||||
}
|
||||
|
||||
if (!framework) {
|
||||
framework = await select({
|
||||
message: c.gray('Select frontend:'),
|
||||
default: 'rpc-react-18',
|
||||
loop: true,
|
||||
choices: Object.values(choices),
|
||||
})
|
||||
} else {
|
||||
console.log(c.gray('Frontend:'), framework)
|
||||
}
|
||||
|
||||
console.log(
|
||||
c.gray('\nScaffolding template project into'),
|
||||
folder,
|
||||
c.gray('with'),
|
||||
choices[framework].name,
|
||||
c.gray('as a frontend..'),
|
||||
)
|
||||
|
||||
cloneBranch(
|
||||
'https://git.entityseven.com/entityseven/rage-framework-example',
|
||||
path.join(process.cwd(), folder),
|
||||
framework,
|
||||
)
|
||||
.then(() => {
|
||||
console.log(c.gray('Scaffolded project into'), folder)
|
||||
console.log(
|
||||
c.gray(
|
||||
`Project was created at dir: ${path.join(process.cwd(), folder)}`,
|
||||
),
|
||||
)
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(c.red('Error occured: \n', e))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user