Compare commits

..

3 Commits

Author SHA1 Message Date
04412d7cbc update checker middleware 2024-06-13 19:41:05 +01:00
9204eb81be Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	cli/src/commands/create.ts
2024-06-13 19:27:36 +01:00
1fd65c6b86 optional cli arguments against selector 2024-06-13 19:26:30 +01:00
3 changed files with 70 additions and 40 deletions

View File

@ -1,33 +1,62 @@
import type { CommandModule } from 'yargs' import type { CommandModule, Argv, ArgumentsCamelCase } from 'yargs'
import c from 'chalk' import c from 'chalk'
import { input, select } from '@inquirer/prompts' import { input, select } from '@inquirer/prompts'
import clone from 'git-clone' import clone from 'git-clone'
import path from 'node:path' import path from 'node:path'
// the handler function will be called when our command is executed import { checkForUpdate } from '../utils/update'
// it will receive the command line arguments parsed by yargs
async function handler() { function builder(yargs: Argv) {
const folder = await input({ return yargs
message: c.gray('Enter project name:'), .option('projectName', {
default: 'rage-fw', alias: 'p',
}) description: 'Name of the folder to scaffold a project to',
const framework = await select({ type: 'string',
message: c.gray('Select frontend:'), demandOption: false,
default: 'react', })
loop: true, .option('template', {
choices: [ alias: 't',
{ description: 'Frontend framework to use for CEF',
name: 'React + TypeScript (Vite)', type: 'string',
value: 'react', demandOption: false,
description: 'React + TypeScript (Vite) as a frontend', })
}, .middleware(async () => await checkForUpdate())
// { }
// name: 'vue',
// value: 'vue', async function handler(args: ArgumentsCamelCase) {
// description: 'npm is the most popular package manager', let folder = (args.projectName as string) ?? args.p
// }, let framework = (args.template as string) ?? args.t
],
}) if (!folder) {
folder = await input({
message: c.gray('Enter project name:'),
default: 'rage-fw',
})
} else {
console.log(c.gray('Project name:'), folder)
}
if (!framework) {
framework = await select({
message: c.gray('Select frontend:'),
default: 'react',
loop: true,
choices: [
{
name: 'React + TypeScript (Vite)',
value: 'react',
description: 'React + TypeScript (Vite) as a frontend',
},
// {
// name: 'vue',
// value: 'vue',
// description: 'npm is the most popular package manager',
// },
],
})
} else {
console.log(c.gray('Frontend:'), framework)
}
console.log( console.log(
c.gray('\nScaffolding template project into'), c.gray('\nScaffolding template project into'),
@ -56,11 +85,11 @@ async function handler() {
) )
} }
// name and description for our command module
const init: CommandModule = { const init: CommandModule = {
command: 'create [template]', command: 'create [folderName] [template]',
aliases: 'c', aliases: 'c',
describe: 'Scaffold a template project using RageFW', describe: 'Scaffold a template project using RageFW',
builder,
handler, handler,
} }

View File

@ -1,13 +1,11 @@
import yargs from 'yargs' import yargs from 'yargs'
import create from './commands/create' import create from './commands/create'
import { checkForUpdate } from './utils/update'
yargs.middleware(checkForUpdate)
yargs yargs
.usage('<cmd> [args]') .usage('<cmd> [args]')
// .scriptName('rage-fw') // .scriptName('rage-fw')
// .usage('$0 <cmd> [args]') // .usage('$0 <cmd> [args]')
// @ts-ignore
.command(create) .command(create)
.help().argv .help().argv

View File

@ -10,17 +10,20 @@ type Version = {
message: string message: string
} }
export async function checkForUpdate() { export async function checkForUpdate(): Promise<void> {
yargs.showVersion(version => return new Promise(res => {
axios.get<Version[]>(latestVersionURL).then(({ data }) => { yargs.showVersion(version =>
const latestVersion = data[0].name axios
.get<Version[]>(latestVersionURL)
.then(({ data }) => {
const latestVersion = data[0].name
if (!(latestVersion === version)) if (!(latestVersion === version))
notifyUserAboutUpdate(latestVersion) notifyUserAboutUpdate(latestVersion)
})
return .then(() => res()),
}), )
) })
} }
function notifyUserAboutUpdate(version: string) { function notifyUserAboutUpdate(version: string) {