Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch from wget to CURL when download template #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/cli/src/lib/dlFunctionTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { TemplateType } from '@/config/config'
import { TEMPLATE_VERSION } from '@/config/templateVersion'
import { execAsync } from '@skeet-framework/utils'
import chalk from 'chalk'
import {downloadTemplate} from '@/lib/files/downloadFiles'

export const dlFunctionTemplate = async (functionName: string) => {
const version = TEMPLATE_VERSION.BASE_FUNCTIONS
const template: TemplateType = 'base-functions'
const BASE_TEMP = `https://registry.npmjs.org/@skeet-framework/${template}/-/${template}-${version}.tgz`
const fileName = `${template}-${version}.tgz`
const cmd = `wget ${BASE_TEMP}`
const functionPath = `functions/${functionName}-func`
console.log(chalk.blue('🕰️ Downloading function template...'))
await execAsync(cmd)
if (!(await downloadTemplate(template, version))) {
console.log(chalk.yellow(`⚠️ Fail when download template`))
return false
}
const functionPath = `functions/${functionName}-func`
const fileName = `${template}-${version}.tgz`
await execAsync(`tar -xvzf ${fileName} -C ${functionPath}`)
await execAsync(
`find ${functionPath}/package -mindepth 1 -maxdepth 1 -exec mv {} ${functionPath}/ \\;`,
Expand Down
12 changes: 8 additions & 4 deletions packages/cli/src/lib/dlSQLTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { TEMPLATE_VERSION } from '@/config/templateVersion'
import { execAsync } from '@skeet-framework/utils'
import chalk from 'chalk'
import {downloadTemplate} from '@/lib/files/downloadFiles'

export const dlSQLTemplate = async (sqlName: string) => {
const version = TEMPLATE_VERSION.BASE_SQL
const template = 'base-sql'
const BASE_TEMP = `https://registry.npmjs.org/@skeet-framework/${template}/-/${template}-${version}.tgz`

console.log(chalk.blue('🕰️ Downloading SQL Template...'))
if (await downloadTemplate(template, version)) {
console.log(chalk.yellow(`⚠️ Fail when download template`))
return false
}

const fileName = `${template}-${version}.tgz`
const cmd = `wget ${BASE_TEMP}`
const fileDir = `sql/${sqlName}`
console.log(chalk.blue('🕰️ Downloading SQL Template...'))
await execAsync(cmd)
await execAsync(`tar -xvzf ${fileName} -C ${fileDir}`)
await execAsync(
`find ${fileDir}/package -mindepth 1 -maxdepth 1 -exec mv {} ${fileDir}/ \\;`,
Expand Down
12 changes: 8 additions & 4 deletions packages/cli/src/lib/dlSkeetFunctionTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { TEMPLATE_VERSION } from '@/config/templateVersion'
import { execAsync, existsAsync } from '@skeet-framework/utils'
import chalk from 'chalk'
import { mkdir } from 'fs/promises'
import { downloadTemplate } from '@/lib/files/downloadFiles'

export const dlSkeetFunctionTemplate = async (appName: string) => {
const version = TEMPLATE_VERSION.SKEET_FUNC
const template: TemplateType = 'skeet-func-template'
const BASE_TEMP = `https://registry.npmjs.org/@skeet-framework/${template}/-/${template}-${version}.tgz`
const fileName = `${template}-${version}.tgz`
const cmd = `wget ${BASE_TEMP}`
await execAsync(cmd)

if (!(await downloadTemplate(template, version))) {
console.log(chalk.yellow(`⚠️ Fail when download template`))
return false
}

if (await existsAsync(appName)) {
console.log(chalk.yellow('⚠️ Folder already exists'))
return false
}
await mkdir(appName)
const fileName = `${template}-${version}.tgz`
await execAsync(`tar -xvzf ${fileName} -C ${appName}`)
await execAsync(
`find ${appName}/package -mindepth 1 -maxdepth 1 -exec mv {} ${appName}/ \\;`,
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/lib/files/downloadFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {execAsync} from '@skeet-framework/utils'

export const downloadTemplate = async (
template: string,
version: string,
): Promise<boolean> => {
const fileName = `${template}-${version}.tgz`
const fileUrl = `https://registry.npmjs.org/@skeet-framework/${template}/-/${fileName}`
const cmd = `curl ${fileUrl} -o ${fileName} --fail --silent --show-error `
const downloadTemplate = await execAsync(cmd)
if (downloadTemplate.stderr) {
console.error('Error downloading file:', downloadTemplate.stderr)
return false
}
return true
}